clif.cpp 670 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281
  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. }
  1508. break;
  1509. case BL_NPC:
  1510. {
  1511. TBL_NPC *nd = ((TBL_NPC*)bl);
  1512. if( nd->size == SZ_BIG )
  1513. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1514. else if( nd->size == SZ_MEDIUM )
  1515. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1516. clif_efst_status_change_sub(bl, bl, AREA);
  1517. clif_progressbar_npc_area(nd);
  1518. }
  1519. break;
  1520. case BL_PET:
  1521. if (vd->head_bottom)
  1522. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1523. break;
  1524. }
  1525. return 0;
  1526. }
  1527. /// Sends information about owned homunculus to the client . [orn]
  1528. /// 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)
  1529. /// 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)
  1530. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1531. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1532. nullpo_retv( sd );
  1533. nullpo_retv( hd );
  1534. struct status_data *status = &hd->battle_status;
  1535. struct PACKET_ZC_PROPERTY_HOMUN p;
  1536. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1537. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1538. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1539. 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 );
  1540. p.level = hd->homunculus.level;
  1541. p.hunger = hd->homunculus.hunger;
  1542. p.intimacy = hd->homunculus.intimacy / 100;
  1543. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1544. p.itemId = 0; // equip id
  1545. #endif
  1546. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1547. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1548. p.hit = status->hit;
  1549. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1550. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1551. }else{
  1552. p.crit = status->cri / 10;
  1553. }
  1554. #ifdef RENEWAL
  1555. p.def = status->def + status->def2;
  1556. p.mdef = status->mdef + status->mdef2;
  1557. #else
  1558. p.def = status->def + status->vit;
  1559. p.mdef = status->mdef;
  1560. #endif
  1561. p.flee = status->flee;
  1562. p.amotion = (flag) ? 0 : status->amotion;
  1563. #if PACKETVER >= 20141016
  1564. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1565. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1566. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1567. p.hp = status->hp / ( status->max_hp / 100 );
  1568. p.maxHp = 100;
  1569. }else{
  1570. p.hp = status->hp;
  1571. p.maxHp = status->max_hp;
  1572. }
  1573. #else
  1574. if( status->max_hp > INT16_MAX ){
  1575. p.hp = status->hp / ( status->max_hp / 100 );
  1576. p.maxHp = 100;
  1577. }else{
  1578. p.hp = status->hp;
  1579. p.maxHp = status->max_hp;
  1580. }
  1581. #endif
  1582. if( status->max_sp > INT16_MAX ){
  1583. p.sp = status->sp / ( status->max_sp / 100 );
  1584. p.maxSp = 100;
  1585. }else{
  1586. p.sp = status->sp;
  1587. p.maxSp = status->max_sp;
  1588. }
  1589. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1590. p.exp = hd->homunculus.exp;
  1591. p.expNext = hd->exp_next;
  1592. #else
  1593. p.exp = (uint32)hd->homunculus.exp;
  1594. p.expNext = (uint32)hd->exp_next;
  1595. #endif
  1596. switch( hom_class2type( hd->homunculus.class_ ) ){
  1597. case HT_REG:
  1598. case HT_EVO:
  1599. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1600. p.expNext = 0;
  1601. }
  1602. break;
  1603. case HT_S:
  1604. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1605. p.expNext = 0;
  1606. }
  1607. break;
  1608. }
  1609. p.skillPoints = hd->homunculus.skillpts;
  1610. p.range = status_get_range( &hd->bl );
  1611. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1612. #endif
  1613. }
  1614. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1615. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1616. /// type:
  1617. /// unused
  1618. /// state:
  1619. /// 0 = pre-init
  1620. /// 1 = intimacy
  1621. /// 2 = hunger
  1622. /// 3 = accessory?
  1623. /// ? = ignored
  1624. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1625. { //[orn]
  1626. int fd = sd->fd;
  1627. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1628. hom_calc_skilltree(sd->hd, 0);
  1629. WFIFOHEAD(fd, packet_len(0x230));
  1630. WFIFOW(fd,0)=0x230;
  1631. WFIFOB(fd,2)=0;
  1632. WFIFOB(fd,3)=state;
  1633. WFIFOL(fd,4)=sd->hd->bl.id;
  1634. WFIFOL(fd,8)=param;
  1635. WFIFOSET(fd,packet_len(0x230));
  1636. }
  1637. int clif_homskillinfoblock(struct map_session_data *sd)
  1638. { //[orn]
  1639. struct homun_data *hd;
  1640. int fd = sd->fd;
  1641. int i, len=4;
  1642. nullpo_ret(sd);
  1643. hd = sd->hd;
  1644. if ( !hd )
  1645. return 0 ;
  1646. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1647. WFIFOW(fd,0)=0x235;
  1648. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1649. int id = hd->homunculus.hskill[i].id;
  1650. if( id != 0 ){
  1651. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1652. short idx = hom_skill_get_index(id);
  1653. if (idx == -1)
  1654. continue;
  1655. WFIFOW(fd,len ) = id;
  1656. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1657. WFIFOW(fd,len+4) = 0;
  1658. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1659. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1660. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1661. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1662. 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;
  1663. len+=37;
  1664. }
  1665. }
  1666. WFIFOW(fd,2)=len;
  1667. WFIFOSET(fd,len);
  1668. return 0;
  1669. }
  1670. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1671. { //[orn]
  1672. struct homun_data *hd;
  1673. int fd;
  1674. short idx = -1;
  1675. nullpo_retv(sd);
  1676. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1677. return;
  1678. fd = sd->fd;
  1679. hd = sd->hd;
  1680. WFIFOHEAD(fd, packet_len(0x239));
  1681. WFIFOW(fd,0) = 0x239;
  1682. WFIFOW(fd,2) = skill_id;
  1683. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1684. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1685. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1686. 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;
  1687. WFIFOSET(fd,packet_len(0x239));
  1688. }
  1689. /// Result of request to feed a homun/merc.
  1690. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1691. /// result:
  1692. /// 0 = failure
  1693. /// 1 = success
  1694. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1695. nullpo_retv( sd );
  1696. struct PACKET_ZC_FEED_MER p;
  1697. p.packetType = 0x22f;
  1698. p.result = fail;
  1699. p.itemId = client_nameid( foodid );
  1700. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1701. }
  1702. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1703. /// 0087 <walk start time>.L <walk data>.6B
  1704. void clif_walkok(struct map_session_data *sd)
  1705. {
  1706. int fd=sd->fd;
  1707. WFIFOHEAD(fd, packet_len(0x87));
  1708. WFIFOW(fd,0)=0x87;
  1709. WFIFOL(fd,2)=client_tick(gettick());
  1710. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1711. WFIFOSET(fd,packet_len(0x87));
  1712. }
  1713. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1714. struct status_change *sc = NULL;
  1715. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1716. clif_ally_only = true;
  1717. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1718. if(vd->cloth_color)
  1719. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1720. if(vd->body_style)
  1721. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1722. switch(bl->type) {
  1723. case BL_PC:
  1724. {
  1725. TBL_PC *sd = ((TBL_PC*)bl);
  1726. // clif_movepc(sd);
  1727. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1728. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1729. else if(sd->state.size==SZ_MEDIUM)
  1730. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1731. if (sd->status.robe)
  1732. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1733. }
  1734. break;
  1735. case BL_MOB:
  1736. {
  1737. TBL_MOB *md = ((TBL_MOB*)bl);
  1738. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1739. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1740. else if(md->special_state.size==SZ_MEDIUM)
  1741. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1742. }
  1743. break;
  1744. case BL_PET:
  1745. if(vd->head_bottom) // needed to display pet equip properly
  1746. clif_pet_equip_area((TBL_PET*)bl);
  1747. break;
  1748. }
  1749. clif_ally_only = false;
  1750. }
  1751. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1752. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1753. /// Note: unit must not be self
  1754. void clif_move(struct unit_data *ud)
  1755. {
  1756. unsigned char buf[16];
  1757. struct view_data* vd;
  1758. struct block_list* bl = ud->bl;
  1759. struct status_change *sc = NULL;
  1760. vd = status_get_viewdata(bl);
  1761. if (!vd )
  1762. return;
  1763. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1764. else if( vd->class_ == JT_INVISIBLE ){
  1765. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1766. if(disguised(bl)) {
  1767. WBUFW(buf,0)=0x86;
  1768. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1769. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1770. WBUFL(buf,12)=client_tick(gettick());
  1771. clif_send(buf, packet_len(0x86), bl, SELF);
  1772. }
  1773. return;
  1774. }
  1775. // Hide NPC from Maya Purple card
  1776. if (clif_npc_mayapurple(bl))
  1777. return;
  1778. if (ud->state.speed_changed) {
  1779. // Since we don't know how to update the speed of other objects,
  1780. // use the old walk packet to update the data.
  1781. ud->state.speed_changed = 0;
  1782. clif_move2(bl, vd, ud);
  1783. return;
  1784. }
  1785. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1786. clif_ally_only = true;
  1787. WBUFW(buf,0)=0x86;
  1788. WBUFL(buf,2)=bl->id;
  1789. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1790. WBUFL(buf,12)=client_tick(gettick());
  1791. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1792. if (disguised(bl)) {
  1793. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1794. clif_send(buf, packet_len(0x86), bl, SELF);
  1795. }
  1796. clif_ally_only = false;
  1797. }
  1798. /*==========================================
  1799. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1800. *------------------------------------------*/
  1801. static TIMER_FUNC(clif_delayquit){
  1802. struct map_session_data *sd = NULL;
  1803. //Remove player from map server
  1804. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1805. map_quit(sd);
  1806. return 0;
  1807. }
  1808. /*==========================================
  1809. *
  1810. *------------------------------------------*/
  1811. void clif_quitsave(int fd,struct map_session_data *sd) {
  1812. if (!battle_config.prevent_logout ||
  1813. sd->canlog_tick == 0 ||
  1814. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1815. map_quit(sd);
  1816. else if (session_isValid(sd->fd)) {
  1817. //Disassociate session from player (session is deleted after this function was called)
  1818. //And set a timer to make him quit later.
  1819. session[sd->fd]->session_data = NULL;
  1820. sd->fd = 0;
  1821. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1822. }
  1823. }
  1824. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1825. /// 0091 <map name>.16B <x>.W <y>.W
  1826. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1827. {
  1828. nullpo_retv(sd);
  1829. int fd = sd->fd;
  1830. WFIFOHEAD(fd,packet_len(0x91));
  1831. WFIFOW(fd,0) = 0x91;
  1832. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1833. WFIFOW(fd,18) = x;
  1834. WFIFOW(fd,20) = y;
  1835. WFIFOSET(fd,packet_len(0x91));
  1836. }
  1837. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1838. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1839. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1840. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1841. {
  1842. int fd;
  1843. #if PACKETVER >= 20170315
  1844. int cmd = 0xac7;
  1845. #else
  1846. int cmd = 0x92;
  1847. #endif
  1848. nullpo_retv(sd);
  1849. fd = sd->fd;
  1850. WFIFOHEAD(fd,packet_len(cmd));
  1851. WFIFOW(fd,0) = cmd;
  1852. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1853. WFIFOW(fd,18) = x;
  1854. WFIFOW(fd,20) = y;
  1855. WFIFOL(fd,22) = htonl(ip);
  1856. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1857. #if PACKETVER >= 20170315
  1858. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1859. #endif
  1860. WFIFOSET(fd,packet_len(cmd));
  1861. }
  1862. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1863. /// This function combines both calls and allows to simplify the calling code
  1864. void clif_blown(struct block_list *bl)
  1865. {
  1866. clif_slide(bl, bl->x, bl->y);
  1867. clif_fixpos(bl);
  1868. }
  1869. /// Visually moves(slides) a character to x,y. If the target cell
  1870. /// isn't walkable, the char doesn't move at all. If the char is
  1871. /// sitting it will stand up (ZC_STOPMOVE).
  1872. /// 0088 <id>.L <x>.W <y>.W
  1873. void clif_fixpos(struct block_list *bl)
  1874. {
  1875. unsigned char buf[10];
  1876. nullpo_retv(bl);
  1877. WBUFW(buf,0) = 0x88;
  1878. WBUFL(buf,2) = bl->id;
  1879. WBUFW(buf,6) = bl->x;
  1880. WBUFW(buf,8) = bl->y;
  1881. clif_send(buf, packet_len(0x88), bl, AREA);
  1882. if( disguised(bl) ) {
  1883. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1884. clif_send(buf, packet_len(0x88), bl, SELF);
  1885. }
  1886. }
  1887. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1888. /// 00c4 <shop id>.L
  1889. void clif_npcbuysell(struct map_session_data* sd, int id)
  1890. {
  1891. int fd;
  1892. nullpo_retv(sd);
  1893. fd=sd->fd;
  1894. WFIFOHEAD(fd, packet_len(0xc4));
  1895. WFIFOW(fd,0)=0xc4;
  1896. WFIFOL(fd,2)=id;
  1897. WFIFOSET(fd,packet_len(0xc4));
  1898. }
  1899. /// Presents list of items, that can be bought in an NPC shop.
  1900. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1901. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1902. nullpo_retv( sd );
  1903. nullpo_retv( nd );
  1904. int fd = sd->fd;
  1905. if( !session_isActive( fd ) ){
  1906. return;
  1907. }
  1908. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1909. WFIFOHEAD( fd, len );
  1910. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1911. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1912. int count = 0;
  1913. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1914. int val = nd->u.shop.shop_item[i].value;
  1915. p->items[count].price = val;
  1916. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1917. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1918. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1919. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1920. struct item_data* id = itemdb_exists( nd->u.shop.shop_item[i].nameid );
  1921. p->items[count].viewSprite = id->look;
  1922. p->items[count].location = pc_equippoint_sub( sd, id );
  1923. #endif
  1924. count++;
  1925. }
  1926. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1927. WFIFOSET( fd, p->packetLength );
  1928. }
  1929. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1930. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1931. void clif_selllist(struct map_session_data *sd)
  1932. {
  1933. int fd,i,c=0,val;
  1934. struct npc_data *nd;
  1935. nullpo_retv(sd);
  1936. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1937. return;
  1938. fd=sd->fd;
  1939. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1940. WFIFOW(fd,0)=0xc7;
  1941. for( i = 0; i < MAX_INVENTORY; i++ )
  1942. {
  1943. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1944. {
  1945. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1946. continue;
  1947. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1948. val = 0;
  1949. else {
  1950. val = sd->inventory_data[i]->value_sell;
  1951. if( val < 0 )
  1952. continue;
  1953. }
  1954. WFIFOW(fd,4+c*10)=i+2;
  1955. WFIFOL(fd,6+c*10)=val;
  1956. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1957. c++;
  1958. }
  1959. }
  1960. WFIFOW(fd,2)=c*10+4;
  1961. WFIFOSET(fd,WFIFOW(fd,2));
  1962. }
  1963. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1964. /// 09d4
  1965. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1966. // TODO: State tracking?
  1967. sd->npc_shopid = 0;
  1968. }
  1969. /**
  1970. * Presents list of items, that can be sold to a Market shop.
  1971. * @author: Ind and Yommy
  1972. **/
  1973. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1974. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1975. #if PACKETVER >= 20131223
  1976. nullpo_retv( sd );
  1977. nullpo_retv( nd );
  1978. if( sd->state.trading ){
  1979. return;
  1980. }
  1981. int fd = sd->fd;
  1982. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1983. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1984. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1985. int count = 0;
  1986. for( int i = 0; i < nd->u.shop.count; i++ ){
  1987. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1988. if( !item->nameid ){
  1989. continue;
  1990. }
  1991. struct item_data *id = itemdb_exists( item->nameid );
  1992. if( !id ){
  1993. continue;
  1994. }
  1995. // Out of stock
  1996. if( item->qty == 0 ){
  1997. continue;
  1998. }
  1999. p->list[count].nameid = client_nameid( item->nameid );
  2000. p->list[count].type = itemtype( item->nameid );
  2001. p->list[count].price = item->value;
  2002. p->list[count].qty = item->qty;
  2003. p->list[count].weight = id->weight;
  2004. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2005. p->list[count].location = pc_equippoint_sub( sd, id );
  2006. #endif
  2007. count++;
  2008. }
  2009. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2010. WFIFOSET( fd, p->packetLength );
  2011. sd->state.trading = 1;
  2012. #endif
  2013. }
  2014. /// Closes the Market shop window.
  2015. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  2016. nullpo_retv(sd);
  2017. sd->npc_shopid = 0;
  2018. sd->state.trading = 0;
  2019. }
  2020. /// Purchase item from Market shop.
  2021. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2022. void clif_npc_market_purchase_ack( struct map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2023. #if PACKETVER >= 20131223
  2024. nullpo_retv( sd );
  2025. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2026. nullpo_retv( nd );
  2027. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2028. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2029. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2030. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2031. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2032. #else
  2033. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2034. #endif
  2035. if( p->result ){
  2036. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2037. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2038. // Not found
  2039. if( j == nd->u.shop.count ){
  2040. continue;
  2041. }
  2042. p->list[count].ITID = client_nameid( list[i].nameid );
  2043. p->list[count].qty = list[i].qty;
  2044. p->list[count].price = nd->u.shop.shop_item[j].value;
  2045. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2046. count++;
  2047. }
  2048. }
  2049. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2050. #endif
  2051. }
  2052. /// Purchase item from Market shop.
  2053. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2054. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  2055. #if PACKETVER >= 20131223
  2056. nullpo_retv( sd );
  2057. if( !sd->npc_shopid ){
  2058. return;
  2059. }
  2060. const struct packet_npc_market_purchase *p = (struct packet_npc_market_purchase *)RFIFOP( fd, 0 );
  2061. int count = ( p->PacketLength - sizeof( struct packet_npc_market_purchase ) ) / sizeof( struct packet_npc_market_purchase_sub );
  2062. std::vector<s_npc_buy_list> items;
  2063. items.reserve( count );
  2064. for( int i = 0; i < count; i++ ){
  2065. s_npc_buy_list item = {};
  2066. item.nameid = p->list[i].ITID;
  2067. item.qty = p->list[i].qty;
  2068. items.push_back( item );
  2069. }
  2070. e_purchase_result res = npc_buylist( sd, items );
  2071. clif_npc_market_purchase_ack( sd, res, items );
  2072. #endif
  2073. }
  2074. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2075. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2076. /// Client behavior (dialog window):
  2077. /// - disable mouse targeting
  2078. /// - open the dialog window
  2079. /// - set npcid of dialog window (0 by default)
  2080. /// - if set to clear on next mes, clear contents
  2081. /// - append this text
  2082. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  2083. {
  2084. int fd = sd->fd;
  2085. int slen = strlen(mes) + 9;
  2086. WFIFOHEAD(fd, slen);
  2087. WFIFOW(fd,0)=0xb4;
  2088. WFIFOW(fd,2)=slen;
  2089. WFIFOL(fd,4)=npcid;
  2090. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2091. WFIFOSET(fd,WFIFOW(fd,2));
  2092. }
  2093. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2094. /// 00b5 <npc id>.L
  2095. /// Client behavior (dialog window):
  2096. /// - disable mouse targeting
  2097. /// - open the dialog window
  2098. /// - add 'next' button
  2099. /// When 'next' is pressed:
  2100. /// - 00B9 <npcid of dialog window>.L
  2101. /// - set to clear on next mes
  2102. /// - remove 'next' button
  2103. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2104. {
  2105. int fd;
  2106. nullpo_retv(sd);
  2107. fd=sd->fd;
  2108. WFIFOHEAD(fd, packet_len(0xb5));
  2109. WFIFOW(fd,0)=0xb5;
  2110. WFIFOL(fd,2)=npcid;
  2111. WFIFOSET(fd,packet_len(0xb5));
  2112. }
  2113. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2114. /// 00b6 <npc id>.L
  2115. /// Client behavior:
  2116. /// - if dialog window is open:
  2117. /// - remove 'next' button
  2118. /// - add 'close' button
  2119. /// - else:
  2120. /// - enable mouse targeting
  2121. /// - close the dialog window
  2122. /// - close the menu window
  2123. /// When 'close' is pressed:
  2124. /// - enable mouse targeting
  2125. /// - close the dialog window
  2126. /// - close the menu window
  2127. /// - 0146 <npcid of dialog window>.L
  2128. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2129. {
  2130. int fd;
  2131. nullpo_retv(sd);
  2132. fd=sd->fd;
  2133. WFIFOHEAD(fd, packet_len(0xb6));
  2134. WFIFOW(fd,0)=0xb6;
  2135. WFIFOL(fd,2)=npcid;
  2136. WFIFOSET(fd,packet_len(0xb6));
  2137. }
  2138. /**
  2139. * Close script when player is idle
  2140. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2141. * @author [Ind/Hercules]
  2142. * @param sd : player pointer
  2143. * @param npcid : npc gid to close
  2144. */
  2145. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2146. {
  2147. struct s_packet_db* info;
  2148. int16 len;
  2149. int cmd = 0;
  2150. int fd;
  2151. nullpo_retv(sd);
  2152. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2153. if(!cmd) cmd = 0x8d6; //default
  2154. info = &packet_db[cmd];
  2155. len = info->len;
  2156. fd = sd->fd;
  2157. WFIFOHEAD(fd, len);
  2158. WFIFOW(fd,0)=0x8d6;
  2159. WFIFOL(fd,info->pos[0])=npcid;
  2160. WFIFOSET(fd,len);
  2161. }
  2162. /*==========================================
  2163. *
  2164. *------------------------------------------*/
  2165. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2166. unsigned char *buf;
  2167. int fd = sd->fd;
  2168. sd->state.using_fake_npc = 1;
  2169. WFIFOHEAD(fd, packet_len(0x78));
  2170. buf = WFIFOP(fd,0);
  2171. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2172. WBUFW(buf,0)=0x78;
  2173. #if PACKETVER >= 20071106
  2174. WBUFB(buf,2) = 0; // object type
  2175. buf = WFIFOP(fd,1);
  2176. #endif
  2177. WBUFL(buf,2)=npcid;
  2178. WBUFW(buf,14)=111;
  2179. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2180. WBUFB(buf,49)=5;
  2181. WBUFB(buf,50)=5;
  2182. WFIFOSET(fd, packet_len(0x78));
  2183. }
  2184. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2185. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2186. /// Client behavior:
  2187. /// - disable mouse targeting
  2188. /// - close the menu window
  2189. /// - open the menu window
  2190. /// - add options to the menu (separated in the text by ":")
  2191. /// - set npcid of menu window
  2192. /// - if dialog window is open:
  2193. /// - remove 'next' button
  2194. /// When 'ok' is pressed:
  2195. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2196. /// - close the menu window
  2197. /// When 'cancel' is pressed:
  2198. /// - 00B8 <npcid of menu window>.L <-1>.B
  2199. /// - enable mouse targeting
  2200. /// - close a bunch of windows...
  2201. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2202. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2203. /// TODO investigate behavior of other windows [FlavioJS]
  2204. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2205. {
  2206. int fd = sd->fd;
  2207. int slen = strlen(mes) + 9;
  2208. struct block_list *bl = NULL;
  2209. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2210. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2211. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2212. clif_sendfakenpc(sd, npcid);
  2213. WFIFOHEAD(fd, slen);
  2214. WFIFOW(fd,0)=0xb7;
  2215. WFIFOW(fd,2)=slen;
  2216. WFIFOL(fd,4)=npcid;
  2217. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2218. WFIFOSET(fd,WFIFOW(fd,2));
  2219. }
  2220. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2221. /// 0142 <npc id>.L
  2222. /// Client behavior (inputnum window):
  2223. /// - if npcid exists in the client:
  2224. /// - open the inputnum window
  2225. /// - set npcid of inputnum window
  2226. /// When 'ok' is pressed:
  2227. /// - if inputnum window has text:
  2228. /// - if npcid exists in the client:
  2229. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2230. /// - close inputnum window
  2231. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2232. {
  2233. int fd;
  2234. struct block_list *bl = NULL;
  2235. nullpo_retv(sd);
  2236. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2237. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2238. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2239. clif_sendfakenpc(sd, npcid);
  2240. fd=sd->fd;
  2241. WFIFOHEAD(fd, packet_len(0x142));
  2242. WFIFOW(fd,0)=0x142;
  2243. WFIFOL(fd,2)=npcid;
  2244. WFIFOSET(fd,packet_len(0x142));
  2245. }
  2246. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2247. /// 01d4 <npc id>.L
  2248. /// Client behavior (inputstr window):
  2249. /// - if npcid is 0 or npcid exists in the client:
  2250. /// - open the inputstr window
  2251. /// - set npcid of inputstr window
  2252. /// When 'ok' is pressed:
  2253. /// - if inputstr window has text and isn't an insult(manner.txt):
  2254. /// - if npcid is 0 or npcid exists in the client:
  2255. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2256. /// - close inputstr window
  2257. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2258. {
  2259. int fd;
  2260. struct block_list *bl = NULL;
  2261. nullpo_retv(sd);
  2262. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2263. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2264. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2265. clif_sendfakenpc(sd, npcid);
  2266. fd=sd->fd;
  2267. WFIFOHEAD(fd, packet_len(0x1d4));
  2268. WFIFOW(fd,0)=0x1d4;
  2269. WFIFOL(fd,2)=npcid;
  2270. WFIFOSET(fd,packet_len(0x1d4));
  2271. }
  2272. /// Marks a position on client's minimap (ZC_COMPASS).
  2273. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2274. /// npc id:
  2275. /// is ignored in the client
  2276. /// type:
  2277. /// 0 = display mark for 15 seconds
  2278. /// 1 = display mark until dead or teleported
  2279. /// 2 = remove mark
  2280. /// color:
  2281. /// 0x00RRGGBB
  2282. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2283. {
  2284. int fd;
  2285. nullpo_retv(sd);
  2286. fd=sd->fd;
  2287. WFIFOHEAD(fd, packet_len(0x144));
  2288. WFIFOW(fd,0)=0x144;
  2289. WFIFOL(fd,2)=npc_id;
  2290. WFIFOL(fd,6)=type;
  2291. WFIFOL(fd,10)=x;
  2292. WFIFOL(fd,14)=y;
  2293. WFIFOB(fd,18)=id;
  2294. WFIFOL(fd,19)=color;
  2295. WFIFOSET(fd,packet_len(0x144));
  2296. }
  2297. /// Displays an illustration image.
  2298. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2299. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2300. /// type:
  2301. /// 0 = bottom left corner
  2302. /// 1 = bottom middle
  2303. /// 2 = bottom right corner
  2304. /// 3 = middle of screen, inside a movable window
  2305. /// 4 = middle of screen, movable with a close button, chrome-less
  2306. /// 255 = clear all displayed cutins
  2307. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2308. {
  2309. int fd;
  2310. nullpo_retv(sd);
  2311. fd=sd->fd;
  2312. WFIFOHEAD(fd, packet_len(0x1b3));
  2313. WFIFOW(fd,0)=0x1b3;
  2314. strncpy(WFIFOCP(fd,2),image,64);
  2315. WFIFOB(fd,66)=type;
  2316. WFIFOSET(fd,packet_len(0x1b3));
  2317. }
  2318. /*==========================================
  2319. * Fills in card data from the given item and into the buffer. [Skotlex]
  2320. *------------------------------------------*/
  2321. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2322. nullpo_retv( buf );
  2323. // Blank data
  2324. if( item == nullptr ){
  2325. buf->card[0] = 0;
  2326. buf->card[1] = 0;
  2327. buf->card[2] = 0;
  2328. buf->card[3] = 0;
  2329. return;
  2330. }
  2331. // Pet eggs
  2332. if( item->card[0] == CARD0_PET ){
  2333. buf->card[0] = 0;
  2334. buf->card[1] = 0;
  2335. // Pet intimacy
  2336. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2337. buf->card[2] = item->card[3] >> 1;
  2338. // Pet renamed flag
  2339. buf->card[3] = item->card[3] & 1;
  2340. return;
  2341. }
  2342. // Forged/created items
  2343. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2344. buf->card[0] = item->card[0];
  2345. buf->card[1] = item->card[1];
  2346. buf->card[2] = item->card[2];
  2347. buf->card[3] = item->card[3];
  2348. return;
  2349. }
  2350. int i = 0, j;
  2351. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2352. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2353. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2354. }
  2355. // Normal items.
  2356. for( int k = 0; k < 4; k++, i++ ){
  2357. if( item->card[i] > 0 ){
  2358. buf->card[k] = client_nameid( item->card[i] );
  2359. }else{
  2360. buf->card[k] = 0;
  2361. }
  2362. }
  2363. }
  2364. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2365. /// A maximum of 5 random options can be supported.
  2366. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2367. nullpo_retr( 0, it );
  2368. uint8 count = 0;
  2369. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2370. if( it->option[i].id ){
  2371. buf[i].index = it->option[i].id; // OptIndex
  2372. buf[i].value = it->option[i].value; // Value
  2373. buf[i].param = it->option[i].param; // Param1
  2374. count++;
  2375. }else{
  2376. buf[i].index = 0;
  2377. buf[i].value = 0;
  2378. buf[i].param = 0;
  2379. }
  2380. }
  2381. #if MAX_ITEM_RDM_OPT < 5
  2382. for( ; i < 5; i++ ){
  2383. buf[i].index = 0; // OptIndex
  2384. buf[i].value = 0; // Value
  2385. buf[i].param = 0; // Param1
  2386. }
  2387. #endif
  2388. return count;
  2389. }
  2390. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2391. /// 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)
  2392. /// 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)
  2393. /// 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)
  2394. /// 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)
  2395. /// 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)
  2396. /// 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)
  2397. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2398. nullpo_retv( sd );
  2399. int fd = sd->fd;
  2400. if( !session_isActive( fd ) ){
  2401. return;
  2402. }
  2403. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2404. if( fail ){
  2405. p = {};
  2406. }else{
  2407. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2408. return;
  2409. }
  2410. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2411. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2412. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2413. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2414. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2415. p.location = pc_equippoint(sd,n);
  2416. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2417. #if PACKETVER >= 20061218
  2418. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2419. #if PACKETVER >= 20071002
  2420. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2421. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2422. */
  2423. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2424. #if PACKETVER >= 20150226
  2425. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2426. #if PACKETVER >= 20160921
  2427. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2428. p.look = sd->inventory_data[n]->look;
  2429. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2430. p.enchantgrade = sd->inventory.u.items_inventory[n].enchantgrade;
  2431. #endif
  2432. #endif
  2433. #endif
  2434. #endif
  2435. #endif
  2436. }
  2437. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2438. p.Index = client_index( n );
  2439. p.count = amount;
  2440. p.result = fail;
  2441. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2442. }
  2443. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2444. /// 00af <index>.W <amount>.W
  2445. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2446. {
  2447. int fd;
  2448. nullpo_retv(sd);
  2449. fd=sd->fd;
  2450. WFIFOHEAD(fd, packet_len(0xaf));
  2451. WFIFOW(fd,0)=0xaf;
  2452. WFIFOW(fd,2)=n+2;
  2453. WFIFOW(fd,4)=amount;
  2454. WFIFOSET(fd,packet_len(0xaf));
  2455. }
  2456. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2457. /// 07fa <delete type>.W <index>.W <amount>.W
  2458. /// delete type:
  2459. /// 0 = Normal
  2460. /// 1 = Item used for a skill
  2461. /// 2 = Refine failed
  2462. /// 3 = Material changed
  2463. /// 4 = Moved to storage
  2464. /// 5 = Moved to cart
  2465. /// 6 = Item sold
  2466. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2467. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2468. {
  2469. #if PACKETVER < 20091117
  2470. clif_dropitem(sd,n,amount);
  2471. #else
  2472. int fd;
  2473. nullpo_retv(sd);
  2474. fd=sd->fd;
  2475. WFIFOHEAD(fd, packet_len(0x7fa));
  2476. WFIFOW(fd,0)=0x7fa;
  2477. WFIFOW(fd,2)=reason;
  2478. WFIFOW(fd,4)=n+2;
  2479. WFIFOW(fd,6)=amount;
  2480. WFIFOSET(fd,packet_len(0x7fa));
  2481. #endif
  2482. }
  2483. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2484. nullpo_retv( p );
  2485. nullpo_retv( it );
  2486. nullpo_retv( id );
  2487. p->index = idx;
  2488. p->ITID = client_nameid( it->nameid );
  2489. p->type = itemtype( it->nameid );
  2490. #if PACKETVER < 20120925
  2491. p->IsIdentified = it->identify ? 1 : 0;
  2492. #endif
  2493. p->location = eqp_pos;
  2494. p->WearState = it->equip;
  2495. #if PACKETVER < 20120925
  2496. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2497. #endif
  2498. p->RefiningLevel = it->refine;
  2499. clif_addcards( &p->slot, it );
  2500. #if PACKETVER >= 20071002
  2501. p->HireExpireDate = it->expire_time;
  2502. #endif
  2503. #if PACKETVER >= 20080102
  2504. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2505. #endif
  2506. #if PACKETVER >= 20100629
  2507. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2508. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2509. #endif
  2510. #if PACKETVER >= 20120925
  2511. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2512. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2513. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2514. p->Flag.SpareBits = 0;
  2515. #endif
  2516. #if PACKETVER >= 20150226
  2517. p->option_count = clif_add_random_options( p->option_data, it );
  2518. #endif
  2519. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2520. p->enchantgrade = it->enchantgrade;
  2521. #endif
  2522. }
  2523. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2524. nullpo_retv(p);
  2525. nullpo_retv(i);
  2526. nullpo_retv(id);
  2527. p->index = idx;
  2528. p->ITID = client_nameid( i->nameid );
  2529. p->type = itemtype( i->nameid );
  2530. #if PACKETVER < 20120925
  2531. p->IsIdentified = i->identify ? 1 : 0;
  2532. #endif
  2533. p->count = i->amount;
  2534. p->WearState = id->equip;
  2535. #if PACKETVER >= 5
  2536. clif_addcards( &p->slot, i );
  2537. #endif
  2538. #if PACKETVER >= 20080102
  2539. p->HireExpireDate = i->expire_time;
  2540. #endif
  2541. #if PACKETVER >= 20120925
  2542. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2543. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2544. p->Flag.SpareBits = 0;
  2545. #endif
  2546. }
  2547. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2548. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2549. nullpo_retv(sd);
  2550. nullpo_retv(name);
  2551. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2552. memset(buf, 0, sizeof(buf));
  2553. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2554. p->packetType = HEADER_ZC_INVENTORY_START;
  2555. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2556. p->invType = type;
  2557. #endif
  2558. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2559. int strLen = (int)safestrnlen(name, 24) + 1;
  2560. if (strLen > 24)
  2561. strLen = 24;
  2562. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2563. p->packetLength = len;
  2564. safestrncpy(p->name, name, strLen);
  2565. #else
  2566. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2567. safestrncpy(p->name, name, NAME_LENGTH);
  2568. #endif
  2569. clif_send( p, len, &sd->bl, SELF );
  2570. #endif
  2571. }
  2572. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2573. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2574. nullpo_retv(sd);
  2575. struct PACKET_ZC_INVENTORY_END p;
  2576. p.packetType = HEADER_ZC_INVENTORY_END;
  2577. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2578. p.invType = type;
  2579. #endif
  2580. p.flag = 0;
  2581. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2582. #endif
  2583. }
  2584. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2585. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2586. void clif_inventorylist( struct map_session_data *sd ){
  2587. nullpo_retv( sd );
  2588. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2589. e_inventory_type type = INVTYPE_INVENTORY;
  2590. clif_inventoryStart( sd, type, "" );
  2591. #endif
  2592. static struct packet_itemlist_normal itemlist_normal;
  2593. static struct packet_itemlist_equip itemlist_equip;
  2594. int equip = 0;
  2595. int normal = 0;
  2596. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2597. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2598. continue;
  2599. }
  2600. // Non-stackable (Equippable)
  2601. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2602. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2603. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2604. itemlist_equip.PacketType = inventorylistequipType;
  2605. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2606. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2607. itemlist_equip.invType = type;
  2608. #endif
  2609. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2610. equip = 0;
  2611. }
  2612. // Stackable (Normal)
  2613. }else{
  2614. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2615. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2616. itemlist_normal.PacketType = inventorylistnormalType;
  2617. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2618. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2619. itemlist_normal.invType = type;
  2620. #endif
  2621. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2622. normal = 0;
  2623. }
  2624. }
  2625. }
  2626. if( normal ){
  2627. itemlist_normal.PacketType = inventorylistnormalType;
  2628. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2629. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2630. itemlist_normal.invType = type;
  2631. #endif
  2632. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2633. }
  2634. if( sd->equip_index[EQI_AMMO] >= 0 )
  2635. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2636. if( equip ) {
  2637. itemlist_equip.PacketType = inventorylistequipType;
  2638. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2639. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2640. itemlist_equip.invType = type;
  2641. #endif
  2642. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2643. }
  2644. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2645. clif_inventoryEnd( sd, type );
  2646. #endif
  2647. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2648. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2649. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2650. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2651. continue;
  2652. if ( sd->inventory.u.items_inventory[i].favorite )
  2653. clif_favorite_item(sd, i);
  2654. }
  2655. #endif
  2656. }
  2657. //Required when items break/get-repaired. Only sends equippable item list.
  2658. void clif_equiplist( struct map_session_data *sd ){
  2659. // TODO: implement again => only send equip part
  2660. clif_inventorylist( sd );
  2661. }
  2662. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2663. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2664. e_inventory_type type = INVTYPE_STORAGE;
  2665. clif_inventoryStart( sd, type, storename );
  2666. #endif
  2667. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2668. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2669. int equip = 0;
  2670. int normal = 0;
  2671. for( int i = 0; i < items_length; i++ ){
  2672. if( items[i].nameid == 0 ){
  2673. continue;
  2674. }
  2675. struct item_data* id = itemdb_search( items[i].nameid );
  2676. // Non-stackable (Equippable)
  2677. if( !itemdb_isstackable2( id ) ){
  2678. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2679. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2680. storage_itemlist_equip.PacketType = storageListEquipType;
  2681. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2682. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2683. storage_itemlist_equip.invType = type;
  2684. #elif PACKETVER >= 20120925
  2685. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2686. #endif
  2687. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2688. equip = 0;
  2689. }
  2690. // Stackable (Normal)
  2691. }else{
  2692. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2693. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2694. storage_itemlist_normal.PacketType = storageListNormalType;
  2695. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2696. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2697. storage_itemlist_normal.invType = type;
  2698. #elif PACKETVER >= 20120925
  2699. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2700. #endif
  2701. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2702. normal = 0;
  2703. }
  2704. }
  2705. }
  2706. if( normal ){
  2707. storage_itemlist_normal.PacketType = storageListNormalType;
  2708. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2709. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2710. storage_itemlist_normal.invType = type;
  2711. #elif PACKETVER >= 20120925
  2712. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2713. #endif
  2714. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2715. }
  2716. if( equip ) {
  2717. storage_itemlist_equip.PacketType = storageListEquipType;
  2718. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2719. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2720. storage_itemlist_equip.invType = type;
  2721. #elif PACKETVER >= 20120925
  2722. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2723. #endif
  2724. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2725. }
  2726. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2727. clif_inventoryEnd( sd, type );
  2728. #endif
  2729. }
  2730. void clif_cartlist( struct map_session_data *sd ){
  2731. nullpo_retv( sd );
  2732. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2733. e_inventory_type type = INVTYPE_CART;
  2734. clif_inventoryStart( sd, type, "" );
  2735. #endif
  2736. static struct packet_itemlist_normal itemlist_normal;
  2737. static struct packet_itemlist_equip itemlist_equip;
  2738. int normal = 0;
  2739. int equip = 0;
  2740. for( int i = 0; i < MAX_CART; i++ ){
  2741. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2742. continue;
  2743. }
  2744. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2745. // Non-stackable (Equippable)
  2746. if( !itemdb_isstackable2(id) ){
  2747. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2748. // Stackable (Normal)
  2749. }else{
  2750. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2751. }
  2752. }
  2753. if( normal ){
  2754. itemlist_normal.PacketType = cartlistnormalType;
  2755. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2756. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2757. itemlist_normal.invType = type;
  2758. #endif
  2759. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2760. }
  2761. if( equip ){
  2762. itemlist_equip.PacketType = cartlistequipType;
  2763. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2764. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2765. itemlist_equip.invType = type;
  2766. #endif
  2767. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2768. }
  2769. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2770. clif_inventoryEnd( sd, type );
  2771. #endif
  2772. }
  2773. /// Removes cart (ZC_CARTOFF).
  2774. /// 012b
  2775. /// Client behaviour:
  2776. /// Closes the cart storage and removes all it's items from memory.
  2777. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2778. void clif_clearcart(int fd)
  2779. {
  2780. WFIFOHEAD(fd, packet_len(0x12b));
  2781. WFIFOW(fd,0) = 0x12b;
  2782. WFIFOSET(fd, packet_len(0x12b));
  2783. }
  2784. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2785. /// 01eb <account id>.L <x>.W <y>.W
  2786. void clif_guild_xy(struct map_session_data *sd)
  2787. {
  2788. unsigned char buf[10];
  2789. nullpo_retv(sd);
  2790. WBUFW(buf,0)=0x1eb;
  2791. WBUFL(buf,2)=sd->status.account_id;
  2792. WBUFW(buf,6)=sd->bl.x;
  2793. WBUFW(buf,8)=sd->bl.y;
  2794. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2795. }
  2796. /*==========================================
  2797. * Sends x/y dot to a single fd. [Skotlex]
  2798. *------------------------------------------*/
  2799. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2800. {
  2801. if( sd->bg_id )
  2802. return;
  2803. WFIFOHEAD(fd,packet_len(0x1eb));
  2804. WFIFOW(fd,0)=0x1eb;
  2805. WFIFOL(fd,2)=sd->status.account_id;
  2806. WFIFOW(fd,6)=sd->bl.x;
  2807. WFIFOW(fd,8)=sd->bl.y;
  2808. WFIFOSET(fd,packet_len(0x1eb));
  2809. }
  2810. // Guild XY locators [Valaris]
  2811. void clif_guild_xy_remove(struct map_session_data *sd)
  2812. {
  2813. unsigned char buf[10];
  2814. nullpo_retv(sd);
  2815. WBUFW(buf,0)=0x1eb;
  2816. WBUFL(buf,2)=sd->status.account_id;
  2817. WBUFW(buf,6)=-1;
  2818. WBUFW(buf,8)=-1;
  2819. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2820. }
  2821. /*==========================================
  2822. *
  2823. *------------------------------------------*/
  2824. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2825. {
  2826. struct map_session_data *sd, *tsd;
  2827. #if PACKETVER < 20100126
  2828. const int cmd = 0x106;
  2829. #else
  2830. const int cmd = 0x80e;
  2831. #endif
  2832. sd = va_arg(ap, struct map_session_data *);
  2833. tsd = (TBL_PC *)bl;
  2834. nullpo_ret(sd);
  2835. nullpo_ret(tsd);
  2836. if( !session_isActive(tsd->fd) || tsd == sd )
  2837. return 0;
  2838. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2839. return 0;
  2840. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2841. WFIFOW(tsd->fd,0) = cmd;
  2842. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2843. #if PACKETVER < 20100126
  2844. if( sd->battle_status.max_hp > INT16_MAX )
  2845. { //To correctly display the %hp bar. [Skotlex]
  2846. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2847. WFIFOW(tsd->fd,8) = 100;
  2848. } else {
  2849. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2850. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2851. }
  2852. #else
  2853. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2854. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2855. #endif
  2856. WFIFOSET(tsd->fd,packet_len(cmd));
  2857. return 0;
  2858. }
  2859. /*==========================================
  2860. * Server tells all players that are allowed to view HP bars
  2861. * and are nearby 'sd' that 'sd' hp bar was updated.
  2862. *------------------------------------------*/
  2863. static int clif_hpmeter(struct map_session_data *sd)
  2864. {
  2865. nullpo_ret(sd);
  2866. 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);
  2867. return 0;
  2868. }
  2869. /// Notifies client of a character parameter change.
  2870. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2871. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2872. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2873. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2874. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2875. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2876. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2877. /// TODO: Extract individual packets.
  2878. /// FIXME: Packet lengths from packet_len(cmd)
  2879. void clif_updatestatus(struct map_session_data *sd,int type)
  2880. {
  2881. int fd,len=8;
  2882. nullpo_retv(sd);
  2883. fd=sd->fd;
  2884. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2885. return;
  2886. WFIFOHEAD(fd, 14);
  2887. WFIFOW(fd,0)=0xb0;
  2888. WFIFOW(fd,2)=type;
  2889. switch(type){
  2890. // 00b0
  2891. case SP_WEIGHT:
  2892. pc_updateweightstatus(sd);
  2893. WFIFOHEAD(fd,14);
  2894. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2895. WFIFOW(fd,2)=type;
  2896. WFIFOL(fd,4)=sd->weight;
  2897. break;
  2898. case SP_MAXWEIGHT:
  2899. WFIFOL(fd,4)=sd->max_weight;
  2900. break;
  2901. case SP_SPEED:
  2902. WFIFOL(fd,4)=sd->battle_status.speed;
  2903. break;
  2904. case SP_BASELEVEL:
  2905. WFIFOL(fd,4)=sd->status.base_level;
  2906. break;
  2907. case SP_JOBLEVEL:
  2908. WFIFOL(fd,4)=sd->status.job_level;
  2909. break;
  2910. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2911. WFIFOL(fd,4)=sd->status.karma;
  2912. break;
  2913. case SP_MANNER:
  2914. WFIFOL(fd,4)=sd->status.manner;
  2915. break;
  2916. case SP_STATUSPOINT:
  2917. WFIFOL(fd,4)=sd->status.status_point;
  2918. break;
  2919. case SP_SKILLPOINT:
  2920. WFIFOL(fd,4)=sd->status.skill_point;
  2921. break;
  2922. case SP_HIT:
  2923. WFIFOL(fd,4)=sd->battle_status.hit;
  2924. break;
  2925. case SP_FLEE1:
  2926. WFIFOL(fd,4)=sd->battle_status.flee;
  2927. break;
  2928. case SP_FLEE2:
  2929. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2930. break;
  2931. case SP_MAXHP:
  2932. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2933. break;
  2934. case SP_MAXSP:
  2935. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2936. break;
  2937. case SP_HP:
  2938. // On officials the HP never go below 1, even if you die [Lemongrass]
  2939. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2940. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2941. break;
  2942. case SP_SP:
  2943. WFIFOL(fd,4)=sd->battle_status.sp;
  2944. break;
  2945. case SP_ASPD:
  2946. WFIFOL(fd,4)=sd->battle_status.amotion;
  2947. break;
  2948. case SP_ATK1:
  2949. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2950. break;
  2951. case SP_DEF1:
  2952. WFIFOL(fd,4)=pc_leftside_def(sd);
  2953. break;
  2954. case SP_MDEF1:
  2955. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2956. break;
  2957. case SP_ATK2:
  2958. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2959. break;
  2960. case SP_DEF2:
  2961. WFIFOL(fd,4)=pc_rightside_def(sd);
  2962. break;
  2963. case SP_MDEF2: {
  2964. //negative check (in case you have something like Berserk active)
  2965. int mdef2 = pc_rightside_mdef(sd);
  2966. WFIFOL(fd,4)=
  2967. #ifndef RENEWAL
  2968. ( mdef2 < 0 ) ? 0 :
  2969. #endif
  2970. mdef2;
  2971. }
  2972. break;
  2973. case SP_CRITICAL:
  2974. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2975. break;
  2976. case SP_MATK1:
  2977. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2978. break;
  2979. case SP_MATK2:
  2980. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2981. break;
  2982. case SP_ZENY:
  2983. WFIFOW(fd,0)=0xb1;
  2984. WFIFOL(fd,4)=sd->status.zeny;
  2985. break;
  2986. #if PACKETVER >= 20170830
  2987. case SP_BASEEXP:
  2988. WFIFOW(fd,0)=0xacb;
  2989. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2990. len = packet_len(0xacb);
  2991. break;
  2992. case SP_JOBEXP:
  2993. WFIFOW(fd,0)=0xacb;
  2994. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2995. len = packet_len(0xacb);
  2996. break;
  2997. case SP_NEXTBASEEXP:
  2998. WFIFOW(fd,0)=0xacb;
  2999. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3000. len = packet_len(0xacb);
  3001. break;
  3002. case SP_NEXTJOBEXP:
  3003. WFIFOW(fd,0)=0xacb;
  3004. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3005. len = packet_len(0xacb);
  3006. break;
  3007. #else
  3008. case SP_BASEEXP:
  3009. WFIFOW(fd,0)=0xb1;
  3010. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3011. break;
  3012. case SP_JOBEXP:
  3013. WFIFOW(fd,0)=0xb1;
  3014. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3015. break;
  3016. case SP_NEXTBASEEXP:
  3017. WFIFOW(fd,0)=0xb1;
  3018. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3019. break;
  3020. case SP_NEXTJOBEXP:
  3021. WFIFOW(fd,0)=0xb1;
  3022. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3023. break;
  3024. #endif
  3025. /**
  3026. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3027. **/
  3028. case SP_USTR:
  3029. case SP_UAGI:
  3030. case SP_UVIT:
  3031. case SP_UINT:
  3032. case SP_UDEX:
  3033. case SP_ULUK:
  3034. WFIFOW(fd,0)=0xbe;
  3035. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3036. len=5;
  3037. break;
  3038. /**
  3039. * Tells the client how far it is allowed to attack (weapon range)
  3040. **/
  3041. case SP_ATTACKRANGE:
  3042. WFIFOW(fd,0)=0x13a;
  3043. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3044. len=4;
  3045. break;
  3046. case SP_STR:
  3047. WFIFOW(fd,0)=0x141;
  3048. WFIFOL(fd,2)=type;
  3049. WFIFOL(fd,6)=sd->status.str;
  3050. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3051. len=14;
  3052. break;
  3053. case SP_AGI:
  3054. WFIFOW(fd,0)=0x141;
  3055. WFIFOL(fd,2)=type;
  3056. WFIFOL(fd,6)=sd->status.agi;
  3057. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3058. len=14;
  3059. break;
  3060. case SP_VIT:
  3061. WFIFOW(fd,0)=0x141;
  3062. WFIFOL(fd,2)=type;
  3063. WFIFOL(fd,6)=sd->status.vit;
  3064. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3065. len=14;
  3066. break;
  3067. case SP_INT:
  3068. WFIFOW(fd,0)=0x141;
  3069. WFIFOL(fd,2)=type;
  3070. WFIFOL(fd,6)=sd->status.int_;
  3071. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3072. len=14;
  3073. break;
  3074. case SP_DEX:
  3075. WFIFOW(fd,0)=0x141;
  3076. WFIFOL(fd,2)=type;
  3077. WFIFOL(fd,6)=sd->status.dex;
  3078. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3079. len=14;
  3080. break;
  3081. case SP_LUK:
  3082. WFIFOW(fd,0)=0x141;
  3083. WFIFOL(fd,2)=type;
  3084. WFIFOL(fd,6)=sd->status.luk;
  3085. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3086. len=14;
  3087. break;
  3088. case SP_CARTINFO:
  3089. WFIFOW(fd,0)=0x121;
  3090. WFIFOW(fd,2)=sd->cart_num;
  3091. WFIFOW(fd,4)=MAX_CART;
  3092. WFIFOL(fd,6)=sd->cart_weight;
  3093. WFIFOL(fd,10)=sd->cart_weight_max;
  3094. len=14;
  3095. break;
  3096. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3097. case SP_AP:
  3098. WFIFOL(fd, 4) = sd->battle_status.ap;
  3099. break;
  3100. case SP_TRAITPOINT:
  3101. WFIFOL(fd, 4) = sd->status.trait_point;
  3102. break;
  3103. case SP_MAXAP:
  3104. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3105. break;
  3106. case SP_POW:
  3107. WFIFOW(fd, 0) = 0x141;
  3108. WFIFOL(fd, 2) = type;
  3109. WFIFOL(fd, 6) = sd->status.pow;
  3110. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3111. len = 14;
  3112. break;
  3113. case SP_STA:
  3114. WFIFOW(fd, 0) = 0x141;
  3115. WFIFOL(fd, 2) = type;
  3116. WFIFOL(fd, 6) = sd->status.sta;
  3117. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3118. len = 14;
  3119. break;
  3120. case SP_WIS:
  3121. WFIFOW(fd, 0) = 0x141;
  3122. WFIFOL(fd, 2) = type;
  3123. WFIFOL(fd, 6) = sd->status.wis;
  3124. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3125. len = 14;
  3126. break;
  3127. case SP_SPL:
  3128. WFIFOW(fd, 0) = 0x141;
  3129. WFIFOL(fd, 2) = type;
  3130. WFIFOL(fd, 6) = sd->status.spl;
  3131. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3132. len = 14;
  3133. break;
  3134. case SP_CON:
  3135. WFIFOW(fd, 0) = 0x141;
  3136. WFIFOL(fd, 2) = type;
  3137. WFIFOL(fd, 6) = sd->status.con;
  3138. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3139. len = 14;
  3140. break;
  3141. case SP_CRT:
  3142. WFIFOW(fd, 0) = 0x141;
  3143. WFIFOL(fd, 2) = type;
  3144. WFIFOL(fd, 6) = sd->status.crt;
  3145. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3146. len = 14;
  3147. break;
  3148. case SP_UPOW:
  3149. case SP_USTA:
  3150. case SP_UWIS:
  3151. case SP_USPL:
  3152. case SP_UCON:
  3153. case SP_UCRT:
  3154. WFIFOW(fd, 0) = 0xbe;
  3155. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3156. len = 5;
  3157. break;
  3158. case SP_PATK:
  3159. WFIFOL(fd, 4) = sd->battle_status.patk;
  3160. break;
  3161. case SP_SMATK:
  3162. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3163. break;
  3164. case SP_RES:
  3165. WFIFOL(fd, 4) = sd->battle_status.res;
  3166. break;
  3167. case SP_MRES:
  3168. WFIFOL(fd, 4) = sd->battle_status.mres;
  3169. break;
  3170. case SP_HPLUS:
  3171. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3172. break;
  3173. case SP_CRATE:
  3174. WFIFOL(fd, 4) = sd->battle_status.crate;
  3175. break;
  3176. #else
  3177. case SP_AP:
  3178. case SP_TRAITPOINT:
  3179. case SP_MAXAP:
  3180. case SP_POW:
  3181. case SP_STA:
  3182. case SP_WIS:
  3183. case SP_SPL:
  3184. case SP_CON:
  3185. case SP_CRT:
  3186. case SP_UPOW:
  3187. case SP_USTA:
  3188. case SP_UWIS:
  3189. case SP_USPL:
  3190. case SP_UCON:
  3191. case SP_UCRT:
  3192. case SP_PATK:
  3193. case SP_SMATK:
  3194. case SP_RES:
  3195. case SP_MRES:
  3196. case SP_HPLUS:
  3197. case SP_CRATE:
  3198. // 4th job status are not supported by older clients
  3199. return;
  3200. #endif
  3201. default:
  3202. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3203. return;
  3204. }
  3205. WFIFOSET(fd,len);
  3206. // Additional update packets that should be sent right after
  3207. switch( type ){
  3208. case SP_BASELEVEL:
  3209. if( sd->status.party_id ){
  3210. struct party_data* p;
  3211. int i;
  3212. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3213. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3214. if( i < MAX_PARTY ){
  3215. p->party.member[i].lv = sd->status.base_level;
  3216. clif_party_job_and_level(sd);
  3217. }
  3218. }
  3219. }
  3220. break;
  3221. case SP_HP:
  3222. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3223. clif_hpmeter(sd);
  3224. }
  3225. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3226. clif_party_hp(sd);
  3227. }
  3228. if( sd->bg_id ){
  3229. clif_bg_hp(sd);
  3230. }
  3231. break;
  3232. }
  3233. }
  3234. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3235. /// 01ab <account id>.L <var id>.W <value>.L
  3236. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3237. {
  3238. unsigned char buf[12];
  3239. nullpo_retv(sd);
  3240. WBUFW(buf,0)=0x1ab;
  3241. WBUFL(buf,2)=sd->bl.id;
  3242. WBUFW(buf,6)=type;
  3243. switch(type)
  3244. {
  3245. case SP_MANNER:
  3246. WBUFL(buf,8)=val;
  3247. break;
  3248. default:
  3249. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3250. return;
  3251. }
  3252. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3253. }
  3254. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3255. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3256. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3257. struct PACKET_ZC_SPRITE_CHANGE p;
  3258. p.packetType = sendLookType;
  3259. p.AID = id;
  3260. p.type = type;
  3261. p.val = val;
  3262. #if PACKETVER >= 4
  3263. p.val2 = val2;
  3264. #endif
  3265. clif_send( &p, sizeof( p ), bl, target );
  3266. }
  3267. /// Updates sprite/style properties of an object.
  3268. void clif_changelook(struct block_list *bl, int type, int val) {
  3269. struct map_session_data* sd;
  3270. struct status_change* sc;
  3271. struct view_data* vd;
  3272. enum send_target target = AREA;
  3273. int val2 = 0;
  3274. nullpo_retv(bl);
  3275. sd = BL_CAST(BL_PC, bl);
  3276. sc = status_get_sc(bl);
  3277. vd = status_get_viewdata(bl);
  3278. if( vd ) //temp hack to let Warp Portal change appearance
  3279. switch(type) {
  3280. case LOOK_WEAPON:
  3281. if (sd) {
  3282. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3283. val = vd->weapon;
  3284. }
  3285. else
  3286. vd->weapon = val;
  3287. break;
  3288. case LOOK_SHIELD:
  3289. if (sd) {
  3290. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3291. val = vd->shield;
  3292. }
  3293. else
  3294. vd->shield = val;
  3295. break;
  3296. case LOOK_BASE:
  3297. if (!sd)
  3298. break;
  3299. if ( val == JT_INVISIBLE )
  3300. return;
  3301. if (sd->sc.option&OPTION_COSTUME)
  3302. vd->weapon = vd->shield = 0;
  3303. if (!vd->cloth_color)
  3304. break;
  3305. if (sd) {
  3306. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3307. vd->cloth_color = 0;
  3308. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3309. vd->cloth_color = 0;
  3310. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3311. vd->cloth_color = 0;
  3312. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3313. vd->cloth_color = 0;
  3314. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3315. vd->cloth_color = 0;
  3316. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3317. vd->body_style = 0;
  3318. }
  3319. break;
  3320. case LOOK_HAIR:
  3321. vd->hair_style = val;
  3322. break;
  3323. case LOOK_HEAD_BOTTOM:
  3324. vd->head_bottom = val;
  3325. break;
  3326. case LOOK_HEAD_TOP:
  3327. vd->head_top = val;
  3328. break;
  3329. case LOOK_HEAD_MID:
  3330. vd->head_mid = val;
  3331. break;
  3332. case LOOK_HAIR_COLOR:
  3333. vd->hair_color = val;
  3334. break;
  3335. case LOOK_CLOTHES_COLOR:
  3336. if (val && sd) {
  3337. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3338. val = 0;
  3339. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3340. val = 0;
  3341. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3342. val = 0;
  3343. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3344. val = 0;
  3345. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3346. val = 0;
  3347. }
  3348. vd->cloth_color = val;
  3349. break;
  3350. case LOOK_SHOES:
  3351. #if PACKETVER > 3
  3352. if (sd) {
  3353. int n;
  3354. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3355. if(sd->inventory_data[n]->view_id > 0)
  3356. val = sd->inventory_data[n]->view_id;
  3357. else
  3358. val = sd->inventory.u.items_inventory[n].nameid;
  3359. } else
  3360. val = 0;
  3361. }
  3362. #endif
  3363. //Shoes? No packet uses this....
  3364. break;
  3365. case LOOK_BODY:
  3366. // unknown purpose
  3367. break;
  3368. case LOOK_ROBE:
  3369. #if PACKETVER < 20110111
  3370. return;
  3371. #else
  3372. vd->robe = val;
  3373. #endif
  3374. break;
  3375. case LOOK_BODY2:
  3376. #if PACKETVER < 20150513
  3377. return;
  3378. #else
  3379. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3380. val = 0;
  3381. vd->body_style = val;
  3382. #endif
  3383. break;
  3384. }
  3385. // prevent leaking the presence of GM-hidden objects
  3386. if( sc && sc->option&OPTION_INVISIBLE )
  3387. target = SELF;
  3388. #if PACKETVER < 4
  3389. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3390. #else
  3391. if (bl->type != BL_NPC) {
  3392. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3393. type = LOOK_WEAPON;
  3394. val = (vd ? vd->weapon : 0);
  3395. val2 = (vd ? vd->shield : 0);
  3396. }
  3397. if (disguised(bl)) {
  3398. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3399. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3400. } else
  3401. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3402. } else
  3403. unit_refresh(bl);
  3404. #endif
  3405. }
  3406. //Sends a change-base-look packet required for traps as they are triggered.
  3407. void clif_changetraplook(struct block_list *bl,int val) {
  3408. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3409. }
  3410. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3411. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3412. clif_sprite_change(bl, id, type, val, 0, target);
  3413. }
  3414. /// Character status (ZC_STATUS).
  3415. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3416. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3417. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3418. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3419. void clif_initialstatus(struct map_session_data *sd) {
  3420. int fd, mdef2;
  3421. unsigned char *buf;
  3422. nullpo_retv(sd);
  3423. fd=sd->fd;
  3424. WFIFOHEAD(fd, packet_len(0xbd));
  3425. buf = WFIFOP(fd,0);
  3426. WBUFW(buf,0) = 0xbd;
  3427. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3428. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3429. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3430. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3431. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3432. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3433. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3434. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3435. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3436. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3437. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3438. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3439. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3440. WBUFW(buf,16) = pc_leftside_atk(sd);
  3441. WBUFW(buf,18) = pc_rightside_atk(sd);
  3442. WBUFW(buf,20) = pc_rightside_matk(sd);
  3443. WBUFW(buf,22) = pc_leftside_matk(sd);
  3444. WBUFW(buf,24) = pc_leftside_def(sd);
  3445. WBUFW(buf,26) = pc_rightside_def(sd);
  3446. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3447. mdef2 = pc_rightside_mdef(sd);
  3448. WBUFW(buf,30) =
  3449. #ifndef RENEWAL
  3450. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3451. #endif
  3452. mdef2;
  3453. WBUFW(buf,32) = sd->battle_status.hit;
  3454. WBUFW(buf,34) = sd->battle_status.flee;
  3455. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3456. WBUFW(buf,38) = sd->battle_status.cri/10;
  3457. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3458. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3459. WFIFOSET(fd, packet_len(0xbd));
  3460. clif_updatestatus(sd, SP_STR);
  3461. clif_updatestatus(sd, SP_AGI);
  3462. clif_updatestatus(sd, SP_VIT);
  3463. clif_updatestatus(sd, SP_INT);
  3464. clif_updatestatus(sd, SP_DEX);
  3465. clif_updatestatus(sd, SP_LUK);
  3466. clif_updatestatus(sd, SP_ATTACKRANGE);
  3467. clif_updatestatus(sd, SP_ASPD);
  3468. #ifdef RENEWAL
  3469. clif_updatestatus(sd, SP_POW);
  3470. clif_updatestatus(sd, SP_STA);
  3471. clif_updatestatus(sd, SP_WIS);
  3472. clif_updatestatus(sd, SP_SPL);
  3473. clif_updatestatus(sd, SP_CON);
  3474. clif_updatestatus(sd, SP_CRT);
  3475. clif_updatestatus(sd, SP_PATK);
  3476. clif_updatestatus(sd, SP_SMATK);
  3477. clif_updatestatus(sd, SP_RES);
  3478. clif_updatestatus(sd, SP_MRES);
  3479. clif_updatestatus(sd, SP_HPLUS);
  3480. clif_updatestatus(sd, SP_CRATE);
  3481. clif_updatestatus(sd, SP_TRAITPOINT);
  3482. clif_updatestatus(sd, SP_AP);
  3483. clif_updatestatus(sd, SP_MAXAP);
  3484. clif_updatestatus(sd, SP_UPOW);
  3485. clif_updatestatus(sd, SP_USTA);
  3486. clif_updatestatus(sd, SP_UWIS);
  3487. clif_updatestatus(sd, SP_USPL);
  3488. clif_updatestatus(sd, SP_UCON);
  3489. clif_updatestatus(sd, SP_UCRT);
  3490. #endif
  3491. }
  3492. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3493. /// 013c <index>.W
  3494. void clif_arrowequip(struct map_session_data *sd,int val) {
  3495. int fd;
  3496. nullpo_retv(sd);
  3497. #if PACKETVER >= 20121128
  3498. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3499. #endif
  3500. fd=sd->fd;
  3501. WFIFOHEAD(fd, packet_len(0x013c));
  3502. WFIFOW(fd,0) = 0x013c;
  3503. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3504. WFIFOSET(fd, packet_len(0x013c));
  3505. }
  3506. /// Ammunition action message (ZC_ACTION_FAILURE).
  3507. /// 013b <type>.W
  3508. /// type:
  3509. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3510. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3511. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3512. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3513. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3514. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3515. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3516. int fd;
  3517. nullpo_retv(sd);
  3518. fd=sd->fd;
  3519. WFIFOHEAD(fd, packet_len(0x013b));
  3520. WFIFOW(fd,0) = 0x013b;
  3521. WFIFOW(fd,2) = type;
  3522. WFIFOSET(fd, packet_len(0x013b));
  3523. }
  3524. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3525. /// 01ad <packet len>.W { <name id>.W }*
  3526. void clif_arrow_create_list( struct map_session_data *sd ){
  3527. nullpo_retv( sd );
  3528. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3529. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3530. int count = 0;
  3531. for (const auto &it : skill_arrow_db) {
  3532. t_itemid nameid = it.second->nameid;
  3533. if( !item_db.exists( nameid ) ){
  3534. continue;
  3535. }
  3536. int index = pc_search_inventory( sd, nameid );
  3537. if( index < 0 ){
  3538. continue;
  3539. }
  3540. if( sd->inventory.u.items_inventory[index].equip ){
  3541. continue;
  3542. }
  3543. if( !sd->inventory.u.items_inventory[index].identify ){
  3544. continue;
  3545. }
  3546. p->items[count].itemId = client_nameid( nameid );
  3547. count++;
  3548. }
  3549. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3550. clif_send( p, p->packetLength, &sd->bl, SELF );
  3551. if( count > 0 ){
  3552. sd->menuskill_id = AC_MAKINGARROW;
  3553. sd->menuskill_val = count;
  3554. }
  3555. }
  3556. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3557. /// 00bc <status id>.W <result>.B <value>.B
  3558. /// status id:
  3559. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3560. /// result:
  3561. /// 0 = failure
  3562. /// 1 = success
  3563. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3564. int fd;
  3565. nullpo_retv(sd);
  3566. fd=sd->fd;
  3567. WFIFOHEAD(fd, packet_len(0xbc));
  3568. WFIFOW(fd,0) = 0xbc;
  3569. WFIFOW(fd,2) = type;
  3570. WFIFOB(fd,4) = ok;
  3571. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3572. WFIFOSET(fd, packet_len(0xbc));
  3573. }
  3574. /// Notifies the client about the result of a request to equip an item.
  3575. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3576. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3577. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3578. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3579. /// @ok: //inversed forv2 v5
  3580. /// 0 = failure
  3581. /// 1 = success
  3582. /// 2 = failure due to low level
  3583. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3584. {
  3585. int fd = 0, cmd = 0, look = 0;
  3586. struct s_packet_db *info = NULL;
  3587. nullpo_retv(sd);
  3588. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3589. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3590. return;
  3591. fd = sd->fd;
  3592. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3593. look = sd->inventory_data[n]->look;
  3594. WFIFOHEAD(fd, info->len);
  3595. WFIFOW(fd, 0) = cmd;
  3596. WFIFOW(fd, info->pos[0]) = n+2;
  3597. switch (cmd) {
  3598. case 0xaa:
  3599. WFIFOW(fd, info->pos[1]) = pos;
  3600. #if PACKETVER < 20100629
  3601. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3602. #else
  3603. WFIFOL(fd, info->pos[2]) = look;
  3604. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3605. #endif
  3606. break;
  3607. case 0x8d0:
  3608. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3609. flag = 1;
  3610. case 0x999:
  3611. if (cmd == 0x999)
  3612. WFIFOL(fd, info->pos[1]) = pos;
  3613. else
  3614. WFIFOW(fd, info->pos[1]) = pos;
  3615. WFIFOL(fd, info->pos[2]) = look;
  3616. WFIFOW(fd, info->pos[3]) = flag;
  3617. break;
  3618. }
  3619. WFIFOSET(fd, info->len);
  3620. }
  3621. /// Notifies the client about the result of a request to take off an item.
  3622. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3623. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3624. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3625. /// @ok : //inversed for v2 v5
  3626. /// 0 = failure
  3627. /// 1 = success
  3628. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3629. {
  3630. int fd, header, offs = 0;
  3631. #if PACKETVER >= 20130000
  3632. header = 0x99a;
  3633. ok = ok ? 0 : 1;
  3634. #elif PACKETVER >= 20110824
  3635. header = 0x8d1;
  3636. ok = ok ? 0 : 1;
  3637. #else
  3638. header = 0xac;
  3639. #endif
  3640. nullpo_retv(sd);
  3641. fd=sd->fd;
  3642. WFIFOHEAD(fd, packet_len(header));
  3643. WFIFOW(fd,offs+0) = header;
  3644. WFIFOW(fd,offs+2) = n+2;
  3645. #if PACKETVER >= 20130000
  3646. WFIFOL(fd,offs+4) = pos;
  3647. offs += 2;
  3648. #else
  3649. WFIFOW(fd,offs+4) = pos;
  3650. #endif
  3651. WFIFOB(fd,offs+6) = ok;
  3652. WFIFOSET(fd, packet_len(header));
  3653. }
  3654. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3655. /// 019b <id>.L <effect id>.L
  3656. /// effect id:
  3657. /// 0 = base level up
  3658. /// 1 = job level up
  3659. /// 2 = refine failure
  3660. /// 3 = refine success
  3661. /// 4 = game over
  3662. /// 5 = pharmacy success
  3663. /// 6 = pharmacy failure
  3664. /// 7 = base level up (super novice)
  3665. /// 8 = job level up (super novice)
  3666. /// 9 = base level up (taekwon)
  3667. void clif_misceffect(struct block_list* bl,int type)
  3668. {
  3669. unsigned char buf[32];
  3670. nullpo_retv(bl);
  3671. WBUFW(buf,0) = 0x19b;
  3672. WBUFL(buf,2) = bl->id;
  3673. WBUFL(buf,6) = type;
  3674. clif_send(buf,packet_len(0x19b),bl,AREA);
  3675. }
  3676. /// Notifies clients in the area of a state change.
  3677. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3678. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3679. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3680. nullpo_retv( bl );
  3681. struct status_change* sc = status_get_sc( bl );
  3682. //How can an option change if there's no sc?
  3683. if( sc == nullptr ){
  3684. return;
  3685. }
  3686. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3687. struct PACKET_ZC_STATE_CHANGE p;
  3688. p.packetType = HEADER_ZC_STATE_CHANGE;
  3689. p.AID = bl->id;
  3690. p.bodyState = sc->opt1;
  3691. p.healthState = sc->opt2;
  3692. p.effectState = sc->option;
  3693. p.isPKModeON = sd ? sd->status.karma : false;
  3694. if( target == nullptr ){
  3695. if( disguised( bl ) ){
  3696. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3697. p.AID = disguised_bl_id( p.AID );
  3698. clif_send( &p, sizeof( p ), bl, SELF );
  3699. p.AID = disguised_bl_id( p.AID );
  3700. p.effectState = OPTION_INVISIBLE;
  3701. clif_send( &p, sizeof( p ), bl, SELF );
  3702. }else{
  3703. clif_send( &p, sizeof( p ), bl, AREA );
  3704. }
  3705. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3706. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3707. if( sc->data[SC_PROVOKE] ){
  3708. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3709. clif_status_change( bl, StatusIconChangeTable[SC_PROVOKE], 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3710. }
  3711. }else{
  3712. if( disguised( bl ) ){
  3713. p.AID = disguised_bl_id( p.AID );
  3714. clif_send( &p, sizeof( p ), target, SELF );
  3715. p.AID = disguised_bl_id( p.AID );
  3716. p.effectState = OPTION_INVISIBLE;
  3717. clif_send( &p, sizeof( p ), target, SELF );
  3718. }else{
  3719. clif_send( &p, sizeof( p ), target, SELF );
  3720. }
  3721. }
  3722. }
  3723. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3724. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3725. void clif_changeoption2(struct block_list* bl)
  3726. {
  3727. unsigned char buf[20];
  3728. struct status_change *sc;
  3729. sc = status_get_sc(bl);
  3730. if (!sc) return; //How can an option change if there's no sc?
  3731. WBUFW(buf,0) = 0x28a;
  3732. WBUFL(buf,2) = bl->id;
  3733. WBUFL(buf,6) = sc->option;
  3734. WBUFL(buf,10) = clif_setlevel(bl);
  3735. WBUFL(buf,14) = sc->opt3;
  3736. if(disguised(bl)) {
  3737. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3738. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3739. clif_send(buf,packet_len(0x28a),bl,SELF);
  3740. WBUFL(buf,2) = bl->id;
  3741. WBUFL(buf,6) = OPTION_INVISIBLE;
  3742. clif_send(buf,packet_len(0x28a),bl,SELF);
  3743. } else
  3744. clif_send(buf,packet_len(0x28a),bl,AREA);
  3745. }
  3746. /// Notifies the client about the result of an item use request.
  3747. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3748. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3749. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3750. nullpo_retv( sd );
  3751. int fd = sd->fd;
  3752. if( !session_isActive( fd ) ){
  3753. return;
  3754. }
  3755. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3756. return;
  3757. }
  3758. struct PACKET_ZC_USE_ITEM_ACK p;
  3759. p.packetType = useItemAckType;
  3760. p.index = index + 2;
  3761. #if PACKETVER > 3
  3762. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3763. p.AID = sd->bl.id;
  3764. #endif
  3765. p.amount = amount;
  3766. p.result = ok;
  3767. if( !ok ){
  3768. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3769. }else{
  3770. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3771. }
  3772. }
  3773. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3774. /// 00d6 <flag>.B
  3775. /// flag:
  3776. /// 0 = Room has been successfully created (opens chat room)
  3777. /// 1 = Room limit exceeded
  3778. /// 2 = Same room already exists
  3779. void clif_createchat(struct map_session_data* sd, int flag)
  3780. {
  3781. int fd;
  3782. nullpo_retv(sd);
  3783. fd = sd->fd;
  3784. WFIFOHEAD(fd,packet_len(0xd6));
  3785. WFIFOW(fd,0) = 0xd6;
  3786. WFIFOB(fd,2) = flag;
  3787. WFIFOSET(fd,packet_len(0xd6));
  3788. }
  3789. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3790. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3791. /// type:
  3792. /// 0 = private (password protected)
  3793. /// 1 = public
  3794. /// 2 = arena (npc waiting room)
  3795. /// 3 = PK zone (non-clickable)
  3796. void clif_dispchat(struct chat_data* cd, int fd)
  3797. {
  3798. unsigned char buf[128];
  3799. uint8 type;
  3800. if( cd == NULL || cd->owner == NULL )
  3801. return;
  3802. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3803. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3804. : 1;
  3805. WBUFW(buf, 0) = 0xd7;
  3806. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3807. WBUFL(buf, 4) = cd->owner->id;
  3808. WBUFL(buf, 8) = cd->bl.id;
  3809. WBUFW(buf,12) = cd->limit;
  3810. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3811. WBUFB(buf,16) = type;
  3812. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3813. if( session_isActive(fd) ) {
  3814. WFIFOHEAD(fd,WBUFW(buf,2));
  3815. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3816. WFIFOSET(fd,WBUFW(buf,2));
  3817. } else {
  3818. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3819. }
  3820. }
  3821. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3822. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3823. /// type:
  3824. /// 0 = private (password protected)
  3825. /// 1 = public
  3826. /// 2 = arena (npc waiting room)
  3827. /// 3 = PK zone (non-clickable)
  3828. void clif_changechatstatus(struct chat_data* cd)
  3829. {
  3830. unsigned char buf[128];
  3831. uint8 type;
  3832. if( cd == NULL || cd->usersd[0] == NULL )
  3833. return;
  3834. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3835. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3836. : 1;
  3837. WBUFW(buf, 0) = 0xdf;
  3838. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3839. WBUFL(buf, 4) = cd->owner->id;
  3840. WBUFL(buf, 8) = cd->bl.id;
  3841. WBUFW(buf,12) = cd->limit;
  3842. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3843. WBUFB(buf,16) = type;
  3844. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3845. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3846. }
  3847. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3848. /// 00d8 <chat id>.L
  3849. void clif_clearchat(struct chat_data *cd,int fd)
  3850. {
  3851. unsigned char buf[32];
  3852. nullpo_retv(cd);
  3853. WBUFW(buf,0) = 0xd8;
  3854. WBUFL(buf,2) = cd->bl.id;
  3855. if( session_isActive(fd) ) {
  3856. WFIFOHEAD(fd,packet_len(0xd8));
  3857. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3858. WFIFOSET(fd,packet_len(0xd8));
  3859. } else {
  3860. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3861. }
  3862. }
  3863. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3864. /// 00da <result>.B
  3865. /// result:
  3866. /// 0 = room full
  3867. /// 1 = wrong password
  3868. /// 2 = kicked
  3869. /// 3 = success (no message)
  3870. /// 4 = no enough zeny
  3871. /// 5 = too low level
  3872. /// 6 = too high level
  3873. /// 7 = unsuitable job class
  3874. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3875. {
  3876. int fd;
  3877. nullpo_retv(sd);
  3878. fd = sd->fd;
  3879. WFIFOHEAD(fd,packet_len(0xda));
  3880. WFIFOW(fd,0) = 0xda;
  3881. WFIFOB(fd,2) = flag;
  3882. WFIFOSET(fd,packet_len(0xda));
  3883. }
  3884. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3885. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3886. /// role:
  3887. /// 0 = owner (menu)
  3888. /// 1 = normal
  3889. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3890. {
  3891. int fd;
  3892. int i,t;
  3893. nullpo_retv(sd);
  3894. nullpo_retv(cd);
  3895. fd = sd->fd;
  3896. if (!session_isActive(fd))
  3897. return;
  3898. t = (int)(cd->owner->type == BL_NPC);
  3899. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3900. WFIFOW(fd, 0) = 0xdb;
  3901. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3902. WFIFOL(fd, 4) = cd->bl.id;
  3903. if(cd->owner->type == BL_NPC){
  3904. WFIFOL(fd, 30) = 1;
  3905. WFIFOL(fd, 8) = 0;
  3906. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3907. for (i = 0; i < cd->users; i++) {
  3908. WFIFOL(fd, 8+(i+1)*28) = 1;
  3909. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3910. }
  3911. }else{
  3912. for (i = 0; i < cd->users; i++) {
  3913. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3914. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3915. }
  3916. }
  3917. WFIFOSET(fd, WFIFOW(fd, 2));
  3918. }
  3919. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3920. /// 00dc <users>.W <name>.24B
  3921. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3922. {
  3923. unsigned char buf[29];
  3924. nullpo_retv(sd);
  3925. nullpo_retv(cd);
  3926. WBUFW(buf, 0) = 0xdc;
  3927. WBUFW(buf, 2) = cd->users;
  3928. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3929. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3930. }
  3931. /// Announce the new owner (ZC_ROLE_CHANGE).
  3932. /// 00e1 <role>.L <nick>.24B
  3933. /// role:
  3934. /// 0 = owner (menu)
  3935. /// 1 = normal
  3936. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3937. {
  3938. unsigned char buf[64];
  3939. nullpo_retv(sd);
  3940. nullpo_retv(cd);
  3941. WBUFW(buf, 0) = 0xe1;
  3942. WBUFL(buf, 2) = 1;
  3943. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3944. WBUFW(buf,30) = 0xe1;
  3945. WBUFL(buf,32) = 0;
  3946. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3947. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3948. }
  3949. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3950. /// 00dd <users>.W <nick>.24B <flag>.B
  3951. /// flag:
  3952. /// 0 = left
  3953. /// 1 = kicked
  3954. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3955. {
  3956. unsigned char buf[32];
  3957. nullpo_retv(sd);
  3958. nullpo_retv(cd);
  3959. WBUFW(buf, 0) = 0xdd;
  3960. WBUFW(buf, 2) = cd->users-1;
  3961. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3962. WBUFB(buf,28) = flag;
  3963. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3964. }
  3965. /// Opens a trade request window from char 'name'.
  3966. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3967. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3968. void clif_traderequest(struct map_session_data* sd, const char* name)
  3969. {
  3970. int fd = sd->fd;
  3971. #if PACKETVER < 6
  3972. WFIFOHEAD(fd,packet_len(0xe5));
  3973. WFIFOW(fd,0) = 0xe5;
  3974. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3975. WFIFOSET(fd,packet_len(0xe5));
  3976. #else
  3977. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3978. if( !tsd ) return;
  3979. WFIFOHEAD(fd,packet_len(0x1f4));
  3980. WFIFOW(fd,0) = 0x1f4;
  3981. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3982. WFIFOL(fd,26) = tsd->status.char_id;
  3983. WFIFOW(fd,30) = tsd->status.base_level;
  3984. WFIFOSET(fd,packet_len(0x1f4));
  3985. #endif
  3986. }
  3987. /// Reply to a trade-request.
  3988. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3989. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3990. /// result:
  3991. /// 0 = Char is too far
  3992. /// 1 = Character does not exist
  3993. /// 2 = Trade failed
  3994. /// 3 = Accept
  3995. /// 4 = Cancel
  3996. /// 5 = Busy
  3997. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3998. {
  3999. int fd = sd->fd;
  4000. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  4001. if( PACKETVER < 6 || !tsd ) {
  4002. WFIFOHEAD(fd,packet_len(0xe7));
  4003. WFIFOW(fd,0) = 0xe7;
  4004. WFIFOB(fd,2) = type;
  4005. WFIFOSET(fd,packet_len(0xe7));
  4006. } else {
  4007. WFIFOHEAD(fd,packet_len(0x1f5));
  4008. WFIFOW(fd,0) = 0x1f5;
  4009. WFIFOB(fd,2) = type;
  4010. WFIFOL(fd,3) = tsd->status.char_id;
  4011. WFIFOW(fd,7) = tsd->status.base_level;
  4012. WFIFOSET(fd,packet_len(0x1f5));
  4013. }
  4014. }
  4015. /// Notifies the client about an item from other player in current trade.
  4016. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4017. /// 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)
  4018. /// 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)
  4019. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  4020. nullpo_retv( sd );
  4021. nullpo_retv( tsd );
  4022. int fd = tsd->fd;
  4023. if( !session_isActive( fd ) ){
  4024. return;
  4025. }
  4026. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4027. if( index ){
  4028. index = server_index( index );
  4029. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4030. return;
  4031. }
  4032. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4033. #if PACKETVER >= 20100223
  4034. p.itemType = sd->inventory_data[index]->type;
  4035. #endif
  4036. p.identified = sd->inventory.u.items_inventory[index].identify;
  4037. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4038. p.refine = sd->inventory.u.items_inventory[index].refine;
  4039. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4040. #if PACKETVER >= 20150226
  4041. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  4042. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4043. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4044. p.look = sd->inventory_data[index]->look;
  4045. p.enchantgrade = sd->inventory.u.items_inventory[index].enchantgrade;
  4046. #endif
  4047. #endif
  4048. }else{
  4049. p = {};
  4050. }
  4051. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4052. p.amount = amount;
  4053. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4054. }
  4055. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4056. /// 00ea <index>.W <result>.B
  4057. /// result:
  4058. /// 0 = success
  4059. /// 1 = overweight
  4060. /// 2 = trade canceled
  4061. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  4062. {
  4063. int fd;
  4064. nullpo_retv(sd);
  4065. fd = sd->fd;
  4066. WFIFOHEAD(fd,packet_len(0xea));
  4067. WFIFOW(fd,0) = 0xea;
  4068. WFIFOW(fd,2) = index;
  4069. WFIFOB(fd,4) = fail;
  4070. WFIFOSET(fd,packet_len(0xea));
  4071. }
  4072. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4073. /// 00ec <who>.B
  4074. /// who:
  4075. /// 0 = self
  4076. /// 1 = other player
  4077. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4078. {
  4079. int fd;
  4080. nullpo_retv(sd);
  4081. fd = sd->fd;
  4082. WFIFOHEAD(fd,packet_len(0xec));
  4083. WFIFOW(fd,0) = 0xec;
  4084. WFIFOB(fd,2) = fail;
  4085. WFIFOSET(fd,packet_len(0xec));
  4086. }
  4087. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4088. /// 00ee
  4089. void clif_tradecancelled(struct map_session_data* sd)
  4090. {
  4091. int fd;
  4092. nullpo_retv(sd);
  4093. fd = sd->fd;
  4094. WFIFOHEAD(fd,packet_len(0xee));
  4095. WFIFOW(fd,0) = 0xee;
  4096. WFIFOSET(fd,packet_len(0xee));
  4097. }
  4098. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4099. /// 00f0 <result>.B
  4100. /// result:
  4101. /// 0 = success
  4102. /// 1 = failure
  4103. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4104. {
  4105. int fd;
  4106. nullpo_retv(sd);
  4107. fd = sd->fd;
  4108. WFIFOHEAD(fd,packet_len(0xf0));
  4109. WFIFOW(fd,0) = 0xf0;
  4110. WFIFOB(fd,2) = fail;
  4111. WFIFOSET(fd,packet_len(0xf0));
  4112. }
  4113. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4114. /// 00f1
  4115. /// NOTE: Unknown purpose. Items are not removed until the window is
  4116. /// refreshed (ex. by putting another item in there).
  4117. void clif_tradeundo(struct map_session_data* sd)
  4118. {
  4119. int fd = sd->fd;
  4120. WFIFOHEAD(fd,packet_len(0xf1));
  4121. WFIFOW(fd,0) = 0xf1;
  4122. WFIFOSET(fd,packet_len(0xf1));
  4123. }
  4124. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4125. /// 00f2 <current count>.W <max count>.W
  4126. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4127. {
  4128. int fd;
  4129. nullpo_retv(sd);
  4130. fd=sd->fd;
  4131. WFIFOHEAD(fd,packet_len(0xf2));
  4132. WFIFOW(fd,0) = 0xf2;
  4133. WFIFOW(fd,2) = amount;
  4134. WFIFOW(fd,4) = max_amount;
  4135. WFIFOSET(fd,packet_len(0xf2));
  4136. }
  4137. /// Notifies the client of an item being added to the storage.
  4138. /// 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)
  4139. /// 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)
  4140. /// 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)
  4141. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4142. nullpo_retv( sd );
  4143. nullpo_retv( i );
  4144. int fd = sd->fd;
  4145. if( !session_isActive( fd ) ){
  4146. return;
  4147. }
  4148. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4149. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4150. p.index = client_storage_index( index ); // index
  4151. p.amount = amount; // amount
  4152. p.itemId = client_nameid( i->nameid ); // id
  4153. #if PACKETVER >= 5
  4154. p.itemType = itemtype( i->nameid ); //type
  4155. #endif
  4156. p.identified = i->identify; //identify flag
  4157. p.damaged = i->attribute; // attribute
  4158. p.refine = i->refine; //refine
  4159. clif_addcards( &p.slot, i );
  4160. #if PACKETVER >= 20150226
  4161. clif_add_random_options( p.option_data, i );
  4162. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4163. p.enchantgrade = i->enchantgrade;
  4164. #endif
  4165. #endif
  4166. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4167. }
  4168. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4169. /// 00f6 <index>.W <amount>.L
  4170. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4171. {
  4172. int fd;
  4173. nullpo_retv(sd);
  4174. fd=sd->fd;
  4175. WFIFOHEAD(fd,packet_len(0xf6));
  4176. WFIFOW(fd,0)=0xf6; // Storage item removed
  4177. WFIFOW(fd,2)=client_storage_index(index);
  4178. WFIFOL(fd,4)=amount;
  4179. WFIFOSET(fd,packet_len(0xf6));
  4180. }
  4181. /// Closes storage (ZC_CLOSE_STORE).
  4182. /// 00f8
  4183. void clif_storageclose(struct map_session_data* sd)
  4184. {
  4185. int fd;
  4186. nullpo_retv(sd);
  4187. fd=sd->fd;
  4188. WFIFOHEAD(fd,packet_len(0xf8));
  4189. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4190. WFIFOSET(fd,packet_len(0xf8));
  4191. }
  4192. /// Notifies clients in an area of a player's souls.
  4193. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4194. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4195. /// 0b73 <id>.L <amount>.W
  4196. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4197. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4198. struct PACKET_ZC_UNCONFIRMED_SPIRITS3 p = {};
  4199. p.packetType = HEADER_ZC_UNCONFIRMED_SPIRITS3;
  4200. #else
  4201. struct PACKET_ZC_SPIRITS p = {};
  4202. p.packetType = HEADER_ZC_SPIRITS;
  4203. #endif
  4204. p.GID = sd->bl.id;
  4205. p.amount = sd->soulball;
  4206. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4207. }
  4208. /*==========================================
  4209. * Server tells 'sd' player client the abouts of 'dstsd' player
  4210. *------------------------------------------*/
  4211. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4212. {
  4213. struct block_list *d_bl;
  4214. int i;
  4215. if( dstsd->chatID ) {
  4216. struct chat_data *cd = NULL;
  4217. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4218. clif_dispchat(cd,sd->fd);
  4219. } else if( dstsd->state.vending )
  4220. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4221. else if( dstsd->state.buyingstore )
  4222. clif_buyingstore_entry_single(sd, dstsd);
  4223. if(dstsd->spiritball > 0)
  4224. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4225. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4226. clif_millenniumshield_single(sd->fd, dstsd);
  4227. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4228. clif_spiritcharm_single(sd->fd, dstsd);
  4229. if (dstsd->soulball > 0)
  4230. clif_soulball( dstsd, &sd->bl, SELF );
  4231. if (dstsd->servantball > 0)
  4232. clif_servantball( *dstsd, &sd->bl, SELF );
  4233. if (dstsd->abyssball > 0)
  4234. clif_abyssball( *dstsd, &sd->bl, SELF );
  4235. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4236. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4237. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4238. )
  4239. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4240. // display link (sd - dstsd) to sd
  4241. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4242. if( i < MAX_DEVOTION )
  4243. clif_devotion(&sd->bl, sd);
  4244. // display links (dstsd - devotees) to sd
  4245. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4246. if( i < MAX_DEVOTION )
  4247. clif_devotion(&dstsd->bl, sd);
  4248. // display link (dstsd - crusader) to sd
  4249. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4250. clif_devotion(d_bl, sd);
  4251. }
  4252. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4253. struct unit_data *ud;
  4254. struct view_data *vd;
  4255. bool option = false;
  4256. unsigned int option_val = 0;
  4257. vd = status_get_viewdata(bl);
  4258. if (!vd || vd->class_ == JT_INVISIBLE)
  4259. return;
  4260. // Hide NPC from Maya Purple card
  4261. if (clif_npc_mayapurple(bl))
  4262. return;
  4263. ud = unit_bl2ud(bl);
  4264. if( ud && ud->walktimer != INVALID_TIMER ){
  4265. clif_set_unit_walking( bl, sd, ud, SELF );
  4266. }else{
  4267. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4268. }
  4269. if (vd->cloth_color)
  4270. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4271. if (vd->body_style)
  4272. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4273. switch (bl->type)
  4274. {
  4275. case BL_PC:
  4276. {
  4277. TBL_PC* tsd = (TBL_PC*)bl;
  4278. clif_getareachar_pc(sd, tsd);
  4279. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4280. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4281. else if(tsd->state.size==SZ_MEDIUM)
  4282. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4283. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4284. clif_sendbgemblem_single(sd->fd,tsd);
  4285. if ( tsd->status.robe )
  4286. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4287. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4288. clif_hat_effects(sd,bl,SELF);
  4289. }
  4290. break;
  4291. case BL_MER: // Devotion Effects
  4292. if( ((TBL_MER*)bl)->devotion_flag )
  4293. clif_devotion(bl, sd);
  4294. break;
  4295. case BL_NPC:
  4296. {
  4297. TBL_NPC* nd = (TBL_NPC*)bl;
  4298. if( nd->chat_id )
  4299. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4300. if( nd->size == SZ_BIG )
  4301. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4302. else if( nd->size == SZ_MEDIUM )
  4303. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4304. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4305. clif_progressbar_npc(nd, sd);
  4306. }
  4307. break;
  4308. case BL_MOB:
  4309. {
  4310. TBL_MOB* md = (TBL_MOB*)bl;
  4311. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4312. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4313. else if(md->special_state.size==SZ_MEDIUM)
  4314. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4315. #if PACKETVER >= 20120404
  4316. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4317. int i;
  4318. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4319. if( md->dmglog[i].id == sd->status.char_id )
  4320. clif_monster_hp_bar(md, sd->fd);
  4321. }
  4322. #endif
  4323. }
  4324. break;
  4325. case BL_PET:
  4326. if (vd->head_bottom)
  4327. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4328. break;
  4329. }
  4330. }
  4331. //Modifies the type of damage according to status changes [Skotlex]
  4332. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4333. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4334. {
  4335. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4336. }
  4337. /*==========================================
  4338. * Estimates walk delay based on the damage criteria. [Skotlex]
  4339. *------------------------------------------*/
  4340. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4341. {
  4342. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4343. return 0;
  4344. if (bl->type == BL_PC) {
  4345. if (battle_config.pc_walk_delay_rate != 100)
  4346. delay = delay*battle_config.pc_walk_delay_rate/100;
  4347. } else
  4348. if (battle_config.walk_delay_rate != 100)
  4349. delay = delay*battle_config.walk_delay_rate/100;
  4350. if (div_ > 1) //Multi-hit skills mean higher delays.
  4351. delay += battle_config.multihit_delay*(div_-1);
  4352. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4353. }
  4354. /*========================================== [Playtester]
  4355. * Returns hallucination damage the client displays
  4356. *------------------------------------------*/
  4357. static int clif_hallucination_damage()
  4358. {
  4359. int digit = rnd() % 5 + 1;
  4360. switch (digit)
  4361. {
  4362. case 1:
  4363. return (rnd() % 10);
  4364. case 2:
  4365. return (rnd() % 100);
  4366. case 3:
  4367. return (rnd() % 1000);
  4368. case 4:
  4369. return (rnd() % 10000);
  4370. }
  4371. return (rnd() % 32767);
  4372. }
  4373. /// Sends a 'damage' packet (src performs action on dst)
  4374. /// 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)
  4375. /// 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)
  4376. /// 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)
  4377. /// type:
  4378. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4379. /// 1 = pick up item
  4380. /// 2 = sit down
  4381. /// 3 = stand up
  4382. /// 4 = damage (endure)
  4383. /// 5 = (splash?)
  4384. /// 6 = (skill?)
  4385. /// 7 = (repeat damage?)
  4386. /// 8 = multi-hit damage
  4387. /// 9 = multi-hit damage (endure)
  4388. /// 10 = critical hit
  4389. /// 11 = lucky dodge
  4390. /// 12 = (touch skill?)
  4391. /// 13 = multi-hit critical
  4392. 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)
  4393. {
  4394. unsigned char buf[34];
  4395. struct status_change *sc;
  4396. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4397. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4398. #if PACKETVER < 20071113
  4399. const int cmd = 0x8a;
  4400. int offset = 0;
  4401. #elif PACKETVER < 20131223
  4402. const int cmd = 0x2e1;
  4403. int offset = 2;
  4404. #else
  4405. const int cmd = 0x8c8;
  4406. int offset = 3;
  4407. #endif
  4408. nullpo_ret(src);
  4409. nullpo_ret(dst);
  4410. if (type != DMG_MULTI_HIT_CRITICAL)
  4411. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4412. sc = status_get_sc(dst);
  4413. if(sc && sc->count) {
  4414. if(sc->data[SC_HALLUCINATION]) {
  4415. if(damage) damage = clif_hallucination_damage();
  4416. if(damage2) damage2 = clif_hallucination_damage();
  4417. }
  4418. }
  4419. WBUFW(buf,0) = cmd;
  4420. WBUFL(buf,2) = src->id;
  4421. WBUFL(buf,6) = dst->id;
  4422. WBUFL(buf,10) = client_tick(tick);
  4423. WBUFL(buf,14) = sdelay;
  4424. WBUFL(buf,18) = ddelay;
  4425. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4426. #if PACKETVER < 20071113
  4427. WBUFW(buf,22) = damage ? div : 0;
  4428. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4429. #else
  4430. WBUFL(buf, 22) = damage ? div : 0;
  4431. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4432. #endif
  4433. } else {
  4434. #if PACKETVER < 20071113
  4435. WBUFW(buf,22) = min(damage, INT16_MAX);
  4436. WBUFW(buf,27+offset) = damage2;
  4437. #else
  4438. WBUFL(buf,22) = damage;
  4439. WBUFL(buf,27+offset) = damage2;
  4440. #endif
  4441. }
  4442. #if PACKETVER >= 20131223
  4443. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4444. #endif
  4445. WBUFW(buf,24+offset) = div;
  4446. WBUFB(buf,26+offset) = type;
  4447. if(disguised(dst)) {
  4448. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4449. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4450. clif_send(buf, packet_len(cmd), dst, SELF);
  4451. } else
  4452. clif_send(buf, packet_len(cmd), dst, AREA);
  4453. if(disguised(src)) {
  4454. WBUFL(buf,2) = disguised_bl_id( src->id );
  4455. if (disguised(dst))
  4456. WBUFL(buf,6) = dst->id;
  4457. #if PACKETVER < 20071113
  4458. if(damage > 0) WBUFW(buf,22) = -1;
  4459. if(damage2 > 0) WBUFW(buf,27) = -1;
  4460. #else
  4461. if(damage > 0) WBUFL(buf,22) = -1;
  4462. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4463. #endif
  4464. clif_send(buf,packet_len(cmd),src,SELF);
  4465. }
  4466. if(src == dst) {
  4467. unit_setdir(src, unit_getdir(src));
  4468. }
  4469. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4470. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4471. //Return adjusted can't walk delay for further processing.
  4472. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4473. }
  4474. /*==========================================
  4475. * src picks up dst
  4476. *------------------------------------------*/
  4477. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4478. {
  4479. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4480. unsigned char buf[32];
  4481. nullpo_retv(src);
  4482. nullpo_retv(dst);
  4483. WBUFW(buf, 0) = 0x8a;
  4484. WBUFL(buf, 2) = src->id;
  4485. WBUFL(buf, 6) = dst->id;
  4486. WBUFB(buf,26) = 1;
  4487. clif_send(buf, packet_len(0x8a), src, AREA);
  4488. }
  4489. /*==========================================
  4490. * inform clients in area that `bl` is sitting
  4491. *------------------------------------------*/
  4492. void clif_sitting(struct block_list* bl)
  4493. {
  4494. unsigned char buf[32];
  4495. nullpo_retv(bl);
  4496. WBUFW(buf, 0) = 0x8a;
  4497. WBUFL(buf, 2) = bl->id;
  4498. WBUFB(buf,26) = 2;
  4499. clif_send(buf, packet_len(0x8a), bl, AREA);
  4500. if(disguised(bl)) {
  4501. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4502. clif_send(buf, packet_len(0x8a), bl, SELF);
  4503. }
  4504. }
  4505. /*==========================================
  4506. * inform clients in area that `bl` is standing
  4507. *------------------------------------------*/
  4508. void clif_standing(struct block_list* bl)
  4509. {
  4510. unsigned char buf[32];
  4511. nullpo_retv(bl);
  4512. WBUFW(buf, 0) = 0x8a;
  4513. WBUFL(buf, 2) = bl->id;
  4514. WBUFB(buf,26) = 3;
  4515. clif_send(buf, packet_len(0x8a), bl, AREA);
  4516. if(disguised(bl)) {
  4517. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4518. clif_send(buf, packet_len(0x8a), bl, SELF);
  4519. }
  4520. }
  4521. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4522. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4523. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4524. {
  4525. unsigned char buf[32];
  4526. WBUFW(buf,0) = 0x192;
  4527. WBUFW(buf,2) = x;
  4528. WBUFW(buf,4) = y;
  4529. WBUFW(buf,6) = type;
  4530. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4531. if( session_isActive(fd) )
  4532. {
  4533. WFIFOHEAD(fd,packet_len(0x192));
  4534. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4535. WFIFOSET(fd,packet_len(0x192));
  4536. }
  4537. else
  4538. {
  4539. struct block_list dummy_bl;
  4540. dummy_bl.type = BL_NUL;
  4541. dummy_bl.x = x;
  4542. dummy_bl.y = y;
  4543. dummy_bl.m = m;
  4544. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4545. }
  4546. }
  4547. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4548. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4549. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4550. nullpo_retv( sd );
  4551. nullpo_retv( fitem );
  4552. struct PACKET_ZC_ITEM_ENTRY p;
  4553. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4554. p.AID = fitem->bl.id;
  4555. p.itemId = client_nameid( fitem->item.nameid );
  4556. p.identify = fitem->item.identify;
  4557. p.x = fitem->bl.x;
  4558. p.y = fitem->bl.y;
  4559. p.amount = fitem->item.amount;
  4560. p.subX = fitem->subx;
  4561. p.subY = fitem->suby;
  4562. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4563. }
  4564. /// Notifes client about Graffiti
  4565. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4566. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4567. unsigned char buf[128];
  4568. nullpo_retv(bl);
  4569. nullpo_retv(unit);
  4570. WBUFW(buf, 0) = 0x1c9;
  4571. WBUFL(buf, 2) = unit->bl.id;
  4572. WBUFL(buf, 6) = unit->group->src_id;
  4573. WBUFW(buf,10) = unit->bl.x;
  4574. WBUFW(buf,12) = unit->bl.y;
  4575. WBUFB(buf,14) = unit->group->unit_id;
  4576. WBUFB(buf,15) = 1;
  4577. WBUFB(buf,16) = 1;
  4578. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4579. clif_send(buf,packet_len(0x1c9),bl,target);
  4580. }
  4581. /// Notifies the client of a skill unit.
  4582. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4583. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4584. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4585. /// 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)
  4586. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4587. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4588. unsigned char buf[128];
  4589. nullpo_retv(bl);
  4590. nullpo_retv(unit);
  4591. if (bl->type == BL_PC)
  4592. fd = ((TBL_PC*)bl)->fd;
  4593. if (unit->group->state.guildaura)
  4594. return;
  4595. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4596. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4597. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4598. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4599. else
  4600. unit_id = unit->group->unit_id;
  4601. if (!visible)
  4602. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4603. #if PACKETVER >= 3
  4604. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4605. clif_graffiti(bl, unit, target);
  4606. return;
  4607. }
  4608. #endif
  4609. #if PACKETVER <= 20120702
  4610. header = 0x011f;
  4611. //#if PACKETVER < 20110718
  4612. // header = 0x011f;
  4613. //#elif PACKETVER < 20121212
  4614. // header = 0x08c7;
  4615. #elif PACKETVER < 20130731
  4616. header = 0x099f;
  4617. #else
  4618. header = 0x09ca;
  4619. #endif
  4620. len = packet_len(header);
  4621. WBUFW(buf,pos) = header;
  4622. if (header != 0x011f) {
  4623. WBUFW(buf, pos+2) = len;
  4624. pos += 2;
  4625. }
  4626. WBUFL(buf,pos+2) = unit->bl.id;
  4627. WBUFL(buf,pos+6) = unit->group->src_id;
  4628. WBUFW(buf,pos+10) = unit->bl.x;
  4629. WBUFW(buf,pos+12) = unit->bl.y;
  4630. switch (header) {
  4631. case 0x011f:
  4632. WBUFB(buf,pos+14) = unit_id;
  4633. WBUFB(buf,pos+15) = visible;
  4634. break;
  4635. case 0x08c7:
  4636. WBUFB(buf,pos+14) = unit_id;
  4637. WBUFW(buf,pos+15) = unit->range;
  4638. WBUFB(buf,pos+17) = visible;
  4639. break;
  4640. case 0x099f:
  4641. WBUFL(buf,pos+14) = unit_id;
  4642. WBUFW(buf,pos+18) = unit->range;
  4643. WBUFB(buf,pos+20) = visible;
  4644. break;
  4645. case 0x09ca:
  4646. WBUFL(buf,pos+14) = unit_id;
  4647. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4648. WBUFB(buf,pos+19) = visible;
  4649. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4650. break;
  4651. }
  4652. clif_send(buf, len, bl, target);
  4653. if (unit->group->skill_id == WZ_ICEWALL)
  4654. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4655. }
  4656. /// 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)
  4657. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4658. unsigned char buf[128];
  4659. nullpo_retv(bl);
  4660. WBUFW(buf, 0) = 0x09ca;
  4661. WBUFW(buf, 2) = packet_len(0x09ca);
  4662. WBUFL(buf, 4) = 1000;
  4663. WBUFL(buf, 8) = 2000;
  4664. WBUFW(buf, 12) = x;
  4665. WBUFW(buf, 14) = y;
  4666. WBUFL(buf, 16) = unit_id;
  4667. WBUFB(buf, 20) = (unsigned char)range;
  4668. WBUFB(buf, 21) = 1;
  4669. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4670. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4671. }
  4672. /*==========================================
  4673. * Server tells client to remove unit of id 'unit->bl.id'
  4674. *------------------------------------------*/
  4675. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4676. {
  4677. nullpo_retv(unit);
  4678. WFIFOHEAD(fd,packet_len(0x120));
  4679. WFIFOW(fd, 0)=0x120;
  4680. WFIFOL(fd, 2)=unit->bl.id;
  4681. WFIFOSET(fd,packet_len(0x120));
  4682. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4683. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4684. }
  4685. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4686. /// 0120 <id>.L
  4687. void clif_skill_delunit(struct skill_unit *unit)
  4688. {
  4689. unsigned char buf[16];
  4690. nullpo_retv(unit);
  4691. WBUFW(buf, 0)=0x120;
  4692. WBUFL(buf, 2)=unit->bl.id;
  4693. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4694. }
  4695. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4696. /// 01ac <id>.L
  4697. /// Only affects units with class [139,153] client-side.
  4698. void clif_skillunit_update(struct block_list* bl)
  4699. {
  4700. unsigned char buf[6];
  4701. nullpo_retv(bl);
  4702. WBUFW(buf,0) = 0x1ac;
  4703. WBUFL(buf,2) = bl->id;
  4704. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4705. }
  4706. /*==========================================
  4707. *
  4708. *------------------------------------------*/
  4709. static int clif_getareachar(struct block_list* bl,va_list ap)
  4710. {
  4711. struct map_session_data *sd;
  4712. nullpo_ret(bl);
  4713. sd=va_arg(ap,struct map_session_data*);
  4714. if (!clif_session_isValid(sd))
  4715. return 0;
  4716. switch(bl->type){
  4717. case BL_ITEM:
  4718. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4719. break;
  4720. case BL_SKILL:
  4721. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4722. break;
  4723. default:
  4724. if(&sd->bl == bl)
  4725. break;
  4726. clif_getareachar_unit(sd,bl);
  4727. break;
  4728. }
  4729. return 0;
  4730. }
  4731. /*==========================================
  4732. * tbl has gone out of view-size of bl
  4733. *------------------------------------------*/
  4734. int clif_outsight(struct block_list *bl,va_list ap)
  4735. {
  4736. struct block_list *tbl;
  4737. struct view_data *vd;
  4738. TBL_PC *sd, *tsd;
  4739. tbl=va_arg(ap,struct block_list*);
  4740. if(bl == tbl) return 0;
  4741. sd = BL_CAST(BL_PC, bl);
  4742. tsd = BL_CAST(BL_PC, tbl);
  4743. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4744. nullpo_ret(bl);
  4745. switch(bl->type){
  4746. case BL_PC:
  4747. if(sd->vd.class_ != JT_INVISIBLE)
  4748. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4749. if(sd->chatID){
  4750. struct chat_data *cd;
  4751. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4752. if(cd->usersd[0]==sd)
  4753. clif_dispchat(cd,tsd->fd);
  4754. }
  4755. if(sd->state.vending)
  4756. clif_closevendingboard(bl,tsd->fd);
  4757. if(sd->state.buyingstore)
  4758. clif_buyingstore_disappear_entry_single(tsd, sd);
  4759. break;
  4760. case BL_ITEM:
  4761. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4762. break;
  4763. case BL_SKILL:
  4764. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4765. break;
  4766. case BL_NPC:
  4767. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4768. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4769. break;
  4770. default:
  4771. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4772. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4773. break;
  4774. }
  4775. }
  4776. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4777. nullpo_ret(tbl);
  4778. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4779. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4780. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4781. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4782. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4783. }
  4784. return 0;
  4785. }
  4786. /*==========================================
  4787. * tbl has come into view of bl
  4788. *------------------------------------------*/
  4789. int clif_insight(struct block_list *bl,va_list ap)
  4790. {
  4791. struct block_list *tbl;
  4792. TBL_PC *sd, *tsd;
  4793. tbl=va_arg(ap,struct block_list*);
  4794. if (bl == tbl) return 0;
  4795. sd = BL_CAST(BL_PC, bl);
  4796. tsd = BL_CAST(BL_PC, tbl);
  4797. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4798. switch(bl->type){
  4799. case BL_ITEM:
  4800. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4801. break;
  4802. case BL_SKILL:
  4803. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4804. break;
  4805. default:
  4806. clif_getareachar_unit(tsd,bl);
  4807. break;
  4808. }
  4809. }
  4810. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4811. clif_getareachar_unit(sd,tbl);
  4812. }
  4813. return 0;
  4814. }
  4815. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4816. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4817. void clif_skillinfoblock(struct map_session_data *sd)
  4818. {
  4819. int fd;
  4820. int i,len,id;
  4821. nullpo_retv(sd);
  4822. fd = sd->fd;
  4823. if (!session_isActive(fd))
  4824. return;
  4825. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4826. WFIFOW(fd,0) = 0x10f;
  4827. bool haveCallPartnerSkill = false;
  4828. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4829. {
  4830. if( (id = sd->status.skill[i].id) != 0 )
  4831. {
  4832. // workaround for bugreport:5348
  4833. if (len + 37 > 8192)
  4834. break;
  4835. // skip WE_CALLPARTNER and send it in special way
  4836. if (id == WE_CALLPARTNER) {
  4837. haveCallPartnerSkill = true;
  4838. continue;
  4839. }
  4840. WFIFOW(fd,len) = id;
  4841. WFIFOL(fd,len+2) = skill_get_inf(id);
  4842. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4843. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4844. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4845. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4846. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4847. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4848. else
  4849. WFIFOB(fd,len+36) = 0;
  4850. len += 37;
  4851. }
  4852. }
  4853. WFIFOW(fd,2)=len;
  4854. WFIFOSET(fd,len);
  4855. // adoption fix
  4856. if (haveCallPartnerSkill) {
  4857. clif_addskill(sd, WE_CALLPARTNER);
  4858. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4859. }
  4860. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4861. for ( ; i < MAX_SKILL; i++)
  4862. {
  4863. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4864. {
  4865. clif_addskill(sd, id);
  4866. clif_skillinfo(sd, id, 0);
  4867. }
  4868. }
  4869. }
  4870. /**
  4871. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4872. **/
  4873. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4874. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4875. void clif_addskill(struct map_session_data *sd, int skill_id)
  4876. {
  4877. nullpo_retv(sd);
  4878. int fd = sd->fd;
  4879. uint16 idx = skill_get_index(skill_id);
  4880. if (!session_isActive(fd) || !idx)
  4881. return;
  4882. if( sd->status.skill[idx].id <= 0 )
  4883. return;
  4884. WFIFOHEAD(fd, packet_len(0x111));
  4885. WFIFOW(fd,0) = 0x111;
  4886. WFIFOW(fd,2) = skill_id;
  4887. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4888. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4889. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4890. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4891. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4892. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4893. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4894. else
  4895. WFIFOB(fd,38) = 0;
  4896. WFIFOSET(fd,packet_len(0x111));
  4897. }
  4898. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4899. /// 0441 <skill id>.W
  4900. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4901. {
  4902. #if PACKETVER >= 20081217
  4903. nullpo_retv(sd);
  4904. int fd = sd->fd;
  4905. uint16 idx = skill_get_index(skill_id);
  4906. if (!session_isActive(fd) || !idx)
  4907. return;
  4908. WFIFOHEAD(fd,packet_len(0x441));
  4909. WFIFOW(fd,0) = 0x441;
  4910. WFIFOW(fd,2) = skill_id;
  4911. WFIFOSET(fd,packet_len(0x441));
  4912. #endif
  4913. clif_skillinfoblock(sd);
  4914. }
  4915. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4916. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4917. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4918. nullpo_retv(sd);
  4919. int fd = sd->fd;
  4920. uint16 idx = skill_get_index(skill_id);
  4921. if (!session_isActive(fd) || !idx)
  4922. return;
  4923. WFIFOHEAD(fd, packet_len(0x10e));
  4924. WFIFOW(fd, 0) = 0x10e;
  4925. WFIFOW(fd, 2) = skill_id;
  4926. WFIFOW(fd, 4) = lv;
  4927. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4928. WFIFOW(fd, 8) = range;
  4929. WFIFOB(fd, 10) = upgradable;
  4930. WFIFOSET(fd, packet_len(0x10e));
  4931. }
  4932. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4933. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4934. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4935. {
  4936. nullpo_retv(sd);
  4937. const int fd = sd->fd;
  4938. uint16 idx = skill_get_index(skill_id);
  4939. if (!session_isActive(fd) || !idx)
  4940. return;
  4941. WFIFOHEAD(fd,packet_len(0x7e1));
  4942. WFIFOW(fd,0) = 0x7e1;
  4943. WFIFOW(fd,2) = skill_id;
  4944. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4945. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4946. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4947. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4948. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4949. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4950. else
  4951. WFIFOB(fd,14) = 0;
  4952. WFIFOSET(fd,packet_len(0x7e1));
  4953. }
  4954. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4955. #if PACKETVER >= 20151223
  4956. if( !battle_config.show_skill_scale ){
  4957. return;
  4958. }
  4959. struct PACKET_ZC_SKILL_SCALE p;
  4960. p.PacketType = skillscale;
  4961. p.AID = src_id;
  4962. p.skill_id = skill_id;
  4963. p.skill_lv = skill_lv;
  4964. p.x = x;
  4965. p.y = y;
  4966. p.casttime = casttime;
  4967. if( disguised( bl ) ){
  4968. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4969. p.AID = disguised_bl_id( bl->id );
  4970. clif_send( &p, sizeof( p ), bl, SELF );
  4971. }else{
  4972. clif_send( &p, sizeof( p ), bl, AREA );
  4973. }
  4974. #endif
  4975. }
  4976. /// Notifies clients in area, that an object is about to use a skill.
  4977. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4978. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4979. /// property:
  4980. /// 0 = Yellow cast aura
  4981. /// 1 = Water elemental cast aura
  4982. /// 2 = Earth elemental cast aura
  4983. /// 3 = Fire elemental cast aura
  4984. /// 4 = Wind elemental cast aura
  4985. /// 5 = Poison elemental cast aura
  4986. /// 6 = Holy elemental cast aura
  4987. /// ? = like 0
  4988. /// is disposable:
  4989. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4990. /// 1 = no text
  4991. 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)
  4992. {
  4993. #if PACKETVER < 20091124
  4994. const int cmd = 0x13e;
  4995. #else
  4996. const int cmd = 0x7fb;
  4997. #endif
  4998. unsigned char buf[32];
  4999. WBUFW(buf,0) = cmd;
  5000. WBUFL(buf,2) = src_id;
  5001. WBUFL(buf,6) = dst_id;
  5002. WBUFW(buf,10) = dst_x;
  5003. WBUFW(buf,12) = dst_y;
  5004. WBUFW(buf,14) = skill_id;
  5005. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5006. WBUFL(buf,20) = casttime;
  5007. #if PACKETVER >= 20091124
  5008. WBUFB(buf,24) = 0; // isDisposable
  5009. #endif
  5010. if (disguised(bl)) {
  5011. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5012. WBUFL(buf,2) = disguised_bl_id( src_id );
  5013. clif_send(buf,packet_len(cmd), bl, SELF);
  5014. } else
  5015. clif_send(buf,packet_len(cmd), bl, AREA);
  5016. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5017. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5018. }
  5019. }
  5020. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5021. /// 01b9 <id>.L
  5022. void clif_skillcastcancel(struct block_list* bl)
  5023. {
  5024. unsigned char buf[16];
  5025. nullpo_retv(bl);
  5026. WBUFW(buf,0) = 0x1b9;
  5027. WBUFL(buf,2) = bl->id;
  5028. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5029. }
  5030. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5031. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5032. /// num (only used when skill id = NV_BASIC and cause = 0):
  5033. /// 0 = "skill failed" MsgStringTable[159]
  5034. /// 1 = "no emotions" MsgStringTable[160]
  5035. /// 2 = "no sit" MsgStringTable[161]
  5036. /// 3 = "no chat" MsgStringTable[162]
  5037. /// 4 = "no party" MsgStringTable[163]
  5038. /// 5 = "no shout" MsgStringTable[164]
  5039. /// 6 = "no PKing" MsgStringTable[165]
  5040. /// 7 = "no alligning" MsgStringTable[383]
  5041. /// ? = ignored
  5042. /// cause:
  5043. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5044. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5045. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5046. /// "skill failed" MsgStringTable[204] (otherwise)
  5047. /// ... = @see enum useskill_fail_cause
  5048. /// ? = ignored
  5049. ///
  5050. /// if(result!=0) doesn't display any of the previous messages
  5051. /// Note: when this packet is received an unknown flag is always set to 0,
  5052. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5053. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5054. nullpo_retv( sd );
  5055. int fd = sd->fd;
  5056. if( !session_isActive( fd ) ){
  5057. return;
  5058. }
  5059. if(battle_config.display_skill_fail&1)
  5060. return; //Disable all skill failed messages
  5061. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5062. return; //Disable delay failed messages
  5063. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5064. return;
  5065. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5066. return;
  5067. struct PACKET_ZC_ACK_TOUSESKILL p;
  5068. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5069. p.skillId = skill_id;
  5070. p.btype = btype;
  5071. p.itemId = itemId;
  5072. p.flag = 0; // 0 - failed
  5073. p.cause = cause;
  5074. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5075. }
  5076. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5077. /// 043d <skill ID>.W <tick>.L
  5078. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5079. {
  5080. #if PACKETVER>=20081112
  5081. int fd;
  5082. nullpo_retv(sd);
  5083. fd=sd->fd;
  5084. WFIFOHEAD(fd,packet_len(0x43d));
  5085. WFIFOW(fd,0) = 0x43d;
  5086. WFIFOW(fd,2) = skill_id;
  5087. WFIFOL(fd,4) = client_tick(tick);
  5088. WFIFOSET(fd,packet_len(0x43d));
  5089. #endif
  5090. }
  5091. /// Skill attack effect and damage.
  5092. /// 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)
  5093. /// 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)
  5094. 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)
  5095. {
  5096. unsigned char buf[64];
  5097. struct status_change *sc;
  5098. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5099. nullpo_ret(src);
  5100. nullpo_ret(dst);
  5101. type = clif_calc_delay(type,div,damage,ddelay);
  5102. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5103. if(sc->data[SC_HALLUCINATION] && damage)
  5104. damage = clif_hallucination_damage();
  5105. }
  5106. #if PACKETVER < 3
  5107. WBUFW(buf,0)=0x114;
  5108. WBUFW(buf,2)=skill_id;
  5109. WBUFL(buf,4)=src->id;
  5110. WBUFL(buf,8)=dst->id;
  5111. WBUFL(buf,12)=client_tick(tick);
  5112. WBUFL(buf,16)=sdelay;
  5113. WBUFL(buf,20)=ddelay;
  5114. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5115. WBUFW(buf,24)=damage?div:0;
  5116. } else {
  5117. WBUFW(buf,24)=damage;
  5118. }
  5119. WBUFW(buf,26)=skill_lv;
  5120. WBUFW(buf,28)=div;
  5121. WBUFB(buf,30)=type;
  5122. if (disguised(dst)) {
  5123. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5124. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5125. clif_send(buf,packet_len(0x114),dst,SELF);
  5126. } else
  5127. clif_send(buf,packet_len(0x114),dst,AREA);
  5128. if(disguised(src)) {
  5129. WBUFL(buf,4)=disguised_bl_id(src->id);
  5130. if (disguised(dst))
  5131. WBUFL(buf,8)=dst->id;
  5132. if(damage > 0)
  5133. WBUFW(buf,24)=-1;
  5134. clif_send(buf,packet_len(0x114),src,SELF);
  5135. }
  5136. #else
  5137. WBUFW(buf,0)=0x1de;
  5138. WBUFW(buf,2)=skill_id;
  5139. WBUFL(buf,4)=src->id;
  5140. WBUFL(buf,8)=dst->id;
  5141. WBUFL(buf,12)=client_tick(tick);
  5142. WBUFL(buf,16)=sdelay;
  5143. WBUFL(buf,20)=ddelay;
  5144. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5145. WBUFL(buf,24)=damage?div:0;
  5146. } else {
  5147. WBUFL(buf,24)=damage;
  5148. }
  5149. WBUFW(buf,28)=skill_lv;
  5150. WBUFW(buf,30)=div;
  5151. // For some reason, late 2013 and newer clients have
  5152. // a issue that causes players and monsters to endure
  5153. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5154. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5155. #if PACKETVER < 20131223
  5156. WBUFB(buf,32)=type;
  5157. #else
  5158. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5159. #endif
  5160. if (disguised(dst)) {
  5161. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5162. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5163. clif_send(buf,packet_len(0x1de),dst,SELF);
  5164. } else
  5165. clif_send(buf,packet_len(0x1de),dst,AREA);
  5166. if(disguised(src)) {
  5167. WBUFL(buf,4)=disguised_bl_id(src->id);
  5168. if (disguised(dst))
  5169. WBUFL(buf,8)=dst->id;
  5170. if(damage > 0)
  5171. WBUFL(buf,24)=-1;
  5172. clif_send(buf,packet_len(0x1de),src,SELF);
  5173. }
  5174. #endif
  5175. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5176. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5177. }
  5178. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5179. /// 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
  5180. /*
  5181. 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)
  5182. {
  5183. unsigned char buf[64];
  5184. struct status_change *sc;
  5185. nullpo_ret(src);
  5186. nullpo_ret(dst);
  5187. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5188. type = clif_calc_delay(type,div,damage,ddelay);
  5189. sc = status_get_sc(dst);
  5190. if(sc && sc->count) {
  5191. if(sc->data[SC_HALLUCINATION] && damage)
  5192. damage = clif_hallucination_damage();
  5193. }
  5194. WBUFW(buf,0)=0x115;
  5195. WBUFW(buf,2)=skill_id;
  5196. WBUFL(buf,4)=src->id;
  5197. WBUFL(buf,8)=dst->id;
  5198. WBUFL(buf,12)=client_tick(tick);
  5199. WBUFL(buf,16)=sdelay;
  5200. WBUFL(buf,20)=ddelay;
  5201. WBUFW(buf,24)=dst->x;
  5202. WBUFW(buf,26)=dst->y;
  5203. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5204. WBUFW(buf,28)=damage?div:0;
  5205. } else {
  5206. WBUFW(buf,28)=damage;
  5207. }
  5208. WBUFW(buf,30)=skill_lv;
  5209. WBUFW(buf,32)=div;
  5210. WBUFB(buf,34)=type;
  5211. clif_send(buf,packet_len(0x115),src,AREA);
  5212. if(disguised(src)) {
  5213. WBUFL(buf,4)=disguised_bl_id(src->id);
  5214. if(damage > 0)
  5215. WBUFW(buf,28)=-1;
  5216. clif_send(buf,packet_len(0x115),src,SELF);
  5217. }
  5218. if (disguised(dst)) {
  5219. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5220. if (disguised(src))
  5221. WBUFL(buf,4)=src->id;
  5222. else if(damage > 0)
  5223. WBUFW(buf,28)=-1;
  5224. clif_send(buf,packet_len(0x115),dst,SELF);
  5225. }
  5226. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5227. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5228. }
  5229. */
  5230. /// Non-damaging skill effect
  5231. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5232. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5233. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5234. {
  5235. unsigned char buf[17];
  5236. #if PACKETVER < 20130731
  5237. const int cmd = 0x11a;
  5238. #else
  5239. const int cmd = 0x9cb;
  5240. #endif
  5241. int offset = 0;
  5242. bool success = ( tick != 0 );
  5243. nullpo_ret(dst);
  5244. WBUFW(buf,0) = cmd;
  5245. WBUFW(buf,2) = skill_id;
  5246. #if PACKETVER < 20130731
  5247. WBUFW(buf,4) = min(heal, INT16_MAX);
  5248. #else
  5249. WBUFL(buf,4) = min(heal, INT32_MAX);
  5250. offset += 2;
  5251. #endif
  5252. WBUFL(buf,6+offset) = dst->id;
  5253. WBUFL(buf,10+offset) = src ? src->id : 0;
  5254. WBUFB(buf,14+offset) = success;
  5255. if (disguised(dst)) {
  5256. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5257. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5258. clif_send(buf, packet_len(cmd), dst, SELF);
  5259. } else
  5260. clif_send(buf, packet_len(cmd), dst, AREA);
  5261. if(src && disguised(src)) {
  5262. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5263. if (disguised(dst))
  5264. WBUFL(buf,6+offset) = dst->id;
  5265. clif_send(buf, packet_len(cmd), src, SELF);
  5266. }
  5267. return success;
  5268. }
  5269. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5270. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5271. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5272. {
  5273. unsigned char buf[32];
  5274. nullpo_retv(src);
  5275. WBUFW(buf,0)=0x117;
  5276. WBUFW(buf,2)=skill_id;
  5277. WBUFL(buf,4)=src->id;
  5278. WBUFW(buf,8)=val;
  5279. WBUFW(buf,10)=x;
  5280. WBUFW(buf,12)=y;
  5281. WBUFL(buf,14)=client_tick(tick);
  5282. if(disguised(src)) {
  5283. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5284. WBUFL(buf,4)=disguised_bl_id(src->id);
  5285. clif_send(buf,packet_len(0x117),src,SELF);
  5286. } else
  5287. clif_send(buf,packet_len(0x117),src,AREA);
  5288. }
  5289. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5290. /// 011c <skill id>.W { <map name>.16B }*4
  5291. 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)
  5292. {
  5293. int fd;
  5294. nullpo_retv(sd);
  5295. fd = sd->fd;
  5296. WFIFOHEAD(fd,packet_len(0x11c));
  5297. WFIFOW(fd,0) = 0x11c;
  5298. WFIFOW(fd,2) = skill_id;
  5299. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5300. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5301. else // normal map name
  5302. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5303. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5304. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5305. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5306. WFIFOSET(fd,packet_len(0x11c));
  5307. sd->menuskill_id = skill_id;
  5308. if (skill_id == AL_WARP) {
  5309. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5310. sd->state.workinprogress = WIP_DISABLE_ALL;
  5311. } else
  5312. sd->menuskill_val = skill_lv;
  5313. }
  5314. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5315. /// 011e <type>.B
  5316. /// type:
  5317. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5318. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5319. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5320. ///
  5321. /// @param sd Who receives the message
  5322. /// @param type What message
  5323. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5324. {
  5325. int fd;
  5326. nullpo_retv(sd);
  5327. fd=sd->fd;
  5328. WFIFOHEAD(fd,packet_len(0x11e));
  5329. WFIFOW(fd,0)=0x11e;
  5330. WFIFOB(fd,2)=type;
  5331. WFIFOSET(fd,packet_len(0x11e));
  5332. }
  5333. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5334. /// 0189 <type>.W
  5335. /// type:
  5336. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5337. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5338. ///
  5339. /// @param sd Who receives the message
  5340. /// @param type What message
  5341. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5342. {
  5343. int fd;
  5344. nullpo_retv(sd);
  5345. fd=sd->fd;
  5346. WFIFOHEAD(fd,packet_len(0x189));
  5347. WFIFOW(fd,0)=0x189;
  5348. WFIFOW(fd,2)=type;
  5349. WFIFOSET(fd,packet_len(0x189));
  5350. }
  5351. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5352. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5353. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5354. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5355. {
  5356. struct status_data *status;
  5357. unsigned char buf[64];
  5358. int i, fix;
  5359. nullpo_retv(sd);
  5360. nullpo_retv(dst);
  5361. if( dst->type != BL_MOB )
  5362. return;
  5363. status = status_get_status_data(dst);
  5364. WBUFW(buf, 0)=0x18c;
  5365. WBUFW(buf, 2)=status_get_class(dst);
  5366. WBUFW(buf, 4)=status_get_lv(dst);
  5367. WBUFW(buf, 6)=status->size;
  5368. WBUFL(buf, 8)=status->hp;
  5369. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5370. +(battle_config.estimation_type&2?status->def2:0);
  5371. WBUFW(buf,14)=status->race;
  5372. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5373. +(battle_config.estimation_type&2?status->mdef2:0);
  5374. WBUFW(buf,18)= status->def_ele;
  5375. for(i=0;i<9;i++)
  5376. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5377. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5378. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5379. }
  5380. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5381. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5382. /// material id:
  5383. /// unused by the client
  5384. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5385. nullpo_retv(sd);
  5386. int fd = sd->fd;
  5387. if( !session_isActive( fd ) ){
  5388. return;
  5389. }
  5390. if (sd->menuskill_id == skill_id)
  5391. return; //Avoid resending the menu twice or more times...
  5392. if (skill_id == GC_CREATENEWPOISON)
  5393. skill_id = GC_RESEARCHNEWPOISON;
  5394. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5395. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5396. p->packetType = 0x18d;
  5397. int count = 0;
  5398. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5399. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5400. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5401. )
  5402. {
  5403. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5404. p->items[count].material[0] = 0;
  5405. p->items[count].material[1] = 0;
  5406. p->items[count].material[2] = 0;
  5407. count++;
  5408. }
  5409. }
  5410. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5411. WFIFOSET( fd, p->packetLength );
  5412. if( count > 0 ){
  5413. sd->menuskill_id = skill_id;
  5414. sd->menuskill_val = trigger;
  5415. return;
  5416. }
  5417. }
  5418. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5419. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5420. /// mk type:
  5421. /// 1 = cooking
  5422. /// 2 = arrow
  5423. /// 3 = elemental
  5424. /// 4 = GN_MIX_COOKING
  5425. /// 5 = GN_MAKEBOMB
  5426. /// 6 = GN_S_PHARMACY
  5427. /// 7 = MT_M_MACHINE - Unconfirmed
  5428. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5429. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5430. nullpo_retv( sd );
  5431. // Avoid resending the menu twice or more times...
  5432. if( sd->menuskill_id == skill_id ){
  5433. return;
  5434. }
  5435. int fd = sd->fd;
  5436. if( !session_isActive( fd ) ){
  5437. return;
  5438. }
  5439. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5440. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5441. p->packetType = 0x25a;
  5442. p->makeItem = list_type; // list type
  5443. int count = 0;
  5444. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5445. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5446. continue;
  5447. }
  5448. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5449. count++;
  5450. }
  5451. if( count > 0 || skill_id == AM_PHARMACY ){
  5452. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5453. WFIFOSET( fd, p->packetLength );
  5454. sd->menuskill_id = skill_id;
  5455. sd->menuskill_val = trigger;
  5456. sd->menuskill_val2 = qty; // amount.
  5457. }else{
  5458. clif_menuskill_clear(sd);
  5459. #if PACKETVER >= 20090922
  5460. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5461. #else
  5462. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5463. WFIFOSET( fd, p->packetLength );
  5464. #endif
  5465. }
  5466. }
  5467. /// Notifies clients of a status change.
  5468. /// 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)]
  5469. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5470. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5471. /// @param bl Sends packet to clients around this object
  5472. /// @param id ID of object that has this effect
  5473. /// @param type Status icon see enum efst_types
  5474. /// @param flag 1:Active, 0:Deactive
  5475. /// @param tick Duration in ms
  5476. /// @param val1
  5477. /// @param val2
  5478. /// @param val3
  5479. 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)
  5480. {
  5481. unsigned char buf[32];
  5482. if (type == EFST_BLANK) //It shows nothing on the client...
  5483. return;
  5484. if (type == EFST_POSTDELAY && tick == 0)
  5485. return;
  5486. nullpo_retv(bl);
  5487. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5488. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5489. tick = 200;
  5490. #if PACKETVER >= 20120618
  5491. if (flag && battle_config.display_status_timers)
  5492. WBUFW(buf,0) = 0x983;
  5493. else
  5494. #elif PACKETVER >= 20090121
  5495. if (flag && battle_config.display_status_timers)
  5496. WBUFW(buf,0) = 0x43f;
  5497. else
  5498. #endif
  5499. WBUFW(buf,0) = 0x196;
  5500. WBUFW(buf,2) = type;
  5501. WBUFL(buf,4) = id;
  5502. WBUFB(buf,8) = flag;
  5503. #if PACKETVER >= 20120618
  5504. if (flag && battle_config.display_status_timers) {
  5505. if (tick <= 0)
  5506. tick = 9999; // this is indeed what official servers do
  5507. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5508. WBUFL(buf,13) = client_tick(tick);
  5509. WBUFL(buf,17) = val1;
  5510. WBUFL(buf,21) = val2;
  5511. WBUFL(buf,25) = val3;
  5512. }
  5513. #elif PACKETVER >= 20090121
  5514. if (flag && battle_config.display_status_timers) {
  5515. if (tick <= 0)
  5516. tick = 9999; // this is indeed what official servers do
  5517. WBUFL(buf,9) = client_tick(tick);
  5518. WBUFL(buf,13) = val1;
  5519. WBUFL(buf,17) = val2;
  5520. WBUFL(buf,21) = val3;
  5521. }
  5522. #endif
  5523. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5524. }
  5525. /* Sends status effect to clients around the bl
  5526. * @param bl Object that has the effect
  5527. * @param type Status icon see enum efst_types
  5528. * @param flag 1:Active, 0:Deactive
  5529. * @param tick Duration in ms
  5530. * @param val1
  5531. * @param val2
  5532. * @param val3
  5533. */
  5534. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5535. struct map_session_data *sd = NULL;
  5536. if (type == EFST_BLANK) //It shows nothing on the client...
  5537. return;
  5538. if (type == EFST_POSTDELAY && tick == 0)
  5539. return;
  5540. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5541. return;
  5542. nullpo_retv(bl);
  5543. sd = BL_CAST(BL_PC, bl);
  5544. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5545. return;
  5546. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5547. }
  5548. /**
  5549. * Send any active EFST to those around.
  5550. * @param tbl: Unit to send the packet to
  5551. * @param bl: Objects walking into view
  5552. * @param target: Client send type
  5553. */
  5554. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5555. unsigned char i;
  5556. struct sc_display_entry **sc_display;
  5557. unsigned char sc_display_count;
  5558. bool spheres_sent;
  5559. nullpo_retv(bl);
  5560. switch( bl->type ){
  5561. case BL_PC: {
  5562. struct map_session_data* sd = (struct map_session_data*)bl;
  5563. sc_display = sd->sc_display;
  5564. sc_display_count = sd->sc_display_count;
  5565. spheres_sent = !sd->state.connect_new;
  5566. }
  5567. break;
  5568. case BL_NPC: {
  5569. struct npc_data* nd = (struct npc_data*)bl;
  5570. sc_display = nd->sc_display;
  5571. sc_display_count = nd->sc_display_count;
  5572. spheres_sent = true;
  5573. }
  5574. break;
  5575. default:
  5576. return;
  5577. }
  5578. for (i = 0; i < sc_display_count; i++) {
  5579. enum sc_type type = sc_display[i]->type;
  5580. struct status_change *sc = status_get_sc(bl);
  5581. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5582. t_tick tick = 0;
  5583. if (td)
  5584. tick = DIFF_TICK(td->tick, gettick());
  5585. // Status changes that need special handling
  5586. switch( type ){
  5587. case SC_SPHERE_1:
  5588. case SC_SPHERE_2:
  5589. case SC_SPHERE_3:
  5590. case SC_SPHERE_4:
  5591. case SC_SPHERE_5:
  5592. if( spheres_sent ){
  5593. target = AREA_WOS;
  5594. }
  5595. break;
  5596. case SC_HELLS_PLANT:
  5597. if( sc && sc->data[type] ){
  5598. tick = sc->data[type]->val4;
  5599. }
  5600. break;
  5601. }
  5602. #if PACKETVER > 20120418
  5603. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5604. #else
  5605. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5606. #endif
  5607. }
  5608. }
  5609. /// Notifies the client when a player enters the screen with an active EFST.
  5610. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5611. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5612. 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) {
  5613. #if PACKETVER >= 20111108
  5614. unsigned char buf[32];
  5615. #if PACKETVER >= 20120618
  5616. const int cmd = 0x984;
  5617. #elif PACKETVER >= 20111108
  5618. const int cmd = 0x8ff;
  5619. #endif
  5620. int offset = 0;
  5621. if (type == EFST_BLANK)
  5622. return;
  5623. nullpo_retv(bl);
  5624. if (tick <= 0)
  5625. tick = 9999;
  5626. WBUFW(buf,offset + 0) = cmd;
  5627. WBUFL(buf,offset + 2) = tid;
  5628. WBUFW(buf,offset + 6) = type;
  5629. #if PACKETVER >= 20111108
  5630. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5631. #if PACKETVER >= 20120618
  5632. WBUFL(buf,offset + 12) = client_tick(tick);
  5633. offset += 4;
  5634. #endif
  5635. WBUFL(buf,offset + 12) = val1;
  5636. WBUFL(buf,offset + 16) = val2;
  5637. WBUFL(buf,offset + 20) = val3;
  5638. #endif
  5639. clif_send(buf,packet_len(cmd),bl,target);
  5640. #endif
  5641. }
  5642. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5643. /// 008e <packet len>.W <message>.?B
  5644. void clif_displaymessage(const int fd, const char* mes)
  5645. {
  5646. nullpo_retv(mes);
  5647. if( session_isActive( fd ) ){
  5648. char *message, *line;
  5649. message = aStrdup(mes);
  5650. line = strtok(message, "\n");
  5651. while(line != NULL) {
  5652. #if PACKETVER == 20141022
  5653. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5654. /** so we redirect to ZC_NPC_CHAT **/
  5655. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5656. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5657. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5658. if (len > 0) {
  5659. WFIFOHEAD(fd, 13 + len);
  5660. WFIFOW(fd, 0) = 0x2C1;
  5661. WFIFOW(fd, 2) = 13 + len;
  5662. WFIFOL(fd, 4) = 0;
  5663. WFIFOL(fd, 8) = color;
  5664. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5665. WFIFOSET(fd, WFIFOW(fd, 2));
  5666. }
  5667. #else
  5668. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5669. int len = strnlen(line, CHAT_SIZE_MAX);
  5670. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5671. WFIFOHEAD(fd, 5 + len);
  5672. WFIFOW(fd,0) = 0x8e;
  5673. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5674. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5675. WFIFOSET(fd, 5 + len);
  5676. }
  5677. #endif
  5678. line = strtok(NULL, "\n");
  5679. }
  5680. aFree(message);
  5681. }
  5682. }
  5683. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5684. /// 009a <packet len>.W <message>.?B
  5685. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5686. {
  5687. nullpo_retv(mes);
  5688. if (len < 2)
  5689. return;
  5690. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5691. p->packetType = HEADER_ZC_BROADCAST;
  5692. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5693. if( ( type&BC_BLUE ) != 0 ){
  5694. const char* color = "blue";
  5695. int16 length = (int16)strlen( color );
  5696. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5697. strcpy( p->message, color );
  5698. strncpy( &p->message[length], mes, len );
  5699. p->PacketLength += length;
  5700. }else if( ( type&BC_WOE ) != 0 ){
  5701. const char* color = "ssss";
  5702. int16 length = (int16)strlen( color );
  5703. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5704. strcpy( p->message, color );
  5705. strncpy( &p->message[length], mes, len );
  5706. p->PacketLength += length;
  5707. }else{
  5708. strncpy( p->message, mes, len );
  5709. }
  5710. clif_send( p, p->PacketLength, bl, target );
  5711. }
  5712. /*==========================================
  5713. * Displays a message on a 'bl' to all it's nearby clients
  5714. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5715. *------------------------------------------*/
  5716. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5717. nullpo_retv(bl);
  5718. nullpo_retv(message);
  5719. int16 len = (int16)( strlen( message ) + 1 );
  5720. if( len > CHAT_SIZE_MAX ) {
  5721. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5722. len = CHAT_SIZE_MAX;
  5723. }
  5724. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5725. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5726. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5727. p->GID = bl->id;
  5728. safestrncpy( p->Message, message, len );
  5729. clif_send( p, p->PacketLength, bl, target );
  5730. }
  5731. /// Send broadcast message with font formatting.
  5732. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5733. 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)
  5734. {
  5735. nullpo_retv(mes);
  5736. if (len < 2)
  5737. return;
  5738. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5739. p->packetType = HEADER_ZC_BROADCAST2;
  5740. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5741. p->fontColor = fontColor;
  5742. p->fontType = fontType;
  5743. p->fontSize = fontSize;
  5744. p->fontAlign = fontAlign;
  5745. p->fontY = fontY;
  5746. strncpy( p->message, mes, len );
  5747. clif_send( p, p->PacketLength, bl, target );
  5748. }
  5749. /*
  5750. * Display *msg to all *users in channel
  5751. */
  5752. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5753. DBIterator *iter;
  5754. struct map_session_data *user;
  5755. unsigned short msg_len = 0, len = 0;
  5756. unsigned char buf[CHAT_SIZE_MAX];
  5757. if (!channel || !msg)
  5758. return;
  5759. msg_len = (unsigned short)(strlen(msg) + 1);
  5760. if( msg_len > sizeof(buf)-12 ) {
  5761. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5762. msg_len = sizeof(buf)-12;
  5763. }
  5764. WBUFW(buf,0) = 0x2C1;
  5765. WBUFW(buf,2) = (len = msg_len + 12);
  5766. WBUFL(buf,4) = 0;
  5767. WBUFL(buf,8) = color;
  5768. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5769. iter = db_iterator(channel->users);
  5770. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5771. clif_send(buf, len, &user->bl, SELF);
  5772. }
  5773. dbi_destroy(iter);
  5774. }
  5775. /// Displays heal effect.
  5776. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5777. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5778. /// var id:
  5779. /// 5 = HP (SP_HP)
  5780. /// 7 = SP (SP_SP)
  5781. /// ? = ignored
  5782. void clif_heal(int fd,int type,int val) {
  5783. #if PACKETVER < 20141022
  5784. const int cmd = 0x13d;
  5785. #else
  5786. const int cmd = 0xa27;
  5787. #endif
  5788. WFIFOHEAD(fd, packet_len(cmd));
  5789. WFIFOW(fd,0) = cmd;
  5790. WFIFOW(fd,2) = type;
  5791. #if PACKETVER < 20141022
  5792. WFIFOW(fd,4) = min(val, INT16_MAX);
  5793. #else
  5794. WFIFOL(fd,4) = min(val, INT32_MAX);
  5795. #endif
  5796. WFIFOSET(fd, packet_len(cmd));
  5797. }
  5798. /// Displays resurrection effect (ZC_RESURRECTION).
  5799. /// 0148 <id>.L <type>.W
  5800. /// type:
  5801. /// ignored
  5802. void clif_resurrection(struct block_list *bl,int type)
  5803. {
  5804. unsigned char buf[16];
  5805. nullpo_retv(bl);
  5806. WBUFW(buf,0)=0x148;
  5807. WBUFL(buf,2)=bl->id;
  5808. WBUFW(buf,6)=0;
  5809. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5810. if (disguised(bl))
  5811. clif_spawn(bl);
  5812. }
  5813. /// Sets the map property
  5814. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5815. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5816. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5817. {
  5818. #if PACKETVER >= 20121010
  5819. short cmd = 0x99b;
  5820. unsigned char buf[8];
  5821. #else
  5822. short cmd = 0x199;
  5823. unsigned char buf[4];
  5824. #endif
  5825. WBUFW(buf,0)=cmd;
  5826. WBUFW(buf,2)=property;
  5827. #if PACKETVER >= 20121010
  5828. struct map_data *mapdata = map_getmapdata(bl->m);
  5829. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0 || (bl->type == BL_PC && ((TBL_PC *)bl)->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5830. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5831. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5832. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5833. ((mapdata->flag[MF_NOLOCKON] || mapdata_flag_vs(mapdata)?1:0)<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5834. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5835. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5836. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5837. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5838. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5839. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5840. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5841. #endif
  5842. clif_send(buf,packet_len(cmd),bl,t);
  5843. }
  5844. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5845. /// 01d6 <type>.W
  5846. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5847. {
  5848. int fd;
  5849. nullpo_retv(sd);
  5850. fd=sd->fd;
  5851. WFIFOHEAD(fd,packet_len(0x1D6));
  5852. WFIFOW(fd,0)=0x1D6;
  5853. WFIFOW(fd,2)=type;
  5854. WFIFOSET(fd,packet_len(0x1D6));
  5855. }
  5856. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5857. /// 019a <id>.L <ranking>.L <total>.L
  5858. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5859. {
  5860. if(type == 2) {
  5861. int fd = sd->fd;
  5862. WFIFOHEAD(fd,packet_len(0x19a));
  5863. WFIFOW(fd,0) = 0x19a;
  5864. WFIFOL(fd,2) = sd->bl.id;
  5865. WFIFOL(fd,6) = pvprank;
  5866. WFIFOL(fd,10) = pvpnum;
  5867. WFIFOSET(fd,packet_len(0x19a));
  5868. } else {
  5869. unsigned char buf[32];
  5870. WBUFW(buf,0) = 0x19a;
  5871. WBUFL(buf,2) = sd->bl.id;
  5872. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5873. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5874. else
  5875. WBUFL(buf,6) = pvprank;
  5876. WBUFL(buf,10) = pvpnum;
  5877. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5878. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5879. else if(!type)
  5880. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5881. else
  5882. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5883. }
  5884. }
  5885. /*==========================================
  5886. *
  5887. *------------------------------------------*/
  5888. void clif_map_property_mapall(int map_idx, enum map_property property)
  5889. {
  5890. struct block_list bl;
  5891. bl.id = 0;
  5892. bl.type = BL_NUL;
  5893. bl.m = map_idx;
  5894. clif_map_property( &bl, property, ALL_SAMEMAP );
  5895. }
  5896. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5897. /// 0188 <result>.W <index>.W <refine>.W
  5898. /// result:
  5899. /// 0 = success
  5900. /// 1 = failure
  5901. /// 2 = downgrade
  5902. void clif_refine(int fd, int fail, int index, int val)
  5903. {
  5904. WFIFOHEAD(fd,packet_len(0x188));
  5905. WFIFOW(fd,0)=0x188;
  5906. WFIFOW(fd,2)=fail;
  5907. WFIFOW(fd,4)=index+2;
  5908. WFIFOW(fd,6)=val;
  5909. WFIFOSET(fd,packet_len(0x188));
  5910. }
  5911. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5912. /// 0223 <result>.L <nameid>.W
  5913. /// result:
  5914. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5915. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5916. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5917. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5918. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5919. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5920. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5921. p.result = result;
  5922. p.itemId = client_nameid( item_id );
  5923. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5924. }
  5925. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5926. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5927. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5928. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5929. int fd;
  5930. nullpo_retv(sd);
  5931. fd = sd->fd;
  5932. #if PACKETVER < 20091104
  5933. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5934. WFIFOW(fd,0) = 0x97;
  5935. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5936. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5937. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5938. WFIFOSET(fd,WFIFOW(fd,2));
  5939. #else
  5940. struct map_session_data *ssd = map_nick2sd(nick,false);
  5941. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5942. WFIFOW(fd,0) = 0x97;
  5943. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5944. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5945. // If it is not a message from the server or a player from another map-server
  5946. if( ssd ){
  5947. gmlvl = pc_get_group_level(ssd);
  5948. }
  5949. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5950. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5951. WFIFOSET(fd,WFIFOW(fd,2));
  5952. #endif
  5953. }
  5954. /// Inform the player about the result of his whisper action
  5955. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5956. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5957. /// result:
  5958. /// 0 = success to send wisper
  5959. /// 1 = target character is not loged in
  5960. /// 2 = ignored by target
  5961. /// 3 = everyone ignored by target
  5962. void clif_wis_end(int fd, int result)
  5963. {
  5964. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5965. #if PACKETVER < 20131223
  5966. const int cmd = 0x98;
  5967. #else
  5968. const int cmd = 0x9df;
  5969. #endif
  5970. if (!sd)
  5971. return;
  5972. WFIFOHEAD(fd,packet_len(cmd));
  5973. WFIFOW(fd,0) = cmd;
  5974. WFIFOB(fd,2) = (char)result;
  5975. #if PACKETVER >= 20131223
  5976. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5977. #endif
  5978. WFIFOSET(fd,packet_len(cmd));
  5979. }
  5980. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5981. /// 0194 <char id>.L <name>.24B
  5982. /// 0af7 <flag>.W <char id>.L <name>.24B
  5983. void clif_solved_charname(int fd, int charid, const char* name)
  5984. {
  5985. #if PACKETVER >= 20180221
  5986. WFIFOHEAD(fd,packet_len(0xaf7));
  5987. WFIFOW(fd,0) = 0xaf7;
  5988. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5989. WFIFOL(fd,4) = charid;
  5990. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5991. WFIFOSET(fd,packet_len(0x0af7));
  5992. #else
  5993. WFIFOHEAD(fd,packet_len(0x194));
  5994. WFIFOW(fd,0)=0x194;
  5995. WFIFOL(fd,2)=charid;
  5996. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5997. WFIFOSET(fd,packet_len(0x194));
  5998. #endif
  5999. }
  6000. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6001. /// 017b <packet len>.W { <name id>.W }*
  6002. void clif_use_card(struct map_session_data *sd,int idx)
  6003. {
  6004. int i,c,ep;
  6005. int fd=sd->fd;
  6006. nullpo_retv(sd);
  6007. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6008. return;
  6009. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6010. return; //Avoid parsing invalid item indexes (no card/no item)
  6011. ep=sd->inventory_data[idx]->equip;
  6012. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6013. WFIFOW(fd,0)=0x17b;
  6014. for(i=c=0;i<MAX_INVENTORY;i++){
  6015. int j;
  6016. if(sd->inventory_data[i] == NULL)
  6017. continue;
  6018. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6019. continue;
  6020. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6021. continue;
  6022. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6023. continue;
  6024. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6025. continue;
  6026. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6027. continue;
  6028. 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.
  6029. continue;
  6030. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6031. if( j == sd->inventory_data[i]->slots ) // No room
  6032. continue;
  6033. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6034. continue;
  6035. WFIFOW(fd,4+c*2)=i+2;
  6036. c++;
  6037. }
  6038. if( !c ) return; // no item is available for card insertion
  6039. WFIFOW(fd,2)=4+c*2;
  6040. WFIFOSET(fd,WFIFOW(fd,2));
  6041. }
  6042. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6043. /// 017d <equip index>.W <card index>.W <result>.B
  6044. /// result:
  6045. /// 0 = success
  6046. /// 1 = failure
  6047. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  6048. {
  6049. int fd;
  6050. nullpo_retv(sd);
  6051. fd=sd->fd;
  6052. WFIFOHEAD(fd,packet_len(0x17d));
  6053. WFIFOW(fd,0)=0x17d;
  6054. WFIFOW(fd,2)=idx_equip+2;
  6055. WFIFOW(fd,4)=idx_card+2;
  6056. WFIFOB(fd,6)=flag;
  6057. WFIFOSET(fd,packet_len(0x17d));
  6058. }
  6059. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6060. /// 0177 <packet len>.W { <index>.W }*
  6061. void clif_item_identify_list(struct map_session_data *sd)
  6062. {
  6063. int i,c;
  6064. int fd;
  6065. nullpo_retv(sd);
  6066. fd=sd->fd;
  6067. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6068. WFIFOW(fd,0)=0x177;
  6069. for(i=c=0;i<MAX_INVENTORY;i++){
  6070. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6071. WFIFOW(fd,c*2+4)=client_index(i);
  6072. c++;
  6073. }
  6074. }
  6075. if(c > 0) {
  6076. WFIFOW(fd,2)=c*2+4;
  6077. WFIFOSET(fd,WFIFOW(fd,2));
  6078. sd->menuskill_id = MC_IDENTIFY;
  6079. sd->menuskill_val = c;
  6080. sd->state.workinprogress = WIP_DISABLE_ALL;
  6081. }
  6082. }
  6083. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6084. /// 0179 <index>.W <result>.B
  6085. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6086. {
  6087. int fd;
  6088. nullpo_retv(sd);
  6089. fd=sd->fd;
  6090. WFIFOHEAD(fd,packet_len(0x179));
  6091. WFIFOW(fd, 0)=0x179;
  6092. WFIFOW(fd, 2)=idx+2;
  6093. WFIFOB(fd, 4)=flag;
  6094. WFIFOSET(fd,packet_len(0x179));
  6095. }
  6096. /// Presents a list of items that can be repaired.
  6097. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6098. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6099. nullpo_retv( sd );
  6100. nullpo_retv( dstsd );
  6101. int fd = sd->fd;
  6102. if( !session_isActive( fd ) ){
  6103. return;
  6104. }
  6105. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6106. // Preallocate the maximum size
  6107. WFIFOHEAD( fd, len );
  6108. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6109. int c = 0;
  6110. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6111. 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)){
  6112. p->items[c].index = i;
  6113. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6114. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6115. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6116. c++;
  6117. }
  6118. }
  6119. if( c > 0 ){
  6120. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6121. // Recalculate real length
  6122. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6123. p->packetLength = len;
  6124. WFIFOSET( fd, len );
  6125. sd->menuskill_id = BS_REPAIRWEAPON;
  6126. sd->menuskill_val = dstsd->bl.id;
  6127. sd->menuskill_val2 = lv;
  6128. }else{
  6129. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6130. }
  6131. }
  6132. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6133. /// 01fe <index>.W <result>.B
  6134. /// index:
  6135. /// ignored (inventory index)
  6136. /// result:
  6137. /// 0 = Item repair success.
  6138. /// 1 = Item repair failure.
  6139. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6140. {
  6141. int fd;
  6142. nullpo_retv(sd);
  6143. fd = sd->fd;
  6144. WFIFOHEAD(fd,packet_len(0x1fe));
  6145. WFIFOW(fd, 0)=0x1fe;
  6146. WFIFOW(fd, 2)=idx+2;
  6147. WFIFOB(fd, 4)=flag;
  6148. WFIFOSET(fd,packet_len(0x1fe));
  6149. }
  6150. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6151. /// 02bb <equip location>.W <account id>.L
  6152. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6153. {
  6154. int fd = sd->fd;
  6155. WFIFOHEAD(fd,packet_len(0x2bb));
  6156. WFIFOW(fd,0) = 0x2bb;
  6157. WFIFOW(fd,2) = position;
  6158. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6159. WFIFOSET(fd,packet_len(0x2bb));
  6160. }
  6161. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6162. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6163. void clif_item_refine_list( struct map_session_data *sd ){
  6164. nullpo_retv( sd );
  6165. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6166. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6167. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6168. int refine_item[MAX_WEAPON_LEVEL];
  6169. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6170. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6171. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6172. #ifdef RENEWAL
  6173. refine_item[4] = -1;
  6174. #endif
  6175. int count = 0;
  6176. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6177. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6178. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6179. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6180. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6181. p->items[count].index = client_index( i );
  6182. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6183. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6184. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6185. count++;
  6186. }
  6187. }
  6188. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6189. clif_send( p, p->packetLength, &sd->bl, SELF );
  6190. if( count > 0 ){
  6191. sd->menuskill_id = WS_WEAPONREFINE;
  6192. sd->menuskill_val = skill_lv;
  6193. }
  6194. }
  6195. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6196. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6197. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6198. nullpo_retv( sd );
  6199. struct PACKET_ZC_AUTORUN_SKILL p;
  6200. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6201. p.skill_id = skill_id;
  6202. p.skill_type = skill_get_inf( skill_id );
  6203. p.skill_lv = skill_lv;
  6204. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6205. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6206. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6207. p.up_flag = false;
  6208. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6209. }
  6210. /// Adds an item to character's cart.
  6211. /// 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)
  6212. /// 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)
  6213. /// 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)
  6214. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6215. nullpo_retv( sd );
  6216. int fd = sd->fd;
  6217. if( !session_isActive( fd ) ){
  6218. return;
  6219. }
  6220. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6221. return;
  6222. }
  6223. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6224. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6225. p.index = client_index( n );
  6226. p.amount = amount;
  6227. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6228. #if PACKETVER >= 5
  6229. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6230. #endif
  6231. p.identified = sd->cart.u.items_cart[n].identify;
  6232. p.damaged = sd->cart.u.items_cart[n].attribute;
  6233. p.refine = sd->cart.u.items_cart[n].refine;
  6234. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6235. #if PACKETVER >= 20150226
  6236. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6237. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6238. p.enchantgrade = sd->cart.u.items_cart[n].enchantgrade;
  6239. #endif
  6240. #endif
  6241. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6242. }
  6243. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6244. /* Acknowledge an item have been added to cart
  6245. * 012c <result>B
  6246. * result :
  6247. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6248. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6249. */
  6250. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6251. {
  6252. int fd;
  6253. unsigned char *buf;
  6254. nullpo_retv(sd);
  6255. fd = sd->fd;
  6256. buf = WFIFOP(fd,0);
  6257. WBUFW(buf,0) = 0x12c;
  6258. WBUFB(buf,2) = flag;
  6259. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6260. }
  6261. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6262. void clif_bank_open(struct map_session_data *sd){
  6263. int fd;
  6264. nullpo_retv(sd);
  6265. fd = sd->fd;
  6266. WFIFOHEAD(fd,4);
  6267. WFIFOW(fd,0) = 0x09b7;
  6268. WFIFOW(fd,2) = 0;
  6269. WFIFOSET(fd,4);
  6270. }
  6271. /*
  6272. * Request to Open the banking system
  6273. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6274. */
  6275. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6276. //TODO check if preventing trade or stuff like that
  6277. //also mark something in case char ain't available for saving, should we check now ?
  6278. nullpo_retv(sd);
  6279. if( !battle_config.feature_banking ) {
  6280. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6281. return;
  6282. }
  6283. else {
  6284. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6285. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6286. if(sd->status.account_id == aid){
  6287. sd->state.banking = 1;
  6288. //request save ?
  6289. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6290. //on succes open bank ?
  6291. clif_bank_open(sd);
  6292. }
  6293. }
  6294. }
  6295. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6296. void clif_bank_close(struct map_session_data *sd){
  6297. int fd;
  6298. nullpo_retv(sd);
  6299. fd = sd->fd;
  6300. WFIFOHEAD(fd,4);
  6301. WFIFOW(fd,0) = 0x09B9;
  6302. WFIFOW(fd,2) = 0;
  6303. WFIFOSET(fd,4);
  6304. }
  6305. /*
  6306. * Request to close the banking system
  6307. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6308. */
  6309. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6310. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6311. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6312. nullpo_retv(sd);
  6313. if( !battle_config.feature_banking ) {
  6314. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6315. //still allow to go trough to not stuck player if we have disable it while they was in
  6316. }
  6317. if(sd->status.account_id == aid){
  6318. sd->state.banking = 0;
  6319. clif_bank_close(sd);
  6320. }
  6321. }
  6322. /*
  6323. * Display how much we got in bank (I suppose)
  6324. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6325. */
  6326. void clif_Bank_Check(struct map_session_data* sd) {
  6327. unsigned char buf[13];
  6328. struct s_packet_db* info;
  6329. int16 len;
  6330. int cmd = 0;
  6331. nullpo_retv(sd);
  6332. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6333. if(!cmd) cmd = 0x09A6; //default
  6334. info = &packet_db[cmd];
  6335. len = info->len;
  6336. if(!len) return; //version as packet disable
  6337. // sd->state.banking = 1; //mark opening and closing
  6338. WBUFW(buf,0) = cmd;
  6339. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6340. WBUFW(buf,info->pos[1]) = 0; //reason
  6341. clif_send(buf,len,&sd->bl,SELF);
  6342. }
  6343. /*
  6344. * Requesting the data in bank
  6345. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6346. */
  6347. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6348. nullpo_retv(sd);
  6349. if( !battle_config.feature_banking ) {
  6350. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6351. return;
  6352. }
  6353. else {
  6354. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6355. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6356. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6357. clif_Bank_Check(sd);
  6358. }
  6359. }
  6360. /*
  6361. * Acknowledge of deposit some money in bank
  6362. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6363. */
  6364. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6365. unsigned char buf[17];
  6366. struct s_packet_db* info;
  6367. int16 len;
  6368. int cmd =0;
  6369. nullpo_retv(sd);
  6370. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6371. if(!cmd) cmd = 0x09A8;
  6372. info = &packet_db[cmd];
  6373. len = info->len;
  6374. if(!len) return; //version as packet disable
  6375. WBUFW(buf,0) = cmd;
  6376. WBUFW(buf,info->pos[0]) = (short)reason;
  6377. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6378. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6379. clif_send(buf,len,&sd->bl,SELF);
  6380. }
  6381. /*
  6382. * Request saving some money in bank
  6383. * @author : original [Yommy/Hercules]
  6384. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6385. */
  6386. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6387. nullpo_retv(sd);
  6388. if( !battle_config.feature_banking ) {
  6389. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6390. return;
  6391. }
  6392. else {
  6393. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6394. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6395. int money = RFIFOL(fd,info->pos[1]);
  6396. if(sd->status.account_id == aid){
  6397. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6398. clif_bank_deposit(sd,reason);
  6399. }
  6400. }
  6401. }
  6402. /*
  6403. * Acknowledge of withdrawing some money from bank
  6404. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6405. */
  6406. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6407. unsigned char buf[17];
  6408. struct s_packet_db* info;
  6409. int16 len;
  6410. int cmd;
  6411. nullpo_retv(sd);
  6412. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6413. if(!cmd) cmd = 0x09AA;
  6414. info = &packet_db[cmd];
  6415. len = info->len;
  6416. if(!len) return; //version as packet disable
  6417. WBUFW(buf,0) = cmd;
  6418. WBUFW(buf,info->pos[0]) = (short)reason;
  6419. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6420. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6421. clif_send(buf,len,&sd->bl,SELF);
  6422. }
  6423. /*
  6424. * Request Withdrawing some money from bank
  6425. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6426. */
  6427. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6428. nullpo_retv(sd);
  6429. if( !battle_config.feature_banking ) {
  6430. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6431. return;
  6432. }
  6433. else {
  6434. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6435. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6436. int money = RFIFOL(fd,info->pos[1]);
  6437. if(sd->status.account_id == aid){
  6438. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6439. clif_bank_withdraw(sd,reason);
  6440. }
  6441. }
  6442. }
  6443. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6444. /// 0125 <index>.W <amount>.L
  6445. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6446. {
  6447. int fd;
  6448. nullpo_retv(sd);
  6449. fd=sd->fd;
  6450. WFIFOHEAD(fd,packet_len(0x125));
  6451. WFIFOW(fd,0)=0x125;
  6452. WFIFOW(fd,2)=n+2;
  6453. WFIFOL(fd,4)=amount;
  6454. WFIFOSET(fd,packet_len(0x125));
  6455. }
  6456. /// Opens the shop creation menu (ZC_OPENSTORE).
  6457. /// 012d <num>.W
  6458. /// num:
  6459. /// number of allowed item slots
  6460. void clif_openvendingreq(struct map_session_data* sd, int num)
  6461. {
  6462. int fd;
  6463. nullpo_retv(sd);
  6464. fd = sd->fd;
  6465. WFIFOHEAD(fd,packet_len(0x12d));
  6466. WFIFOW(fd,0) = 0x12d;
  6467. WFIFOW(fd,2) = num;
  6468. WFIFOSET(fd,packet_len(0x12d));
  6469. }
  6470. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6471. /// 0131 <owner id>.L <message>.80B
  6472. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6473. {
  6474. unsigned char buf[128];
  6475. nullpo_retv(bl);
  6476. WBUFW(buf,0) = 0x131;
  6477. WBUFL(buf,2) = bl->id;
  6478. safestrncpy(WBUFCP(buf,6), message, 80);
  6479. if( session_isActive(fd) ) {
  6480. WFIFOHEAD(fd,packet_len(0x131));
  6481. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6482. WFIFOSET(fd,packet_len(0x131));
  6483. } else {
  6484. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6485. }
  6486. }
  6487. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6488. /// 0132 <owner id>.L
  6489. void clif_closevendingboard(struct block_list* bl, int fd)
  6490. {
  6491. unsigned char buf[16];
  6492. nullpo_retv(bl);
  6493. WBUFW(buf,0) = 0x132;
  6494. WBUFL(buf,2) = bl->id;
  6495. if( session_isActive(fd) ) {
  6496. WFIFOHEAD(fd,packet_len(0x132));
  6497. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6498. WFIFOSET(fd,packet_len(0x132));
  6499. } else {
  6500. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6501. }
  6502. }
  6503. /// Sends a list of items in a shop.
  6504. /// 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)
  6505. /// 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)
  6506. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6507. nullpo_retv( sd );
  6508. nullpo_retv( vsd );
  6509. nullpo_retv( vsd->vending );
  6510. int fd = sd->fd;
  6511. if( !session_isActive( fd ) ){
  6512. return;
  6513. }
  6514. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6515. WFIFOHEAD( fd, len );
  6516. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6517. p->packetType = vendinglistType;
  6518. p->packetLength = len;
  6519. p->AID = vsd->status.account_id;
  6520. #if PACKETVER >= 20100105
  6521. p->venderId = vsd->vender_id;
  6522. #endif
  6523. for( int i = 0; i < vsd->vend_num; i++ ){
  6524. int index = vsd->vending[i].index;
  6525. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6526. p->items[i].price = vsd->vending[i].value;
  6527. p->items[i].amount = vsd->vending[i].amount;
  6528. p->items[i].index = client_index( index );
  6529. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6530. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6531. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6532. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6533. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6534. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6535. #if PACKETVER >= 20150226
  6536. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6537. #if PACKETVER >= 20160921
  6538. p->items[i].location = pc_equippoint_sub( sd, data );
  6539. p->items[i].viewSprite = data->look;
  6540. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6541. p->items[i].enchantgrade = vsd->cart.u.items_cart[index].enchantgrade;
  6542. #endif
  6543. #endif
  6544. #endif
  6545. }
  6546. WFIFOSET( fd, len );
  6547. }
  6548. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6549. /// 0135 <index>.W <amount>.W <result>.B
  6550. /// result:
  6551. /// 0 = success
  6552. /// 1 = not enough zeny
  6553. /// 2 = overweight
  6554. /// 4 = out of stock
  6555. /// 5 = "cannot use an npc shop while in a trade"
  6556. /// 6 = Because the store information was incorrect the item was not purchased.
  6557. /// 7 = No sales information.
  6558. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6559. {
  6560. int fd;
  6561. nullpo_retv(sd);
  6562. fd = sd->fd;
  6563. WFIFOHEAD(fd,packet_len(0x135));
  6564. WFIFOW(fd,0) = 0x135;
  6565. WFIFOW(fd,2) = index+2;
  6566. WFIFOW(fd,4) = amount;
  6567. WFIFOB(fd,6) = fail;
  6568. WFIFOSET(fd,packet_len(0x135));
  6569. }
  6570. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6571. /// 0a28 <Result>.B
  6572. /// result:
  6573. /// 0 = Successed
  6574. /// 1 = Failed
  6575. void clif_openvending_ack(struct map_session_data* sd, int result)
  6576. {
  6577. int fd;
  6578. nullpo_retv(sd);
  6579. fd = sd->fd;
  6580. WFIFOHEAD(fd, 3);
  6581. WFIFOW(fd,0) = 0xa28;
  6582. WFIFOB(fd,2) = result;
  6583. WFIFOSET(fd, 3);
  6584. }
  6585. /// Shop creation success.
  6586. /// 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)
  6587. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6588. nullpo_retv( sd );
  6589. nullpo_retv( vending );
  6590. int fd = sd->fd;
  6591. if( !session_isActive( fd ) ){
  6592. return;
  6593. }
  6594. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6595. WFIFOHEAD( fd, len );
  6596. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6597. p->packetType = openvendingType;
  6598. p->packetLength = len;
  6599. p->AID = id;
  6600. for( int i = 0; i < sd->vend_num; i++ ) {
  6601. int index = vending[i].index;
  6602. p->items[i].price = vending[i].value;
  6603. p->items[i].index = client_index( index );
  6604. p->items[i].amount = vending[i].amount;
  6605. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6606. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6607. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6608. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6609. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6610. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6611. #if PACKETVER >= 20150226
  6612. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6613. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6614. p->items[i].enchantgrade = sd->cart.u.items_cart[index].enchantgrade;
  6615. #endif
  6616. #endif
  6617. }
  6618. WFIFOSET( fd, len );
  6619. #if PACKETVER >= 20141022
  6620. /// 0 = Successed
  6621. /// 1 = Failed
  6622. clif_openvending_ack( sd, 0 );
  6623. #endif
  6624. }
  6625. /// Inform merchant that someone has bought an item.
  6626. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6627. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6628. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6629. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6630. const int cmd = 0x137;
  6631. #else
  6632. const int cmd = 0x9e5;
  6633. #endif
  6634. int fd = sd->fd;
  6635. nullpo_retv(sd);
  6636. WFIFOHEAD(fd,packet_len(cmd));
  6637. WFIFOW(fd,0) = cmd;
  6638. WFIFOW(fd,2) = index+2;
  6639. WFIFOW(fd,4) = amount;
  6640. #if PACKETVER >= 20141016
  6641. WFIFOL(fd,6) = char_id; // GID
  6642. WFIFOL(fd,10) = (int)time(NULL); // Date
  6643. WFIFOL(fd,14) = zeny; // zeny
  6644. #endif
  6645. WFIFOSET(fd,packet_len(cmd));
  6646. }
  6647. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6648. /// 00fa <result>.B
  6649. /// result:
  6650. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6651. /// 1 = MsgStringTable[78]="party name already exists"
  6652. /// 2 = MsgStringTable[79]="already in a party"
  6653. /// 3 = cannot organize parties on this map
  6654. /// ? = nothing
  6655. void clif_party_created(struct map_session_data *sd,int result)
  6656. {
  6657. int fd;
  6658. nullpo_retv(sd);
  6659. fd=sd->fd;
  6660. WFIFOHEAD(fd,packet_len(0xfa));
  6661. WFIFOW(fd,0)=0xfa;
  6662. WFIFOB(fd,2)=result;
  6663. WFIFOSET(fd,packet_len(0xfa));
  6664. }
  6665. /// Adds new member to a party.
  6666. /// 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)
  6667. /// 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)
  6668. /// 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)
  6669. /// role:
  6670. /// 0 = leader
  6671. /// 1 = normal
  6672. /// state:
  6673. /// 0 = connected
  6674. /// 1 = disconnected
  6675. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6676. {
  6677. int i;
  6678. #if PACKETVER < 20170502
  6679. unsigned char buf[81];
  6680. int cmd = 0x1e9;
  6681. int offset = 0;
  6682. #else
  6683. unsigned char buf[85];
  6684. int cmd = 0xa43;
  6685. int offset = 4;
  6686. #endif
  6687. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6688. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6689. } else {
  6690. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6691. }
  6692. if (i >= MAX_PARTY) return; //Should never happen...
  6693. sd = p->data[i].sd;
  6694. WBUFW(buf, 0) = cmd;
  6695. WBUFL(buf, 2) = sd->status.account_id;
  6696. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6697. #if PACKETVER >= 20170502
  6698. WBUFW(buf,10) = sd->status.class_;
  6699. WBUFW(buf,12) = sd->status.base_level;
  6700. #endif
  6701. WBUFW(buf,offset+10) = sd->bl.x;
  6702. WBUFW(buf,offset+12) = sd->bl.y;
  6703. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6704. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6705. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6706. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6707. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6708. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6709. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6710. }
  6711. /// Sends party information (ZC_GROUP_LIST).
  6712. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6713. /// role:
  6714. /// 0 = leader
  6715. /// 1 = normal
  6716. /// state:
  6717. /// 0 = connected
  6718. /// 1 = disconnected
  6719. /// 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
  6720. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6721. {
  6722. struct map_session_data* party_sd = NULL;
  6723. int i, c;
  6724. #if PACKETVER < 20170502
  6725. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6726. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6727. int cmd = 0xfb;
  6728. #else
  6729. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6730. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6731. int cmd = 0xa44;
  6732. #endif
  6733. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6734. nullpo_retv(p);
  6735. WBUFW(buf,0) = cmd;
  6736. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6737. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6738. {
  6739. struct party_member* m = &p->party.member[i];
  6740. if(!m->account_id) continue;
  6741. if(party_sd == NULL) party_sd = p->data[i].sd;
  6742. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6743. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6744. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6745. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6746. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6747. #if PACKETVER >= 20170502
  6748. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6749. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6750. #endif
  6751. c++;
  6752. }
  6753. #if PACKETVER < 20170502
  6754. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6755. #else
  6756. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6757. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6758. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6759. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6760. #endif
  6761. if(sd) { // send only to self
  6762. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6763. } else if (party_sd) { // send to whole party
  6764. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6765. }
  6766. }
  6767. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6768. /// 02c9 <flag>.B
  6769. /// flag:
  6770. /// 0 = allow party invites
  6771. /// 1 = auto-deny party invites
  6772. void clif_partyinvitationstate(struct map_session_data* sd)
  6773. {
  6774. int fd;
  6775. nullpo_retv(sd);
  6776. fd = sd->fd;
  6777. WFIFOHEAD(fd, packet_len(0x2c9));
  6778. WFIFOW(fd, 0) = 0x2c9;
  6779. WFIFOB(fd, 2) = 0; // not implemented
  6780. WFIFOSET(fd, packet_len(0x2c9));
  6781. }
  6782. /// Party invitation request.
  6783. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6784. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6785. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6786. {
  6787. #if PACKETVER < 20070821
  6788. const int cmd = 0xfe;
  6789. #else
  6790. const int cmd = 0x2c6;
  6791. #endif
  6792. int fd;
  6793. struct party_data *p;
  6794. nullpo_retv(sd);
  6795. nullpo_retv(tsd);
  6796. fd=tsd->fd;
  6797. if( (p=party_search(sd->status.party_id))==NULL )
  6798. return;
  6799. WFIFOHEAD(fd,packet_len(cmd));
  6800. WFIFOW(fd,0)=cmd;
  6801. WFIFOL(fd,2)=sd->status.party_id;
  6802. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6803. WFIFOSET(fd,packet_len(cmd));
  6804. }
  6805. /// Party invite result.
  6806. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6807. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6808. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6809. {
  6810. int fd;
  6811. nullpo_retv(sd);
  6812. fd=sd->fd;
  6813. #if PACKETVER < 20070904
  6814. if( reply == PARTY_REPLY_OFFLINE ) {
  6815. clif_displaymessage(fd, msg_txt(sd,3));
  6816. return;
  6817. }
  6818. #endif
  6819. #if PACKETVER < 20070821
  6820. WFIFOHEAD(fd,packet_len(0xfd));
  6821. WFIFOW(fd,0) = 0xfd;
  6822. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6823. WFIFOB(fd,26) = reply;
  6824. WFIFOSET(fd,packet_len(0xfd));
  6825. #else
  6826. WFIFOHEAD(fd,packet_len(0x2c5));
  6827. WFIFOW(fd,0) = 0x2c5;
  6828. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6829. WFIFOL(fd,26) = reply;
  6830. WFIFOSET(fd,packet_len(0x2c5));
  6831. #endif
  6832. }
  6833. /// Updates party settings.
  6834. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6835. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6836. /// exp option:
  6837. /// 0 = exp sharing disabled
  6838. /// 1 = exp sharing enabled
  6839. /// 2 = cannot change exp sharing
  6840. ///
  6841. /// flag:
  6842. /// 0 = send to party
  6843. /// 1 = send to sd
  6844. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6845. {
  6846. unsigned char buf[16];
  6847. #if PACKETVER < 20090603
  6848. const int cmd = 0x101;
  6849. #else
  6850. const int cmd = 0x7d8;
  6851. #endif
  6852. nullpo_retv(p);
  6853. if(!sd && flag==0){
  6854. int i;
  6855. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6856. if (i < MAX_PARTY)
  6857. sd = p->data[i].sd;
  6858. }
  6859. if(!sd) return;
  6860. WBUFW(buf,0)=cmd;
  6861. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6862. #if PACKETVER >= 20090603
  6863. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6864. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6865. #endif
  6866. if(flag==0)
  6867. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6868. else
  6869. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6870. }
  6871. /**
  6872. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6873. * @param sd Send the notification for this player
  6874. * @param account_id Account ID of kicked member
  6875. * @param name Name of kicked member
  6876. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6877. * @param target Send target
  6878. **/
  6879. 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) {
  6880. unsigned char buf[2+4+NAME_LENGTH+1];
  6881. if (!sd)
  6882. return;
  6883. WBUFW(buf,0) = 0x0105;
  6884. WBUFL(buf,2) = account_id;
  6885. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6886. WBUFB(buf,6+NAME_LENGTH) = result;
  6887. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6888. }
  6889. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6890. /// 0109 <packet len>.W <account id>.L <message>.?B
  6891. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6892. {
  6893. struct map_session_data *sd;
  6894. int i;
  6895. nullpo_retv(p);
  6896. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6897. if(i < MAX_PARTY){
  6898. unsigned char buf[1024];
  6899. if( len > sizeof(buf)-8 )
  6900. {
  6901. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6902. len = sizeof(buf)-8;
  6903. }
  6904. sd = p->data[i].sd;
  6905. WBUFW(buf,0)=0x109;
  6906. WBUFW(buf,2)=len+8;
  6907. WBUFL(buf,4)=account_id;
  6908. safestrncpy(WBUFCP(buf,8), mes, len);
  6909. clif_send(buf,len+8,&sd->bl,PARTY);
  6910. }
  6911. }
  6912. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6913. /// 0107 <account id>.L <x>.W <y>.W
  6914. void clif_party_xy(struct map_session_data *sd)
  6915. {
  6916. unsigned char buf[16];
  6917. nullpo_retv(sd);
  6918. WBUFW(buf,0)=0x107;
  6919. WBUFL(buf,2)=sd->status.account_id;
  6920. WBUFW(buf,6)=sd->bl.x;
  6921. WBUFW(buf,8)=sd->bl.y;
  6922. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6923. }
  6924. /*==========================================
  6925. * Sends x/y dot to a single fd. [Skotlex]
  6926. *------------------------------------------*/
  6927. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6928. {
  6929. WFIFOHEAD(fd,packet_len(0x107));
  6930. WFIFOW(fd,0)=0x107;
  6931. WFIFOL(fd,2)=sd->status.account_id;
  6932. WFIFOW(fd,6)=sd->bl.x;
  6933. WFIFOW(fd,8)=sd->bl.y;
  6934. WFIFOSET(fd,packet_len(0x107));
  6935. }
  6936. /// Updates HP bar of a party member.
  6937. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6938. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6939. void clif_party_hp(struct map_session_data *sd)
  6940. {
  6941. unsigned char buf[16];
  6942. #if PACKETVER < 20100126
  6943. const int cmd = 0x106;
  6944. #else
  6945. const int cmd = 0x80e;
  6946. #endif
  6947. nullpo_retv(sd);
  6948. WBUFW(buf,0)=cmd;
  6949. WBUFL(buf,2)=sd->status.account_id;
  6950. #if PACKETVER < 20100126
  6951. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6952. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6953. WBUFW(buf,8) = 100;
  6954. } else {
  6955. WBUFW(buf,6) = sd->battle_status.hp;
  6956. WBUFW(buf,8) = sd->battle_status.max_hp;
  6957. }
  6958. #else
  6959. WBUFL(buf,6) = sd->battle_status.hp;
  6960. WBUFL(buf,10) = sd->battle_status.max_hp;
  6961. #endif
  6962. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6963. }
  6964. /// Notifies the party members of a character's death or revival.
  6965. /// 0AB2 <GID>.L <dead>.B
  6966. void clif_party_dead( struct map_session_data *sd ){
  6967. #if PACKETVER >= 20170502
  6968. unsigned char buf[7];
  6969. nullpo_retv(sd);
  6970. WBUFW(buf, 0) = 0xab2;
  6971. WBUFL(buf, 2) = sd->status.account_id;
  6972. WBUFB(buf, 6) = pc_isdead(sd);
  6973. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6974. #endif
  6975. }
  6976. /// Updates the job and level of a party member
  6977. /// 0abd <account id>.L <job>.W <level>.W
  6978. void clif_party_job_and_level(struct map_session_data *sd){
  6979. #if PACKETVER >= 20170502
  6980. unsigned char buf[10];
  6981. nullpo_retv(sd);
  6982. WBUFW(buf, 0) = 0xabd;
  6983. WBUFL(buf, 2) = sd->status.account_id;
  6984. WBUFW(buf, 6) = sd->status.class_;
  6985. WBUFW(buf, 8) = sd->status.base_level;
  6986. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6987. #endif
  6988. }
  6989. /*==========================================
  6990. * Sends HP bar to a single fd. [Skotlex]
  6991. *------------------------------------------*/
  6992. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6993. {
  6994. #if PACKETVER < 20100126
  6995. const int cmd = 0x106;
  6996. #else
  6997. const int cmd = 0x80e;
  6998. #endif
  6999. WFIFOHEAD(fd,packet_len(cmd));
  7000. WFIFOW(fd,0) = cmd;
  7001. WFIFOL(fd,2) = id;
  7002. #if PACKETVER < 20100126
  7003. if( maxhp > INT16_MAX )
  7004. {// To correctly display the %hp bar. [Skotlex]
  7005. WFIFOW(fd,6) = hp/(maxhp/100);
  7006. WFIFOW(fd,8) = 100;
  7007. } else {
  7008. WFIFOW(fd,6) = hp;
  7009. WFIFOW(fd,8) = maxhp;
  7010. }
  7011. #else
  7012. WFIFOL(fd,6) = hp;
  7013. WFIFOL(fd,10) = maxhp;
  7014. #endif
  7015. WFIFOSET(fd, packet_len(cmd));
  7016. }
  7017. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7018. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7019. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  7020. {
  7021. int fd;
  7022. nullpo_retv(sd);
  7023. nullpo_retv(bl);
  7024. fd=sd->fd;
  7025. WFIFOHEAD(fd,packet_len(0x139));
  7026. WFIFOW(fd, 0)=0x139;
  7027. WFIFOL(fd, 2)=bl->id;
  7028. WFIFOW(fd, 6)=bl->x;
  7029. WFIFOW(fd, 8)=bl->y;
  7030. WFIFOW(fd,10)=sd->bl.x;
  7031. WFIFOW(fd,12)=sd->bl.y;
  7032. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7033. WFIFOSET(fd,packet_len(0x139));
  7034. }
  7035. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7036. /// 018f <result>.W <name id>.W
  7037. /// result:
  7038. /// 0 = success
  7039. /// 1 = failure
  7040. /// 2 = success (alchemist)
  7041. /// 3 = failure (alchemist)
  7042. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  7043. nullpo_retv( sd );
  7044. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7045. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7046. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7047. p.result = flag;
  7048. p.itemId = client_nameid( nameid );
  7049. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7050. }
  7051. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7052. /// 019e
  7053. void clif_catch_process(struct map_session_data *sd)
  7054. {
  7055. int fd;
  7056. nullpo_retv(sd);
  7057. fd=sd->fd;
  7058. WFIFOHEAD(fd,packet_len(0x19e));
  7059. WFIFOW(fd,0)=0x19e;
  7060. WFIFOSET(fd,packet_len(0x19e));
  7061. }
  7062. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7063. /// 01a0 <result>.B
  7064. /// 0 = failure
  7065. /// 1 = success
  7066. void clif_pet_roulette(struct map_session_data *sd,int data)
  7067. {
  7068. int fd;
  7069. nullpo_retv(sd);
  7070. fd=sd->fd;
  7071. WFIFOHEAD(fd,packet_len(0x1a0));
  7072. WFIFOW(fd,0)=0x1a0;
  7073. WFIFOB(fd,2)=data;
  7074. WFIFOSET(fd,packet_len(0x1a0));
  7075. }
  7076. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7077. /// 01a6 <packet len>.W { <index>.W }*
  7078. void clif_sendegg(struct map_session_data *sd)
  7079. {
  7080. int i,n=0,fd;
  7081. nullpo_retv(sd);
  7082. fd=sd->fd;
  7083. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7084. clif_displaymessage(fd, msg_txt(sd,666));
  7085. return;
  7086. }
  7087. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7088. WFIFOW(fd,0)=0x1a6;
  7089. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7090. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7091. sd->inventory_data[i]->type != IT_PETEGG ||
  7092. sd->inventory.u.items_inventory[i].amount <= 0)
  7093. continue;
  7094. WFIFOW(fd,n*2+4)=client_index(i);
  7095. n++;
  7096. }
  7097. WFIFOW(fd,2)=4+n*2;
  7098. WFIFOSET(fd,WFIFOW(fd,2));
  7099. sd->menuskill_id = SA_TAMINGMONSTER;
  7100. sd->menuskill_val = -1;
  7101. }
  7102. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7103. /// 01a4 <type>.B <id>.L <data>.L
  7104. /// type:
  7105. /// 0 = pre-init (data = 0)
  7106. /// 1 = intimacy (data = 0~4)
  7107. /// 2 = hunger (data = 0~4)
  7108. /// 3 = accessory
  7109. /// 4 = performance (data = 1~3: normal, 4: special)
  7110. /// 5 = hairstyle
  7111. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7112. ///
  7113. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7114. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  7115. {
  7116. uint8 buf[16];
  7117. nullpo_retv(pd);
  7118. WBUFW(buf,0) = 0x1a4;
  7119. WBUFB(buf,2) = type;
  7120. WBUFL(buf,3) = pd->bl.id;
  7121. WBUFL(buf,7) = param;
  7122. if (sd)
  7123. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7124. else
  7125. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7126. }
  7127. /// Pet's base data (ZC_PROPERTY_PET).
  7128. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7129. void clif_send_petstatus(struct map_session_data *sd)
  7130. {
  7131. int fd;
  7132. struct s_pet *pet;
  7133. nullpo_retv(sd);
  7134. nullpo_retv(sd->pd);
  7135. fd=sd->fd;
  7136. pet = &sd->pd->pet;
  7137. WFIFOHEAD(fd,packet_len(0x1a2));
  7138. WFIFOW(fd,0)=0x1a2;
  7139. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7140. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7141. WFIFOW(fd,27)=pet->level;
  7142. WFIFOW(fd,29)=pet->hungry;
  7143. WFIFOW(fd,31)=pet->intimate;
  7144. WFIFOW(fd,33)=pet->equip;
  7145. #if PACKETVER >= 20081126
  7146. WFIFOW(fd,35)=pet->class_;
  7147. #endif
  7148. WFIFOSET(fd,packet_len(0x1a2));
  7149. }
  7150. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7151. /// 01aa <id>.L <data>.L
  7152. /// data:
  7153. /// @see CZ_PET_ACT.
  7154. void clif_pet_emotion(struct pet_data *pd,int param)
  7155. {
  7156. unsigned char buf[16];
  7157. nullpo_retv(pd);
  7158. memset(buf,0,packet_len(0x1aa));
  7159. WBUFW(buf,0)=0x1aa;
  7160. WBUFL(buf,2)=pd->bl.id;
  7161. WBUFL(buf,6)=param;
  7162. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7163. }
  7164. /// Result of request to feed a pet (ZC_FEED_PET).
  7165. /// 01a3 <result>.B <name id>.W
  7166. /// result:
  7167. /// 0 = failure
  7168. /// 1 = success
  7169. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7170. nullpo_retv( sd );
  7171. struct PACKET_ZC_FEED_PET p;
  7172. p.packetType = 0x1a3;
  7173. p.result = fail;
  7174. p.itemId = client_nameid( foodid );
  7175. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7176. }
  7177. /// Send pet auto feed info.
  7178. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7179. #if PACKETVER >= 20141008
  7180. nullpo_retv(sd);
  7181. if (force || battle_config.pet_autofeed_always) {
  7182. // Always send ON or OFF
  7183. if (sd->pd && battle_config.feature_pet_autofeed) {
  7184. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7185. }
  7186. else {
  7187. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7188. }
  7189. }
  7190. else {
  7191. // Only send when enabled
  7192. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7193. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7194. }
  7195. }
  7196. #endif
  7197. }
  7198. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7199. /// 01cd { <skill id>.L }*7
  7200. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7201. {
  7202. nullpo_retv(sd);
  7203. int fd = sd->fd;
  7204. #ifdef RENEWAL
  7205. uint16 autospell_skill[][2] = {
  7206. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7207. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7208. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7209. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7210. };
  7211. int count = 0;
  7212. WFIFOHEAD(fd, 2 * 6 + 4);
  7213. WFIFOW(fd, 0) = 0x442;
  7214. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7215. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7216. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7217. count++;
  7218. }
  7219. }
  7220. WFIFOW(fd, 2) = 8 + count * 2;
  7221. WFIFOL(fd, 4) = count;
  7222. WFIFOSET(fd, WFIFOW(fd, 2));
  7223. #else
  7224. WFIFOHEAD(fd,packet_len(0x1cd));
  7225. WFIFOW(fd, 0)=0x1cd;
  7226. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7227. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7228. else
  7229. WFIFOL(fd,2)= 0x00000000;
  7230. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7231. WFIFOL(fd,6)= MG_COLDBOLT;
  7232. else
  7233. WFIFOL(fd,6)= 0x00000000;
  7234. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7235. WFIFOL(fd,10)= MG_FIREBOLT;
  7236. else
  7237. WFIFOL(fd,10)= 0x00000000;
  7238. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7239. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7240. else
  7241. WFIFOL(fd,14)= 0x00000000;
  7242. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7243. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7244. else
  7245. WFIFOL(fd,18)= 0x00000000;
  7246. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7247. WFIFOL(fd,22)= MG_FIREBALL;
  7248. else
  7249. WFIFOL(fd,22)= 0x00000000;
  7250. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7251. WFIFOL(fd,26)= MG_FROSTDIVER;
  7252. else
  7253. WFIFOL(fd,26)= 0x00000000;
  7254. WFIFOSET(fd,packet_len(0x1cd));
  7255. #endif
  7256. sd->menuskill_id = SA_AUTOSPELL;
  7257. sd->menuskill_val = skill_lv;
  7258. }
  7259. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7260. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7261. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7262. {
  7263. unsigned char buf[56];
  7264. nullpo_retv(src);
  7265. memset(buf,0,packet_len(0x1cf));
  7266. WBUFW(buf,0) = 0x1cf;
  7267. WBUFL(buf,2) = src->id;
  7268. if( src->type == BL_MER )
  7269. {
  7270. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7271. if( md && md->master && md->devotion_flag )
  7272. WBUFL(buf,6) = md->master->bl.id;
  7273. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7274. }
  7275. else
  7276. {
  7277. int i;
  7278. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7279. if( sd == NULL )
  7280. return;
  7281. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7282. WBUFL(buf,6+4*i) = sd->devotion[i];
  7283. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7284. }
  7285. if( tsd )
  7286. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7287. else
  7288. clif_send(buf, packet_len(0x1cf), src, AREA);
  7289. }
  7290. /// Notifies the client of an object's spirits.
  7291. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7292. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7293. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7294. nullpo_retv( bl );
  7295. struct PACKET_ZC_SPIRITS p = {};
  7296. p.packetType = HEADER_ZC_SPIRITS;
  7297. p.GID = bl->id;
  7298. switch( bl->type ){
  7299. case BL_PC:
  7300. p.amount = ( (struct map_session_data*)bl )->spiritball;
  7301. break;
  7302. case BL_HOM:
  7303. p.amount = ( (struct homun_data*)bl )->homunculus.spiritball;
  7304. break;
  7305. }
  7306. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7307. }
  7308. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7309. /// 01d2 <account id>.L <delay>.L
  7310. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7311. {
  7312. unsigned char buf[32];
  7313. nullpo_retv(bl);
  7314. WBUFW(buf,0)=0x1d2;
  7315. WBUFL(buf,2)=bl->id;
  7316. WBUFL(buf,6)=client_tick(wait);
  7317. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7318. }
  7319. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7320. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7321. /// flag:
  7322. /// 0 = inactive
  7323. /// 1 = active
  7324. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7325. {
  7326. unsigned char buf[32];
  7327. nullpo_retv(src);
  7328. WBUFW(buf,0)=0x1d1;
  7329. WBUFL(buf,2)=src->id;
  7330. WBUFL(buf,6)=dst_id;
  7331. WBUFL(buf,10)=active;
  7332. clif_send(buf,packet_len(0x1d1),src,AREA);
  7333. }
  7334. /// MVP effect (ZC_MVP).
  7335. /// 010c <account id>.L
  7336. void clif_mvp_effect(struct map_session_data *sd)
  7337. {
  7338. unsigned char buf[16];
  7339. nullpo_retv(sd);
  7340. WBUFW(buf,0)=0x10c;
  7341. WBUFL(buf,2)=sd->bl.id;
  7342. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7343. }
  7344. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7345. /// 010a <name id>.W
  7346. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7347. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7348. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7349. p.itemId = client_nameid( nameid );
  7350. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7351. }
  7352. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7353. /// 010b <exp>.L
  7354. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7355. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7356. if (battle_config.mvp_exp_reward_message) {
  7357. char e_msg[CHAT_SIZE_MAX];
  7358. sprintf(e_msg, msg_txt(sd, 717), exp);
  7359. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7360. }
  7361. #else
  7362. int fd;
  7363. nullpo_retv(sd);
  7364. fd = sd->fd;
  7365. WFIFOHEAD(fd, packet_len(0x10b));
  7366. WFIFOW(fd,0) = 0x10b;
  7367. WFIFOL(fd,2) = (uint32)min( exp, MAX_EXP );
  7368. WFIFOSET(fd, packet_len(0x10b));
  7369. #endif
  7370. }
  7371. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7372. /// 010d
  7373. ///
  7374. /// "You are the MVP, but cannot obtain the reward because
  7375. /// you are overweight."
  7376. void clif_mvp_noitem(struct map_session_data* sd)
  7377. {
  7378. int fd = sd->fd;
  7379. WFIFOHEAD(fd,packet_len(0x10d));
  7380. WFIFOW(fd,0) = 0x10d;
  7381. WFIFOSET(fd,packet_len(0x10d));
  7382. }
  7383. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7384. /// 0167 <result>.B
  7385. /// result:
  7386. /// 0 = "Guild has been created."
  7387. /// 1 = "You are already in a Guild."
  7388. /// 2 = "That Guild Name already exists."
  7389. /// 3 = "You need the neccessary item to create a Guild."
  7390. void clif_guild_created(struct map_session_data *sd,int flag)
  7391. {
  7392. int fd;
  7393. nullpo_retv(sd);
  7394. fd=sd->fd;
  7395. WFIFOHEAD(fd,packet_len(0x167));
  7396. WFIFOW(fd,0)=0x167;
  7397. WFIFOB(fd,2)=flag;
  7398. WFIFOSET(fd,packet_len(0x167));
  7399. }
  7400. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7401. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7402. /// mode:
  7403. /// &0x01 = allow invite
  7404. /// &0x10 = allow expel
  7405. void clif_guild_belonginfo(struct map_session_data *sd)
  7406. {
  7407. int ps,fd;
  7408. struct guild* g;
  7409. nullpo_retv(sd);
  7410. nullpo_retv(g = sd->guild);
  7411. fd=sd->fd;
  7412. ps=guild_getposition(sd);
  7413. WFIFOHEAD(fd,packet_len(0x16c));
  7414. WFIFOW(fd,0)=0x16c;
  7415. WFIFOL(fd,2)=g->guild_id;
  7416. WFIFOL(fd,6)=g->emblem_id;
  7417. WFIFOL(fd,10)=g->position[ps].mode;
  7418. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7419. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7420. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7421. WFIFOSET(fd,packet_len(0x16c));
  7422. }
  7423. /// Guild member login notice.
  7424. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7425. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7426. /// status:
  7427. /// 0 = offline
  7428. /// 1 = online
  7429. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7430. {
  7431. unsigned char buf[64];
  7432. struct map_session_data* sd;
  7433. nullpo_retv(g);
  7434. WBUFW(buf, 0)=0x1f2;
  7435. WBUFL(buf, 2)=g->member[idx].account_id;
  7436. WBUFL(buf, 6)=g->member[idx].char_id;
  7437. WBUFL(buf,10)=flag;
  7438. if( ( sd = g->member[idx].sd ) != NULL )
  7439. {
  7440. WBUFW(buf,14) = sd->status.sex;
  7441. WBUFW(buf,16) = sd->status.hair;
  7442. WBUFW(buf,18) = sd->status.hair_color;
  7443. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7444. }
  7445. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7446. {
  7447. WBUFW(buf,14) = 0;
  7448. WBUFW(buf,16) = 0;
  7449. WBUFW(buf,18) = 0;
  7450. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7451. }
  7452. }
  7453. // Function `clif_guild_memberlogin_notice` sends info about
  7454. // logins and logouts of a guild member to the rest members.
  7455. // But at the 1st time (after a player login or map changing)
  7456. // the client won't show the message.
  7457. // So I suggest use this function for sending "first-time-info"
  7458. // to some player on entering the game or changing location.
  7459. // At next time the client would always show the message.
  7460. // The function sends all the statuses in the single packet
  7461. // to economize traffic. [LuzZza]
  7462. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7463. {
  7464. struct guild *g;
  7465. unsigned char buf[14*128];
  7466. int i, count=0, p_len;
  7467. nullpo_retv(sd);
  7468. p_len = packet_len(0x16d);
  7469. if(!(g = sd->guild))
  7470. return;
  7471. for(i=0; i<g->max_member; i++) {
  7472. if(g->member[i].account_id > 0 &&
  7473. g->member[i].account_id != sd->status.account_id) {
  7474. WBUFW(buf,count*p_len) = 0x16d;
  7475. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7476. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7477. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7478. count++;
  7479. }
  7480. }
  7481. clif_send(buf, p_len*count, &sd->bl, SELF);
  7482. }
  7483. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7484. /// 014e <menu flag>.L
  7485. /// menu flag:
  7486. /// 0x00 = Basic Info (always on)
  7487. /// &0x01 = Member manager
  7488. /// &0x02 = Positions
  7489. /// &0x04 = Skills
  7490. /// &0x10 = Expulsion list
  7491. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7492. /// &0x80 = Notice
  7493. void clif_guild_masterormember(struct map_session_data *sd)
  7494. {
  7495. int fd;
  7496. nullpo_retv(sd);
  7497. fd=sd->fd;
  7498. WFIFOHEAD(fd,packet_len(0x14e));
  7499. WFIFOW(fd,0) = 0x14e;
  7500. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7501. WFIFOSET(fd,packet_len(0x14e));
  7502. }
  7503. /// Guild basic information (Territories [Valaris])
  7504. /// 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)
  7505. /// 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)
  7506. /// 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)
  7507. void clif_guild_basicinfo(struct map_session_data *sd) {
  7508. int fd;
  7509. struct guild *g;
  7510. #if PACKETVER < 20160622
  7511. int cmd = 0x1b6;
  7512. int offset = NAME_LENGTH;
  7513. #else
  7514. int cmd = 0xa84;
  7515. int offset = 0;
  7516. #endif
  7517. nullpo_retv(sd);
  7518. fd = sd->fd;
  7519. if( (g = sd->guild) == NULL )
  7520. return;
  7521. WFIFOHEAD(fd,packet_len(cmd));
  7522. WFIFOW(fd, 0)=cmd;
  7523. WFIFOL(fd, 2)=g->guild_id;
  7524. WFIFOL(fd, 6)=g->guild_lv;
  7525. WFIFOL(fd,10)=g->connect_member;
  7526. WFIFOL(fd,14)=g->max_member;
  7527. WFIFOL(fd,18)=g->average_lv;
  7528. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7529. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7530. WFIFOL(fd,30)=0; // Tax Points
  7531. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7532. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7533. WFIFOL(fd,42)=g->emblem_id;
  7534. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7535. #if PACKETVER < 20160622
  7536. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7537. #endif
  7538. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7539. WFIFOL(fd,70+offset+16) = 0; // zeny
  7540. #if PACKETVER >= 20160622
  7541. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7542. #endif
  7543. WFIFOSET(fd,packet_len(cmd));
  7544. }
  7545. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7546. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7547. void clif_guild_allianceinfo(struct map_session_data *sd)
  7548. {
  7549. int fd,i,c;
  7550. struct guild *g;
  7551. nullpo_retv(sd);
  7552. if( (g = sd->guild) == NULL )
  7553. return;
  7554. fd = sd->fd;
  7555. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7556. WFIFOW(fd, 0)=0x14c;
  7557. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7558. struct guild_alliance *a=&g->alliance[i];
  7559. if(a->guild_id>0){
  7560. WFIFOL(fd,c*32+4)=a->opposition;
  7561. WFIFOL(fd,c*32+8)=a->guild_id;
  7562. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7563. c++;
  7564. }
  7565. }
  7566. WFIFOW(fd, 2)=c*32+4;
  7567. WFIFOSET(fd,WFIFOW(fd,2));
  7568. }
  7569. /// Guild member manager information
  7570. /// 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)
  7571. /// state:
  7572. /// 0 = offline
  7573. /// 1 = online
  7574. /// memo:
  7575. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7576. /// 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)
  7577. void clif_guild_memberlist(struct map_session_data *sd)
  7578. {
  7579. int fd;
  7580. int i,c;
  7581. struct guild *g;
  7582. #if PACKETVER < 20161026
  7583. int cmd = 0x154;
  7584. int size = 104;
  7585. #else
  7586. int cmd = 0xaa5;
  7587. int size = 34;
  7588. #endif
  7589. nullpo_retv(sd);
  7590. if( !session_isActive(fd = sd->fd) )
  7591. return;
  7592. if( (g = sd->guild) == NULL )
  7593. return;
  7594. WFIFOHEAD(fd, g->max_member * size + 4);
  7595. WFIFOW(fd, 0)=cmd;
  7596. for(i=0,c=0;i<g->max_member;i++){
  7597. struct guild_member *m=&g->member[i];
  7598. if(m->account_id==0)
  7599. continue;
  7600. WFIFOL(fd,c*size+ 4)=m->account_id;
  7601. WFIFOL(fd,c*size+ 8)=m->char_id;
  7602. WFIFOW(fd,c*size+12)=m->hair;
  7603. WFIFOW(fd,c*size+14)=m->hair_color;
  7604. WFIFOW(fd,c*size+16)=m->gender;
  7605. WFIFOW(fd,c*size+18)=m->class_;
  7606. WFIFOW(fd,c*size+20)=m->lv;
  7607. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7608. WFIFOL(fd,c*size+26)=m->online;
  7609. WFIFOL(fd,c*size+30)=m->position;
  7610. #if PACKETVER < 20161026
  7611. 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.
  7612. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7613. #else
  7614. WFIFOL(fd,c*size+34)=m->last_login;
  7615. #endif
  7616. c++;
  7617. }
  7618. WFIFOW(fd, 2)=c*size+4;
  7619. WFIFOSET(fd,WFIFOW(fd,2));
  7620. }
  7621. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7622. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7623. void clif_guild_positionnamelist(struct map_session_data *sd)
  7624. {
  7625. int i,fd;
  7626. struct guild *g;
  7627. nullpo_retv(sd);
  7628. if( (g = sd->guild) == NULL )
  7629. return;
  7630. fd = sd->fd;
  7631. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7632. WFIFOW(fd, 0)=0x166;
  7633. for(i=0;i<MAX_GUILDPOSITION;i++){
  7634. WFIFOL(fd,i*28+4)=i;
  7635. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7636. }
  7637. WFIFOW(fd,2)=i*28+4;
  7638. WFIFOSET(fd,WFIFOW(fd,2));
  7639. }
  7640. /// Guild position information (ZC_POSITION_INFO).
  7641. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7642. /// mode:
  7643. /// &0x01 = allow invite
  7644. /// &0x10 = allow expel
  7645. /// ranking:
  7646. /// TODO
  7647. void clif_guild_positioninfolist(struct map_session_data *sd)
  7648. {
  7649. int i,fd;
  7650. struct guild *g;
  7651. nullpo_retv(sd);
  7652. if( (g = sd->guild) == NULL )
  7653. return;
  7654. fd = sd->fd;
  7655. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7656. WFIFOW(fd, 0)=0x160;
  7657. for(i=0;i<MAX_GUILDPOSITION;i++){
  7658. struct guild_position *p=&g->position[i];
  7659. WFIFOL(fd,i*16+ 4)=i;
  7660. WFIFOL(fd,i*16+ 8)=p->mode;
  7661. WFIFOL(fd,i*16+12)=i;
  7662. WFIFOL(fd,i*16+16)=p->exp_mode;
  7663. }
  7664. WFIFOW(fd, 2)=i*16+4;
  7665. WFIFOSET(fd,WFIFOW(fd,2));
  7666. }
  7667. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7668. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7669. /// mode:
  7670. /// &0x01 = allow invite
  7671. /// &0x10 = allow expel
  7672. /// ranking:
  7673. /// TODO
  7674. void clif_guild_positionchanged(struct guild *g,int idx)
  7675. {
  7676. // FIXME: This packet is intended to update the clients after a
  7677. // commit of position info changes, not sending one packet per
  7678. // position.
  7679. struct map_session_data *sd;
  7680. unsigned char buf[128];
  7681. nullpo_retv(g);
  7682. WBUFW(buf, 0)=0x174;
  7683. WBUFW(buf, 2)=44; // packet len
  7684. // GUILD_REG_POSITION_INFO{
  7685. WBUFL(buf, 4)=idx;
  7686. WBUFL(buf, 8)=g->position[idx].mode;
  7687. WBUFL(buf,12)=idx;
  7688. WBUFL(buf,16)=g->position[idx].exp_mode;
  7689. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7690. // }*
  7691. if( (sd=guild_getavailablesd(g))!=NULL )
  7692. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7693. }
  7694. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7695. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7696. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7697. {
  7698. // FIXME: This packet is intended to update the clients after a
  7699. // commit of member position assignment changes, not sending one
  7700. // packet per position.
  7701. struct map_session_data *sd;
  7702. unsigned char buf[64];
  7703. nullpo_retv(g);
  7704. WBUFW(buf, 0)=0x156;
  7705. WBUFW(buf, 2)=16; // packet len
  7706. // MEMBER_POSITION_INFO{
  7707. WBUFL(buf, 4)=g->member[idx].account_id;
  7708. WBUFL(buf, 8)=g->member[idx].char_id;
  7709. WBUFL(buf,12)=g->member[idx].position;
  7710. // }*
  7711. if( (sd=guild_getavailablesd(g))!=NULL )
  7712. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7713. }
  7714. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7715. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7716. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7717. {
  7718. int fd;
  7719. nullpo_retv(sd);
  7720. nullpo_retv(g);
  7721. fd = sd->fd;
  7722. if( g->emblem_len <= 0 )
  7723. return;
  7724. WFIFOHEAD(fd,g->emblem_len+12);
  7725. WFIFOW(fd,0)=0x152;
  7726. WFIFOW(fd,2)=g->emblem_len+12;
  7727. WFIFOL(fd,4)=g->guild_id;
  7728. WFIFOL(fd,8)=g->emblem_id;
  7729. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7730. WFIFOSET(fd,WFIFOW(fd,2));
  7731. }
  7732. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7733. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7734. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7735. void clif_guild_emblem_area(struct block_list* bl)
  7736. {
  7737. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7738. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7739. PACKET_ZC_CHANGE_GUILD p{};
  7740. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7741. p.guild_id = status_get_guild_id(bl);
  7742. p.emblem_id = status_get_emblem_id(bl);
  7743. #if PACKETVER < 20190724
  7744. p.aid = bl->id;
  7745. #else
  7746. p.unknown = 0;
  7747. #endif
  7748. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7749. }
  7750. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7751. /// 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 }*
  7752. void clif_guild_skillinfo(struct map_session_data* sd)
  7753. {
  7754. int fd;
  7755. struct guild* g;
  7756. int i,c;
  7757. nullpo_retv(sd);
  7758. if( (g = sd->guild) == NULL )
  7759. return;
  7760. fd = sd->fd;
  7761. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7762. WFIFOW(fd,0) = 0x0162;
  7763. WFIFOW(fd,4) = g->skill_point;
  7764. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7765. {
  7766. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7767. {
  7768. int id = g->skill[i].id;
  7769. int p = 6 + c*37;
  7770. WFIFOW(fd,p+0) = id;
  7771. WFIFOL(fd,p+2) = skill_get_inf(id);
  7772. WFIFOW(fd,p+6) = g->skill[i].lv;
  7773. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7774. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7775. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7776. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7777. c++;
  7778. }
  7779. }
  7780. WFIFOW(fd,2) = 6 + c*37;
  7781. WFIFOSET(fd,WFIFOW(fd,2));
  7782. }
  7783. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7784. /// 016f <subject>.60B <notice>.120B
  7785. void clif_guild_notice(struct map_session_data* sd)
  7786. {
  7787. struct guild* g;
  7788. nullpo_retv(sd);
  7789. nullpo_retv(g = sd->guild);
  7790. int fd = sd->fd;
  7791. if ( !session_isActive(fd) )
  7792. return;
  7793. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7794. return;
  7795. WFIFOHEAD(fd,packet_len(0x16f));
  7796. WFIFOW(fd,0) = 0x16f;
  7797. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7798. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7799. WFIFOSET(fd,packet_len(0x16f));
  7800. }
  7801. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7802. /// 016a <guild id>.L <guild name>.24B
  7803. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7804. {
  7805. int fd;
  7806. nullpo_retv(sd);
  7807. nullpo_retv(g);
  7808. fd=sd->fd;
  7809. WFIFOHEAD(fd,packet_len(0x16a));
  7810. WFIFOW(fd,0)=0x16a;
  7811. WFIFOL(fd,2)=g->guild_id;
  7812. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7813. WFIFOSET(fd,packet_len(0x16a));
  7814. }
  7815. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7816. /// 0169 <answer>.B
  7817. /// answer:
  7818. /// 0 = Already in guild.
  7819. /// 1 = Offer rejected.
  7820. /// 2 = Offer accepted.
  7821. /// 3 = Guild full.
  7822. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7823. {
  7824. int fd;
  7825. nullpo_retv(sd);
  7826. fd=sd->fd;
  7827. WFIFOHEAD(fd,packet_len(0x169));
  7828. WFIFOW(fd,0)=0x169;
  7829. WFIFOB(fd,2)=flag;
  7830. WFIFOSET(fd,packet_len(0x169));
  7831. }
  7832. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7833. /// 015a <char name>.24B <reason>.40B
  7834. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7835. {
  7836. unsigned char buf[128];
  7837. nullpo_retv(sd);
  7838. WBUFW(buf, 0)=0x15a;
  7839. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7840. memcpy(WBUFP(buf,26),mes,40);
  7841. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7842. }
  7843. /// Notifies clients of a guild of an expelled member.
  7844. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7845. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7846. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7847. {
  7848. unsigned char buf[128];
  7849. #if PACKETVER < 20100803
  7850. const unsigned short cmd = 0x15c;
  7851. #else
  7852. const unsigned short cmd = 0x839;
  7853. #endif
  7854. nullpo_retv(sd);
  7855. WBUFW(buf,0) = cmd;
  7856. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7857. safestrncpy(WBUFCP(buf,26), mes, 40);
  7858. #if PACKETVER < 20100803
  7859. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7860. #endif
  7861. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7862. }
  7863. /// Guild expulsion list (ZC_BAN_LIST).
  7864. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7865. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7866. void clif_guild_expulsionlist(struct map_session_data* sd)
  7867. {
  7868. #if PACKETVER < 20100803
  7869. const int offset = NAME_LENGTH*2+40;
  7870. #else
  7871. const int offset = NAME_LENGTH+40;
  7872. #endif
  7873. int fd, i, c = 0;
  7874. struct guild* g;
  7875. nullpo_retv(sd);
  7876. if( (g = sd->guild) == NULL )
  7877. return;
  7878. fd = sd->fd;
  7879. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7880. WFIFOW(fd,0) = 0x163;
  7881. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7882. {
  7883. struct guild_expulsion* e = &g->expulsion[i];
  7884. if( e->account_id > 0 )
  7885. {
  7886. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7887. #if PACKETVER < 20100803
  7888. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7889. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7890. #else
  7891. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7892. #endif
  7893. c++;
  7894. }
  7895. }
  7896. WFIFOW(fd,2) = 4 + c*offset;
  7897. WFIFOSET(fd,WFIFOW(fd,2));
  7898. }
  7899. /// Guild chat message (ZC_GUILD_CHAT).
  7900. /// 017f <packet len>.W <message>.?B
  7901. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7902. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7903. struct map_session_data *sd;
  7904. uint8 buf[256];
  7905. if( len == 0 )
  7906. {
  7907. return;
  7908. }
  7909. else if( len > sizeof(buf)-5 )
  7910. {
  7911. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7912. len = sizeof(buf)-5;
  7913. }
  7914. WBUFW(buf, 0) = 0x17f;
  7915. WBUFW(buf, 2) = len + 5;
  7916. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7917. if ((sd = guild_getavailablesd(g)) != NULL)
  7918. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7919. }
  7920. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7921. /// 0171 <inviter account id>.L <guild name>.24B
  7922. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7923. {
  7924. int fd;
  7925. nullpo_retv(sd);
  7926. fd=sd->fd;
  7927. WFIFOHEAD(fd,packet_len(0x171));
  7928. WFIFOW(fd,0)=0x171;
  7929. WFIFOL(fd,2)=account_id;
  7930. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7931. WFIFOSET(fd,packet_len(0x171));
  7932. }
  7933. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7934. /// 0173 <answer>.B
  7935. /// answer:
  7936. /// 0 = Already allied.
  7937. /// 1 = You rejected the offer.
  7938. /// 2 = You accepted the offer.
  7939. /// 3 = They have too any alliances.
  7940. /// 4 = You have too many alliances.
  7941. /// 5 = Alliances are disabled.
  7942. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7943. {
  7944. int fd;
  7945. nullpo_retv(sd);
  7946. fd=sd->fd;
  7947. WFIFOHEAD(fd,packet_len(0x173));
  7948. WFIFOW(fd,0)=0x173;
  7949. WFIFOL(fd,2)=flag;
  7950. WFIFOSET(fd,packet_len(0x173));
  7951. }
  7952. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7953. /// 0184 <other guild id>.L <relation>.L
  7954. /// relation:
  7955. /// 0 = Ally
  7956. /// 1 = Enemy
  7957. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7958. {
  7959. nullpo_retv(sd);
  7960. int fd = sd->fd;
  7961. if ( !session_isActive(fd) )
  7962. return;
  7963. WFIFOHEAD(fd,packet_len(0x184));
  7964. WFIFOW(fd,0)=0x184;
  7965. WFIFOL(fd,2)=guild_id;
  7966. WFIFOL(fd,6)=flag;
  7967. WFIFOSET(fd,packet_len(0x184));
  7968. }
  7969. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7970. /// 0181 <result>.B
  7971. /// result:
  7972. /// 0 = Antagonist has been set.
  7973. /// 1 = Guild has too many Antagonists.
  7974. /// 2 = Already set as an Antagonist.
  7975. /// 3 = Antagonists are disabled.
  7976. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7977. {
  7978. int fd;
  7979. nullpo_retv(sd);
  7980. fd=sd->fd;
  7981. WFIFOHEAD(fd,packet_len(0x181));
  7982. WFIFOW(fd,0)=0x181;
  7983. WFIFOB(fd,2)=flag;
  7984. WFIFOSET(fd,packet_len(0x181));
  7985. }
  7986. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7987. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7988. /*
  7989. void clif_guild_allianceadded(struct guild *g,int idx)
  7990. {
  7991. unsigned char buf[64];
  7992. WBUFW(buf,0)=0x185;
  7993. WBUFL(buf,2)=g->alliance[idx].opposition;
  7994. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7995. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7996. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7997. }
  7998. */
  7999. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  8000. /// 015e <reason>.L
  8001. /// 0 = success
  8002. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  8003. /// 2 = there are still members in the guild
  8004. void clif_guild_broken(struct map_session_data *sd,int flag)
  8005. {
  8006. int fd;
  8007. nullpo_retv(sd);
  8008. fd=sd->fd;
  8009. WFIFOHEAD(fd,packet_len(0x15e));
  8010. WFIFOW(fd,0)=0x15e;
  8011. WFIFOL(fd,2)=flag;
  8012. WFIFOSET(fd,packet_len(0x15e));
  8013. }
  8014. /// Displays emotion on an object (ZC_EMOTION).
  8015. /// 00c0 <id>.L <type>.B
  8016. /// type:
  8017. /// enum emotion_type
  8018. void clif_emotion(struct block_list *bl,int type)
  8019. {
  8020. unsigned char buf[8];
  8021. nullpo_retv(bl);
  8022. WBUFW(buf,0)=0xc0;
  8023. WBUFL(buf,2)=bl->id;
  8024. WBUFB(buf,6)=type;
  8025. clif_send(buf,packet_len(0xc0),bl,AREA);
  8026. }
  8027. /// Displays the contents of a talkiebox trap.
  8028. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8029. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8030. nullpo_retv( bl );
  8031. nullpo_retv( talkie );
  8032. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8033. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8034. p.aid = bl->id;
  8035. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8036. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8037. }
  8038. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8039. /// 01ea <id>.L
  8040. void clif_wedding_effect(struct block_list *bl)
  8041. {
  8042. unsigned char buf[6];
  8043. nullpo_retv(bl);
  8044. WBUFW(buf,0) = 0x1ea;
  8045. WBUFL(buf,2) = bl->id;
  8046. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8047. }
  8048. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8049. /// 01e6 <partner name>.24B
  8050. void clif_callpartner(struct map_session_data *sd)
  8051. {
  8052. unsigned char buf[26];
  8053. nullpo_retv(sd);
  8054. WBUFW(buf,0) = 0x1e6;
  8055. if( sd->status.partner_id ) {
  8056. const char *p = map_charid2nick(sd->status.partner_id);
  8057. struct map_session_data *p_sd = pc_get_partner(sd);
  8058. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  8059. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  8060. else
  8061. WBUFB(buf,2) = 0;
  8062. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8063. WBUFB(buf,2) = 0;
  8064. }
  8065. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  8066. }
  8067. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8068. /// 01e4
  8069. /// This packet while still implemented by the client is no longer being officially used.
  8070. /*
  8071. void clif_marriage_process(struct map_session_data *sd)
  8072. {
  8073. int fd;
  8074. nullpo_retv(sd);
  8075. fd=sd->fd;
  8076. WFIFOHEAD(fd,packet_len(0x1e4));
  8077. WFIFOW(fd,0)=0x1e4;
  8078. WFIFOSET(fd,packet_len(0x1e4));
  8079. }
  8080. */
  8081. /// Notice of divorce (ZC_DIVORCE).
  8082. /// 0205 <partner name>.24B
  8083. void clif_divorced(struct map_session_data* sd, const char* name)
  8084. {
  8085. int fd;
  8086. nullpo_retv(sd);
  8087. fd=sd->fd;
  8088. WFIFOHEAD(fd,packet_len(0x205));
  8089. WFIFOW(fd,0)=0x205;
  8090. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8091. WFIFOSET(fd, packet_len(0x205));
  8092. }
  8093. /// Marriage proposal (ZC_REQ_COUPLE).
  8094. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8095. /// This packet while still implemented by the client is no longer being officially used.
  8096. /*
  8097. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  8098. {
  8099. nullpo_retv(sd);
  8100. WFIFOHEAD(fd,packet_len(0x1e2));
  8101. WFIFOW(fd,0) = 0x1e2;
  8102. WFIFOL(fd,2) = ssd->status.account_id;
  8103. WFIFOL(fd,6) = ssd->status.char_id;
  8104. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8105. WFIFOSET(fd, packet_len(0x1e2));
  8106. }
  8107. */
  8108. /*==========================================
  8109. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8110. *------------------------------------------*/
  8111. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8112. {
  8113. unsigned char buf[256];
  8114. if( len == 0 ) {
  8115. return;
  8116. } else if( len > sizeof(buf)-5 ) {
  8117. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8118. len = sizeof(buf)-5;
  8119. }
  8120. WBUFW(buf, 0) = 0x17f;
  8121. WBUFW(buf, 2) = len + 5;
  8122. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8123. clif_send(buf, WBUFW(buf,2), src, target);
  8124. }
  8125. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8126. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8127. /// 00cd <result>.B
  8128. /// result:
  8129. /// 0 = failure
  8130. /// 1 = success
  8131. void clif_GM_kickack(struct map_session_data *sd, int id)
  8132. {
  8133. int fd;
  8134. nullpo_retv(sd);
  8135. fd = sd->fd;
  8136. WFIFOHEAD(fd,packet_len(0xcd));
  8137. WFIFOW(fd,0) = 0xcd;
  8138. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8139. WFIFOSET(fd, packet_len(0xcd));
  8140. }
  8141. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  8142. {
  8143. nullpo_retv(tsd);
  8144. if (sd == NULL)
  8145. tsd->state.keepshop = true;
  8146. if (session_isActive(tsd->fd))
  8147. clif_authfail_fd(tsd->fd, 15);
  8148. else
  8149. map_quit(tsd);
  8150. if (sd)
  8151. clif_GM_kickack(sd, tsd->status.account_id);
  8152. }
  8153. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8154. /// 014a <result>.L
  8155. /// result:
  8156. /// 0 = "A manner point has been successfully aligned."
  8157. /// 1 = MP_FAILURE_EXHAUST
  8158. /// 2 = MP_FAILURE_ALREADY_GIVING
  8159. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8160. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8161. /// 5 = "You got a good point from %s."
  8162. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8163. {
  8164. int fd;
  8165. nullpo_retv(sd);
  8166. fd = sd->fd;
  8167. WFIFOHEAD(fd,packet_len(0x14a));
  8168. WFIFOW(fd,0) = 0x14a;
  8169. WFIFOL(fd,2) = type;
  8170. WFIFOSET(fd, packet_len(0x14a));
  8171. }
  8172. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8173. /// 014b <type>.B <GM name>.24B
  8174. /// type:
  8175. /// 0 = positive (unmute)
  8176. /// 1 = negative (mute)
  8177. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8178. {
  8179. int fd;
  8180. nullpo_retv(sd);
  8181. nullpo_retv(tsd);
  8182. fd = tsd->fd;
  8183. WFIFOHEAD(fd,packet_len(0x14b));
  8184. WFIFOW(fd,0) = 0x14b;
  8185. WFIFOB(fd,2) = type;
  8186. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8187. WFIFOSET(fd, packet_len(0x14b));
  8188. }
  8189. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8190. /// 00d1 <type>.B <result>.B
  8191. /// type:
  8192. /// 0 = /ex (deny)
  8193. /// 1 = /in (allow)
  8194. /// result:
  8195. /// 0 = success
  8196. /// 1 = failure
  8197. /// 2 = too many blocks
  8198. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8199. {
  8200. int fd;
  8201. nullpo_retv(sd);
  8202. fd=sd->fd;
  8203. WFIFOHEAD(fd,packet_len(0xd1));
  8204. WFIFOW(fd,0)=0xd1;
  8205. WFIFOB(fd,2)=type;
  8206. WFIFOB(fd,3)=flag;
  8207. WFIFOSET(fd,packet_len(0xd1));
  8208. }
  8209. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8210. /// 00d2 <type>.B <result>.B
  8211. /// type:
  8212. /// 0 = /exall (deny)
  8213. /// 1 = /inall (allow)
  8214. /// result:
  8215. /// 0 = success
  8216. /// 1 = failure
  8217. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8218. {
  8219. int fd;
  8220. nullpo_retv(sd);
  8221. fd=sd->fd;
  8222. WFIFOHEAD(fd,packet_len(0xd2));
  8223. WFIFOW(fd,0)=0xd2;
  8224. WFIFOB(fd,2)=type;
  8225. WFIFOB(fd,3)=flag;
  8226. WFIFOSET(fd,packet_len(0xd2));
  8227. }
  8228. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8229. /// 07fe <bgm>.24B
  8230. void clif_playBGM(struct map_session_data* sd, const char* name)
  8231. {
  8232. int fd;
  8233. nullpo_retv(sd);
  8234. fd = sd->fd;
  8235. WFIFOHEAD(fd,packet_len(0x7fe));
  8236. WFIFOW(fd,0) = 0x7fe;
  8237. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8238. WFIFOSET(fd,packet_len(0x7fe));
  8239. }
  8240. /// Plays/stops a wave sound (ZC_SOUND).
  8241. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8242. /// file name:
  8243. /// relative to data\wav
  8244. /// act:
  8245. /// 0 = play (once)
  8246. /// 1 = play (repeat, does not work)
  8247. /// 2 = stops all sound instances of file name (does not work)
  8248. /// term:
  8249. /// unknown purpose, only relevant to act = 1
  8250. /// npc id:
  8251. /// The accustic direction of the sound is determined by the
  8252. /// relative position of the NPC to the player (3D sound).
  8253. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8254. {
  8255. int fd;
  8256. nullpo_retv(sd);
  8257. nullpo_retv(bl);
  8258. fd = sd->fd;
  8259. WFIFOHEAD(fd,packet_len(0x1d3));
  8260. WFIFOW(fd,0) = 0x1d3;
  8261. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8262. WFIFOB(fd,26) = type;
  8263. WFIFOL(fd,27) = 0;
  8264. WFIFOL(fd,31) = bl->id;
  8265. WFIFOSET(fd,packet_len(0x1d3));
  8266. }
  8267. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8268. {
  8269. unsigned char buf[40];
  8270. nullpo_retv(bl);
  8271. WBUFW(buf,0) = 0x1d3;
  8272. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8273. WBUFB(buf,26) = type;
  8274. WBUFL(buf,27) = 0;
  8275. WBUFL(buf,31) = bl->id;
  8276. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8277. }
  8278. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8279. /// 01f3 <id>.L <effect id>.L
  8280. /// effect id:
  8281. /// @see doc/effect_list.txt
  8282. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8283. {
  8284. unsigned char buf[24];
  8285. nullpo_retv(bl);
  8286. memset(buf, 0, packet_len(0x1f3));
  8287. WBUFW(buf,0) = 0x1f3;
  8288. WBUFL(buf,2) = bl->id;
  8289. WBUFL(buf,6) = type;
  8290. clif_send(buf, packet_len(0x1f3), bl, target);
  8291. if (disguised(bl)) {
  8292. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8293. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8294. }
  8295. }
  8296. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8297. {
  8298. WFIFOHEAD(fd,10);
  8299. WFIFOW(fd,0) = 0x1f3;
  8300. WFIFOL(fd,2) = bl->id;
  8301. WFIFOL(fd,6) = type;
  8302. WFIFOSET(fd,10);
  8303. }
  8304. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8305. /// 0284 <id>.L <effect id>.L <num data>.L
  8306. /// effect id:
  8307. /// @see doc/effect_list.txt
  8308. /// num data:
  8309. /// effect-dependent value
  8310. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8311. {
  8312. uint8 buf[14];
  8313. WBUFW(buf,0) = 0x284;
  8314. WBUFL(buf,2) = bl->id;
  8315. WBUFL(buf,6) = effect_id;
  8316. WBUFL(buf,10) = num;
  8317. clif_send(buf, packet_len(0x284), bl, target);
  8318. if( disguised(bl) )
  8319. {
  8320. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8321. clif_send(buf, packet_len(0x284), bl, SELF);
  8322. }
  8323. }
  8324. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8325. {
  8326. #if PACKETVER >= 20181002
  8327. nullpo_retv( bl_src );
  8328. nullpo_retv( bl_target );
  8329. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8330. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8331. p.aid = bl_src->id;
  8332. p.effectId = effect;
  8333. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8334. if( disguised(bl_src) )
  8335. {
  8336. p.aid = disguised_bl_id( bl_src->id );
  8337. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8338. }
  8339. #endif
  8340. }
  8341. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8342. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8343. 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) {
  8344. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8345. uint8 buf[CHAT_SIZE_MAX];
  8346. nullpo_retv(bl);
  8347. if (msg_len > sizeof(buf) - 12) {
  8348. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8349. msg_len = sizeof(buf) - 12;
  8350. }
  8351. if (rgb2bgr)
  8352. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8353. WBUFW(buf,0) = 0x2C1;
  8354. WBUFW(buf,2) = msg_len + 12;
  8355. WBUFL(buf,4) = bl->id;
  8356. WBUFL(buf,8) = color;
  8357. memcpy(WBUFCP(buf,12), msg, msg_len);
  8358. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8359. }
  8360. /**
  8361. * Notifies the client that the storage window is still open
  8362. *
  8363. * Should only be used in cases where the client closed the
  8364. * storage window without server's consent
  8365. */
  8366. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8367. // Notify the client that the storage is open
  8368. if( sd->state.storage_flag == 1 ) {
  8369. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8370. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8371. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8372. }
  8373. // Notify the client that the gstorage is open otherwise it will
  8374. // remain locked forever and nobody will be able to access it
  8375. if( sd->state.storage_flag == 2 ) {
  8376. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8377. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8378. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8379. else {
  8380. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8381. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8382. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8383. }
  8384. }
  8385. // Notify the client that the premium storage is open
  8386. if (sd->state.storage_flag == 3) {
  8387. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8388. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8389. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8390. }
  8391. }
  8392. // refresh the client's screen, getting rid of any effects
  8393. void clif_refresh(struct map_session_data *sd)
  8394. {
  8395. nullpo_retv(sd);
  8396. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8397. clif_inventorylist(sd);
  8398. clif_equipswitch_list(sd);
  8399. if(pc_iscarton(sd)) {
  8400. clif_cartlist(sd);
  8401. clif_updatestatus(sd,SP_CARTINFO);
  8402. }
  8403. clif_updatestatus(sd,SP_WEIGHT);
  8404. clif_updatestatus(sd,SP_MAXWEIGHT);
  8405. clif_updatestatus(sd,SP_STR);
  8406. clif_updatestatus(sd,SP_AGI);
  8407. clif_updatestatus(sd,SP_VIT);
  8408. clif_updatestatus(sd,SP_INT);
  8409. clif_updatestatus(sd,SP_DEX);
  8410. clif_updatestatus(sd,SP_LUK);
  8411. #ifdef RENEWAL
  8412. clif_updatestatus(sd,SP_POW);
  8413. clif_updatestatus(sd,SP_STA);
  8414. clif_updatestatus(sd,SP_WIS);
  8415. clif_updatestatus(sd,SP_SPL);
  8416. clif_updatestatus(sd,SP_CON);
  8417. clif_updatestatus(sd,SP_CRT);
  8418. #endif
  8419. if (sd->spiritball)
  8420. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8421. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8422. clif_millenniumshield_single(sd->fd, sd);
  8423. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8424. clif_spiritcharm_single(sd->fd, sd);
  8425. if (sd->soulball)
  8426. clif_soulball( sd, &sd->bl, SELF );
  8427. if (sd->servantball)
  8428. clif_servantball( *sd, &sd->bl, SELF );
  8429. if (sd->abyssball)
  8430. clif_abyssball( *sd, &sd->bl, SELF );
  8431. if (sd->vd.cloth_color)
  8432. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8433. if (sd->vd.body_style)
  8434. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8435. if(hom_is_active(sd->hd))
  8436. clif_send_homdata(sd,SP_ACK,0);
  8437. if( sd->md ) {
  8438. clif_mercenary_info(sd);
  8439. clif_mercenary_skillblock(sd);
  8440. }
  8441. if( sd->ed )
  8442. clif_elemental_info(sd);
  8443. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8444. clif_weather_check(sd);
  8445. if( sd->chatID )
  8446. chat_leavechat(sd,0);
  8447. if( sd->state.vending )
  8448. clif_openvending(sd, sd->bl.id, sd->vending);
  8449. if( pc_issit(sd) )
  8450. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8451. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8452. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8453. else
  8454. clif_changed_dir(&sd->bl, SELF);
  8455. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8456. //Issue #2143
  8457. //Cancel Trading State
  8458. if (sd->state.trading)
  8459. trade_tradecancel(sd);
  8460. //Cancel Buying/Selling State
  8461. if (sd->state.buyingstore)
  8462. buyingstore_close(sd);
  8463. mail_clear(sd);
  8464. clif_loadConfirm( sd );
  8465. if( disguised(&sd->bl) ) {/* refresh-da */
  8466. short disguise = sd->disguise;
  8467. pc_disguise(sd, 0);
  8468. pc_disguise(sd, disguise);
  8469. }
  8470. clif_refresh_storagewindow(sd);
  8471. }
  8472. /// Updates the object's (bl) name on client.
  8473. /// Used to update when a char leaves a party/guild. [Skotlex]
  8474. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8475. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8476. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8477. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8478. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8479. nullpo_retv( src );
  8480. nullpo_retv( bl );
  8481. switch( bl->type ){
  8482. case BL_PC: {
  8483. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8484. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8485. packet.gid = bl->id;
  8486. map_session_data *sd = (map_session_data *)bl;
  8487. //Requesting your own "shadow" name. [Skotlex]
  8488. if( src == bl && target == SELF && sd->disguise ){
  8489. packet.gid = -bl->id;
  8490. }
  8491. if( sd->fakename[0] ) {
  8492. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8493. clif_send( &packet, sizeof(packet), src, target );
  8494. return;
  8495. }
  8496. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8497. party_data *p = nullptr;
  8498. if( sd->status.party_id ){
  8499. p = party_search( sd->status.party_id );
  8500. }
  8501. // do not display party unless the player is also in a guild
  8502. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8503. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8504. }
  8505. if( sd->guild ){
  8506. int position;
  8507. // Will get the position of the guild the player is in
  8508. position = guild_getposition( sd );
  8509. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8510. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8511. }else if( sd->clan ){
  8512. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8513. }
  8514. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8515. packet.title_id = sd->status.title_id; // Title ID
  8516. #endif
  8517. clif_send(&packet, sizeof(packet), src, target);
  8518. }
  8519. break;
  8520. //[blackhole89]
  8521. case BL_HOM:
  8522. case BL_MER:
  8523. case BL_PET:
  8524. case BL_NPC:
  8525. case BL_ELEM: {
  8526. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8527. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8528. packet.gid = bl->id;
  8529. switch (bl->type) {
  8530. case BL_HOM:
  8531. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8532. break;
  8533. case BL_MER:
  8534. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8535. break;
  8536. case BL_PET:
  8537. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8538. break;
  8539. case BL_NPC:
  8540. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8541. break;
  8542. case BL_ELEM:
  8543. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8544. break;
  8545. }
  8546. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8547. unit_data *ud = unit_bl2ud(bl);
  8548. if (ud != nullptr) {
  8549. memcpy(packet.title, ud->title, NAME_LENGTH);
  8550. packet.groupId = ud->group_id;
  8551. }
  8552. #endif
  8553. clif_send(&packet, sizeof(packet), src, target);
  8554. }
  8555. break;
  8556. case BL_MOB: {
  8557. mob_data *md = (mob_data *)bl;
  8558. if( md->guardian_data && md->guardian_data->guild_id ){
  8559. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8560. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8561. packet.gid = bl->id;
  8562. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8563. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8564. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8565. clif_send(&packet, sizeof(packet), src, target);
  8566. }else if( battle_config.show_mob_info ){
  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. char mobhp[50], *str_p = mobhp;
  8572. if( battle_config.show_mob_info&4 ){
  8573. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8574. }
  8575. if( battle_config.show_mob_info&1 ){
  8576. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8577. }
  8578. if( battle_config.show_mob_info&2 ){
  8579. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8580. }
  8581. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8582. if( str_p != mobhp ){
  8583. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8584. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8585. }
  8586. clif_send(&packet, sizeof(packet), src, target);
  8587. } else {
  8588. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8589. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8590. packet.gid = bl->id;
  8591. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8592. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8593. unit_data *ud = unit_bl2ud(bl);
  8594. if (ud != nullptr) {
  8595. memcpy(packet.title, ud->title, NAME_LENGTH);
  8596. packet.groupId = ud->group_id;
  8597. }
  8598. #endif
  8599. clif_send(&packet, sizeof(packet), src, target);
  8600. }
  8601. }
  8602. break;
  8603. case BL_CHAT:
  8604. case BL_SKILL:
  8605. // Newer clients request this, but do not need an answer
  8606. return;
  8607. default:
  8608. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8609. return;
  8610. }
  8611. }
  8612. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8613. /// 01ff <id>.L <x>.W <y>.W
  8614. ///
  8615. /// Visually moves(instant) a character to x,y. The char moves even
  8616. /// when the target cell isn't walkable. If the char is sitting it
  8617. /// stays that way.
  8618. void clif_slide(struct block_list *bl, int x, int y)
  8619. {
  8620. unsigned char buf[10];
  8621. nullpo_retv(bl);
  8622. WBUFW(buf, 0) = 0x01ff;
  8623. WBUFL(buf, 2) = bl->id;
  8624. WBUFW(buf, 6) = x;
  8625. WBUFW(buf, 8) = y;
  8626. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8627. if( disguised(bl) )
  8628. {
  8629. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8630. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8631. }
  8632. }
  8633. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8634. /// 008d <packet len>.W <id>.L <message>.?B
  8635. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8636. {
  8637. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8638. int len_mes = strlen(mes)+1; //Account for \0
  8639. if (len_mes > sizeof(buf)-8) {
  8640. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8641. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8642. }
  8643. // send message to others
  8644. if (flag == AREA) {
  8645. WBUFW(buf,0) = 0x8d;
  8646. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8647. WBUFL(buf,4) = bl->id;
  8648. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8649. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8650. }
  8651. // send back message to the speaker
  8652. if( bl->type == BL_PC ) {
  8653. WBUFW(buf,0) = 0x8e;
  8654. WBUFW(buf, 2) = len_mes + 4;
  8655. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8656. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8657. }
  8658. }
  8659. /*==========================
  8660. * Minimap fix [Kevin]
  8661. * Remove dot from minimap
  8662. *--------------------------*/
  8663. void clif_party_xy_remove(struct map_session_data *sd)
  8664. {
  8665. unsigned char buf[16];
  8666. nullpo_retv(sd);
  8667. WBUFW(buf,0)=0x107;
  8668. WBUFL(buf,2)=sd->status.account_id;
  8669. WBUFW(buf,6)=-1;
  8670. WBUFW(buf,8)=-1;
  8671. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8672. }
  8673. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8674. /// 0215 <msg id>.L
  8675. /// msg id:
  8676. /// 0x15 = End all negative status (PA_GOSPEL)
  8677. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8678. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8679. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8680. /// 0x19 = All stats +20 (PA_GOSPEL)
  8681. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8682. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8683. /// 0x1e = DEF +25% (PA_GOSPEL)
  8684. /// 0x1f = ATK +100% (PA_GOSPEL)
  8685. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8686. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8687. /// ? = nothing
  8688. void clif_gospel_info(struct map_session_data *sd, int type)
  8689. {
  8690. int fd=sd->fd;
  8691. WFIFOHEAD(fd,packet_len(0x215));
  8692. WFIFOW(fd,0)=0x215;
  8693. WFIFOL(fd,2)=type;
  8694. WFIFOSET(fd, packet_len(0x215));
  8695. }
  8696. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8697. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8698. /// result:
  8699. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8700. /// star:
  8701. /// 0 = Place of the Sun
  8702. /// 1 = Place of the Moon
  8703. /// 2 = Place of the Stars
  8704. /// 1 = Star Gladiator %s's %s: <mapname>
  8705. /// star:
  8706. /// 0 = Place of the Sun
  8707. /// 1 = Place of the Moon
  8708. /// 2 = Place of the Stars
  8709. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8710. /// star:
  8711. /// 0 = Target of the Sun
  8712. /// 1 = Target of the Moon
  8713. /// 2 = Target of the Stars
  8714. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8715. /// star:
  8716. /// 0 = Monster of the Sun
  8717. /// 1 = Monster of the Moon
  8718. /// 2 = Monster of the Stars
  8719. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8720. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8721. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8722. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8723. /// 40 = Target HP : <monster_id used as HP>
  8724. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8725. {
  8726. int fd = sd->fd;
  8727. WFIFOHEAD(fd,packet_len(0x20e));
  8728. WFIFOW(fd,0) = 0x20e;
  8729. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8730. WFIFOL(fd,26) = monster_id;
  8731. WFIFOB(fd,30) = star;
  8732. WFIFOB(fd,31) = result;
  8733. WFIFOSET(fd,packet_len(0x20e));
  8734. }
  8735. /*==========================================
  8736. * Info about Star Glaldiator save map [Komurka]
  8737. * type: 1: Information, 0: Map registered
  8738. *------------------------------------------*/
  8739. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8740. {
  8741. char mapname[MAP_NAME_LENGTH_EXT];
  8742. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8743. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8744. }
  8745. /*==========================================
  8746. * Info about Star Glaldiator hate mob [Komurka]
  8747. * type: 1: Register mob, 0: Information.
  8748. *------------------------------------------*/
  8749. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8750. {
  8751. if( pcdb_checkid(class_) ) {
  8752. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8753. } else if( mobdb_checkid(class_) ) {
  8754. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8755. } else {
  8756. 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);
  8757. }
  8758. }
  8759. /*==========================================
  8760. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8761. *------------------------------------------*/
  8762. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8763. {
  8764. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8765. }
  8766. /*==========================================
  8767. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8768. *------------------------------------------*/
  8769. void clif_feel_hate_reset(struct map_session_data *sd)
  8770. {
  8771. clif_starskill(sd, "", 0, 0, 30);
  8772. }
  8773. /// Send out reply to configuration change
  8774. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8775. /// type: see enum e_config_type
  8776. /// value:
  8777. /// false = disabled
  8778. /// true = enabled
  8779. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8780. int fd;
  8781. nullpo_retv(sd);
  8782. fd = sd->fd;
  8783. WFIFOHEAD(fd, packet_len(0x2d9));
  8784. WFIFOW(fd, 0) = 0x2d9;
  8785. WFIFOL(fd, 2) = type;
  8786. WFIFOL(fd, 6) = enabled;
  8787. WFIFOSET(fd, packet_len(0x2d9));
  8788. }
  8789. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8790. /// 02da <open equip window>.B
  8791. /// open equip window:
  8792. /// 0 = disabled
  8793. /// 1 = enabled
  8794. void clif_equipcheckbox(struct map_session_data* sd)
  8795. {
  8796. int fd;
  8797. nullpo_retv(sd);
  8798. fd = sd->fd;
  8799. WFIFOHEAD(fd, packet_len(0x2da));
  8800. WFIFOW(fd, 0) = 0x2da;
  8801. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8802. WFIFOSET(fd, packet_len(0x2da));
  8803. }
  8804. /// Sends info about a player's equipped items.
  8805. /// 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)
  8806. /// 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)
  8807. /// 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)
  8808. /// 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)
  8809. /// 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)
  8810. /// 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)
  8811. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8812. nullpo_retv( sd );
  8813. nullpo_retv( tsd );
  8814. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8815. int equip = 0;
  8816. for( int i = 0; i < EQI_MAX; i++ ){
  8817. int k = tsd->equip_index[i];
  8818. if( k >= 0 ){
  8819. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8820. continue;
  8821. }
  8822. if( !tsd->inventory.u.items_inventory[k].equip ){
  8823. continue;
  8824. }
  8825. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8826. continue;
  8827. }
  8828. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8829. }
  8830. }
  8831. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8832. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8833. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8834. p->job = tsd->status.class_;
  8835. p->head = tsd->vd.hair_style;
  8836. p->accessory = tsd->vd.head_bottom;
  8837. p->accessory2 = tsd->vd.head_mid;
  8838. p->accessory3 = tsd->vd.head_top;
  8839. #if PACKETVER >= 20110111
  8840. p->robe = tsd->vd.robe;
  8841. #endif
  8842. p->headpalette = tsd->vd.hair_color;
  8843. p->bodypalette = tsd->vd.cloth_color;
  8844. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8845. p->body2 = tsd->vd.body_style;
  8846. #endif
  8847. p->sex = tsd->vd.sex;
  8848. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8849. }
  8850. /// Display msgstringtable.txt string (ZC_MSG).
  8851. /// 0291 <message>.W
  8852. void clif_msg(struct map_session_data* sd, unsigned short id)
  8853. {
  8854. int fd;
  8855. nullpo_retv(sd);
  8856. fd = sd->fd;
  8857. WFIFOHEAD(fd, packet_len(0x291));
  8858. WFIFOW(fd, 0) = 0x291;
  8859. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8860. WFIFOSET(fd, packet_len(0x291));
  8861. }
  8862. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8863. /// 0x7e2 <message>.W <value>.L
  8864. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8865. {
  8866. int fd = sd->fd;
  8867. WFIFOHEAD(fd, packet_len(0x7e2));
  8868. WFIFOW(fd,0) = 0x7e2;
  8869. WFIFOW(fd,2) = id;
  8870. WFIFOL(fd,4) = value;
  8871. WFIFOSET(fd, packet_len(0x7e2));
  8872. }
  8873. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8874. /// 07e6 <skill id>.W <msg id>.L
  8875. ///
  8876. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8877. /// "[SkillName] Message"
  8878. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8879. {
  8880. int fd = sd->fd;
  8881. WFIFOHEAD(fd, packet_len(0x7e6));
  8882. WFIFOW(fd,0) = 0x7e6;
  8883. WFIFOW(fd,2) = skill_id;
  8884. WFIFOL(fd,4) = msg_id;
  8885. WFIFOSET(fd, packet_len(0x7e6));
  8886. }
  8887. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8888. /// 09cd <msg id>.W <color>.L
  8889. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8890. nullpo_retv(sd);
  8891. int fd = sd->fd;
  8892. WFIFOHEAD(fd, packet_len(0x9cd));
  8893. WFIFOW(fd, 0) = 0x9cd;
  8894. WFIFOW(fd, 2) = msg_id;
  8895. WFIFOL(fd, 4) = color;
  8896. WFIFOSET(fd, packet_len(0x9cd));
  8897. }
  8898. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8899. /// Returns true if the packet was parsed successfully.
  8900. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8901. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8902. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8903. const char* seperator = " : ";
  8904. int fd;
  8905. struct s_packet_db* info;
  8906. uint16 packetLength, inputLength;
  8907. const char *input, *name, *message;
  8908. size_t nameLength, messageLength;
  8909. fd = sd->fd;
  8910. info = &packet_db[RFIFOW(fd,0)];
  8911. packetLength = RFIFOW(fd,info->pos[0]);
  8912. input = RFIFOCP(fd,info->pos[1]);
  8913. // basic structure check for the 4-byte header
  8914. if( packetLength < 4 ){
  8915. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8916. return false;
  8917. }else{
  8918. inputLength = packetLength - 4;
  8919. }
  8920. // process <name> part of the packet
  8921. if( whisperFormat ) {
  8922. // name has fixed width
  8923. if( inputLength < NAME_LENGTH + 1 ) {
  8924. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8925. return false;
  8926. }
  8927. name = input;
  8928. // validate name
  8929. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8930. // only restriction is that the name must be zero-terminated
  8931. if( name[nameLength] != '\0' ) {
  8932. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8933. return false;
  8934. }
  8935. message = input + NAME_LENGTH;
  8936. messageLength = inputLength - NAME_LENGTH;
  8937. }else{
  8938. // name and message are separated by ' : '
  8939. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8940. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8941. // check if there's enough data provided
  8942. if( inputLength < nameLength + seperatorLength + 1 ){
  8943. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8944. return false;
  8945. }
  8946. name = input;
  8947. // validate name
  8948. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8949. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8950. {
  8951. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8952. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8953. set_eof(sd->fd); // Just kick them out to correct it.
  8954. return false;
  8955. }
  8956. message = input + nameLength + seperatorLength;
  8957. messageLength = inputLength - nameLength - seperatorLength;
  8958. }
  8959. #if PACKETVER < 20151001
  8960. // the declared length must match real length
  8961. if( messageLength != strnlen(message, messageLength)+1 ) {
  8962. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8963. return false;
  8964. }
  8965. // verify <message> part of the packet
  8966. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8967. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8968. return false;
  8969. }
  8970. #else
  8971. // No zero termination anymore
  8972. messageLength += 1;
  8973. #endif
  8974. // messages mustn't be too long
  8975. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8976. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8977. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8978. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8979. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8980. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8981. return false;
  8982. }
  8983. // If it is not a whisper message, set the name to the fakename of the player
  8984. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8985. strcpy( out_name, sd->fakename );
  8986. }else{
  8987. safestrncpy( out_name, name, nameLength + 1 );
  8988. }
  8989. safestrncpy( out_message, message, messageLength );
  8990. if( whisperFormat ){
  8991. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8992. out_full_message[nameLength] = '\0';
  8993. }else{
  8994. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8995. }
  8996. if( is_atcommand( fd, sd, out_message, 1 ) )
  8997. return false;
  8998. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8999. return false; //no "chatting" while muted.
  9000. if( battle_config.min_chat_delay ) { //[Skotlex]
  9001. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9002. return false;
  9003. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9004. }
  9005. if (battle_config.idletime_option&IDLE_CHAT)
  9006. sd->idletime = last_tick;
  9007. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  9008. sd->idletime_hom = last_tick;
  9009. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  9010. sd->idletime_mer = last_tick;
  9011. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  9012. return true;
  9013. }
  9014. /**
  9015. * Displays a message if the player enters a PK Zone (during pk_mode)
  9016. * @param sd: Player data
  9017. */
  9018. inline void clif_pk_mode_message(struct map_session_data * sd)
  9019. {
  9020. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9021. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9022. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9023. char output[CHAT_SIZE_MAX];
  9024. // 1504: You've entered a PK Zone (safe until level %d).
  9025. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9026. battle_config.pk_min_level);
  9027. clif_showscript(&sd->bl, output, SELF);
  9028. } else {
  9029. // 1503: You've entered a PK Zone.
  9030. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9031. }
  9032. }
  9033. return;
  9034. }
  9035. // ---------------------
  9036. // clif_parse_wanttoconnect
  9037. // ---------------------
  9038. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9039. // error codes:
  9040. // 0 - Success
  9041. // 1 - Unknown packet_ver
  9042. // 2 - Invalid account_id
  9043. // 3 - Invalid char_id
  9044. // 4 - Invalid login_id1 (reserved)
  9045. // 5 - Invalid client_tick (reserved)
  9046. // 6 - Invalid sex
  9047. // Only the first 'invalid' error that appears is used.
  9048. static int clif_parse_WantToConnection_sub(int fd)
  9049. {
  9050. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9051. unsigned short cmd;
  9052. //By default, start searching on the default one.
  9053. cmd = RFIFOW(fd, 0);
  9054. packet_len = RFIFOREST(fd);
  9055. // FIXME: If the packet is not received at once, this will FAIL.
  9056. // Figure out, when it happens, that only part of the packet is
  9057. // received, or fix the function to be able to deal with that
  9058. // case.
  9059. if( packet_len != packet_db[cmd].len )
  9060. return 1; /* wrong length */
  9061. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9062. return 2; /* invalid account_id */
  9063. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9064. return 3; /* invalid char_id */
  9065. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9066. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9067. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9068. return 6; /* invalid sex */
  9069. else
  9070. return 0;
  9071. }
  9072. /// Request to connect to map-server.
  9073. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9074. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9075. /// There are various variants of this packet, some of them have padding between fields.
  9076. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  9077. {
  9078. struct block_list* bl;
  9079. struct auth_node* node;
  9080. int cmd, account_id, char_id, login_id1, sex, err;
  9081. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9082. if (sd) {
  9083. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9084. return;
  9085. }
  9086. cmd = RFIFOW(fd, 0);
  9087. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9088. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9089. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9090. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9091. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9092. err = clif_parse_WantToConnection_sub(fd);
  9093. if( err ){ // connection rejected
  9094. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9095. err == 1 ? "." :
  9096. err == 2 ? ", possibly for having an invalid account_id." :
  9097. err == 3 ? ", possibly for having an invalid char_id." :
  9098. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9099. err == 4 ? ", possibly for having an invalid login_id1." :
  9100. err == 5 ? ", possibly for having an invalid client_tick." :
  9101. */
  9102. err == 6 ? ", possibly for having an invalid sex." :
  9103. ". ERROR invalid error code"));
  9104. WFIFOHEAD(fd,packet_len(0x6a));
  9105. WFIFOW(fd,0) = 0x6a;
  9106. WFIFOB(fd,2) = err;
  9107. WFIFOSET(fd,packet_len(0x6a));
  9108. #ifdef DUMP_INVALID_PACKET
  9109. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9110. #endif
  9111. RFIFOSKIP(fd, RFIFOREST(fd));
  9112. set_eof(fd);
  9113. return;
  9114. }
  9115. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  9116. clif_authfail_fd(fd,1);// server closed
  9117. return;
  9118. }
  9119. //Check for double login.
  9120. bl = map_id2bl(account_id);
  9121. if(bl && bl->type != BL_PC) {
  9122. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9123. WFIFOHEAD(fd,packet_len(0x6a));
  9124. WFIFOW(fd,0) = 0x6a;
  9125. WFIFOB(fd,2) = 3; // Rejected by server
  9126. WFIFOSET(fd,packet_len(0x6a));
  9127. set_eof(fd);
  9128. return;
  9129. }
  9130. if (bl ||
  9131. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9132. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9133. {
  9134. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9135. return;
  9136. }
  9137. CREATE(sd, TBL_PC, 1);
  9138. sd->fd = fd;
  9139. #ifdef PACKET_OBFUSCATION
  9140. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9141. #endif
  9142. session[fd]->session_data = sd;
  9143. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9144. #if PACKETVER < 20070521
  9145. WFIFOHEAD(fd,4);
  9146. WFIFOL(fd,0) = sd->bl.id;
  9147. WFIFOSET(fd,4);
  9148. #else
  9149. WFIFOHEAD(fd,packet_len(0x283));
  9150. WFIFOW(fd,0) = 0x283;
  9151. WFIFOL(fd,2) = sd->bl.id;
  9152. WFIFOSET(fd,packet_len(0x283));
  9153. #endif
  9154. chrif_authreq(sd,false);
  9155. }
  9156. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9157. /// 007d
  9158. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9159. {
  9160. bool guild_notice = false;
  9161. if(sd->bl.prev != NULL)
  9162. return;
  9163. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9164. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9165. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9166. sd->state.connect_new = 0;
  9167. return;
  9168. }
  9169. if (sd->state.rewarp) { //Rewarp player.
  9170. sd->state.rewarp = 0;
  9171. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9172. return;
  9173. }
  9174. sd->state.warping = 0;
  9175. // look
  9176. #if PACKETVER < 4
  9177. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9178. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9179. #else
  9180. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9181. #endif
  9182. pc_set_costume_view(sd);
  9183. if(sd->vd.cloth_color)
  9184. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9185. if(sd->vd.body_style)
  9186. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9187. // item
  9188. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9189. pc_checkitem(sd);
  9190. clif_equipswitch_list(sd);
  9191. // cart
  9192. if(pc_iscarton(sd)) {
  9193. clif_cartlist(sd);
  9194. clif_updatestatus(sd,SP_CARTINFO);
  9195. }
  9196. // weight
  9197. clif_updatestatus(sd,SP_WEIGHT);
  9198. clif_updatestatus(sd,SP_MAXWEIGHT);
  9199. // guild
  9200. // (needs to go before clif_spawn() to show guild emblems correctly)
  9201. if(sd->status.guild_id)
  9202. guild_send_memberinfoshort(sd,1);
  9203. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9204. if(battle_config.pc_invincible_time > 0) {
  9205. if(mapdata_flag_gvg(mapdata))
  9206. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9207. else
  9208. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9209. }
  9210. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9211. map_spawnmobs(sd->bl.m);
  9212. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9213. mapdata->users_pvp++;
  9214. }
  9215. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9216. // reset the callshop flag if the player changes map
  9217. sd->state.callshop = 0;
  9218. if(map_addblock(&sd->bl))
  9219. return;
  9220. clif_spawn(&sd->bl);
  9221. // Party
  9222. // (needs to go after clif_spawn() to show hp bars correctly)
  9223. if(sd->status.party_id) {
  9224. party_send_movemap(sd);
  9225. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  9226. }
  9227. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9228. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9229. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9230. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9231. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9232. sd->pvp_rank = 0;
  9233. sd->pvp_lastusers = 0;
  9234. sd->pvp_point = 5;
  9235. sd->pvp_won = 0;
  9236. sd->pvp_lost = 0;
  9237. }
  9238. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9239. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9240. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9241. else if (mapdata->flag[MF_GVG_DUNGEON])
  9242. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9243. else if( mapdata_flag_gvg(mapdata) )
  9244. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9245. else
  9246. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9247. // info about nearby objects
  9248. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9249. 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);
  9250. // pet
  9251. if( sd->pd ) {
  9252. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9253. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9254. pet_return_egg( sd, sd->pd );
  9255. } else {
  9256. if(map_addblock(&sd->pd->bl))
  9257. return;
  9258. clif_spawn(&sd->pd->bl);
  9259. clif_send_petdata(sd,sd->pd,0,0);
  9260. clif_send_petstatus(sd);
  9261. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9262. }
  9263. }
  9264. //homunculus [blackhole89]
  9265. if( hom_is_active(sd->hd) ) {
  9266. if(map_addblock(&sd->hd->bl))
  9267. return;
  9268. clif_spawn(&sd->hd->bl);
  9269. clif_send_homdata(sd,SP_ACK,0);
  9270. clif_hominfo(sd,sd->hd,1);
  9271. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9272. clif_homskillinfoblock(sd);
  9273. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9274. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  9275. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9276. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9277. }
  9278. if( sd->md ) {
  9279. if(map_addblock(&sd->md->bl))
  9280. return;
  9281. clif_spawn(&sd->md->bl);
  9282. clif_mercenary_info(sd);
  9283. clif_mercenary_skillblock(sd);
  9284. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  9285. }
  9286. if( sd->ed ) {
  9287. if (map_addblock(&sd->ed->bl))
  9288. return;
  9289. clif_spawn(&sd->ed->bl);
  9290. clif_elemental_info(sd);
  9291. clif_elemental_updatestatus(sd,SP_HP);
  9292. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9293. clif_elemental_updatestatus(sd,SP_SP);
  9294. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9295. }
  9296. if(sd->state.connect_new) {
  9297. int lv;
  9298. guild_notice = true;
  9299. clif_skillinfoblock(sd);
  9300. clif_hotkeys_send(sd,0);
  9301. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9302. clif_hotkeys_send(sd,1);
  9303. #endif
  9304. clif_updatestatus(sd,SP_BASEEXP);
  9305. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9306. clif_updatestatus(sd,SP_JOBEXP);
  9307. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9308. clif_updatestatus(sd,SP_SKILLPOINT);
  9309. clif_initialstatus(sd);
  9310. if (sd->sc.option&OPTION_FALCON)
  9311. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9312. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9313. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9314. else if (sd->sc.option&OPTION_WUGRIDER)
  9315. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9316. else if (sd->sc.data[SC_ALL_RIDING])
  9317. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9318. if(sd->status.manner < 0)
  9319. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9320. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9321. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9322. if(sd->bl.m == sd->feel_map[0].m
  9323. || sd->bl.m == sd->feel_map[1].m
  9324. || sd->bl.m == sd->feel_map[2].m)
  9325. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9326. }
  9327. if(sd->pd && sd->pd->pet.intimate > 900)
  9328. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9329. if(hom_is_active(sd->hd))
  9330. hom_init_timers(sd->hd);
  9331. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9332. sd->state.night = 1;
  9333. clif_status_load(&sd->bl, EFST_SKE, 1);
  9334. }
  9335. // Notify everyone that this char logged in [Skotlex].
  9336. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9337. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9338. //Login Event
  9339. npc_script_event(sd, NPCE_LOGIN);
  9340. }
  9341. } else {
  9342. //For some reason the client "loses" these on warp/map-change.
  9343. clif_updatestatus(sd,SP_STR);
  9344. clif_updatestatus(sd,SP_AGI);
  9345. clif_updatestatus(sd,SP_VIT);
  9346. clif_updatestatus(sd,SP_INT);
  9347. clif_updatestatus(sd,SP_DEX);
  9348. clif_updatestatus(sd,SP_LUK);
  9349. #ifdef RENEWAL
  9350. clif_updatestatus(sd,SP_POW);
  9351. clif_updatestatus(sd,SP_STA);
  9352. clif_updatestatus(sd,SP_WIS);
  9353. clif_updatestatus(sd,SP_SPL);
  9354. clif_updatestatus(sd,SP_CON);
  9355. clif_updatestatus(sd,SP_CRT);
  9356. #endif
  9357. // abort currently running script
  9358. sd->state.using_fake_npc = 0;
  9359. sd->state.menu_or_input = 0;
  9360. sd->npc_menu = 0;
  9361. if(sd->npc_id)
  9362. npc_event_dequeue(sd);
  9363. }
  9364. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9365. #if PACKETVER >= 20070918
  9366. clif_partyinvitationstate(sd);
  9367. clif_equipcheckbox(sd);
  9368. #endif
  9369. clif_pet_autofeed_status(sd,false);
  9370. #if PACKETVER >= 20170920
  9371. if( battle_config.homunculus_autofeed_always ){
  9372. // Always send ON or OFF
  9373. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9374. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9375. }else{
  9376. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9377. }
  9378. }else{
  9379. // Only send when enabled
  9380. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9381. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9382. }
  9383. }
  9384. #endif
  9385. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9386. clif_guild_notice(sd); // Displays after VIP
  9387. guild_notice = false; // Do not display it twice
  9388. }
  9389. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9390. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9391. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9392. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9393. }
  9394. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9395. { //Display night.
  9396. if( !sd->state.night )
  9397. {
  9398. sd->state.night = 1;
  9399. clif_status_load(&sd->bl, EFST_SKE, 1);
  9400. }
  9401. }
  9402. else if( sd->state.night )
  9403. { //Clear night display.
  9404. sd->state.night = 0;
  9405. clif_status_load(&sd->bl, EFST_SKE, 0);
  9406. }
  9407. if( mapdata->flag[MF_BATTLEGROUND] )
  9408. {
  9409. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9410. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9411. clif_bg_updatescore_single(sd);
  9412. }
  9413. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9414. {
  9415. char output[128];
  9416. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9417. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9418. }
  9419. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9420. mapdata->hpmeter_visible++;
  9421. sd->state.hpmeter_visible = 1;
  9422. }
  9423. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9424. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9425. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9426. #ifdef VIP_ENABLE
  9427. if (!sd->state.connect_new &&
  9428. !sd->vip.disableshowrate &&
  9429. sd->state.pmap != sd->bl.m &&
  9430. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9431. )
  9432. {
  9433. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9434. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9435. }
  9436. #endif
  9437. // Instances do not need their own channels
  9438. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9439. channel_mjoin(sd); //join new map
  9440. clif_pk_mode_message(sd);
  9441. }
  9442. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9443. clif_guild_notice(sd); // Displays at end
  9444. }
  9445. mail_clear(sd);
  9446. /* Guild Aura Init */
  9447. if( sd->guild && sd->state.gmaster_flag ) {
  9448. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9449. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9450. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9451. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9452. }
  9453. if( sd->state.vending ) { /* show we have a vending */
  9454. clif_openvending(sd,sd->bl.id,sd->vending);
  9455. clif_showvendingboard(&sd->bl,sd->message,0);
  9456. }
  9457. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9458. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9459. npc_script_event(sd, NPCE_LOADMAP);
  9460. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9461. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9462. if (sd->sc.opt2) //Client loses these on warp.
  9463. clif_changeoption(&sd->bl);
  9464. 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)) {
  9465. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9466. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9467. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9468. }
  9469. clif_weather_check(sd);
  9470. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9471. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9472. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9473. else
  9474. sd->areanpc.clear();
  9475. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9476. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9477. pc_setdead(sd);
  9478. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9479. if(pc_isdead(sd))
  9480. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9481. else {
  9482. skill_usave_trigger(sd);
  9483. if (battle_config.spawn_direction)
  9484. clif_changed_dir(&sd->bl, SELF);
  9485. }
  9486. // Trigger skill effects if you appear standing on them
  9487. if(!battle_config.pc_invincible_time)
  9488. skill_unit_move(&sd->bl,gettick(),1);
  9489. pc_show_questinfo_reinit(sd);
  9490. pc_show_questinfo(sd);
  9491. #if PACKETVER >= 20150513
  9492. if( sd->mail.inbox.unread ){
  9493. clif_Mail_new(sd, 0, NULL, NULL);
  9494. }
  9495. #endif
  9496. sd->state.connect_new = 0;
  9497. sd->state.changemap = false;
  9498. }
  9499. /// Server's tick (ZC_NOTIFY_TIME).
  9500. /// 007f <time>.L
  9501. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9502. {
  9503. int fd = sd->fd;
  9504. WFIFOHEAD(fd,packet_len(0x7f));
  9505. WFIFOW(fd,0) = 0x7f;
  9506. WFIFOL(fd,2) = client_tick(time);
  9507. WFIFOSET(fd,packet_len(0x7f));
  9508. }
  9509. /// Request for server's tick.
  9510. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9511. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9512. /// There are various variants of this packet, some of them have padding between fields.
  9513. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9514. {
  9515. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9516. clif_notify_time(sd, gettick());
  9517. }
  9518. /// Sends hotkey bar.
  9519. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9520. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9521. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9522. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9523. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9524. #ifdef HOTKEY_SAVING
  9525. nullpo_retv( sd );
  9526. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9527. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9528. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9529. if( tab == 0 ){
  9530. p.rotate = sd->status.hotkey_rowshift;
  9531. }else{
  9532. p.rotate = sd->status.hotkey_rowshift2;
  9533. }
  9534. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9535. p.tab = tab;
  9536. #endif
  9537. #endif
  9538. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9539. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9540. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9541. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9542. }
  9543. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9544. #endif
  9545. }
  9546. /// Request to update a position on the hotkey row bar
  9547. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9548. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9549. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9550. if( p->tab == 0 ){
  9551. sd->status.hotkey_rowshift = p->rowshift;
  9552. }else{
  9553. sd->status.hotkey_rowshift2 = p->rowshift;
  9554. }
  9555. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9556. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9557. sd->status.hotkey_rowshift = p->rowshift;
  9558. #endif
  9559. }
  9560. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9561. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9562. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9563. #ifdef HOTKEY_SAVING
  9564. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9565. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9566. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9567. if( idx >= MAX_HOTKEYS_DB ){
  9568. return;
  9569. }
  9570. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9571. sd->status.hotkeys[idx].id = p->hotkey.id;
  9572. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9573. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9574. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9575. const unsigned short idx = p->index;
  9576. if( idx >= MAX_HOTKEYS_DB ){
  9577. return;
  9578. }
  9579. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9580. sd->status.hotkeys[idx].id = p->hotkey.id;
  9581. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9582. #endif
  9583. #endif
  9584. }
  9585. /// Displays cast-like progress bar (ZC_PROGRESS).
  9586. /// 02f0 <color>.L <time>.L
  9587. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9588. {
  9589. int fd = sd->fd;
  9590. WFIFOHEAD(fd,packet_len(0x2f0));
  9591. WFIFOW(fd,0) = 0x2f0;
  9592. WFIFOL(fd,2) = color;
  9593. WFIFOL(fd,6) = second;
  9594. WFIFOSET(fd,packet_len(0x2f0));
  9595. }
  9596. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9597. /// 02f2
  9598. void clif_progressbar_abort(struct map_session_data * sd)
  9599. {
  9600. int fd = sd->fd;
  9601. WFIFOHEAD(fd,packet_len(0x2f2));
  9602. WFIFOW(fd,0) = 0x2f2;
  9603. WFIFOSET(fd,packet_len(0x2f2));
  9604. }
  9605. /// Notification from the client, that the progress bar has reached 100%.
  9606. /// 02f1 (CZ_PROGRESS)
  9607. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9608. // No progressbar active, ignore it
  9609. if( !sd->progressbar.npc_id ){
  9610. return;
  9611. }
  9612. int npc_id = sd->progressbar.npc_id;
  9613. bool closing = false;
  9614. // Check if the progress was canceled
  9615. if( gettick() < sd->progressbar.timeout && sd->st ){
  9616. closing = true;
  9617. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9618. // If a message window was open, offer a close button to the user
  9619. if( sd->st->mes_active ){
  9620. clif_scriptclose( sd, npc_id );
  9621. }
  9622. }
  9623. sd->progressbar.npc_id = 0;
  9624. sd->progressbar.timeout = 0;
  9625. sd->state.workinprogress = WIP_DISABLE_NONE;
  9626. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9627. sd->idletime = last_tick;
  9628. }
  9629. npc_scriptcont(sd, npc_id, closing);
  9630. }
  9631. /// Displays cast-like progress bar on a NPC
  9632. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9633. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9634. #if PACKETVER >= 20130821
  9635. unsigned char buf[14];
  9636. if( nd->progressbar.timeout > 0 ){
  9637. WBUFW(buf,0) = 0x9d1;
  9638. WBUFL(buf,2) = nd->bl.id;
  9639. WBUFL(buf,6) = nd->progressbar.color;
  9640. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9641. if( sd ){
  9642. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9643. }else{
  9644. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9645. }
  9646. }
  9647. #endif
  9648. }
  9649. /// Request to walk to a certain position on the current map.
  9650. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9651. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9652. /// There are various variants of this packet, some of them have padding between fields.
  9653. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9654. {
  9655. short x, y;
  9656. if (pc_isdead(sd)) {
  9657. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9658. return;
  9659. }
  9660. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9661. ; //You CAN walk on this OPT1 value.
  9662. else if (sd->progressbar.npc_id) {
  9663. clif_progressbar_abort(sd);
  9664. return; // First walk attempt cancels the progress bar
  9665. } else if (pc_cant_act(sd))
  9666. return;
  9667. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9668. return;
  9669. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9670. //A move command one cell west is only valid if the target cell is free
  9671. if(battle_config.official_cell_stack_limit > 0
  9672. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9673. return;
  9674. // Cloaking wall check is actually updated when you click to process next movement
  9675. // not when you move each cell. This is official behaviour.
  9676. if (sd->sc.data[SC_CLOAKING])
  9677. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9678. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9679. status_change_end(&sd->bl, SC_CRESCIVEBOLT, INVALID_TIMER);
  9680. pc_delinvincibletimer(sd);
  9681. //Set last idle time... [Skotlex]
  9682. if (battle_config.idletime_option&IDLE_WALK)
  9683. sd->idletime = last_tick;
  9684. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9685. sd->idletime_hom = last_tick;
  9686. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9687. sd->idletime_mer = last_tick;
  9688. unit_walktoxy(&sd->bl, x, y, 4);
  9689. }
  9690. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9691. /// 018b <result>.W
  9692. /// result:
  9693. /// 0 = disconnect (quit)
  9694. /// 1 = cannot disconnect (wait 10 seconds)
  9695. /// ? = ignored
  9696. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9697. {
  9698. int fd = sd->fd;
  9699. WFIFOHEAD(fd,packet_len(0x18b));
  9700. WFIFOW(fd,0) = 0x18b;
  9701. WFIFOW(fd,2) = result;
  9702. WFIFOSET(fd,packet_len(0x18b));
  9703. }
  9704. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9705. /// 018a <type>.W
  9706. /// type:
  9707. /// 0 = quit
  9708. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9709. {
  9710. /* Rovert's prevent logout option fixed [Valaris] */
  9711. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9712. 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] &&
  9713. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9714. {
  9715. pc_damage_log_clear(sd,0);
  9716. clif_disconnect_ack(sd, 0);
  9717. flush_fifo( fd );
  9718. if( battle_config.drop_connection_on_quit ){
  9719. set_eof( fd );
  9720. }
  9721. } else {
  9722. clif_disconnect_ack(sd, 1);
  9723. }
  9724. }
  9725. /// Requesting unit's name.
  9726. /// 0094 <id>.L (CZ_REQNAME)
  9727. /// 0368 <id>.L (CZ_REQNAME2)
  9728. /// There are various variants of this packet, some of them have padding between fields.
  9729. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9730. {
  9731. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9732. struct block_list* bl;
  9733. //struct status_change *sc;
  9734. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9735. id = sd->bl.id;
  9736. bl = map_id2bl(id);
  9737. if( bl == NULL )
  9738. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9739. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9740. return; // Block namerequests past view range
  9741. // 'see people in GM hide' cheat detection
  9742. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9743. sc = status_get_sc(bl);
  9744. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9745. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9746. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9747. ) {
  9748. char gm_msg[256];
  9749. 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);
  9750. ShowWarning(gm_msg);
  9751. // information is sent to all online GMs
  9752. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9753. return;
  9754. }
  9755. */
  9756. clif_name(&sd->bl,bl,SELF);
  9757. }
  9758. /// Validates and processes global messages
  9759. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9760. /// There are various variants of this packet.
  9761. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9762. {
  9763. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9764. size_t length;
  9765. // validate packet and retrieve name and message
  9766. if( !clif_process_message(sd, false, name, message, output ) )
  9767. return;
  9768. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9769. channel_send(sd->gcbind,sd,message);
  9770. return;
  9771. }
  9772. // send message to others (using the send buffer for temp. storage)
  9773. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9774. length = strlen(output) + 1;
  9775. // send back message to the speaker
  9776. WFIFOHEAD(fd,4+length);
  9777. WFIFOW(fd,0) = 0x8e;
  9778. WFIFOW(fd,2) = (uint16)(4+length);
  9779. safestrncpy(WFIFOCP(fd,4), output, length );
  9780. WFIFOSET(fd, WFIFOW(fd,2));
  9781. #ifdef PCRE_SUPPORT
  9782. // trigger listening npcs
  9783. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9784. #endif
  9785. // Chat logging type 'O' / Global Chat
  9786. 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);
  9787. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9788. }
  9789. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9790. /// Request to warp to a map on given coordinates.
  9791. /// 0140 <map name>.16B <x>.W <y>.W
  9792. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9793. {
  9794. char command[MAP_NAME_LENGTH_EXT+25];
  9795. char* map_name;
  9796. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9797. map_name = RFIFOCP(fd,info->pos[0]);
  9798. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9799. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9800. RFIFOW(fd,info->pos[1]), //x
  9801. RFIFOW(fd,info->pos[2])); //y
  9802. is_atcommand(fd, sd, command, 1);
  9803. }
  9804. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9805. /// 009c <id>.L <head dir>.W <dir>.B
  9806. /// head dir:
  9807. /// 0 = straight
  9808. /// 1 = turned CW
  9809. /// 2 = turned CCW
  9810. /// dir:
  9811. /// 0 = north
  9812. /// 1 = northwest
  9813. /// 2 = west
  9814. /// 3 = southwest
  9815. /// 4 = south
  9816. /// 5 = southeast
  9817. /// 6 = east
  9818. /// 7 = northeast
  9819. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9820. {
  9821. unsigned char buf[64];
  9822. WBUFW(buf,0) = 0x9c;
  9823. WBUFL(buf,2) = bl->id;
  9824. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9825. WBUFB(buf,8) = unit_getdir(bl);
  9826. clif_send(buf, packet_len(0x9c), bl, target);
  9827. if (disguised(bl)) {
  9828. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9829. WBUFW(buf,6) = 0;
  9830. clif_send(buf, packet_len(0x9c), bl, SELF);
  9831. }
  9832. }
  9833. /// Request to change own body and head direction.
  9834. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9835. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9836. /// There are various variants of this packet, some of them have padding between fields.
  9837. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9838. {
  9839. unsigned char headdir, dir;
  9840. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9841. headdir = RFIFOB(fd,info->pos[0]);
  9842. dir = RFIFOB(fd,info->pos[1]);
  9843. pc_setdir(sd, dir, headdir);
  9844. clif_changed_dir(&sd->bl, AREA_WOS);
  9845. }
  9846. /// Request to show an emotion (CZ_REQ_EMOTION).
  9847. /// 00bf <type>.B
  9848. /// type:
  9849. /// @see enum emotion_type
  9850. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9851. {
  9852. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9853. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9854. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9855. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9856. return;
  9857. }
  9858. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9859. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9860. sd->emotionlasttime = time(NULL);
  9861. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9862. return;
  9863. }
  9864. sd->emotionlasttime = time(NULL);
  9865. if (battle_config.idletime_option&IDLE_EMOTION)
  9866. sd->idletime = last_tick;
  9867. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9868. sd->idletime_hom = last_tick;
  9869. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9870. sd->idletime_mer = last_tick;
  9871. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9872. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9873. return;
  9874. }
  9875. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9876. emoticon = rnd()%6+ET_DICE1;
  9877. }
  9878. clif_emotion(&sd->bl, emoticon);
  9879. } else
  9880. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9881. }
  9882. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9883. /// 00c2 <count>.L
  9884. void clif_user_count(struct map_session_data* sd, int count)
  9885. {
  9886. int fd = sd->fd;
  9887. WFIFOHEAD(fd,packet_len(0xc2));
  9888. WFIFOW(fd,0) = 0xc2;
  9889. WFIFOL(fd,2) = count;
  9890. WFIFOSET(fd,packet_len(0xc2));
  9891. }
  9892. /// /w /who (CZ_REQ_USER_COUNT).
  9893. /// Request to display amount of currently connected players.
  9894. /// 00c1
  9895. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9896. {
  9897. clif_user_count(sd, map_getusers());
  9898. }
  9899. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9900. {
  9901. if (pc_isdead(sd)) {
  9902. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9903. return;
  9904. }
  9905. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9906. // (not all are included in pc_can_attack)
  9907. if (sd->sc.count &&
  9908. (sd->sc.data[SC_TRICKDEAD] ||
  9909. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9910. sd->sc.data[SC_BLADESTOP] ||
  9911. sd->sc.data[SC__MANHOLE] ||
  9912. sd->sc.data[SC_SUHIDE] ||
  9913. sd->sc.data[SC_GRAVITYCONTROL]))
  9914. return;
  9915. if(action_type != 0x00 && action_type != 0x07)
  9916. pc_stop_walking(sd, 1);
  9917. pc_stop_attack(sd);
  9918. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9919. target_id = sd->bl.id;
  9920. switch(action_type)
  9921. {
  9922. case 0x00: // once attack
  9923. case 0x07: // continuous attack
  9924. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9925. return;
  9926. if( sd->sc.option&OPTION_COSTUME )
  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.count && (
  10200. sd->sc.data[SC_AUTOCOUNTER] ||
  10201. sd->sc.data[SC_BLADESTOP] ||
  10202. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  10203. ))
  10204. break;
  10205. if (!pc_dropitem(sd, item_index, item_amount))
  10206. break;
  10207. if (battle_config.idletime_option&IDLE_DROPITEM)
  10208. sd->idletime = last_tick;
  10209. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10210. sd->idletime_hom = last_tick;
  10211. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10212. sd->idletime_mer = last_tick;
  10213. return;
  10214. }
  10215. //Because the client does not like being ignored.
  10216. clif_dropitem(sd, item_index,0);
  10217. }
  10218. /// Request to use an item.
  10219. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10220. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10221. /// There are various variants of this packet, some of them have padding between fields.
  10222. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10223. {
  10224. int n;
  10225. if (pc_isdead(sd)) {
  10226. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10227. return;
  10228. }
  10229. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10230. clif_msg(sd, WORK_IN_PROGRESS);
  10231. return;
  10232. }
  10233. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10234. if (battle_config.idletime_option&IDLE_USEITEM)
  10235. sd->idletime = last_tick;
  10236. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10237. sd->idletime_hom = last_tick;
  10238. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10239. sd->idletime_mer = last_tick;
  10240. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10241. if(n <0 || n >= MAX_INVENTORY)
  10242. return;
  10243. if (!pc_useitem(sd,n))
  10244. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10245. }
  10246. /// Request to equip an item
  10247. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10248. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10249. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10250. {
  10251. int index;
  10252. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10253. if(pc_isdead(sd)) {
  10254. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10255. return;
  10256. }
  10257. index = RFIFOW(fd,info->pos[0])-2;
  10258. if (index < 0 || index >= MAX_INVENTORY)
  10259. return; //Out of bounds check.
  10260. if(sd->npc_id && !sd->npc_item_flag) {
  10261. return;
  10262. } else if (sd->state.storage_flag || sd->sc.opt1)
  10263. ; //You can equip/unequip stuff while storage is open/under status changes
  10264. else if (pc_cant_act2(sd))
  10265. return;
  10266. if(!sd->inventory.u.items_inventory[index].identify) {
  10267. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  10268. return;
  10269. }
  10270. if(!sd->inventory_data[index])
  10271. return;
  10272. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10273. pet_equipitem(sd,index);
  10274. return;
  10275. }
  10276. if (battle_config.idletime_option&IDLE_USEITEM)
  10277. sd->idletime = last_tick;
  10278. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10279. sd->idletime_hom = last_tick;
  10280. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10281. sd->idletime_mer = last_tick;
  10282. //Client doesn't send the position for ammo.
  10283. if(sd->inventory_data[index]->type == IT_AMMO)
  10284. pc_equipitem(sd,index,EQP_AMMO);
  10285. else {
  10286. int req_pos;
  10287. #if PACKETVER >= 20120925
  10288. req_pos = RFIFOL(fd,info->pos[1]);
  10289. #else
  10290. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10291. #endif
  10292. pc_equipitem(sd,index,req_pos);
  10293. }
  10294. }
  10295. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10296. /// 00ab <index>.W
  10297. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10298. {
  10299. int index;
  10300. if(pc_isdead(sd)) {
  10301. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10302. return;
  10303. }
  10304. if (sd->npc_id && !sd->npc_item_flag) {
  10305. return;
  10306. } else if (sd->state.storage_flag || sd->sc.opt1)
  10307. ; //You can equip/unequip stuff while storage is open/under status changes
  10308. else if (pc_cant_act2(sd))
  10309. return;
  10310. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10311. if (battle_config.idletime_option&IDLE_USEITEM)
  10312. sd->idletime = last_tick;
  10313. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10314. sd->idletime_hom = last_tick;
  10315. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10316. sd->idletime_mer = last_tick;
  10317. pc_unequipitem(sd,index,1);
  10318. }
  10319. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10320. /// 0090 <id>.L <type>.B
  10321. /// type:
  10322. /// 1 = click
  10323. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10324. {
  10325. struct block_list *bl;
  10326. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10327. if(pc_isdead(sd)) {
  10328. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10329. return;
  10330. }
  10331. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10332. #ifdef RENEWAL
  10333. clif_msg( sd, WORK_IN_PROGRESS );
  10334. #endif
  10335. return;
  10336. }
  10337. if( sd->state.mail_writing )
  10338. return;
  10339. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10340. //type = RFIFOB(fd,info->pos[1]);
  10341. if (!bl) return;
  10342. switch (bl->type) {
  10343. case BL_MOB:
  10344. case BL_PC:
  10345. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10346. break;
  10347. case BL_NPC:
  10348. #ifdef RENEWAL
  10349. 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
  10350. clif_msg(sd, WORK_IN_PROGRESS);
  10351. break;
  10352. }
  10353. #endif
  10354. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10355. struct npc_data* nd = (struct npc_data*)bl;
  10356. // Progressbar is running
  10357. if( nd->progressbar.timeout > 0 ){
  10358. return;
  10359. }
  10360. npc_click(sd,nd);
  10361. }
  10362. break;
  10363. }
  10364. }
  10365. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10366. /// 00c5 <id>.L <type>.B
  10367. /// type:
  10368. /// 0 = buy
  10369. /// 1 = sell
  10370. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10371. {
  10372. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10373. if (sd->state.trading)
  10374. return;
  10375. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10376. }
  10377. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10378. /// 00ca <result>.B
  10379. /// result:
  10380. /// 0 = "The deal has successfully completed."
  10381. /// 1 = "You do not have enough zeny."
  10382. /// 2 = "You are over your Weight Limit."
  10383. /// 3 = "Out of the maximum capacity, you have too many items."
  10384. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10385. /// 10 = "Props open-air store sales will be traded in RODEX"
  10386. /// 11 = "The exchange failed."
  10387. /// 12 = "The exchange was well done."
  10388. /// 13 = "The item is already sold and out of stock."
  10389. /// 14 = "There is not enough goods to exchange."
  10390. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10391. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10392. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10393. p.result = (uint8)result;
  10394. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10395. }
  10396. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10397. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10398. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10399. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10400. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10401. e_purchase_result result;
  10402. if( sd->state.trading || !sd->npc_shopid )
  10403. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10404. else{
  10405. std::vector<s_npc_buy_list> items = {};
  10406. items.reserve( n );
  10407. for( uint16 i = 0; i < n; i++ ){
  10408. s_npc_buy_list item = {};
  10409. item.nameid = p->items[i].itemId;
  10410. item.qty = p->items[i].amount;
  10411. items.push_back( item );
  10412. }
  10413. result = npc_buylist( sd, items );
  10414. }
  10415. sd->npc_shopid = 0; //Clear shop data.
  10416. clif_npc_buy_result(sd, result);
  10417. }
  10418. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10419. /// 00cb <result>.B
  10420. /// result:
  10421. /// 0 = "The deal has successfully completed."
  10422. /// 1 = "The deal has failed."
  10423. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10424. {
  10425. int fd = sd->fd;
  10426. WFIFOHEAD(fd,packet_len(0xcb));
  10427. WFIFOW(fd,0) = 0xcb;
  10428. WFIFOB(fd,2) = result;
  10429. WFIFOSET(fd,packet_len(0xcb));
  10430. }
  10431. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10432. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10433. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10434. {
  10435. int fail=0,n;
  10436. unsigned short *item_list;
  10437. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10438. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10439. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10440. if (sd->state.trading || !sd->npc_shopid)
  10441. fail = 1;
  10442. else
  10443. fail = npc_selllist(sd,n,item_list);
  10444. sd->npc_shopid = 0; //Clear shop data.
  10445. clif_npc_sell_result(sd, fail);
  10446. }
  10447. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10448. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10449. /// type:
  10450. /// 0 = private
  10451. /// 1 = public
  10452. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10453. {
  10454. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10455. int len = RFIFOW(fd,info->pos[0])-15;
  10456. int limit = RFIFOW(fd,info->pos[1]);
  10457. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10458. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10459. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10460. char s_password[CHATROOM_PASS_SIZE];
  10461. char s_title[CHATROOM_TITLE_SIZE];
  10462. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10463. return;
  10464. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10465. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10466. return;
  10467. }
  10468. if( npc_isnear(&sd->bl) ) {
  10469. // uncomment to send msg_txt.
  10470. //char output[150];
  10471. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10472. //clif_displaymessage(sd->fd, output);
  10473. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10474. return;
  10475. }
  10476. if( len <= 0 )
  10477. return; // invalid input
  10478. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10479. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10480. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10481. }
  10482. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10483. /// 00d9 <chat ID>.L <passwd>.8B
  10484. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10485. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10486. int chatid = RFIFOL(fd,info->pos[0]);
  10487. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10488. chat_joinchat(sd,chatid,password);
  10489. }
  10490. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10491. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10492. /// type:
  10493. /// 0 = private
  10494. /// 1 = public
  10495. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10496. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10497. int len = RFIFOW(fd,info->pos[0])-15;
  10498. int limit = RFIFOW(fd,info->pos[1]);
  10499. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10500. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10501. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10502. char s_password[CHATROOM_PASS_SIZE];
  10503. char s_title[CHATROOM_TITLE_SIZE];
  10504. if( len <= 0 )
  10505. return; // invalid input
  10506. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10507. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10508. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10509. }
  10510. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10511. /// 00e0 <role>.L <nick>.24B
  10512. /// role:
  10513. /// 0 = owner
  10514. /// 1 = normal
  10515. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10516. {
  10517. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10518. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10519. }
  10520. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10521. /// 00e2 <name>.24B
  10522. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10523. {
  10524. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10525. }
  10526. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10527. /// 00e3
  10528. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10529. {
  10530. chat_leavechat(sd,0);
  10531. }
  10532. //Handles notifying asker and rejecter of what has just ocurred.
  10533. //Type is used to determine the correct msg_txt to use:
  10534. //0:
  10535. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10536. {
  10537. const char* msg;
  10538. char output[256];
  10539. // Your request has been rejected by autoreject option.
  10540. msg = msg_txt(sd,392);
  10541. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10542. //Notice that a request was rejected.
  10543. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10544. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10545. }
  10546. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10547. /// 00e4 <account id>.L
  10548. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10549. {
  10550. struct map_session_data *t_sd;
  10551. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10552. if(!sd->chatID && pc_cant_act(sd))
  10553. return; //You can trade while in a chatroom.
  10554. if(t_sd){
  10555. // @noask [LuzZza]
  10556. if(t_sd->state.noask) {
  10557. clif_noask_sub(sd, t_sd, 0);
  10558. return;
  10559. }
  10560. if (t_sd->state.mail_writing) {
  10561. int old = sd->trade_partner;
  10562. // Fake trading
  10563. sd->trade_partner = t_sd->status.account_id;
  10564. clif_tradestart(sd, 5);
  10565. // Restore old state
  10566. sd->trade_partner = old;
  10567. return;
  10568. }
  10569. }
  10570. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10571. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10572. return;
  10573. }
  10574. trade_traderequest(sd,t_sd);
  10575. }
  10576. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10577. /// 00e6 <result>.B
  10578. /// result:
  10579. /// 3 = accepted
  10580. /// 4 = rejected
  10581. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10582. {
  10583. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10584. }
  10585. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10586. /// 00e8 <index>.W <amount>.L
  10587. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10588. {
  10589. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10590. short index = RFIFOW(fd,info->pos[0]);
  10591. int amount = RFIFOL(fd,info->pos[1]);
  10592. if( index == 0 )
  10593. trade_tradeaddzeny(sd, amount);
  10594. else
  10595. trade_tradeadditem(sd, index, (short)amount);
  10596. }
  10597. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10598. /// 00eb
  10599. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10600. {
  10601. trade_tradeok(sd);
  10602. }
  10603. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10604. /// 00ed
  10605. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10606. {
  10607. trade_tradecancel(sd);
  10608. }
  10609. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10610. /// 00ef
  10611. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10612. {
  10613. trade_tradecommit(sd);
  10614. }
  10615. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10616. /// 0118
  10617. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10618. {
  10619. pc_stop_attack(sd);
  10620. if (sd) sd->ud.state.attack_continue = 0;
  10621. }
  10622. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10623. /// 0126 <index>.W <amount>.L
  10624. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10625. {
  10626. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10627. if (pc_istrading(sd))
  10628. return;
  10629. if (!pc_iscarton(sd))
  10630. return;
  10631. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10632. }
  10633. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10634. /// 0127 <index>.W <amount>.L
  10635. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10636. {
  10637. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10638. if (!pc_iscarton(sd))
  10639. return;
  10640. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10641. }
  10642. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10643. /// 012a
  10644. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10645. {
  10646. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10647. #ifdef NEW_CARTS
  10648. && sd->sc.data[SC_PUSH_CART] )
  10649. pc_setcart(sd,0);
  10650. #else
  10651. )
  10652. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10653. #endif
  10654. else // priority to remove this option before we can clear cart
  10655. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10656. }
  10657. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10658. /// 097f <Length>.W <identity>.L <type>.B
  10659. void clif_SelectCart(struct map_session_data *sd) {
  10660. #if PACKETVER >= 20150826
  10661. int i = 0, carts = 3;
  10662. int fd = sd->fd;
  10663. WFIFOHEAD(fd,8 + carts);
  10664. WFIFOW(fd,0) = 0x97f;
  10665. WFIFOW(fd,2) = 8 + carts;
  10666. WFIFOL(fd,4) = sd->status.account_id;
  10667. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10668. for( i = 0; i < carts; i++ ) {
  10669. WFIFOB(fd,8 + i) = 10 + i;
  10670. }
  10671. WFIFOSET(fd,8 + carts);
  10672. #endif
  10673. }
  10674. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10675. /// 0980 <identity>.L <type>.B
  10676. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10677. #if PACKETVER >= 20150826
  10678. int type;
  10679. // Check identity
  10680. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10681. return;
  10682. type = (int)RFIFOB(fd,6);
  10683. // Check type
  10684. if( type < 10 || type > 12 )
  10685. return;
  10686. pc_setcart(sd, type);
  10687. #endif
  10688. }
  10689. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10690. /// 01af <num>.W
  10691. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10692. {// TODO: State tracking?
  10693. int type;
  10694. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10695. return;
  10696. #ifdef RENEWAL
  10697. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10698. clif_msg(sd, WORK_IN_PROGRESS);
  10699. return;
  10700. }
  10701. #endif
  10702. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10703. if(
  10704. #ifdef NEW_CARTS
  10705. #if PACKETVER >= 20191106
  10706. (type == 13 && sd->status.base_level > 100) ||
  10707. #endif
  10708. (type == 9 && sd->status.base_level > 130) ||
  10709. (type == 8 && sd->status.base_level > 120) ||
  10710. (type == 7 && sd->status.base_level > 110) ||
  10711. (type == 6 && sd->status.base_level > 100) ||
  10712. #endif
  10713. (type == 5 && sd->status.base_level > 90) ||
  10714. (type == 4 && sd->status.base_level > 80) ||
  10715. (type == 3 && sd->status.base_level > 65) ||
  10716. (type == 2 && sd->status.base_level > 40) ||
  10717. (type == 1))
  10718. pc_setcart(sd, type);
  10719. }
  10720. /// Request to increase status (CZ_STATUS_CHANGE).
  10721. /// 00bb <status id>.W <amount>.B
  10722. /// status id:
  10723. /// SP_STR ~ SP_LUK
  10724. /// amount:
  10725. /// Old clients always send 1 for this, even when using /str+ and the like.
  10726. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10727. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10728. {
  10729. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10730. if( increase_amount < 0 ) {
  10731. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10732. fd, increase_amount);
  10733. }
  10734. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10735. }
  10736. /// Request to increase trait status.
  10737. /// 0b24 <status id>.W <amount>.W
  10738. /// status id:
  10739. /// SP_POW ~ SP_CON
  10740. /// amount:
  10741. /// The amount to increase the trait status
  10742. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10743. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10744. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10745. if( p->amount < 0 ){
  10746. 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 );
  10747. return;
  10748. }
  10749. pc_traitstatusup( sd, p->type, p->amount );
  10750. #endif
  10751. }
  10752. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10753. /// 0112 <skill id>.W
  10754. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10755. {
  10756. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10757. }
  10758. 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)
  10759. {
  10760. int lv;
  10761. if( !hd )
  10762. return;
  10763. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10764. clif_emotion(&hd->bl, ET_THINK);
  10765. return;
  10766. }
  10767. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10768. target_id = hd->bl.id;
  10769. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10770. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10771. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10772. clif_emotion(&hd->bl, ET_THINK);
  10773. if (hd->master)
  10774. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10775. return;
  10776. }
  10777. lv = hom_checkskill(hd, skill_id);
  10778. if( skill_lv > lv )
  10779. skill_lv = lv;
  10780. if( skill_lv )
  10781. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10782. }
  10783. 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)
  10784. {
  10785. int lv;
  10786. if( !hd )
  10787. return;
  10788. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10789. clif_emotion(&hd->bl, ET_THINK);
  10790. return;
  10791. }
  10792. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10793. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10794. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10795. clif_emotion(&hd->bl, ET_THINK);
  10796. if (hd->master)
  10797. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10798. return;
  10799. }
  10800. #ifdef RENEWAL
  10801. if (hd->sc.data[SC_BASILICA_CELL])
  10802. #else
  10803. if (hd->sc.data[SC_BASILICA])
  10804. #endif
  10805. return;
  10806. lv = hom_checkskill(hd, skill_id);
  10807. if( skill_lv > lv )
  10808. skill_lv = lv;
  10809. if( skill_lv )
  10810. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10811. }
  10812. 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)
  10813. {
  10814. int lv;
  10815. if( !md )
  10816. return;
  10817. if( skill_isNotOk_mercenary(skill_id, md) )
  10818. return;
  10819. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10820. target_id = md->bl.id;
  10821. if( md->ud.skilltimer != INVALID_TIMER )
  10822. {
  10823. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10824. }
  10825. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10826. return;
  10827. lv = mercenary_checkskill(md, skill_id);
  10828. if( skill_lv > lv )
  10829. skill_lv = lv;
  10830. if( skill_lv )
  10831. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10832. }
  10833. 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)
  10834. {
  10835. int lv;
  10836. if( !md )
  10837. return;
  10838. if( skill_isNotOk_mercenary(skill_id, md) )
  10839. return;
  10840. if( md->ud.skilltimer != INVALID_TIMER )
  10841. return;
  10842. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10843. {
  10844. if (md->master)
  10845. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10846. return;
  10847. }
  10848. #ifdef RENEWAL
  10849. if (md->sc.data[SC_BASILICA_CELL])
  10850. #else
  10851. if (md->sc.data[SC_BASILICA])
  10852. #endif
  10853. return;
  10854. lv = mercenary_checkskill(md, skill_id);
  10855. if( skill_lv > lv )
  10856. skill_lv = lv;
  10857. if( skill_lv )
  10858. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10859. }
  10860. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10861. t_tick tick = gettick();
  10862. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10863. int inf = skill_get_inf(skill_id);
  10864. if (inf&INF_GROUND_SKILL || !inf)
  10865. return; //Using a ground/passive skill on a target? WRONG.
  10866. if (sd->state.block_action & PCBLOCK_SKILL) {
  10867. clif_msg(sd, WORK_IN_PROGRESS);
  10868. return;
  10869. }
  10870. if( SKILL_CHK_HOMUN(skill_id) ) {
  10871. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10872. return;
  10873. }
  10874. if( SKILL_CHK_MERC(skill_id) ) {
  10875. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10876. return;
  10877. }
  10878. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10879. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10880. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10881. sd->idletime = last_tick;
  10882. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10883. sd->idletime_hom = last_tick;
  10884. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10885. sd->idletime_mer = last_tick;
  10886. if( sd->npc_id ){
  10887. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10888. #ifdef RENEWAL
  10889. clif_msg( sd, WORK_IN_PROGRESS );
  10890. #endif
  10891. return;
  10892. }
  10893. }
  10894. if ((pc_cant_act2(sd) || sd->chatID) &&
  10895. skill_id != RK_REFRESH &&
  10896. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10897. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10898. return;
  10899. if( pc_issit(sd) )
  10900. return;
  10901. if( skill_isNotOk(skill_id, sd) )
  10902. return;
  10903. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10904. target_id = sd->bl.id; // never trust the client
  10905. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10906. target_id = sd->bl.id;
  10907. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10908. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10909. return;
  10910. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10911. if( sd->skillitem != skill_id ) {
  10912. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10913. return;
  10914. }
  10915. }
  10916. if( sd->sc.option&OPTION_COSTUME )
  10917. return;
  10918. #ifndef RENEWAL
  10919. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10920. return; // On basilica only caster can use Basilica again to stop it.
  10921. #endif
  10922. if( sd->menuskill_id ) {
  10923. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10924. clif_menuskill_clear(sd); //Cancel pet capture.
  10925. }else if( sd->menuskill_id == SG_FEEL ){
  10926. clif_menuskill_clear( sd ); // Cancel selection
  10927. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10928. return; //Can't use skills while a menu is open.
  10929. }
  10930. if( sd->skillitem == skill_id ) {
  10931. if( skill_lv != sd->skillitemlv )
  10932. skill_lv = sd->skillitemlv;
  10933. if( !(inf&INF_SELF_SKILL) )
  10934. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10935. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10936. return;
  10937. }
  10938. sd->skillitem = sd->skillitemlv = 0;
  10939. if( SKILL_CHK_GUILD(skill_id) ) {
  10940. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10941. skill_lv = guild_checkskill(sd->guild, skill_id);
  10942. else
  10943. skill_lv = 0;
  10944. } else {
  10945. if( skill_id != ALL_EQSWITCH ){
  10946. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10947. }
  10948. }
  10949. pc_delinvincibletimer(sd);
  10950. if( skill_lv )
  10951. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10952. }
  10953. /// Request to use a targeted skill.
  10954. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10955. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10956. /// There are various variants of this packet, some of them have padding between fields.
  10957. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10958. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10959. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10960. }
  10961. /*==========================================
  10962. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10963. *------------------------------------------*/
  10964. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10965. {
  10966. t_tick tick = gettick();
  10967. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10968. return; //Using a target skill on the ground? WRONG.
  10969. if (sd->state.block_action & PCBLOCK_SKILL) {
  10970. clif_msg(sd, WORK_IN_PROGRESS);
  10971. return;
  10972. }
  10973. if( SKILL_CHK_HOMUN(skill_id) ) {
  10974. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10975. return;
  10976. }
  10977. if( SKILL_CHK_MERC(skill_id) ) {
  10978. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10979. return;
  10980. }
  10981. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10982. #ifdef RENEWAL
  10983. clif_msg( sd, WORK_IN_PROGRESS );
  10984. #endif
  10985. return;
  10986. }
  10987. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10988. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10989. sd->idletime = last_tick;
  10990. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10991. sd->idletime_hom = last_tick;
  10992. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10993. sd->idletime_mer = last_tick;
  10994. if( skill_isNotOk(skill_id, sd) )
  10995. return;
  10996. if( skillmoreinfo != -1 ) {
  10997. if( pc_issit(sd) ) {
  10998. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10999. return;
  11000. }
  11001. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  11002. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  11003. }
  11004. if( sd->ud.skilltimer != INVALID_TIMER )
  11005. return;
  11006. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  11007. if( sd->skillitem != skill_id ) {
  11008. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  11009. return;
  11010. }
  11011. }
  11012. if( sd->sc.option&OPTION_COSTUME )
  11013. return;
  11014. #ifndef RENEWAL
  11015. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  11016. return; // On basilica only caster can use Basilica again to stop it.
  11017. #endif
  11018. if( sd->menuskill_id ) {
  11019. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  11020. clif_menuskill_clear(sd); //Cancel pet capture.
  11021. }else if( sd->menuskill_id == SG_FEEL ){
  11022. clif_menuskill_clear( sd ); // Cancel selection
  11023. } else if( sd->menuskill_id != SA_AUTOSPELL )
  11024. return; //Can't use skills while a menu is open.
  11025. }
  11026. pc_delinvincibletimer(sd);
  11027. if( sd->skillitem == skill_id ) {
  11028. if( skill_lv != sd->skillitemlv )
  11029. skill_lv = sd->skillitemlv;
  11030. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  11031. } else {
  11032. int lv;
  11033. sd->skillitem = sd->skillitemlv = 0;
  11034. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  11035. if( skill_lv > lv )
  11036. skill_lv = lv;
  11037. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  11038. }
  11039. }
  11040. }
  11041. /// Request to use a ground skill.
  11042. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11043. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11044. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11045. /// There are various variants of this packet, some of them have padding between fields.
  11046. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  11047. {
  11048. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11049. if (pc_cant_act(sd))
  11050. return;
  11051. if (pc_issit(sd))
  11052. return;
  11053. clif_parse_UseSkillToPosSub(fd, sd,
  11054. RFIFOW(fd,info->pos[0]), //skill lv
  11055. RFIFOW(fd,info->pos[1]), //skill num
  11056. RFIFOW(fd,info->pos[2]), //pos x
  11057. RFIFOW(fd,info->pos[3]), //pos y
  11058. // TODO: find out what this is intended to do
  11059. //RFIFOB(fd, info->pos[4])
  11060. -1 //Skill more info.
  11061. );
  11062. }
  11063. /// Request to use a ground skill with text.
  11064. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11065. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11066. /// There are various variants of this packet, some of them have padding between fields.
  11067. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  11068. {
  11069. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11070. if (pc_cant_act(sd))
  11071. return;
  11072. if (pc_issit(sd))
  11073. return;
  11074. clif_parse_UseSkillToPosSub(fd, sd,
  11075. RFIFOW(fd,info->pos[0]), //Skill lv
  11076. RFIFOW(fd,info->pos[1]), //Skill num
  11077. RFIFOW(fd,info->pos[2]), //pos x
  11078. RFIFOW(fd,info->pos[3]), //pos y
  11079. info->pos[4] //skill more info
  11080. );
  11081. }
  11082. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11083. /// 011b <skill id>.W <map name>.16B
  11084. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  11085. {
  11086. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11087. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11088. char map_name[MAP_NAME_LENGTH];
  11089. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11090. sd->state.workinprogress = WIP_DISABLE_NONE;
  11091. if(skill_id != sd->menuskill_id)
  11092. return;
  11093. //It is possible to use teleport with the storage window open bugreport:8027
  11094. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11095. clif_menuskill_clear(sd);
  11096. return;
  11097. }
  11098. pc_delinvincibletimer(sd);
  11099. skill_castend_map(sd,skill_id,map_name);
  11100. }
  11101. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11102. /// 011d
  11103. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  11104. {
  11105. if (!pc_isdead(sd))
  11106. pc_memo(sd,-1);
  11107. }
  11108. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11109. /// 018e <name id>.W { <material id>.W }*3
  11110. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  11111. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11112. switch( sd->menuskill_id ) {
  11113. case -1:
  11114. case AM_PHARMACY:
  11115. case RK_RUNEMASTERY:
  11116. case GC_RESEARCHNEWPOISON:
  11117. break;
  11118. default:
  11119. return;
  11120. }
  11121. if (pc_istrading(sd)) {
  11122. //Make it fail to avoid shop exploits where you sell something different than you see.
  11123. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11124. clif_menuskill_clear(sd);
  11125. return;
  11126. }
  11127. int produce_idx;
  11128. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11129. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11130. clif_menuskill_clear(sd);
  11131. }
  11132. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11133. /// 025b <mk type>.W <name id>.W
  11134. /// mk type:
  11135. /// 1 = cooking
  11136. /// 2 = arrow
  11137. /// 3 = elemental
  11138. /// 4 = GN_MIX_COOKING
  11139. /// 5 = GN_MAKEBOMB
  11140. /// 6 = GN_S_PHARMACY
  11141. /// 7 = MT_M_MACHINE - Unconfirmed
  11142. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11143. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  11144. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11145. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11146. short food_idx = -1;
  11147. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11148. return;
  11149. if (pc_istrading(sd)) {
  11150. //Make it fail to avoid shop exploits where you sell something different than you see.
  11151. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11152. clif_menuskill_clear(sd);
  11153. return;
  11154. }
  11155. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11156. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11157. clif_menuskill_clear(sd);
  11158. }
  11159. /// Answer to repair weapon item selection dialog
  11160. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11161. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11162. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11163. // Hercules has wrong date -> use correct one here
  11164. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11165. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11166. #else
  11167. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11168. #endif
  11169. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11170. return;
  11171. if (pc_istrading(sd)) {
  11172. //Make it fail to avoid shop exploits where you sell something different than you see.
  11173. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11174. clif_menuskill_clear(sd);
  11175. return;
  11176. }
  11177. skill_repairweapon( sd, p->item.index );
  11178. clif_menuskill_clear(sd);
  11179. }
  11180. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11181. /// 0222 <index>.L
  11182. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11183. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11184. return;
  11185. if (pc_istrading(sd)) {
  11186. //Make it fail to avoid shop exploits where you sell something different than you see.
  11187. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11188. clif_menuskill_clear(sd);
  11189. return;
  11190. }
  11191. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11192. clif_menuskill_clear(sd);
  11193. }
  11194. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11195. /// 00b8 <npc id>.L <choice>.B
  11196. /// choice:
  11197. /// 1~254 = menu item
  11198. /// 255 = cancel
  11199. /// NOTE: If there were more than 254 items in the list, choice
  11200. /// overflows to choice%256.
  11201. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11202. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11203. int npc_id = RFIFOL(fd,info->pos[0]);
  11204. uint8 select = RFIFOB(fd,info->pos[1]);
  11205. #ifdef SECURE_NPCTIMEOUT
  11206. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11207. return;
  11208. #endif
  11209. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11210. TBL_NPC* nd = map_id2nd(npc_id);
  11211. 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);
  11212. clif_GM_kick(NULL,sd);
  11213. return;
  11214. }
  11215. sd->npc_menu = select;
  11216. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11217. sd->idletime = last_tick;
  11218. }
  11219. npc_scriptcont(sd,npc_id, false);
  11220. }
  11221. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11222. /// 00b9 <npc id>.L
  11223. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11224. {
  11225. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11226. sd->idletime = last_tick;
  11227. }
  11228. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11229. }
  11230. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11231. /// 0143 <npc id>.L <value>.L
  11232. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11233. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11234. int npcid = RFIFOL(fd,info->pos[0]);
  11235. int amount = (int)RFIFOL(fd,info->pos[1]);
  11236. sd->npc_amount = amount;
  11237. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11238. sd->idletime = last_tick;
  11239. }
  11240. npc_scriptcont(sd, npcid, false);
  11241. }
  11242. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11243. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11244. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11245. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11246. int message_len = RFIFOW(fd,info->pos[0])-8;
  11247. int npcid = RFIFOL(fd,info->pos[1]);
  11248. const char* message = RFIFOCP(fd,info->pos[2]);
  11249. if( message_len <= 0 )
  11250. return; // invalid input
  11251. #if PACKETVER >= 20151001
  11252. message_len++;
  11253. #endif
  11254. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11255. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11256. sd->idletime = last_tick;
  11257. }
  11258. npc_scriptcont(sd, npcid, false);
  11259. }
  11260. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11261. /// 0146 <npc id>.L
  11262. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11263. {
  11264. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11265. return;
  11266. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11267. sd->idletime = last_tick;
  11268. }
  11269. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11270. }
  11271. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11272. /// 0178 <index>.W
  11273. /// index:
  11274. /// -1 = cancel
  11275. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11276. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11277. if (sd->menuskill_id != MC_IDENTIFY)
  11278. return;
  11279. // Ignore the request
  11280. // - Invalid item index
  11281. // - Invalid item ID or item doesn't exist
  11282. // - Item is already identified
  11283. if (idx < 0 || idx >= MAX_INVENTORY ||
  11284. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11285. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11286. sd->state.workinprogress = WIP_DISABLE_NONE;
  11287. clif_menuskill_clear(sd);
  11288. return;
  11289. }
  11290. skill_identify(sd, idx);
  11291. clif_menuskill_clear(sd);
  11292. }
  11293. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11294. /// 01ae <name id>.W
  11295. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11296. if (pc_istrading(sd)) {
  11297. //Make it fail to avoid shop exploits where you sell something different than you see.
  11298. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11299. clif_menuskill_clear(sd);
  11300. return;
  11301. }
  11302. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11303. switch (sd->menuskill_id) {
  11304. case AC_MAKINGARROW:
  11305. skill_arrow_create(sd,p->itemId);
  11306. break;
  11307. case SA_CREATECON:
  11308. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11309. break;
  11310. case GC_POISONINGWEAPON:
  11311. skill_poisoningweapon(sd,p->itemId);
  11312. break;
  11313. case NC_MAGICDECOY:
  11314. skill_magicdecoy(sd,p->itemId);
  11315. break;
  11316. }
  11317. clif_menuskill_clear(sd);
  11318. }
  11319. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11320. /// 01ce <skill id>.L
  11321. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11322. {
  11323. if (sd->menuskill_id != SA_AUTOSPELL)
  11324. return;
  11325. sd->state.workinprogress = WIP_DISABLE_NONE;
  11326. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11327. clif_menuskill_clear(sd);
  11328. }
  11329. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11330. /// 017a <card index>.W
  11331. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11332. {
  11333. if (sd->state.trading != 0)
  11334. return;
  11335. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11336. }
  11337. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11338. /// 017c <card index>.W <equip index>.W
  11339. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11340. {
  11341. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11342. if (sd->state.trading != 0)
  11343. return;
  11344. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11345. }
  11346. /// Request of character's name by char ID.
  11347. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11348. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11349. /// There are various variants of this packet, some of them have padding between fields.
  11350. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11351. {
  11352. int charid;
  11353. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11354. map_reqnickdb(sd, charid);
  11355. }
  11356. /// /resetskill /resetstate (CZ_RESET).
  11357. /// Request to reset stats or skills.
  11358. /// 0197 <type>.W
  11359. /// type:
  11360. /// 0 = state
  11361. /// 1 = skill
  11362. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11363. char cmd[15];
  11364. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11365. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11366. else
  11367. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11368. is_atcommand(fd, sd, cmd, 1);
  11369. }
  11370. /// /lb /nlb (CZ_LOCALBROADCAST).
  11371. /// Request to broadcast a message on current map.
  11372. /// 019c <packet len>.W <text>.?B
  11373. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11374. {
  11375. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11376. char command[CHAT_SIZE_MAX+16];
  11377. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11378. char* msg = RFIFOCP(fd,info->pos[1]);
  11379. // as the length varies depending on the command used, just block unreasonably long strings
  11380. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11381. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11382. is_atcommand(fd, sd, command, 1);
  11383. }
  11384. /// Request to move an item from inventory to storage.
  11385. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11386. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11387. /// There are various variants of this packet, some of them have padding between fields.
  11388. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11389. {
  11390. int item_index, item_amount;
  11391. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11392. if (pc_istrading(sd))
  11393. return;
  11394. item_index = RFIFOW(fd,info->pos[0])-2;
  11395. item_amount = RFIFOL(fd,info->pos[1]);
  11396. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11397. return;
  11398. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11399. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11400. return;
  11401. }
  11402. if (sd->state.storage_flag == 1)
  11403. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11404. else
  11405. if (sd->state.storage_flag == 2)
  11406. storage_guild_storageadd(sd, item_index, item_amount);
  11407. else if (sd->state.storage_flag == 3)
  11408. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11409. }
  11410. /// Request to move an item from storage to inventory.
  11411. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11412. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11413. /// There are various variants of this packet, some of them have padding between fields.
  11414. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11415. {
  11416. int item_index, item_amount;
  11417. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11418. item_index = RFIFOW(fd,info->pos[0])-1;
  11419. item_amount = RFIFOL(fd,info->pos[1]);
  11420. if (sd->state.storage_flag == 1)
  11421. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11422. else if(sd->state.storage_flag == 2)
  11423. storage_guild_storageget(sd, item_index, item_amount);
  11424. else if(sd->state.storage_flag == 3)
  11425. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11426. }
  11427. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11428. /// 0129 <index>.W <amount>.L
  11429. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11430. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11431. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11432. int amount = RFIFOL(fd,info->pos[1]);
  11433. if( sd->state.vending )
  11434. return;
  11435. if (!pc_iscarton(sd))
  11436. return;
  11437. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11438. return;
  11439. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11440. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11441. return;
  11442. }
  11443. if (sd->state.storage_flag == 1)
  11444. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11445. else if (sd->state.storage_flag == 2)
  11446. storage_guild_storageaddfromcart(sd, idx, amount);
  11447. else if (sd->state.storage_flag == 3)
  11448. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11449. }
  11450. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11451. /// 0128 <index>.W <amount>.L
  11452. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11453. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11454. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11455. int amount = RFIFOL(fd,info->pos[1]);
  11456. if( sd->state.vending )
  11457. return;
  11458. if (!pc_iscarton(sd))
  11459. return;
  11460. if (sd->state.storage_flag == 1)
  11461. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11462. else
  11463. if (sd->state.storage_flag == 2)
  11464. storage_guild_storagegettocart(sd, idx, amount);
  11465. else if (sd->state.storage_flag == 3)
  11466. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11467. }
  11468. /// Request to close storage (CZ_CLOSE_STORE).
  11469. /// 00f7
  11470. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11471. {
  11472. if( sd->state.storage_flag == 1 )
  11473. storage_storageclose(sd);
  11474. else
  11475. if( sd->state.storage_flag == 2 )
  11476. storage_guild_storageclose(sd);
  11477. else if( sd->state.storage_flag == 3 )
  11478. storage_premiumStorage_close(sd);
  11479. }
  11480. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11481. /// 023a <info>.W
  11482. /// info:
  11483. /// 0 = password has not been set yet
  11484. /// 1 = storage is password-protected
  11485. /// 8 = too many wrong passwords
  11486. /// ? = ignored
  11487. /// NOTE: This packet is only available on certain non-kRO clients.
  11488. void clif_storagepassword(struct map_session_data* sd, short info)
  11489. {
  11490. int fd = sd->fd;
  11491. WFIFOHEAD(fd,packet_len(0x23a));
  11492. WFIFOW(fd,0) = 0x23a;
  11493. WFIFOW(fd,2) = info;
  11494. WFIFOSET(fd,packet_len(0x23a));
  11495. }
  11496. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11497. /// 023b <type>.W <password>.16B <new password>.16B
  11498. /// type:
  11499. /// 2 = change password
  11500. /// 3 = check password
  11501. /// NOTE: This packet is only available on certain non-kRO clients.
  11502. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11503. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11504. // int type = RFIFOW(fd,info->pos[0]);
  11505. // char* password = RFIFOP(fd,info->pos[1]);
  11506. // char* new_password = RFIFOP(fd,info->pos[2]);
  11507. // storage_changepass(sd,password,new_password);
  11508. }
  11509. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11510. /// 023c <result>.W <error count>.W
  11511. /// result:
  11512. /// 4 = password change success
  11513. /// 5 = password change failure
  11514. /// 6 = password check success
  11515. /// 7 = password check failure
  11516. /// 8 = too many wrong passwords
  11517. /// ? = ignored
  11518. /// NOTE: This packet is only available on certain non-kRO clients.
  11519. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11520. {
  11521. int fd = sd->fd;
  11522. WFIFOHEAD(fd,packet_len(0x23c));
  11523. WFIFOW(fd,0) = 0x23c;
  11524. WFIFOW(fd,2) = result;
  11525. WFIFOW(fd,4) = error_count;
  11526. WFIFOSET(fd,packet_len(0x23c));
  11527. }
  11528. /// Party creation request
  11529. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11530. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11531. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11532. name[NAME_LENGTH-1] = '\0';
  11533. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11534. clif_displaymessage(fd, msg_txt(sd,227));
  11535. return;
  11536. }
  11537. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11538. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11539. return;
  11540. }
  11541. party_create(sd,name,0,0);
  11542. }
  11543. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11544. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11545. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11546. char* name = RFIFOCP(fd,info->pos[0]);
  11547. int item1 = RFIFOB(fd,info->pos[1]);
  11548. int item2 = RFIFOB(fd,info->pos[2]);
  11549. name[NAME_LENGTH-1] = '\0';
  11550. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11551. clif_displaymessage(fd, msg_txt(sd,227));
  11552. return;
  11553. }
  11554. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11555. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11556. return;
  11557. }
  11558. party_create(sd,name,item1,item2);
  11559. }
  11560. /// Party invitation request
  11561. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11562. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11563. {
  11564. struct map_session_data *t_sd;
  11565. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11566. clif_displaymessage(fd, msg_txt(sd,227));
  11567. return;
  11568. }
  11569. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11570. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11571. clif_noask_sub(sd, t_sd, 1);
  11572. return;
  11573. }
  11574. party_invite(sd, t_sd);
  11575. }
  11576. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11577. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11578. struct map_session_data *t_sd;
  11579. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11580. name[NAME_LENGTH-1] = '\0';
  11581. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11582. clif_displaymessage(fd, msg_txt(sd,227));
  11583. return;
  11584. }
  11585. t_sd = map_nick2sd(name,false);
  11586. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11587. clif_noask_sub(sd, t_sd, 1);
  11588. return;
  11589. }
  11590. party_invite(sd, t_sd);
  11591. }
  11592. /// Party invitation reply
  11593. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11594. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11595. /// flag:
  11596. /// 0 = reject
  11597. /// 1 = accept
  11598. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11599. {
  11600. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11601. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11602. RFIFOL(fd,info->pos[1]));
  11603. }
  11604. //(CZ_PARTY_JOIN_REQ_ACK)
  11605. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11606. {
  11607. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11608. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11609. RFIFOB(fd,info->pos[1]));
  11610. }
  11611. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11612. /// 0100
  11613. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11614. {
  11615. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11616. clif_displaymessage(fd, msg_txt(sd,227));
  11617. return;
  11618. }
  11619. party_leave(sd);
  11620. }
  11621. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11622. /// 0103 <account id>.L <char name>.24B
  11623. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11624. {
  11625. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11626. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11627. clif_displaymessage(fd, msg_txt(sd,227));
  11628. return;
  11629. }
  11630. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11631. RFIFOCP(fd,info->pos[1]));
  11632. }
  11633. /// Request to change party options.
  11634. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11635. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11636. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11637. {
  11638. struct party_data *p;
  11639. int i,expflag;
  11640. int cmd = RFIFOW(fd,0);
  11641. struct s_packet_db* info = &packet_db[cmd];
  11642. if( !sd->status.party_id )
  11643. return;
  11644. p = party_search(sd->status.party_id);
  11645. if( p == NULL )
  11646. return;
  11647. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11648. if( i == MAX_PARTY )
  11649. return; //Shouldn't happen
  11650. if( !p->party.member[i].leader )
  11651. return;
  11652. expflag = RFIFOL(fd,info->pos[0]);
  11653. if(cmd == 0x0102){ //Client can't change the item-field
  11654. party_changeoption(sd, expflag, p->party.item);
  11655. }
  11656. else {
  11657. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11658. party_changeoption(sd, expflag, itemflag);
  11659. }
  11660. }
  11661. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11662. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11663. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11664. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11665. // validate packet and retrieve name and message
  11666. if( !clif_process_message( sd, false, name, message, output ) )
  11667. return;
  11668. party_send_message(sd, output, strlen(output) + 1 );
  11669. }
  11670. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11671. /// 07da <account id>.L
  11672. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11673. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11674. }
  11675. /// Party Booking in KRO [Spiria]
  11676. ///
  11677. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11678. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11679. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11680. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11681. short level = RFIFOW(fd,info->pos[0]);
  11682. short mapid = RFIFOW(fd,info->pos[1]);
  11683. int idxpbj = info->pos[2];
  11684. short job[MAX_PARTY_BOOKING_JOBS];
  11685. int i;
  11686. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11687. job[i] = RFIFOB(fd,idxpbj+i*2);
  11688. party_booking_register(sd, level, mapid, job);
  11689. }
  11690. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11691. /// 0803 <result>.W
  11692. /// result:
  11693. /// 0 = success
  11694. /// 1 = failure
  11695. /// 2 = already registered
  11696. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11697. {
  11698. int fd = sd->fd;
  11699. WFIFOHEAD(fd,packet_len(0x803));
  11700. WFIFOW(fd,0) = 0x803;
  11701. WFIFOW(fd,2) = flag;
  11702. WFIFOSET(fd,packet_len(0x803));
  11703. }
  11704. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11705. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11706. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11707. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11708. short level = RFIFOW(fd,info->pos[0]);
  11709. short mapid = RFIFOW(fd,info->pos[1]);
  11710. short job = RFIFOW(fd,info->pos[2]);
  11711. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11712. short resultcount = RFIFOW(fd,info->pos[4]);
  11713. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11714. }
  11715. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11716. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11717. /// more results:
  11718. /// 0 = no
  11719. /// 1 = yes
  11720. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11721. {
  11722. int i, j;
  11723. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11724. struct party_booking_ad_info *pb_ad;
  11725. WFIFOHEAD(fd,size*count + 5);
  11726. WFIFOW(fd,0) = 0x805;
  11727. WFIFOW(fd,2) = size*count + 5;
  11728. WFIFOB(fd,4) = more_result;
  11729. for(i=0; i<count; i++)
  11730. {
  11731. pb_ad = results[i];
  11732. WFIFOL(fd,i*size+5) = pb_ad->index;
  11733. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11734. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11735. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11736. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11737. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11738. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11739. }
  11740. WFIFOSET(fd,WFIFOW(fd,2));
  11741. }
  11742. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11743. /// 0806
  11744. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11745. {
  11746. if(party_booking_delete(sd))
  11747. clif_PartyBookingDeleteAck(sd, 0);
  11748. }
  11749. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11750. /// 0807 <result>.W
  11751. /// result:
  11752. /// 0 = success
  11753. /// 1 = success (auto-removed expired ad)
  11754. /// 2 = failure
  11755. /// 3 = nothing registered
  11756. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11757. {
  11758. int fd = sd->fd;
  11759. WFIFOHEAD(fd,packet_len(0x807));
  11760. WFIFOW(fd,0) = 0x807;
  11761. WFIFOW(fd,2) = flag;
  11762. WFIFOSET(fd,packet_len(0x807));
  11763. }
  11764. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11765. /// 0808 { <job>.W }*6
  11766. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11767. {
  11768. short job[MAX_PARTY_BOOKING_JOBS];
  11769. int i;
  11770. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11771. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11772. job[i] = RFIFOW(fd,idxpbu+i*2);
  11773. party_booking_update(sd, job);
  11774. }
  11775. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11776. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11777. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11778. {
  11779. int i;
  11780. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11781. if(pb_ad == NULL) return;
  11782. WBUFW(buf,0) = 0x809;
  11783. WBUFL(buf,2) = pb_ad->index;
  11784. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11785. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11786. WBUFW(buf,34) = pb_ad->p_detail.level;
  11787. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11788. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11789. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11790. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11791. }
  11792. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11793. /// 080a <index>.L { <job>.W }*6
  11794. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11795. {
  11796. int i;
  11797. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11798. if(pb_ad == NULL) return;
  11799. WBUFW(buf,0) = 0x80a;
  11800. WBUFL(buf,2) = pb_ad->index;
  11801. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11802. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11803. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11804. }
  11805. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11806. /// 080b <index>.L
  11807. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11808. {
  11809. uint8 buf[6];
  11810. WBUFW(buf,0) = 0x80b;
  11811. WBUFL(buf,2) = index;
  11812. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11813. }
  11814. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11815. /// 012e
  11816. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11817. {
  11818. vending_closevending(sd);
  11819. }
  11820. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11821. /// 0130 <account id>.L
  11822. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11823. {
  11824. if( sd->npc_id ) {// using an NPC
  11825. return;
  11826. }
  11827. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11828. }
  11829. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11830. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11831. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11832. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11833. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11834. int id = (int)RFIFOL(fd,info->pos[1]);
  11835. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11836. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11837. // whether it fails or not, the buy window is closed
  11838. sd->vended_id = 0;
  11839. }
  11840. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11841. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11842. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11843. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11844. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11845. int aid = (int)RFIFOL(fd,info->pos[1]);
  11846. int uid = (int)RFIFOL(fd,info->pos[2]);
  11847. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11848. vending_purchasereq(sd, aid, uid, data, len/4);
  11849. // whether it fails or not, the buy window is closed
  11850. sd->vended_id = 0;
  11851. }
  11852. /// Confirm or cancel the shop preparation window.
  11853. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11854. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11855. /// result:
  11856. /// 0 = canceled
  11857. /// 1 = open
  11858. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11859. int cmd = RFIFOW(fd,0);
  11860. struct s_packet_db* info = &packet_db[cmd];
  11861. short len = (short)RFIFOW(fd,info->pos[0]);
  11862. const char* message = RFIFOCP(fd,info->pos[1]);
  11863. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11864. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11865. len -= 84;
  11866. }
  11867. else { //(CZ_REQ_OPENSTORE2)
  11868. bool flag;
  11869. len -= 85;
  11870. flag = RFIFOB(fd,info->pos[2]) != 0;
  11871. if (!flag) {
  11872. sd->state.prevend = 0;
  11873. sd->state.workinprogress = WIP_DISABLE_NONE;
  11874. }
  11875. }
  11876. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11877. return;
  11878. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11879. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11880. return;
  11881. }
  11882. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11883. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11884. return;
  11885. }
  11886. if( message[0] == '\0' ) // invalid input
  11887. return;
  11888. vending_openvending(sd, message, data, len/8, NULL);
  11889. }
  11890. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11891. /// 0165 <char id>.L <guild name>.24B
  11892. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11893. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11894. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11895. name[NAME_LENGTH-1] = '\0';
  11896. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11897. clif_displaymessage(fd, msg_txt(sd,228));
  11898. return;
  11899. }
  11900. if(sd->clan){
  11901. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11902. return;
  11903. }
  11904. guild_create(sd, name);
  11905. }
  11906. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11907. /// 014d
  11908. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11909. {
  11910. clif_guild_masterormember(sd);
  11911. }
  11912. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11913. /// 014f <type>.L
  11914. /// type:
  11915. /// 0 = basic info
  11916. /// 1 = member manager
  11917. /// 2 = positions
  11918. /// 3 = skills
  11919. /// 4 = expulsion list
  11920. /// 5 = unknown (GM_ALLGUILDLIST)
  11921. /// 6 = notice
  11922. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11923. {
  11924. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11925. if( !sd->status.guild_id && !sd->bg_id )
  11926. return;
  11927. switch( type )
  11928. {
  11929. case 0: // Basic Information Guild, hostile alliance information
  11930. clif_guild_basicinfo(sd);
  11931. clif_guild_allianceinfo(sd);
  11932. break;
  11933. case 1: // Members list, list job title
  11934. clif_guild_positionnamelist(sd);
  11935. clif_guild_memberlist(sd);
  11936. break;
  11937. case 2: // List job title, title information list
  11938. clif_guild_positionnamelist(sd);
  11939. clif_guild_positioninfolist(sd);
  11940. break;
  11941. case 3: // Skill list
  11942. clif_guild_skillinfo(sd);
  11943. break;
  11944. case 4: // Expulsion list
  11945. clif_guild_expulsionlist(sd);
  11946. break;
  11947. default:
  11948. ShowError("clif: guild request info: unknown type %d\n", type);
  11949. break;
  11950. }
  11951. }
  11952. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11953. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11954. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11955. {
  11956. int i;
  11957. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11958. int len = RFIFOW(fd,info->pos[0]);
  11959. int idxgpos = info->pos[1];
  11960. if(!sd->state.gmaster_flag)
  11961. return;
  11962. for(i = idxgpos; i < len; i += 40 ){
  11963. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11964. }
  11965. }
  11966. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11967. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11968. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11969. {
  11970. int i;
  11971. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11972. int len = RFIFOW(fd,info->pos[0]);
  11973. int idxgpos = info->pos[1];
  11974. if(!sd->state.gmaster_flag)
  11975. return;
  11976. // Guild leadership change
  11977. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11978. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11979. clif_msg(sd, GUILD_MASTER_WOE);
  11980. return;
  11981. }
  11982. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11983. clif_msg(sd, GUILD_MASTER_DELAY);
  11984. return;
  11985. }
  11986. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11987. return;
  11988. }
  11989. for(i=idxgpos;i<len;i+=12){
  11990. int position = RFIFOL(fd,i+8);
  11991. if( position > 0 ){
  11992. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11993. }
  11994. }
  11995. }
  11996. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11997. /// 0151 <guild id>.L
  11998. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11999. {
  12000. struct guild* g;
  12001. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12002. if( (g = guild_search(guild_id)) != NULL )
  12003. clif_guild_emblem(sd,g);
  12004. }
  12005. /// Validates data of a guild emblem (compressed bitmap)
  12006. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  12007. EMBVALIDATE_SUCCESS = 0,
  12008. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  12009. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  12010. };
  12011. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12012. {
  12013. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12014. unsigned long buf_len = sizeof(buf);
  12015. int offset = 0;
  12016. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12017. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12018. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12019. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12020. ))
  12021. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12022. if(battle_config.emblem_transparency_limit != 100) {
  12023. int i, transcount = 1, tmp[3];
  12024. for(i = offset; i < buf_len-1; i++) {
  12025. int j = i%3;
  12026. tmp[j] = RBUFL(buf,i);
  12027. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12028. transcount++;
  12029. }
  12030. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  12031. return EMBVALIDATE_ERR_TRANSPARENCY;
  12032. }
  12033. return EMBVALIDATE_SUCCESS;
  12034. }
  12035. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12036. /// 0153 <packet len>.W <emblem data>.?B
  12037. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  12038. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12039. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12040. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12041. int emb_val=0;
  12042. if( !emblem_len || !sd->state.gmaster_flag )
  12043. return;
  12044. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  12045. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12046. return;
  12047. }
  12048. emb_val = clif_validate_emblem(emblem, emblem_len);
  12049. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12050. 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);
  12051. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12052. return;
  12053. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12054. char output[128];
  12055. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  12056. 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"
  12057. return;
  12058. }
  12059. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  12060. }
  12061. /// Request to update the guild emblem id (version, according to Gravity)
  12062. /// 0b46 <guild id>.L <version>.L
  12063. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  12064. nullpo_retv(sd);
  12065. #if PACKETVER >= 20190724
  12066. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12067. guild* g = sd->guild;
  12068. if (g == nullptr || g->guild_id != p->guild_id)
  12069. return;
  12070. if (!sd->state.gmaster_flag)
  12071. return;
  12072. if (!battle_config.emblem_woe_change && is_agit_start()) {
  12073. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12074. return;
  12075. }
  12076. guild_change_emblem_version(sd, p->version);
  12077. #endif
  12078. }
  12079. /// Guild notice update request (CZ_GUILD_NOTICE).
  12080. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12081. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  12082. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12083. int guild_id = RFIFOL(fd,info->pos[0]);
  12084. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12085. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12086. if(!sd->state.gmaster_flag)
  12087. return;
  12088. // compensate for some client defects when using multilanguage mode
  12089. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12090. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12091. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12092. guild_change_notice(sd, guild_id, msg1, msg2);
  12093. }
  12094. // Helper function for guild invite functions
  12095. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  12096. {
  12097. if (t_sd == NULL) // not online or does not exist
  12098. return 1;
  12099. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12100. clif_displaymessage(fd, msg_txt(sd,228));
  12101. return 1;
  12102. }
  12103. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12104. clif_noask_sub(sd, t_sd, 2);
  12105. return 1;
  12106. }
  12107. // Players in a clan can not join a guild
  12108. if(t_sd && t_sd->clan){
  12109. return 1;
  12110. }
  12111. guild_invite(sd, t_sd);
  12112. return 0;
  12113. }
  12114. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12115. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12116. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  12117. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12118. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12119. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12120. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12121. if (clif_sub_guild_invite(fd, sd, t_sd))
  12122. return;
  12123. }
  12124. /// Guild invite request (/guildinvite)
  12125. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12126. void
  12127. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  12128. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12129. if (clif_sub_guild_invite(fd, sd, t_sd))
  12130. return;
  12131. }
  12132. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12133. /// 016b <guild id>.L <answer>.L
  12134. /// answer:
  12135. /// 0 = refuse
  12136. /// 1 = accept
  12137. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  12138. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12139. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12140. RFIFOL(fd,info->pos[1]));
  12141. }
  12142. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12143. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12144. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  12145. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12146. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12147. clif_displaymessage(fd, msg_txt(sd,228));
  12148. return;
  12149. }
  12150. if( sd->bg_id ) {
  12151. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12152. return;
  12153. }
  12154. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12155. RFIFOL(fd,info->pos[1]),
  12156. RFIFOL(fd,info->pos[2]),
  12157. RFIFOCP(fd,info->pos[3]));
  12158. }
  12159. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12160. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12161. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  12162. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12163. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12164. { // Guild locked.
  12165. clif_displaymessage(fd, msg_txt(sd,228));
  12166. return;
  12167. }
  12168. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12169. RFIFOL(fd,info->pos[1]),
  12170. RFIFOL(fd,info->pos[2]),
  12171. RFIFOCP(fd,info->pos[3]));
  12172. }
  12173. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12174. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12175. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12176. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12177. // validate packet and retrieve name and message
  12178. if( !clif_process_message( sd, false, name, message, output ) )
  12179. return;
  12180. if( sd->bg_id )
  12181. bg_send_message(sd, output, strlen(output) );
  12182. else
  12183. guild_send_message(sd, output, strlen(output) );
  12184. }
  12185. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12186. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12187. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12188. {
  12189. struct map_session_data *t_sd;
  12190. if(!sd->state.gmaster_flag)
  12191. return;
  12192. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12193. clif_displaymessage(fd, msg_txt(sd,228));
  12194. return;
  12195. }
  12196. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12197. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12198. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12199. // @noask [LuzZza]
  12200. if(t_sd && t_sd->state.noask) {
  12201. clif_noask_sub(sd, t_sd, 3);
  12202. return;
  12203. }
  12204. guild_reqalliance(sd,t_sd);
  12205. }
  12206. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12207. /// 0172 <inviter account id>.L <answer>.L
  12208. /// answer:
  12209. /// 0 = refuse
  12210. /// 1 = accept
  12211. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12212. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12213. guild_reply_reqalliance(sd,
  12214. RFIFOL(fd,info->pos[0]),
  12215. RFIFOL(fd,info->pos[1]));
  12216. }
  12217. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12218. /// 0183 <opponent guild id>.L <relation>.L
  12219. /// relation:
  12220. /// 0 = Ally
  12221. /// 1 = Enemy
  12222. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12223. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12224. if(!sd->state.gmaster_flag)
  12225. return;
  12226. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12227. clif_displaymessage(fd, msg_txt(sd,228));
  12228. return;
  12229. }
  12230. guild_delalliance(sd,
  12231. RFIFOL(fd,info->pos[0]),
  12232. RFIFOL(fd,info->pos[1]));
  12233. }
  12234. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12235. /// 0180 <account id>.L
  12236. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12237. {
  12238. struct map_session_data *t_sd;
  12239. if(!sd->state.gmaster_flag)
  12240. return;
  12241. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12242. clif_displaymessage(fd, msg_txt(sd,228));
  12243. return;
  12244. }
  12245. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12246. // @noask [LuzZza]
  12247. if(t_sd && t_sd->state.noask) {
  12248. clif_noask_sub(sd, t_sd, 4);
  12249. return;
  12250. }
  12251. guild_opposition(sd,t_sd);
  12252. }
  12253. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12254. /// 015d <key>.40B
  12255. /// key:
  12256. /// now guild name; might have been (intended) email, since the
  12257. /// field name and size is same as the one in CH_DELETE_CHAR.
  12258. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12259. {
  12260. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12261. clif_displaymessage(fd, msg_txt(sd,228));
  12262. return;
  12263. }
  12264. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12265. }
  12266. /// Pet
  12267. ///
  12268. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12269. /// 01a1 <type>.B
  12270. /// type:
  12271. /// 0 = pet information
  12272. /// 1 = feed
  12273. /// 2 = performance
  12274. /// 3 = return to egg
  12275. /// 4 = unequip accessory
  12276. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12277. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12278. }
  12279. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12280. /// 019f <id>.L
  12281. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12282. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12283. }
  12284. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12285. /// 01a7 <index>.W
  12286. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12287. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12288. return;
  12289. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12290. clif_menuskill_clear(sd);
  12291. }
  12292. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12293. /// 01a9 <data>.L
  12294. /// data:
  12295. /// is either emotion (@see enum emotion_type) or a compound value
  12296. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12297. /// entry (given in parentheses) in data\pettalktable.xml
  12298. /// act id:
  12299. /// 0 = feeding
  12300. /// 1 = hunting
  12301. /// 2 = danger
  12302. /// 3 = dead
  12303. /// 4 = normal (stand)
  12304. /// 5 = special performance (perfor_s)
  12305. /// 6 = level up (levelup)
  12306. /// 7 = performance 1 (perfor_1)
  12307. /// 8 = performance 2 (perfor_2)
  12308. /// 9 = performance 3 (perfor_3)
  12309. /// 10 = log-in greeting (connect)
  12310. /// hungry value:
  12311. /// 0 = very hungry (hungry)
  12312. /// 1 = hungry (bit_hungry)
  12313. /// 2 = satisfied (noting)
  12314. /// 3 = stuffed (full)
  12315. /// 4 = full (so_full)
  12316. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12317. {
  12318. if(sd->pd)
  12319. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12320. }
  12321. /// Request to change pet's name (CZ_RENAME_PET).
  12322. /// 01a5 <name>.24B
  12323. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12324. {
  12325. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12326. }
  12327. /// /kill (CZ_DISCONNECT_CHARACTER).
  12328. /// Request to disconnect a character.
  12329. /// 00cc <account id>.L
  12330. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12331. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12332. {
  12333. struct block_list *target;
  12334. int tid;
  12335. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12336. target = map_id2bl(tid);
  12337. if (!target) {
  12338. clif_GM_kickack(sd, 0);
  12339. return;
  12340. }
  12341. switch (target->type) {
  12342. case BL_PC:
  12343. {
  12344. char command[NAME_LENGTH+6];
  12345. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12346. is_atcommand(fd, sd, command, 1);
  12347. }
  12348. break;
  12349. /**
  12350. * This one does not invoke any atcommand, so we need to check for permissions.
  12351. */
  12352. case BL_MOB:
  12353. {
  12354. char command[100];
  12355. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12356. clif_GM_kickack(sd, 0);
  12357. return;
  12358. }
  12359. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12360. log_atcommand(sd, command);
  12361. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12362. }
  12363. break;
  12364. case BL_NPC:
  12365. {
  12366. struct npc_data* nd = (struct npc_data *)target;
  12367. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12368. npc_unload_duplicates(nd);
  12369. npc_unload(nd,true);
  12370. npc_read_event_script();
  12371. }
  12372. }
  12373. break;
  12374. default:
  12375. clif_GM_kickack(sd, 0);
  12376. }
  12377. }
  12378. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12379. /// Request to disconnect all characters.
  12380. /// 00ce
  12381. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12382. char cmd[15];
  12383. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12384. is_atcommand(fd, sd, cmd, 1);
  12385. }
  12386. /// /remove (CZ_REMOVE_AID).
  12387. /// Request to warp to a character with given login ID.
  12388. /// 01ba <account name>.24B
  12389. /// /shift (CZ_SHIFT).
  12390. /// Request to warp to a character with given name.
  12391. /// 01bb <char name>.24B
  12392. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12393. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12394. char *player_name;
  12395. char command[NAME_LENGTH+8];
  12396. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12397. player_name[NAME_LENGTH-1] = '\0';
  12398. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12399. is_atcommand(fd, sd, command, 1);
  12400. }
  12401. /// /remove (CZ_REMOVE_AID_SSO).
  12402. /// Request to warp to a character with given account ID.
  12403. /// 0843 <account id>.L
  12404. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12405. {
  12406. uint32 account_id;
  12407. struct map_session_data* pl_sd;
  12408. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12409. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12410. char command[NAME_LENGTH+8];
  12411. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12412. is_atcommand(fd, sd, command, 1);
  12413. }
  12414. }
  12415. /// /recall (CZ_RECALL).
  12416. /// Request to summon a player with given login ID to own position.
  12417. /// 01bc <account name>.24B
  12418. /// /summon (CZ_RECALL_GID).
  12419. /// Request to summon a player with given name to own position.
  12420. /// 01bd <char name>.24B
  12421. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12422. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12423. char *player_name;
  12424. char command [NAME_LENGTH+8];
  12425. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12426. player_name[NAME_LENGTH-1] = '\0';
  12427. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12428. is_atcommand(fd, sd, command, 1);
  12429. }
  12430. /// /recall (CZ_RECALL_SSO).
  12431. /// Request to summon a player with given account ID to own position.
  12432. /// 0842 <account id>.L
  12433. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12434. {
  12435. uint32 account_id;
  12436. struct map_session_data* pl_sd;
  12437. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12438. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12439. char command[NAME_LENGTH+8];
  12440. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12441. is_atcommand(fd, sd, command, 1);
  12442. }
  12443. }
  12444. /// /item /monster (CZ_ITEM_CREATE).
  12445. /// Request to execute GM commands.
  12446. /// Usage:
  12447. /// /item n - summon n monster or acquire n item/s
  12448. /// /item money - grants 2147483647 zenies
  12449. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12450. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12451. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12452. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12453. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12454. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12455. /// 013f <item/mob name>.24B
  12456. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12457. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12458. {
  12459. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12460. int mob_id = 0;
  12461. StringBuf command;
  12462. char *str;
  12463. //#if PACKETVER >= 20131218
  12464. // char str[100];
  12465. //#else
  12466. // char str[24];
  12467. //#endif
  12468. str = RFIFOCP(fd,info->pos[0]);
  12469. if (!str || str[0] == '\0')
  12470. return;
  12471. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12472. return;
  12473. trim(str);
  12474. // Zeny
  12475. if( strcmpi(str, "money") == 0 ) {
  12476. StringBuf_Init(&command);
  12477. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12478. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12479. StringBuf_Destroy(&command);
  12480. return;
  12481. }
  12482. std::shared_ptr<item_data> id = item_db.searchname( str );
  12483. // Item
  12484. if( id ){
  12485. StringBuf_Init(&command);
  12486. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12487. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12488. }else{
  12489. if (id->flag.guid)
  12490. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12491. else
  12492. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12493. }
  12494. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12495. StringBuf_Destroy(&command);
  12496. return;
  12497. }
  12498. // Monster
  12499. if ((mob_id = mobdb_searchname(str)) == 0)
  12500. mob_id = mobdb_checkid(atoi(str));
  12501. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12502. if( mob != nullptr ) {
  12503. StringBuf_Init(&command);
  12504. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12505. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12506. StringBuf_Destroy(&command);
  12507. return;
  12508. }
  12509. }
  12510. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12511. /// 019d <effect state>.L
  12512. /// effect state:
  12513. /// TODO: Any OPTION_* ?
  12514. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12515. char cmd[6];
  12516. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12517. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12518. is_atcommand(fd, sd, cmd, 1);
  12519. }
  12520. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12521. /// 0149 <account id>.L <type>.B <value>.W
  12522. /// type:
  12523. /// 0 = positive points
  12524. /// 1 = negative points
  12525. /// 2 = self mute (+10 minutes)
  12526. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12527. {
  12528. int id, type, value;
  12529. struct map_session_data *dstsd;
  12530. char command[NAME_LENGTH+15];
  12531. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12532. id = RFIFOL(fd,info->pos[0]);
  12533. type = RFIFOB(fd,info->pos[1]);
  12534. value = RFIFOW(fd,info->pos[2]);
  12535. if( type == 0 )
  12536. value = -value;
  12537. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12538. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12539. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12540. return;
  12541. dstsd = map_id2sd(id);
  12542. if( dstsd == NULL )
  12543. return;
  12544. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12545. is_atcommand(fd, sd, command, 1);
  12546. }
  12547. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12548. /// GM adjustment of a player's manner value by -60.
  12549. /// 0212 <char name>.24B
  12550. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12551. {
  12552. char command[NAME_LENGTH+15];
  12553. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12554. name[NAME_LENGTH-1] = '\0';
  12555. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12556. is_atcommand(fd, sd, command, 1);
  12557. }
  12558. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12559. /// 01e0 <account id>.L <account name>.24B
  12560. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12561. {
  12562. WFIFOHEAD(fd,packet_len(0x1e0));
  12563. WFIFOW(fd,0) = 0x1e0;
  12564. WFIFOL(fd,2) = account_id;
  12565. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12566. WFIFOSET(fd,packet_len(0x1e0));
  12567. }
  12568. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12569. /// 01df <account id>.L
  12570. //! TODO: Figure out how does this actually work
  12571. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12572. {
  12573. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12574. /*
  12575. char query[30];
  12576. safesnprintf(query,sizeof(query),"%d", account_id);
  12577. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12578. */
  12579. clif_account_name(fd, account_id, "");
  12580. }
  12581. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12582. /// GM single cell type change request.
  12583. /// 0198 <x>.W <y>.W <type>.W
  12584. /// type:
  12585. /// 0 = not walkable
  12586. /// 1 = walkable
  12587. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12588. {
  12589. int x,y,type;
  12590. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12591. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12592. return;
  12593. x = RFIFOW(fd,info->pos[0]);
  12594. y = RFIFOW(fd,info->pos[1]);
  12595. type = RFIFOW(fd,info->pos[2]);
  12596. map_setgatcell(sd->bl.m,x,y,type);
  12597. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12598. //FIXME: once players leave the map, the client 'forgets' this information.
  12599. }
  12600. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12601. /// Request to allow/deny whispers from a nick.
  12602. /// 00cf <nick>.24B <type>.B
  12603. /// type:
  12604. /// 0 = (/ex nick) deny speech from nick
  12605. /// 1 = (/in nick) allow speech from nick
  12606. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12607. {
  12608. char* nick;
  12609. uint8 type;
  12610. int i;
  12611. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12612. nick = RFIFOCP(fd,info->pos[0]);
  12613. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12614. type = RFIFOB(fd,info->pos[1]);
  12615. if( type == 0 ) { // Add name to ignore list (block)
  12616. if (strcmp(wisp_server_name, nick) == 0) {
  12617. clif_wisexin(sd, type, 1); // fail
  12618. return;
  12619. }
  12620. // try to find a free spot, while checking for duplicates at the same time
  12621. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12622. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12623. clif_wisexin(sd, type, 2); // too many blocks
  12624. return;
  12625. }
  12626. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12627. clif_wisexin(sd, type, 0); // Aegis reports success.
  12628. return;
  12629. }
  12630. //Insert in position i
  12631. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12632. } else { // Remove name from ignore list (unblock)
  12633. // find entry
  12634. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12635. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12636. clif_wisexin(sd, type, 1); // fail
  12637. return;
  12638. }
  12639. // move everything one place down to overwrite removed entry
  12640. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12641. // wipe last entry
  12642. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12643. }
  12644. clif_wisexin(sd, type, 0); // success
  12645. }
  12646. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12647. /// Request to allow/deny all whispers.
  12648. /// 00d0 <type>.B
  12649. /// type:
  12650. /// 0 = (/exall) deny all speech
  12651. /// 1 = (/inall) allow all speech
  12652. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12653. {
  12654. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12655. if( type == 0 ) {// Deny all
  12656. if( sd->state.ignoreAll ) {
  12657. flag = 1; // fail
  12658. } else {
  12659. sd->state.ignoreAll = 1;
  12660. flag = 0; // success
  12661. }
  12662. } else {//Unblock everyone
  12663. if( sd->state.ignoreAll ) {
  12664. sd->state.ignoreAll = 0;
  12665. flag = 0; // success
  12666. } else {
  12667. if (sd->ignore[0].name[0] != '\0')
  12668. { //Wipe the ignore list.
  12669. memset(sd->ignore, 0, sizeof(sd->ignore));
  12670. flag = 0; // success
  12671. } else {
  12672. flag = 1; // fail
  12673. }
  12674. }
  12675. }
  12676. clif_wisall(sd, type, flag);
  12677. }
  12678. /// Whisper ignore list (ZC_WHISPER_LIST).
  12679. /// 00d4 <packet len>.W { <char name>.24B }*
  12680. void clif_PMIgnoreList(struct map_session_data* sd)
  12681. {
  12682. int i, fd = sd->fd;
  12683. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12684. WFIFOW(fd,0) = 0xd4;
  12685. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12686. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12687. }
  12688. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12689. WFIFOSET(fd,WFIFOW(fd,2));
  12690. }
  12691. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12692. /// 00d3
  12693. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12694. {
  12695. clif_PMIgnoreList(sd);
  12696. }
  12697. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12698. /// 01e7
  12699. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12700. {
  12701. if (sd->state.doridori) return;
  12702. switch (sd->class_&MAPID_UPPERMASK) {
  12703. case MAPID_SOUL_LINKER:
  12704. case MAPID_STAR_GLADIATOR:
  12705. case MAPID_TAEKWON:
  12706. if (!sd->state.rest)
  12707. break;
  12708. case MAPID_SUPER_NOVICE:
  12709. case MAPID_SUPER_BABY:
  12710. case MAPID_SUPER_NOVICE_E:
  12711. case MAPID_SUPER_BABY_E:
  12712. sd->state.doridori=1;
  12713. break;
  12714. }
  12715. }
  12716. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12717. /// 01ed
  12718. /// Note: This packet is caused by 7 lines of any text, followed by
  12719. /// the prayer and an another line of any text. The prayer is
  12720. /// defined by lines 790~793 in data\msgstringtable.txt
  12721. /// "Dear angel, can you hear my voice?"
  12722. /// "I am" (space separated player name) "Super Novice~"
  12723. /// "Help me out~ Please~ T_T"
  12724. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12725. {
  12726. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12727. t_exp next = pc_nextbaseexp(sd);
  12728. if( next ) {
  12729. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12730. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12731. sc_start(&sd->bl,&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12732. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12733. }
  12734. }
  12735. }
  12736. }
  12737. /// Friends List
  12738. ///
  12739. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12740. /// 0206 <account id>.L <char id>.L <state>.B
  12741. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12742. /// state:
  12743. /// 0 = online
  12744. /// 1 = offline
  12745. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12746. {
  12747. int i, fd = sd->fd;
  12748. //Seek friend.
  12749. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12750. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12751. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12752. return; //Not found
  12753. WFIFOHEAD(fd,packet_len(0x206));
  12754. WFIFOW(fd, 0) = 0x206;
  12755. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12756. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12757. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12758. #if PACKETVER >= 20180221
  12759. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12760. #endif
  12761. WFIFOSET(fd, packet_len(0x206));
  12762. }
  12763. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12764. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12765. {
  12766. uint32 account_id, char_id, online;
  12767. account_id = va_arg(ap, int);
  12768. char_id = va_arg(ap, int);
  12769. online = va_arg(ap, int);
  12770. clif_friendslist_toggle(sd, account_id, char_id, online);
  12771. return 0;
  12772. }
  12773. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12774. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12775. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12776. void clif_friendslist_send(struct map_session_data *sd)
  12777. {
  12778. int i = 0, n, fd = sd->fd;
  12779. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12780. const int size = 8 + NAME_LENGTH;
  12781. #else
  12782. const int size = 8;
  12783. #endif
  12784. // Send friends list
  12785. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12786. WFIFOW(fd, 0) = 0x201;
  12787. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12788. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12789. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12790. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12791. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12792. #endif
  12793. }
  12794. if (i) {
  12795. WFIFOW(fd,2) = 4 + size * i;
  12796. WFIFOSET(fd, WFIFOW(fd,2));
  12797. }
  12798. for (n = 0; n < i; n++) { //Sending the online players
  12799. if (map_charid2sd(sd->status.friends[n].char_id))
  12800. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12801. }
  12802. }
  12803. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12804. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12805. /// result:
  12806. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12807. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12808. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12809. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12810. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12811. {
  12812. int fd;
  12813. nullpo_retv(sd);
  12814. fd = sd->fd;
  12815. WFIFOHEAD(fd,packet_len(0x209));
  12816. WFIFOW(fd,0) = 0x209;
  12817. WFIFOW(fd,2) = type;
  12818. if (f_sd) {
  12819. WFIFOL(fd,4) = f_sd->status.account_id;
  12820. WFIFOL(fd,8) = f_sd->status.char_id;
  12821. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12822. }
  12823. WFIFOSET(fd, packet_len(0x209));
  12824. }
  12825. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12826. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12827. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12828. {
  12829. int fd = sd->fd;
  12830. WFIFOHEAD(fd,packet_len(0x207));
  12831. WFIFOW(fd,0) = 0x207;
  12832. WFIFOL(fd,2) = account_id;
  12833. WFIFOL(fd,6) = char_id;
  12834. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12835. WFIFOSET(fd,packet_len(0x207));
  12836. }
  12837. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12838. /// 0202 <name>.24B
  12839. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12840. {
  12841. struct map_session_data *f_sd;
  12842. int i;
  12843. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12844. // Friend doesn't exist (no player with this name)
  12845. if (f_sd == NULL) {
  12846. clif_displaymessage(fd, msg_txt(sd,3));
  12847. return;
  12848. }
  12849. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12850. return;
  12851. }
  12852. // ensure that the request player's friend list is not full
  12853. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12854. if( i == MAX_FRIENDS ){
  12855. clif_friendslist_reqack(sd, f_sd, 2);
  12856. return;
  12857. }
  12858. // @noask [LuzZza]
  12859. if(f_sd->state.noask) {
  12860. clif_noask_sub(sd, f_sd, 5);
  12861. return;
  12862. }
  12863. // Friend already exists
  12864. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12865. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12866. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12867. return;
  12868. }
  12869. }
  12870. f_sd->friend_req = sd->status.char_id;
  12871. sd->friend_req = f_sd->status.char_id;
  12872. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12873. }
  12874. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12875. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12876. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12877. /// reply:
  12878. /// 0 = rejected
  12879. /// 1 = accepted
  12880. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12881. {
  12882. struct map_session_data *f_sd;
  12883. uint32 account_id;
  12884. char reply;
  12885. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12886. account_id = RFIFOL(fd,info->pos[0]);
  12887. //char_id = RFIFOL(fd,info->pos[1]);
  12888. #if PACKETVER < 6
  12889. reply = RFIFOB(fd,info->pos[2]);
  12890. #else
  12891. reply = RFIFOL(fd,info->pos[2]);
  12892. #endif
  12893. if( sd->bl.id == account_id ) {// adding oneself as friend
  12894. return;
  12895. }
  12896. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12897. if (f_sd == NULL)
  12898. return;
  12899. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12900. clif_friendslist_reqack(f_sd, sd, 1);
  12901. else {
  12902. int i;
  12903. // Find an empty slot
  12904. for (i = 0; i < MAX_FRIENDS; i++)
  12905. if (f_sd->status.friends[i].char_id == 0)
  12906. break;
  12907. if (i == MAX_FRIENDS) {
  12908. clif_friendslist_reqack(f_sd, sd, 2);
  12909. return;
  12910. }
  12911. f_sd->status.friends[i].account_id = sd->status.account_id;
  12912. f_sd->status.friends[i].char_id = sd->status.char_id;
  12913. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12914. clif_friendslist_reqack(f_sd, sd, 0);
  12915. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12916. if (battle_config.friend_auto_add) {
  12917. // Also add f_sd to sd's friendlist.
  12918. for (i = 0; i < MAX_FRIENDS; i++) {
  12919. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12920. return; //No need to add anything.
  12921. if (sd->status.friends[i].char_id == 0)
  12922. break;
  12923. }
  12924. if (i == MAX_FRIENDS) {
  12925. clif_friendslist_reqack(sd, f_sd, 2);
  12926. return;
  12927. }
  12928. sd->status.friends[i].account_id = f_sd->status.account_id;
  12929. sd->status.friends[i].char_id = f_sd->status.char_id;
  12930. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12931. clif_friendslist_reqack(sd, f_sd, 0);
  12932. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12933. }
  12934. }
  12935. }
  12936. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12937. /// 0203 <account id>.L <char id>.L
  12938. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12939. {
  12940. struct map_session_data *f_sd = NULL;
  12941. uint32 account_id, char_id;
  12942. int i, j;
  12943. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12944. account_id = RFIFOL(fd,info->pos[0]);
  12945. char_id = RFIFOL(fd,info->pos[1]);
  12946. // Search friend
  12947. for (i = 0; i < MAX_FRIENDS &&
  12948. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12949. if (i == MAX_FRIENDS) {
  12950. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12951. return;
  12952. }
  12953. //remove from friend's list first
  12954. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12955. for (i = 0; i < MAX_FRIENDS &&
  12956. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12957. if (i != MAX_FRIENDS) {
  12958. // move all chars up
  12959. for(j = i + 1; j < MAX_FRIENDS; j++)
  12960. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12961. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12962. //should the guy be notified of some message? we should add it here if so
  12963. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12964. WFIFOW(f_sd->fd,0) = 0x20a;
  12965. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12966. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12967. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12968. }
  12969. } else { //friend not online -- ask char server to delete from his friendlist
  12970. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12971. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12972. return;
  12973. }
  12974. }
  12975. // We can now delete from original requester
  12976. for (i = 0; i < MAX_FRIENDS &&
  12977. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12978. // move all chars up
  12979. for(j = i + 1; j < MAX_FRIENDS; j++)
  12980. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12981. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12982. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12983. WFIFOHEAD(fd,packet_len(0x20a));
  12984. WFIFOW(fd,0) = 0x20a;
  12985. WFIFOL(fd,2) = account_id;
  12986. WFIFOL(fd,6) = char_id;
  12987. WFIFOSET(fd, packet_len(0x20a));
  12988. }
  12989. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12990. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12991. void clif_PVPInfo(struct map_session_data* sd)
  12992. {
  12993. int fd = sd->fd;
  12994. WFIFOHEAD(fd,packet_len(0x210));
  12995. WFIFOW(fd,0) = 0x210;
  12996. WFIFOL(fd,2) = sd->status.char_id;
  12997. WFIFOL(fd,6) = sd->status.account_id;
  12998. WFIFOL(fd,10) = sd->pvp_won; // times won
  12999. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  13000. WFIFOL(fd,18) = sd->pvp_point;
  13001. WFIFOSET(fd, packet_len(0x210));
  13002. }
  13003. /// /pvpinfo (CZ_REQ_PVPPOINT).
  13004. /// 020f <char id>.L <account id>.L
  13005. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  13006. {
  13007. // TODO: Is there a way to use this on an another player (char/acc id)?
  13008. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13009. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13010. clif_PVPInfo(sd);
  13011. }
  13012. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  13013. /// 0254 <which>.B
  13014. /// which: (unused atm for security purpose)
  13015. /// 0 = sun
  13016. /// 1 = moon
  13017. /// 2 = star
  13018. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  13019. {
  13020. int i;
  13021. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13022. if (sd->menuskill_id != SG_FEEL)
  13023. return;
  13024. i = sd->menuskill_val-1;
  13025. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13026. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13027. sd->feel_map[i].m = sd->bl.m;
  13028. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13029. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13030. // clif_misceffect2(&sd->bl, 0x1b0);
  13031. // clif_misceffect2(&sd->bl, 0x21f);
  13032. clif_feel_info(sd, i, 0);
  13033. clif_menuskill_clear(sd);
  13034. }
  13035. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13036. /// 0253 <which>.B
  13037. /// which:
  13038. /// 0 = sun
  13039. /// 1 = moon
  13040. /// 2 = star
  13041. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  13042. {
  13043. WFIFOHEAD(fd,packet_len(0x253));
  13044. WFIFOW(fd,0)=0x253;
  13045. WFIFOB(fd,2)=TOB(skill_lv-1);
  13046. WFIFOSET(fd, packet_len(0x253));
  13047. sd->menuskill_id = SG_FEEL;
  13048. sd->menuskill_val = skill_lv;
  13049. }
  13050. /// Request to change homunculus' name (CZ_RENAME_MER).
  13051. /// 0231 <name>.24B
  13052. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  13053. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13054. }
  13055. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13056. /// 0234 <id>.L
  13057. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  13058. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13059. struct block_list *bl = NULL;
  13060. struct unit_data *ud = NULL;
  13061. if( sd->md && sd->md->bl.id == id )
  13062. bl = &sd->md->bl;
  13063. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13064. bl = &sd->hd->bl; // Moving Homunculus
  13065. else
  13066. return;
  13067. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13068. ud = unit_bl2ud(bl);
  13069. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13070. }
  13071. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13072. /// 0232 <id>.L <position data>.3B
  13073. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  13074. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13075. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13076. struct block_list *bl = NULL;
  13077. short x, y;
  13078. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13079. if( sd->md && sd->md->bl.id == id )
  13080. bl = &sd->md->bl; // Moving Mercenary
  13081. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13082. bl = &sd->hd->bl; // Moving Homunculus
  13083. else
  13084. return;
  13085. unit_walktoxy(bl, x, y, 4);
  13086. }
  13087. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13088. /// 0233 <id>.L <target id>.L <action>.B
  13089. /// action:
  13090. /// always 0
  13091. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  13092. {
  13093. struct block_list *bl = NULL;
  13094. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13095. int id = RFIFOL(fd,info->pos[0]);
  13096. int target_id = RFIFOL(fd,info->pos[1]);
  13097. int action_type = RFIFOB(fd,info->pos[2]);
  13098. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13099. bl = &sd->hd->bl;
  13100. else if( sd->md && sd->md->bl.id == id )
  13101. bl = &sd->md->bl;
  13102. else return;
  13103. unit_stop_attack(bl);
  13104. unit_attack(bl, target_id, action_type != 0);
  13105. }
  13106. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13107. /// 022d <type>.W <command>.B
  13108. /// type:
  13109. /// always 0
  13110. /// command:
  13111. /// 0 = homunculus information
  13112. /// 1 = feed
  13113. /// 2 = delete
  13114. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  13115. { //[orn]
  13116. int cmd = RFIFOW(fd,0);
  13117. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13118. if(!hom_is_active(sd->hd))
  13119. return;
  13120. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13121. }
  13122. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13123. /// 0292
  13124. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  13125. {
  13126. pc_revive_item(sd);
  13127. }
  13128. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13129. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13130. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13131. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13132. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13133. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13134. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13135. void clif_check(int fd, struct map_session_data* pl_sd)
  13136. {
  13137. WFIFOHEAD(fd,packet_len(0x214));
  13138. WFIFOW(fd, 0) = 0x214;
  13139. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13140. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13141. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13142. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13143. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13144. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13145. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13146. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13147. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13148. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13149. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13150. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13151. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13152. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13153. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13154. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13155. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13156. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13157. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13158. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13159. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13160. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13161. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13162. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13163. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13164. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13165. WFIFOSET(fd,packet_len(0x214));
  13166. }
  13167. /// /check (CZ_REQ_STATUS_GM).
  13168. /// Request character's status values.
  13169. /// 0213 <char name>.24B
  13170. void clif_parse_Check(int fd, struct map_session_data *sd)
  13171. {
  13172. char charname[NAME_LENGTH];
  13173. struct map_session_data* pl_sd;
  13174. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13175. return;
  13176. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13177. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13178. {
  13179. return;
  13180. }
  13181. clif_check(fd, pl_sd);
  13182. }
  13183. /// MAIL SYSTEM
  13184. /// By Zephyrus
  13185. ///
  13186. /// Notification about the result of adding an item to mail
  13187. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13188. /// result:
  13189. /// 0 = success
  13190. /// 1 = failure
  13191. /// 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)
  13192. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13193. /// result:
  13194. /// 0 = success
  13195. /// 1 = over weight
  13196. /// 2 = fatal error
  13197. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13198. int fd = sd->fd;
  13199. #if PACKETVER < 20150513
  13200. WFIFOHEAD(fd,packet_len(0x255));
  13201. WFIFOW(fd,0) = 0x255;
  13202. WFIFOW(fd,2) = index;
  13203. WFIFOB(fd,4) = flag;
  13204. WFIFOSET(fd,packet_len(0x255));
  13205. #else
  13206. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13207. if( flag ){
  13208. memset( &p, 0, sizeof( p ) );
  13209. }else{
  13210. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13211. p.index = index;
  13212. p.count = amount;
  13213. p.itemId = client_nameid( item->nameid );
  13214. p.type = itemtype( item->nameid );
  13215. p.IsIdentified = item->identify ? 1 : 0;
  13216. p.IsDamaged = item->attribute ? 1 : 0;
  13217. p.refiningLevel = item->refine;
  13218. clif_addcards( &p.slot, item );
  13219. clif_add_random_options( p.optionData, item );
  13220. p.weight = 0;
  13221. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13222. if( sd->mail.item[i].nameid == 0 ){
  13223. continue;
  13224. }
  13225. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13226. }
  13227. p.favorite = item->favorite;
  13228. p.location = pc_equippoint( sd, server_index( index ) );
  13229. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13230. p.enchantgrade = item->enchantgrade;
  13231. #endif
  13232. }
  13233. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13234. p.result = flag;
  13235. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13236. #endif
  13237. }
  13238. /// Notification about the result of retrieving a mail attachment
  13239. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13240. /// result:
  13241. /// 0 = success
  13242. /// 1 = failure
  13243. /// 2 = too many items
  13244. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13245. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13246. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13247. #if PACKETVER < 20150513
  13248. int fd = sd->fd;
  13249. WFIFOHEAD(fd,packet_len(0x245));
  13250. WFIFOW(fd,0) = 0x245;
  13251. WFIFOB(fd,2) = result;
  13252. WFIFOSET(fd,packet_len(0x245));
  13253. #else
  13254. switch( type ){
  13255. case MAIL_ATT_ITEM:
  13256. case MAIL_ATT_ZENY:
  13257. break;
  13258. default:
  13259. return;
  13260. }
  13261. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13262. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13263. p.MailID = msg->id;
  13264. p.opentype = msg->type;
  13265. p.result = result;
  13266. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13267. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13268. #endif
  13269. }
  13270. /// Notification about the result of sending a mail
  13271. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13272. /// result:
  13273. /// 0 = success
  13274. /// 1 = recipinent does not exist
  13275. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13276. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13277. #if PACKETVER < 20150513
  13278. int fd = sd->fd;
  13279. WFIFOHEAD(fd,packet_len(0x249));
  13280. WFIFOW(fd,0) = 0x249;
  13281. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13282. WFIFOSET(fd,packet_len(0x249));
  13283. #else
  13284. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13285. p.PacketType = rodexwriteresult;
  13286. p.result = result;
  13287. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13288. #endif
  13289. }
  13290. /// Notification about the result of deleting a mail.
  13291. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13292. /// result:
  13293. /// 0 = success
  13294. /// 1 = failure
  13295. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13296. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13297. #if PACKETVER < 20150513
  13298. int fd = sd->fd;
  13299. WFIFOHEAD(fd, packet_len(0x257));
  13300. WFIFOW(fd,0) = 0x257;
  13301. WFIFOL(fd,2) = msg->id;
  13302. WFIFOW(fd,6) = !success;
  13303. WFIFOSET(fd, packet_len(0x257));
  13304. #else
  13305. // This is only a success notification
  13306. if( success ){
  13307. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13308. p.PacketType = rodexdelete;
  13309. p.opentype = msg->type;
  13310. p.MailID = msg->id;
  13311. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13312. }
  13313. #endif
  13314. }
  13315. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13316. /// 0274 <mail id>.L <result>.W
  13317. /// result:
  13318. /// 0 = success
  13319. /// 1 = failure
  13320. void clif_Mail_return(int fd, int mail_id, short fail)
  13321. {
  13322. WFIFOHEAD(fd,packet_len(0x274));
  13323. WFIFOW(fd,0) = 0x274;
  13324. WFIFOL(fd,2) = mail_id;
  13325. WFIFOW(fd,6) = fail;
  13326. WFIFOSET(fd,packet_len(0x274));
  13327. }
  13328. /// Notification about new mail.
  13329. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13330. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13331. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13332. #if PACKETVER < 20150513
  13333. int fd = sd->fd;
  13334. WFIFOHEAD(fd,packet_len(0x24a));
  13335. WFIFOW(fd,0) = 0x24a;
  13336. WFIFOL(fd,2) = mail_id;
  13337. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13338. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13339. WFIFOSET(fd,packet_len(0x24a));
  13340. #else
  13341. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13342. p.PacketType = rodexicon;
  13343. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13344. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13345. #endif
  13346. }
  13347. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13348. /// 0260 <type>.L
  13349. /// type:
  13350. /// 0 = open
  13351. /// 1 = close
  13352. void clif_Mail_window(int fd, int flag)
  13353. {
  13354. WFIFOHEAD(fd,packet_len(0x260));
  13355. WFIFOW(fd,0) = 0x260;
  13356. WFIFOL(fd,2) = flag;
  13357. WFIFOSET(fd,packet_len(0x260));
  13358. }
  13359. /// Lists mails stored in inbox.
  13360. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13361. /// read:
  13362. /// 0 = unread
  13363. /// 1 = read
  13364. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13365. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13366. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13367. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13368. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13369. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13370. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13371. #if PACKETVER < 20150513
  13372. int fd = sd->fd;
  13373. struct mail_data *md = &sd->mail.inbox;
  13374. struct mail_message *msg;
  13375. int len, i, j;
  13376. len = 8 + (73 * md->amount);
  13377. WFIFOHEAD(fd,len);
  13378. WFIFOW(fd,0) = 0x240;
  13379. WFIFOW(fd,2) = len;
  13380. WFIFOL(fd,4) = md->amount;
  13381. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13382. {
  13383. msg = &md->msg[i];
  13384. if (msg->id < 1)
  13385. continue;
  13386. WFIFOL(fd,8+73*j) = msg->id;
  13387. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13388. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13389. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13390. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13391. j++;
  13392. }
  13393. WFIFOSET(fd,len);
  13394. if( md->full ) {// TODO: is this official?
  13395. char output[100];
  13396. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13397. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13398. }
  13399. #else
  13400. int fd = sd->fd;
  13401. struct mail_data *md = &sd->mail.inbox;
  13402. struct mail_message *msg;
  13403. int i, j, k, offset, titleLength;
  13404. uint8 mailType, amount, remaining;
  13405. uint32 now = (uint32)time(NULL);
  13406. #if PACKETVER >= 20170419
  13407. int cmd = 0xac2;
  13408. #elif PACKETVER >= 20160601
  13409. int cmd = 0xa7d;
  13410. #else
  13411. int cmd = 0x9f0;
  13412. #endif
  13413. if( battle_config.mail_daily_count ){
  13414. mail_refresh_remaining_amount(sd);
  13415. }
  13416. #if PACKETVER >= 20170419
  13417. // Always send all
  13418. i = md->amount;
  13419. #else
  13420. // If a starting mail id was sent
  13421. if( mailID != 0 ){
  13422. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13423. // Unknown mail
  13424. if( i == md->amount ){
  13425. // Ignore the request for now
  13426. return; // TODO: Should we just show the first page instead?
  13427. }
  13428. // It was actually the oldest/first mail, there is no further page
  13429. if( i == 0 ){
  13430. return;
  13431. }
  13432. // We actually want the next/older mail
  13433. i -= 1;
  13434. }else{
  13435. i = md->amount;
  13436. }
  13437. #endif
  13438. // Count the remaining mails from the starting mail or the beginning
  13439. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13440. for( j = i, remaining = 0; j >= 0; j-- ){
  13441. msg = &md->msg[j];
  13442. if (msg->id < 1)
  13443. continue;
  13444. #if PACKETVER < 20170419
  13445. if (msg->type != type)
  13446. continue;
  13447. #endif
  13448. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13449. continue;
  13450. remaining++;
  13451. }
  13452. #if PACKETVER >= 20170419
  13453. // Always send all
  13454. amount = remaining;
  13455. #else
  13456. if( remaining > MAIL_PAGE_SIZE ){
  13457. amount = MAIL_PAGE_SIZE;
  13458. }else{
  13459. amount = remaining;
  13460. }
  13461. #endif
  13462. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13463. WFIFOW(fd, 0) = cmd;
  13464. #if PACKETVER >= 20170419
  13465. WFIFOB(fd, 4) = 1; // Unknown
  13466. offset = 5;
  13467. #else
  13468. WFIFOB(fd, 4) = type;
  13469. WFIFOB(fd, 5) = amount;
  13470. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13471. offset = 7;
  13472. #endif
  13473. for( amount = 0; i >= 0; i-- ){
  13474. msg = &md->msg[i];
  13475. if (msg->id < 1)
  13476. continue;
  13477. #if PACKETVER < 20170419
  13478. if (msg->type != type)
  13479. continue;
  13480. #endif
  13481. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13482. continue;
  13483. #if PACKETVER >= 20170419
  13484. WFIFOB(fd, offset) = msg->type;
  13485. offset += 1;
  13486. #endif
  13487. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13488. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13489. mailType = MAIL_TYPE_TEXT; // Normal letter
  13490. if( msg->zeny > 0 ){
  13491. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13492. }
  13493. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13494. if( msg->item[k].nameid > 0 ){
  13495. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13496. break;
  13497. }
  13498. }
  13499. #if PACKETVER >= 20170419
  13500. // If it came from an npc?
  13501. if( !msg->send_id ){
  13502. mailType |= MAIL_TYPE_NPC;
  13503. }
  13504. #endif
  13505. WFIFOB(fd, offset + 9) = mailType;
  13506. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13507. #if PACKETVER < 20170419
  13508. // How much time has passed since you received the mail
  13509. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13510. offset += 4;
  13511. #endif
  13512. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13513. if( msg->scheduled_deletion > 0 ){
  13514. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13515. }else{
  13516. // Fake the scheduled deletion to one year in the future
  13517. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13518. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13519. }
  13520. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13521. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13522. offset += 40 + titleLength;
  13523. }
  13524. WFIFOW(fd, 2) = (int16)offset;
  13525. WFIFOSET(fd, offset);
  13526. #endif
  13527. }
  13528. /// Mail inbox list request.
  13529. /// 023f (CZ_MAIL_GET_LIST)
  13530. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13531. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13532. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13533. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13534. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13535. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13536. if( mail_invalid_operation( sd ) ){
  13537. return;
  13538. }
  13539. #if PACKETVER < 20150513
  13540. struct mail_data* md = &sd->mail.inbox;
  13541. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13542. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13543. else
  13544. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13545. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13546. mail_removezeny(sd, false);
  13547. #else
  13548. int cmd = RFIFOW(fd, 0);
  13549. #if PACKETVER < 20170419
  13550. uint8 openType = RFIFOB(fd, 2);
  13551. uint64 mailId = RFIFOQ(fd, 3);
  13552. #else
  13553. uint8 openType;
  13554. uint64 mailId = RFIFOQ(fd, 2);
  13555. int i;
  13556. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13557. if( i == MAIL_MAX_INBOX ){
  13558. openType = MAIL_INBOX_NORMAL;
  13559. mailId = 0;
  13560. }else{
  13561. openType = sd->mail.inbox.msg[i].type;
  13562. mailId = 0;
  13563. }
  13564. #endif
  13565. switch( openType ){
  13566. case MAIL_INBOX_NORMAL:
  13567. case MAIL_INBOX_ACCOUNT:
  13568. case MAIL_INBOX_RETURNED:
  13569. break;
  13570. default:
  13571. // Unknown type: ignore request
  13572. return;
  13573. }
  13574. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13575. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13576. return;
  13577. }
  13578. // If it is not a next page request
  13579. if( cmd != 0x9ee ){
  13580. mailId = 0;
  13581. }
  13582. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13583. #endif
  13584. }
  13585. /// Opens a mail
  13586. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13587. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13588. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13589. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13590. /// { }*n
  13591. // TODO: Packet description => for repeated block
  13592. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13593. int i, fd = sd->fd;
  13594. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13595. if( i == MAIL_MAX_INBOX ) {
  13596. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13597. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13598. return;
  13599. } else {
  13600. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13601. struct item *item;
  13602. struct item_data *data;
  13603. int msg_len = strlen(msg->body);
  13604. if( msg_len == 0 ) {
  13605. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13606. msg_len = strlen(msg->body);
  13607. }
  13608. #if PACKETVER < 20150513
  13609. item = &msg->item[0];
  13610. int len = 101 + msg_len;
  13611. WFIFOHEAD(fd,len);
  13612. WFIFOW(fd,0) = 0x242;
  13613. WFIFOW(fd,2) = len;
  13614. WFIFOL(fd,4) = msg->id;
  13615. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13616. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13617. WFIFOL(fd,72) = 0;
  13618. WFIFOL(fd,76) = msg->zeny;
  13619. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13620. WFIFOL(fd,80) = item->amount;
  13621. WFIFOW(fd,84) = client_nameid( item->nameid );
  13622. WFIFOW(fd,86) = itemtype( item->nameid );
  13623. WFIFOB(fd,88) = item->identify;
  13624. WFIFOB(fd,89) = item->attribute;
  13625. WFIFOB(fd,90) = item->refine;
  13626. WFIFOW(fd,91) = item->card[0];
  13627. WFIFOW(fd,93) = item->card[1];
  13628. WFIFOW(fd,95) = item->card[2];
  13629. WFIFOW(fd,97) = item->card[3];
  13630. } else // no item, set all to zero
  13631. memset(WFIFOP(fd,80), 0x00, 19);
  13632. WFIFOB(fd,99) = (unsigned char)msg_len;
  13633. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13634. WFIFOSET(fd,len);
  13635. #else
  13636. msg_len += 1; // Zero Termination
  13637. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13638. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13639. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13640. p->opentype = msg->type;
  13641. p->MailID = msg->id;
  13642. p->TextcontentsLength = msg_len;
  13643. p->zeny = msg->zeny;
  13644. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13645. p->PacketLength += p->TextcontentsLength;
  13646. p->ItemCnt = 0;
  13647. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13648. item = &msg->item[j];
  13649. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13650. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13651. mailitem->ITID = client_nameid( item->nameid );
  13652. mailitem->count = item->amount;
  13653. mailitem->type = itemtype( item->nameid );
  13654. mailitem->IsIdentified = item->identify ? 1 : 0;
  13655. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13656. mailitem->refiningLevel = item->refine;
  13657. mailitem->location = pc_equippoint_sub( sd, data );
  13658. mailitem->viewSprite = data->look;
  13659. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13660. clif_addcards( &mailitem->slot, item );
  13661. clif_add_random_options( mailitem->option_data, item );
  13662. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13663. mailitem->enchantgrade = item->enchantgrade;
  13664. #endif
  13665. p->PacketLength += sizeof( *mailitem );
  13666. p->ItemCnt++;
  13667. }
  13668. }
  13669. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13670. #endif
  13671. if (msg->status == MAIL_UNREAD) {
  13672. msg->status = MAIL_READ;
  13673. intif_Mail_read(mail_id);
  13674. clif_parse_Mail_refreshinbox(fd, sd);
  13675. sd->mail.inbox.unread--;
  13676. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13677. }
  13678. }
  13679. }
  13680. /// Request to open a mail.
  13681. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13682. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13683. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13684. #if PACKETVER < 20150513
  13685. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13686. #else
  13687. //uint8 openType = RFIFOB(fd, 2);
  13688. int mail_id = (int)RFIFOQ(fd, 3);
  13689. #endif
  13690. if( mail_id <= 0 )
  13691. return;
  13692. if( mail_invalid_operation(sd) )
  13693. return;
  13694. clif_Mail_read(sd, mail_id);
  13695. }
  13696. /// Allow a player to begin writing a mail
  13697. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13698. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13699. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13700. p.PacketType = rodexopenwrite;
  13701. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13702. p.result = success;
  13703. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13704. }
  13705. /// Request to start writing a mail
  13706. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13707. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13708. char name[NAME_LENGTH];
  13709. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13710. if( mail_invalid_operation( sd ) ){
  13711. return;
  13712. }
  13713. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13714. clif_send_Mail_beginwrite_ack(sd, name, false);
  13715. return;
  13716. }
  13717. mail_clear(sd);
  13718. sd->state.mail_writing = true;
  13719. clif_send_Mail_beginwrite_ack(sd, name,true);
  13720. }
  13721. /// Notification that the client cancelled writing a mail
  13722. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13723. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13724. sd->state.mail_writing = false;
  13725. }
  13726. /// Give the client information about the recipient, if available
  13727. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13728. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13729. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13730. PACKET_ZC_CHECKNAME p = { 0 };
  13731. p.PacketType = HEADER_ZC_CHECKNAME;
  13732. p.CharId = char_id;
  13733. p.Class = class_;
  13734. p.BaseLevel = level;
  13735. #if PACKETVER >= 20160302
  13736. strncpy(p.Name, name, NAME_LENGTH);
  13737. #endif
  13738. clif_send(&p, sizeof(p), &sd->bl, SELF);
  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 + 10) = qi->objectives[i]->count;
  14973. WFIFOW(fd, offset + 12) = 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. char storename[MESSAGE_SIZE];
  15848. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15849. // so that buyingstore_create knows, how many elements it has access to
  15850. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15851. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15852. 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 ) );
  15853. return;
  15854. }
  15855. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15856. }
  15857. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15858. /// 0812 <result>.W <total weight>.L
  15859. /// result:
  15860. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15861. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15862. /// 8 = "No sale (purchase) information available." (0x705)
  15863. /// ? = nothing
  15864. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15865. {
  15866. int fd = sd->fd;
  15867. WFIFOHEAD(fd,packet_len(0x812));
  15868. WFIFOW(fd,0) = 0x812;
  15869. WFIFOW(fd,2) = result;
  15870. WFIFOL(fd,4) = weight;
  15871. WFIFOSET(fd,packet_len(0x812));
  15872. }
  15873. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15874. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15875. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15876. nullpo_retv( sd );
  15877. int fd = sd->fd;
  15878. if( !session_isActive( fd ) ){
  15879. return;
  15880. }
  15881. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15882. WFIFOHEAD( fd, length );
  15883. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15884. p->packetType = 0x813;
  15885. p->packetLength = length;
  15886. p->AID = sd->bl.id;
  15887. p->zenyLimit = sd->buyingstore.zenylimit;
  15888. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15889. p->items[i].price = sd->buyingstore.items[i].price;
  15890. p->items[i].amount = sd->buyingstore.items[i].amount;
  15891. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15892. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15893. }
  15894. WFIFOSET( fd, p->packetLength );
  15895. }
  15896. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15897. /// 0814 <account id>.L <store name>.80B
  15898. void clif_buyingstore_entry(struct map_session_data* sd)
  15899. {
  15900. uint8 buf[MESSAGE_SIZE+6];
  15901. WBUFW(buf,0) = 0x814;
  15902. WBUFL(buf,2) = sd->bl.id;
  15903. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15904. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15905. }
  15906. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15907. {
  15908. int fd = sd->fd;
  15909. WFIFOHEAD(fd,packet_len(0x814));
  15910. WFIFOW(fd,0) = 0x814;
  15911. WFIFOL(fd,2) = pl_sd->bl.id;
  15912. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15913. WFIFOSET(fd,packet_len(0x814));
  15914. }
  15915. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15916. /// 0815
  15917. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15918. {
  15919. buyingstore_close(sd);
  15920. }
  15921. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15922. /// 0816 <account id>.L
  15923. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15924. {
  15925. uint8 buf[6];
  15926. WBUFW(buf,0) = 0x816;
  15927. WBUFL(buf,2) = sd->bl.id;
  15928. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15929. }
  15930. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15931. {
  15932. int fd = sd->fd;
  15933. WFIFOHEAD(fd,packet_len(0x816));
  15934. WFIFOW(fd,0) = 0x816;
  15935. WFIFOL(fd,2) = pl_sd->bl.id;
  15936. WFIFOSET(fd,packet_len(0x816));
  15937. }
  15938. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15939. /// 0817 <account id>.L
  15940. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15941. {
  15942. uint32 account_id;
  15943. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15944. buyingstore_open(sd, account_id);
  15945. }
  15946. /// Sends buying store item list.
  15947. /// 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)
  15948. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15949. nullpo_retv( sd );
  15950. nullpo_retv( pl_sd );
  15951. int fd = sd->fd;
  15952. if( !session_isActive( fd ) ){
  15953. return;
  15954. }
  15955. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15956. WFIFOHEAD( fd, length );
  15957. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15958. p->packetType = 0x818;
  15959. p->packetLength = length;
  15960. p->AID = pl_sd->bl.id;
  15961. p->storeId = pl_sd->buyer_id;
  15962. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15963. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15964. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15965. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15966. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15967. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15968. }
  15969. WFIFOSET( fd, p->packetLength );
  15970. }
  15971. /// Request to sell items to a buying store.
  15972. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15973. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15974. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15975. // minimum packet length
  15976. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15977. 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 );
  15978. return;
  15979. }
  15980. // so that buyingstore_trade knows, how many elements it has access to
  15981. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15982. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15983. 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 ) );
  15984. return;
  15985. }
  15986. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15987. }
  15988. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15989. /// 081a <result>.W
  15990. /// result:
  15991. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15992. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15993. /// ? = nothing
  15994. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15995. {
  15996. int fd = sd->fd;
  15997. WFIFOHEAD(fd,packet_len(0x81a));
  15998. WFIFOW(fd,0) = 0x81a;
  15999. WFIFOW(fd,2) = result;
  16000. WFIFOSET(fd,packet_len(0x81a));
  16001. }
  16002. /// Updates the zeny limit and an item in the buying store item list.
  16003. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16004. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16005. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16006. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16007. p.packetType = buyingStoreUpdateItemType;
  16008. p.itemId = client_nameid( nameid );
  16009. p.amount = amount;
  16010. p.zenyLimit = sd->buyingstore.zenylimit;
  16011. #if PACKETVER >= 20141016
  16012. p.zeny = zeny;
  16013. p.charId = char_id; // GID
  16014. p.updateTime = (int)time(NULL);
  16015. #endif
  16016. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16017. }
  16018. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16019. /// 081c <index>.W <amount>.W <price>.L
  16020. /// message:
  16021. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16022. ///
  16023. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16024. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  16025. {
  16026. int fd = sd->fd;
  16027. WFIFOHEAD(fd,packet_len(0x81c));
  16028. WFIFOW(fd,0) = 0x81c;
  16029. WFIFOW(fd,2) = client_index( index );
  16030. WFIFOW(fd,4) = amount;
  16031. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16032. WFIFOSET(fd,packet_len(0x81c));
  16033. }
  16034. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16035. /// 0824 <result>.W <name id>.W
  16036. /// result:
  16037. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16038. /// 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)
  16039. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16040. /// ? = nothing
  16041. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  16042. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16043. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16044. p.result = result;
  16045. p.itemId = client_nameid( nameid );
  16046. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16047. }
  16048. /// Search Store Info System
  16049. ///
  16050. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16051. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16052. /// type:
  16053. /// 0 = Vending
  16054. /// 1 = Buying Store
  16055. ///
  16056. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16057. /// amount of card slots. If the client does not know about the item it
  16058. /// cannot be searched.
  16059. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  16060. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16061. // minimum packet length
  16062. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16063. 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 );
  16064. return;
  16065. }
  16066. // check, if there is enough data for the claimed count of items
  16067. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16068. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16069. 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 ) );
  16070. return;
  16071. }
  16072. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16073. if( count < p->itemsCount + p->cardsCount ){
  16074. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16075. return;
  16076. }
  16077. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16078. }
  16079. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16080. /// 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 }*
  16081. /// is first page:
  16082. /// 0 = appends to existing results
  16083. /// 1 = clears previous results before displaying this result set
  16084. /// is next page:
  16085. /// 0 = no "next" label
  16086. /// 1 = "next" label to retrieve more results
  16087. void clif_search_store_info_ack( struct map_session_data* sd ){
  16088. nullpo_retv( sd );
  16089. int fd = sd->fd;
  16090. if( !session_isActive( fd ) ){
  16091. return;
  16092. }
  16093. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16094. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16095. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16096. WFIFOHEAD( fd, len );
  16097. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16098. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16099. p->packetLength = len;
  16100. p->firstPage = !sd->searchstore.pages;
  16101. p->nextPage = searchstore_querynext( sd );
  16102. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16103. for( int i = 0; i < end - start; i++ ) {
  16104. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16105. p->items[i].storeId = ssitem->store_id;
  16106. p->items[i].AID = ssitem->account_id;
  16107. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16108. p->items[i].itemId = client_nameid( ssitem->nameid );
  16109. p->items[i].itemType = itemtype( ssitem->nameid );
  16110. p->items[i].price = ssitem->price;
  16111. p->items[i].amount = ssitem->amount;
  16112. p->items[i].refine = ssitem->refine;
  16113. // make-up an item for clif_addcards
  16114. struct item it = {};
  16115. for( int j = 0; j < MAX_SLOTS; j++ ){
  16116. it.card[j] = ssitem->card[j];
  16117. }
  16118. it.nameid = ssitem->nameid;
  16119. it.amount = ssitem->amount;
  16120. clif_addcards( &p->items[i].slot, &it );
  16121. #if PACKETVER >= 20150226
  16122. clif_add_random_options( p->items[i].option_data, &it );
  16123. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16124. p->items[i].enchantgrade = ssitem->enchantgrade;
  16125. #endif
  16126. #endif
  16127. }
  16128. WFIFOSET( fd, len );
  16129. }
  16130. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16131. /// 0837 <reason>.B
  16132. /// reason:
  16133. /// 0 = "No matching stores were found." (0x70b)
  16134. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16135. /// 2 = "You cannot search anymore." (0x706)
  16136. /// 3 = "You cannot search yet." (0x708)
  16137. /// 4 = "No sale (purchase) information available." (0x705)
  16138. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16139. {
  16140. int fd = sd->fd;
  16141. WFIFOHEAD(fd,packet_len(0x837));
  16142. WFIFOW(fd,0) = 0x837;
  16143. WFIFOB(fd,2) = reason;
  16144. WFIFOSET(fd,packet_len(0x837));
  16145. }
  16146. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16147. /// 0838
  16148. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16149. {
  16150. searchstore_next(sd);
  16151. }
  16152. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16153. /// 083a <type>.W <remaining uses>.B
  16154. /// type:
  16155. /// 0 = Search Stores
  16156. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16157. void clif_open_search_store_info(struct map_session_data* sd)
  16158. {
  16159. int fd = sd->fd;
  16160. WFIFOHEAD(fd,packet_len(0x83a));
  16161. WFIFOW(fd,0) = 0x83a;
  16162. WFIFOW(fd,2) = sd->searchstore.effect;
  16163. #if PACKETVER > 20100701
  16164. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16165. #endif
  16166. WFIFOSET(fd,packet_len(0x83a));
  16167. }
  16168. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16169. /// 083b
  16170. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16171. {
  16172. searchstore_close(sd);
  16173. }
  16174. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16175. /// 083c <account id>.L <store id>.L <nameid>.W
  16176. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16177. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16178. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16179. }
  16180. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16181. /// 083d <xPos>.W <yPos>.W
  16182. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16183. {
  16184. int fd = sd->fd;
  16185. WFIFOHEAD(fd,packet_len(0x83d));
  16186. WFIFOW(fd,0) = 0x83d;
  16187. WFIFOW(fd,2) = x;
  16188. WFIFOW(fd,4) = y;
  16189. WFIFOSET(fd,packet_len(0x83d));
  16190. }
  16191. /// Parse function for packet debugging.
  16192. void clif_parse_debug(int fd,struct map_session_data *sd)
  16193. {
  16194. int cmd, packet_len;
  16195. // clif_parse ensures, that there is at least 2 bytes of data
  16196. cmd = RFIFOW(fd,0);
  16197. if( sd ) {
  16198. packet_len = packet_db[cmd].len;
  16199. if( packet_len == 0 )
  16200. {// unknown
  16201. packet_len = RFIFOREST(fd);
  16202. }
  16203. else if( packet_len == -1 )
  16204. {// variable length
  16205. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16206. }
  16207. 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);
  16208. }
  16209. else
  16210. {
  16211. packet_len = RFIFOREST(fd);
  16212. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16213. }
  16214. ShowDump(RFIFOP(fd,0), packet_len);
  16215. }
  16216. /*==========================================
  16217. * Server tells client to display a window similar to Magnifier (item) one
  16218. * Server populates the window with avilable elemental converter options according to player's inventory
  16219. *------------------------------------------*/
  16220. void clif_elementalconverter_list( struct map_session_data *sd ){
  16221. nullpo_retv( sd );
  16222. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16223. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16224. int count = 0;
  16225. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16226. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16227. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16228. count++;
  16229. }
  16230. }
  16231. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16232. clif_send( p, p->packetLength, &sd->bl, SELF );
  16233. if( count > 0 ){
  16234. sd->menuskill_id = SA_CREATECON;
  16235. sd->menuskill_val = count;
  16236. }
  16237. }
  16238. /**
  16239. * Rune Knight
  16240. **/
  16241. void clif_millenniumshield(struct block_list *bl, short shields) {
  16242. #if PACKETVER >= 20081217
  16243. unsigned char buf[10];
  16244. WBUFW(buf,0) = 0x440;
  16245. WBUFL(buf,2) = bl->id;
  16246. WBUFW(buf,6) = shields;
  16247. WBUFW(buf,8) = 0;
  16248. clif_send(buf,packet_len(0x440),bl,AREA);
  16249. #endif
  16250. }
  16251. /**
  16252. * Mechanic
  16253. **/
  16254. /*==========================================
  16255. * Magic Decoy Material List
  16256. *------------------------------------------*/
  16257. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16258. nullpo_retv( sd );
  16259. int fd = sd->fd;
  16260. if( !session_isActive( fd ) ){
  16261. return;
  16262. }
  16263. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16264. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16265. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16266. int count = 0;
  16267. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16268. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16269. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16270. count++;
  16271. }
  16272. }
  16273. if( count > 0 ) {
  16274. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16275. WFIFOSET( fd, p->packetLength );
  16276. sd->menuskill_id = NC_MAGICDECOY;
  16277. sd->menuskill_val = skill_lv;
  16278. sd->sc.comet_x = x;
  16279. sd->sc.comet_y = y;
  16280. }else{
  16281. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16282. }
  16283. }
  16284. /*==========================================
  16285. * Guillotine Cross Poisons List
  16286. *------------------------------------------*/
  16287. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16288. nullpo_retv( sd );
  16289. int fd = sd->fd;
  16290. if( !session_isActive( fd ) ){
  16291. return;
  16292. }
  16293. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16294. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16295. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16296. int count = 0;
  16297. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16298. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16299. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16300. count++;
  16301. }
  16302. }
  16303. if( count > 0 ){
  16304. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16305. WFIFOSET( fd, p->packetLength );
  16306. sd->menuskill_id = GC_POISONINGWEAPON;
  16307. sd->menuskill_val = skill_lv;
  16308. }else{
  16309. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16310. }
  16311. }
  16312. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16313. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16314. int fd, i, c;
  16315. nullpo_ret(sd);
  16316. fd = sd->fd;
  16317. if( !session_isActive(fd) )
  16318. return 0;
  16319. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16320. return 0;
  16321. WFIFOHEAD(fd, 2 * 6 + 4);
  16322. WFIFOW(fd,0) = 0x442;
  16323. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16324. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16325. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16326. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16327. {
  16328. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16329. c++;
  16330. }
  16331. if( c > 0 ) {
  16332. WFIFOW(fd,2) = 8 + c * 2;
  16333. WFIFOL(fd,4) = c;
  16334. WFIFOSET(fd,WFIFOW(fd,2));
  16335. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16336. sd->menuskill_val = c;
  16337. } else {
  16338. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  16339. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16340. }
  16341. return 1;
  16342. }
  16343. /*===========================================
  16344. * Skill list for Four Elemental Analysis
  16345. * and Change Material skills.
  16346. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16347. *------------------------------------------*/
  16348. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16349. #if PACKETVER >= 20090922
  16350. int fd = sd->fd;
  16351. nullpo_ret(sd);
  16352. sd->menuskill_id = skill_id; // To prevent hacking.
  16353. sd->menuskill_val = skill_lv;
  16354. if( skill_id == GN_CHANGEMATERIAL )
  16355. skill_lv = 0; // Changematerial
  16356. WFIFOHEAD(fd, packet_len(0x7e3));
  16357. WFIFOW(fd,0) = 0x7e3;
  16358. WFIFOL(fd,2) = skill_lv;
  16359. WFIFOL(fd,4) = 0;
  16360. WFIFOSET(fd, packet_len(0x7e3));
  16361. #endif
  16362. return 1;
  16363. }
  16364. /*==========================================
  16365. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16366. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16367. * RFIFOL(fd,2) - type (currently not used)
  16368. *------------------------------------------*/
  16369. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16370. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16371. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16372. if (sd->menuskill_id == SA_AUTOSPELL) {
  16373. sd->state.workinprogress = WIP_DISABLE_NONE;
  16374. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16375. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16376. if (pc_istrading(sd)) {
  16377. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16378. clif_menuskill_clear(sd);
  16379. return;
  16380. }
  16381. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16382. } else
  16383. return;
  16384. clif_menuskill_clear(sd);
  16385. }
  16386. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16387. /// 08cf <id>.L <type>.W <num>.W
  16388. void clif_spiritcharm(struct map_session_data *sd) {
  16389. unsigned char buf[10];
  16390. nullpo_retv(sd);
  16391. WBUFW(buf,0) = 0x08cf;
  16392. WBUFL(buf,2) = sd->bl.id;
  16393. WBUFW(buf,6) = sd->spiritcharm_type;
  16394. WBUFW(buf,8) = sd->spiritcharm;
  16395. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16396. }
  16397. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16398. /// 0907 <index>.W
  16399. ///
  16400. /// R 0908 <index>.w <type>.b
  16401. /// type:
  16402. /// 0 = move item to personal tab
  16403. /// 1 = move item to normal tab
  16404. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16405. #if PACKETVER >= 20111122
  16406. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16407. int index = RFIFOW(fd,info->pos[0]) - 2;
  16408. int type = RFIFOB(fd, info->pos[1]);
  16409. /* can't move while dead. */
  16410. if(pc_isdead(sd)) {
  16411. return;
  16412. }
  16413. if (index < 0 || index >= MAX_INVENTORY)
  16414. return;
  16415. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16416. sd->inventory.u.items_inventory[index].favorite = 0;
  16417. else if( type == 0 )
  16418. sd->inventory.u.items_inventory[index].favorite = 1;
  16419. else
  16420. return;/* nothing to do. */
  16421. clif_favorite_item(sd, index);
  16422. #endif
  16423. }
  16424. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16425. /// 0900 <index>.W <favorite>.B
  16426. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16427. int fd = sd->fd;
  16428. WFIFOHEAD(fd,packet_len(0x908));
  16429. WFIFOW(fd,0) = 0x908;
  16430. WFIFOW(fd,2) = index+2;
  16431. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16432. WFIFOSET(fd,packet_len(0x908));
  16433. }
  16434. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16435. void clif_snap( struct block_list *bl, short x, short y ) {
  16436. unsigned char buf[10];
  16437. WBUFW(buf,0) = 0x8d2;
  16438. WBUFL(buf,2) = bl->id;
  16439. WBUFW(buf,6) = x;
  16440. WBUFW(buf,8) = y;
  16441. if( disguised(bl) )
  16442. {
  16443. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16444. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16445. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16446. } else
  16447. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16448. }
  16449. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16450. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16451. #if PACKETVER >= 20120404
  16452. WFIFOHEAD(fd,packet_len(0x977));
  16453. WFIFOW(fd,0) = 0x977;
  16454. WFIFOL(fd,2) = md->bl.id;
  16455. WFIFOL(fd,6) = md->status.hp;
  16456. WFIFOL(fd,10) = md->status.max_hp;
  16457. WFIFOSET(fd,packet_len(0x977));
  16458. #endif
  16459. }
  16460. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16461. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16462. return;
  16463. }
  16464. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16465. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16466. WFIFOW(sd->fd,0) = 0x2c9;
  16467. WFIFOB(sd->fd,2) = flag;
  16468. WFIFOSET(sd->fd, packet_len(0x2c9));
  16469. }
  16470. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16471. /// 0979 <world name>.24B <char name>.24B
  16472. void clif_ackworldinfo(struct map_session_data* sd) {
  16473. int fd;
  16474. nullpo_retv(sd);
  16475. fd = sd->fd;
  16476. WFIFOHEAD(fd,packet_len(0x979));
  16477. WFIFOW(fd,0)=0x979;
  16478. //AID -> world name ?
  16479. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16480. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16481. WFIFOSET(fd,packet_len(0x979));
  16482. }
  16483. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16484. /// 0978 <AID>.L
  16485. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16486. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16487. if(sd)
  16488. clif_ackworldinfo(sd);
  16489. }
  16490. static void clif_loadConfirm( struct map_session_data *sd ){
  16491. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16492. nullpo_retv( sd );
  16493. struct PACKET_ZC_LOAD_CONFIRM p;
  16494. p.packetType = HEADER_ZC_LOAD_CONFIRM;
  16495. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16496. if (sd->instance_id > 0)
  16497. instance_reqinfo(sd, sd->instance_id);
  16498. if (sd->status.party_id > 0)
  16499. party_member_joined(sd);
  16500. if (sd->status.guild_id > 0)
  16501. guild_member_joined(sd);
  16502. if (sd->status.clan_id > 0)
  16503. clan_member_joined(sd);
  16504. #endif
  16505. }
  16506. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16507. /// 0447
  16508. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16509. clif_loadConfirm( sd );
  16510. }
  16511. /// req world info (CZ_CLIENT_VERSION)
  16512. /// 044A <version>.L
  16513. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16514. //if(sd)
  16515. ;
  16516. }
  16517. /// Ranking list
  16518. /// ranking pointlist { <name>.24B <point>.L }*10
  16519. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16520. struct fame_list* list;
  16521. int i, size = MAX_FAME_LIST;
  16522. switch(rankingtype) {
  16523. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16524. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16525. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16526. // PK currently unsupported
  16527. case RANK_KILLER: list = NULL; size = 0; break;
  16528. default:
  16529. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16530. return;
  16531. }
  16532. //Packet size limits this list to 10 elements. [Skotlex]
  16533. for (i = 0; i < min(10,size); i++) {
  16534. if (list[i].id > 0) {
  16535. const char* name;
  16536. if (strcmp(list[i].name, "-") == 0 &&
  16537. (name = map_charid2nick(list[i].id)) != NULL)
  16538. {
  16539. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16540. } else {
  16541. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16542. }
  16543. } else {
  16544. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16545. }
  16546. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16547. }
  16548. for(;i < 10; i++) { //In case the MAX is less than 10.
  16549. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16550. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16551. }
  16552. }
  16553. /// Request for the blacksmith ranklist.
  16554. /// /blacksmith command sends this packet to the server.
  16555. /// 0217 (CZ_BLACKSMITH_RANK)
  16556. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16557. clif_ranklist(sd,RANK_BLACKSMITH);
  16558. }
  16559. /// Request for the alchemist ranklist.
  16560. /// /alchemist command sends this packet to the server.
  16561. /// 0218 (CZ_ALCHEMIST_RANK)
  16562. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16563. clif_ranklist(sd,RANK_ALCHEMIST);
  16564. }
  16565. /// Request for the taekwon ranklist.
  16566. /// /taekwon command sends this packet to the server.
  16567. /// 0225 (CZ_TAEKWON_RANK)
  16568. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16569. clif_ranklist(sd,RANK_TAEKWON);
  16570. }
  16571. /// Request for the killer ranklist.
  16572. /// /pk command sends this packet to the server.
  16573. /// 0237 (CZ_KILLER_RANK)
  16574. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16575. clif_ranklist(sd,RANK_KILLER);
  16576. }
  16577. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16578. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16579. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16580. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16581. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16582. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16583. enum e_rank rank;
  16584. #if PACKETVER < 20130710
  16585. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16586. short cmd;
  16587. switch( rankingType ){
  16588. case RANK_BLACKSMITH: cmd = 0x219; break;
  16589. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16590. case RANK_TAEKWON: cmd = 0x226; break;
  16591. case RANK_KILLER: cmd = 0x238; break;
  16592. default:
  16593. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16594. return;
  16595. }
  16596. // Can be safely casted here, since we validated it before
  16597. rank = (enum e_rank)rankingType;
  16598. WBUFW(buf,0) = cmd;
  16599. clif_sub_ranklist(buf,2,sd,rank);
  16600. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16601. #else
  16602. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16603. int mypoint = 0;
  16604. switch( rankingType ){
  16605. case RANK_BLACKSMITH:
  16606. case RANK_ALCHEMIST:
  16607. case RANK_TAEKWON:
  16608. case RANK_KILLER:
  16609. break;
  16610. default:
  16611. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16612. return;
  16613. }
  16614. // Can be safely casted here, since we validated it before
  16615. rank = (enum e_rank)rankingType;
  16616. WBUFW(buf,0) = 0x97d;
  16617. WBUFW(buf,2) = rank;
  16618. clif_sub_ranklist(buf,4,sd,rank);
  16619. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16620. case MAPID_BLACKSMITH:
  16621. case MAPID_ALCHEMIST:
  16622. case MAPID_TAEKWON:
  16623. mypoint = sd->status.fame;
  16624. }
  16625. WBUFL(buf,284) = mypoint; //mypoint
  16626. clif_send(buf, 288, &sd->bl, SELF);
  16627. #endif
  16628. }
  16629. /*
  16630. * 097c <type> (CZ_REQ_RANKING)
  16631. * type
  16632. * 0: /blacksmith
  16633. * 1: /alchemist
  16634. * 2: /taekwon
  16635. * 3: /pk
  16636. * */
  16637. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16638. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16639. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16640. clif_ranklist(sd,rankingtype);
  16641. }
  16642. /// Updates the fame rank points for the given ranking.
  16643. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16644. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16645. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16646. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16647. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16648. int fd=sd->fd;
  16649. #if PACKETVER < 20130710
  16650. short cmd;
  16651. switch(rankingtype){
  16652. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16653. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16654. case RANK_TAEKWON: cmd = 0x224; break;
  16655. default:
  16656. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16657. return;
  16658. }
  16659. WFIFOHEAD(fd,packet_len(cmd));
  16660. WFIFOW(fd,0) = cmd;
  16661. WFIFOL(fd,2) = point;
  16662. WFIFOL(fd,6) = sd->status.fame;
  16663. WFIFOSET(fd, packet_len(cmd));
  16664. #else
  16665. WFIFOHEAD(fd,packet_len(0x97e));
  16666. WFIFOW(fd,0) = 0x97e;
  16667. WFIFOW(fd,2) = rankingtype;
  16668. WFIFOL(fd,4) = point;
  16669. WFIFOL(fd,8) = sd->status.fame;
  16670. WFIFOSET(fd,packet_len(0x97e));
  16671. #endif
  16672. }
  16673. /**
  16674. * Transmit personal information to player. (rates)
  16675. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16676. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16677. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16678. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16679. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16680. * FIXME!
  16681. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16682. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16683. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16684. */
  16685. #ifdef VIP_ENABLE
  16686. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16687. if (sd) {
  16688. struct s_packet_db* info;
  16689. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16690. int cmd = 0, fd, i = 0;
  16691. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16692. int details_bexp[PINFO_MAX];
  16693. int details_drop[PINFO_MAX];
  16694. int details_penalty[PINFO_MAX];
  16695. /**
  16696. * Set for EXP
  16697. */
  16698. //0:PCRoom
  16699. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16700. if (details_bexp[0] == 100 || !details_bexp[0])
  16701. details_bexp[0] = 0;
  16702. else {
  16703. if (details_bexp[0] < 100) {
  16704. details_bexp[0] = 100 - details_bexp[0];
  16705. details_bexp[0] = 0 - details_bexp[0];
  16706. }
  16707. else
  16708. details_bexp[0] = details_bexp[0] - 100;
  16709. }
  16710. //1:Premium
  16711. if (pc_isvip(sd)) {
  16712. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16713. if (details_bexp[1] < 0)
  16714. details_bexp[1] = 0 - details_bexp[1];
  16715. }
  16716. else
  16717. details_bexp[1] = 0;
  16718. //2:Server
  16719. details_bexp[2] = battle_config.base_exp_rate;
  16720. if (details_bexp[2] == 100)
  16721. details_bexp[2] = 0;
  16722. else {
  16723. if (details_bexp[2] < 100) {
  16724. details_bexp[2] = 100 - details_bexp[2];
  16725. details_bexp[2] = 0 - details_bexp[2];
  16726. }
  16727. else
  16728. details_bexp[2] = details_bexp[2] - 100;
  16729. }
  16730. //3:TPLUS
  16731. details_bexp[3] = 0;
  16732. /* End - EXP set*/
  16733. /**
  16734. * Set for Drop rate
  16735. */
  16736. //0:PCRoom
  16737. details_drop[0] = 0;
  16738. //1:Premium
  16739. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16740. if (pc_isvip(sd)) {
  16741. if (details_drop[1] < 0)
  16742. details_drop[1] = 0 - details_drop[1];
  16743. }
  16744. else
  16745. details_drop[1] = 0;
  16746. //2:Server
  16747. details_drop[2] = battle_config.item_rate_common;
  16748. if (details_drop[2] == 100)
  16749. details_drop[2] = 0;
  16750. else {
  16751. if (details_drop[2] < 100) {
  16752. details_drop[2] = 100 - details_drop[2];
  16753. details_drop[2] = 0 - details_drop[2];
  16754. }
  16755. else
  16756. details_drop[2] = details_drop[2] - 100;
  16757. }
  16758. //3:TPLUS
  16759. details_drop[3] = 0;
  16760. /* End - Drop set*/
  16761. /**
  16762. * Set for Penalty rate
  16763. */
  16764. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16765. //0:PCRoom
  16766. details_penalty[0] = 0;
  16767. //1:Premium
  16768. if (pc_isvip(sd)) {
  16769. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16770. if (details_penalty[1] == 100)
  16771. details_penalty[1] = 0;
  16772. else {
  16773. if (details_penalty[1] < 100) {
  16774. details_penalty[1] = 100 - details_penalty[1];
  16775. details_penalty[1] = 0 - details_penalty[1];
  16776. }
  16777. else
  16778. details_penalty[1] = details_penalty[1] - 100;
  16779. }
  16780. }
  16781. else
  16782. details_penalty[1] = 0;
  16783. //2:Server
  16784. details_penalty[2] = battle_config.death_penalty_base;
  16785. if (details_penalty[2] == 100)
  16786. details_penalty[2] = 0;
  16787. else {
  16788. if (details_penalty[2] < 100) {
  16789. details_penalty[2] = 100 - details_penalty[2];
  16790. details_penalty[2] = 0 - details_penalty[2];
  16791. }
  16792. else
  16793. details_penalty[2] = details_penalty[2] - 100;
  16794. }
  16795. //3:TPLUS
  16796. details_penalty[3] = 0;
  16797. /* End - Penalty set*/
  16798. cmd = packet_db_ack[cmdtype];
  16799. info = &packet_db[cmd];
  16800. len = info->len; //this is the base len without details
  16801. if(!len) return; //version as packet disable
  16802. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16803. szdetails = 7;
  16804. factor = 1;
  16805. }
  16806. else if (cmd == 0x097b) {
  16807. tot_baseexp *= factor;
  16808. tot_drop *= factor;
  16809. tot_penalty *= factor;
  16810. }
  16811. fd = sd->fd;
  16812. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16813. WFIFOW(fd,0) = cmd;
  16814. for (i = 0; i < maxinfotype; i++) {
  16815. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16816. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16817. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16818. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16819. tot_baseexp += details_bexp[i]*factor;
  16820. tot_drop += details_penalty[i]*factor;
  16821. tot_penalty += details_drop[i]*factor;
  16822. len += szdetails;
  16823. }
  16824. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16825. if (cmd == 0x08cb) { //0x08cb version
  16826. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16827. WFIFOW(fd,info->pos[2]) = tot_drop;
  16828. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16829. }
  16830. else { //2013-08-07aRagexe uses 0x097b
  16831. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16832. WFIFOL(fd,info->pos[2]) = tot_drop;
  16833. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16834. }
  16835. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16836. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16837. WFIFOSET(fd,len);
  16838. }
  16839. }
  16840. #endif
  16841. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16842. char cmd[30];
  16843. int t_aid = RFIFOL(fd,2);
  16844. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16845. is_atcommand(fd, sd, cmd, 1);
  16846. }
  16847. /**
  16848. * Marks Crimson Marker target on mini-map to the caster
  16849. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16850. * @param fd
  16851. * @param bl Crimson Marker target
  16852. **/
  16853. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16854. struct s_packet_db* info;
  16855. int cmd = 0;
  16856. int16 len;
  16857. unsigned char buf[11];
  16858. nullpo_retv(sd);
  16859. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16860. if (!cmd)
  16861. cmd = 0x09C1; //default
  16862. info = &packet_db[cmd];
  16863. if (!(len = info->len))
  16864. return;
  16865. WBUFW(buf, 0) = cmd;
  16866. WBUFL(buf, info->pos[0]) = bl->id;
  16867. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16868. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16869. clif_send(buf, len, &sd->bl, SELF);
  16870. }
  16871. /**
  16872. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16873. **/
  16874. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16875. struct s_packet_db *info = NULL;
  16876. int cmd = 0;
  16877. nullpo_retv(sd);
  16878. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16879. info = &packet_db[cmd];
  16880. if (!cmd || !info->len)
  16881. return;
  16882. WFIFOHEAD(sd->fd, info->len);
  16883. WFIFOW(sd->fd, 0) = cmd;
  16884. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16885. WFIFOSET(sd->fd, info->len);
  16886. }
  16887. /**
  16888. * [Ind/Hercules]
  16889. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16890. **/
  16891. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16892. char buf[256];
  16893. size_t len;
  16894. nullpo_retv(bl);
  16895. if(!message)
  16896. return;
  16897. len = strlen(message)+1;
  16898. if( len > sizeof(buf)-8 ) {
  16899. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16900. len = sizeof(buf)-8;
  16901. }
  16902. WBUFW(buf,0) = 0x8b3;
  16903. WBUFW(buf,2) = (uint16)(len+8);
  16904. WBUFL(buf,4) = bl->id;
  16905. safestrncpy(WBUFCP(buf,8), message, len);
  16906. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16907. }
  16908. /**
  16909. * [Ind/Hercules]
  16910. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16911. **/
  16912. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16913. unsigned char buf[10];
  16914. nullpo_retv(sd);
  16915. WBUFW(buf,0) = 0x7fc;
  16916. WBUFL(buf,2) = prev_leader_aid;
  16917. WBUFL(buf,6) = new_leader_aid;
  16918. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16919. }
  16920. /**
  16921. * Sends a clan message to a player
  16922. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16923. **/
  16924. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16925. #if PACKETVER >= 20131223
  16926. struct map_session_data *sd;
  16927. uint8 buf[256];
  16928. if( len == 0 ){
  16929. return;
  16930. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16931. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16932. len = sizeof(buf)-5-NAME_LENGTH;
  16933. }
  16934. WBUFW(buf, 0) = 0x98e;
  16935. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16936. // 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
  16937. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16938. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16939. if((sd = clan_getavailablesd(clan)) != NULL)
  16940. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16941. #endif
  16942. }
  16943. /**
  16944. * Parses a clan message from a player.
  16945. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16946. **/
  16947. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16948. #if PACKETVER >= 20131223
  16949. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16950. // validate packet and retrieve name and message
  16951. if( !clif_process_message(sd, false, name, message, output ) )
  16952. return;
  16953. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16954. #endif
  16955. }
  16956. /**
  16957. * Sends the basic clan informations to the client.
  16958. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16959. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16960. **/
  16961. void clif_clan_basicinfo( struct map_session_data *sd ){
  16962. #if PACKETVER >= 20131223
  16963. int fd, offset, length, i, flag;
  16964. struct clan* clan;
  16965. char mapname[MAP_NAME_LENGTH_EXT];
  16966. nullpo_retv( sd );
  16967. nullpo_retv( clan = sd->clan );
  16968. // Check if the player has a valid session and is not autotrading
  16969. if( !clif_session_isValid( sd ) ){
  16970. return;
  16971. }
  16972. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16973. fd = sd->fd;
  16974. WFIFOHEAD(fd,length);
  16975. memset( WFIFOP(fd, 0), 0, length );
  16976. WFIFOW( fd, 0 ) = 0x98a;
  16977. WFIFOL( fd, 4 ) = clan->id;
  16978. offset = 8;
  16979. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16980. offset += NAME_LENGTH;
  16981. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16982. offset += NAME_LENGTH;
  16983. mapindex_getmapname_ext( clan->map, mapname );
  16984. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16985. offset += MAP_NAME_LENGTH_EXT;
  16986. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16987. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16988. for( flag = 0; flag < 2; flag++ ){
  16989. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16990. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16991. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16992. offset += NAME_LENGTH;
  16993. }
  16994. }
  16995. }
  16996. WFIFOW( fd, 2 ) = offset;
  16997. WFIFOSET(fd,offset);
  16998. #endif
  16999. }
  17000. /**
  17001. * Updates the online and maximum player count of a clan.
  17002. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  17003. **/
  17004. void clif_clan_onlinecount( struct clan* clan ){
  17005. #if PACKETVER >= 20131223
  17006. uint8 buf[6];
  17007. struct map_session_data *sd;
  17008. WBUFW(buf,0) = 0x988;
  17009. WBUFW(buf,2) = clan->connect_member;
  17010. WBUFW(buf,4) = clan->max_member;
  17011. if((sd = clan_getavailablesd(clan)) != NULL)
  17012. clif_send(buf, 6, &sd->bl, CLAN);
  17013. #endif
  17014. }
  17015. /**
  17016. * Notifies the client that the player has left his clan.
  17017. * 0989 (ZC_ACK_CLAN_LEAVE)
  17018. **/
  17019. void clif_clan_leave( struct map_session_data* sd ){
  17020. #if PACKETVER >= 20131223
  17021. int fd;
  17022. nullpo_retv( sd );
  17023. if( !clif_session_isValid( sd ) ){
  17024. return;
  17025. }
  17026. fd = sd->fd;
  17027. WFIFOHEAD(fd,2);
  17028. WFIFOW(fd,0) = 0x989;
  17029. WFIFOSET(fd,2);
  17030. #endif
  17031. }
  17032. /**
  17033. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17034. * 0A2F <result>.B <title_id>.L
  17035. */
  17036. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  17037. {
  17038. #if PACKETVER >= 20150513
  17039. int fd;
  17040. nullpo_retv(sd);
  17041. if (!clif_session_isValid(sd))
  17042. return;
  17043. fd = sd->fd;
  17044. WFIFOHEAD(fd, packet_len(0xa2f));
  17045. WFIFOW(fd, 0) = 0xa2f;
  17046. WFIFOB(fd, 2) = result;
  17047. WFIFOL(fd, 3) = title_id;
  17048. WFIFOSET(fd, packet_len(0xa2f));
  17049. #endif
  17050. }
  17051. /**
  17052. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17053. * 0A2E <title_id>.L
  17054. */
  17055. void clif_parse_change_title(int fd, struct map_session_data *sd)
  17056. {
  17057. int title_id;
  17058. nullpo_retv(sd);
  17059. title_id = RFIFOL(fd, 2);
  17060. if( title_id == sd->status.title_id ){
  17061. // It is exactly the same as the old one
  17062. return;
  17063. }else if( title_id <= 0 ){
  17064. sd->status.title_id = 0;
  17065. }else{
  17066. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17067. clif_change_title_ack(sd, 1, title_id);
  17068. return;
  17069. }
  17070. sd->status.title_id = title_id;
  17071. }
  17072. clif_name_area(&sd->bl);
  17073. clif_change_title_ack(sd, 0, title_id);
  17074. }
  17075. #ifdef DUMP_UNKNOWN_PACKET
  17076. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17077. {
  17078. const char* packet_txt = "save/packet.txt";
  17079. FILE* fp;
  17080. time_t time_server;
  17081. struct tm *datetime;
  17082. char datestr[512];
  17083. time(&time_server); // get time in seconds since 1/1/1970
  17084. datetime = localtime(&time_server); // convert seconds in structure
  17085. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17086. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17087. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17088. if( sd ) {
  17089. 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);
  17090. } else {
  17091. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17092. }
  17093. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17094. fprintf(fp, "\n");
  17095. fclose(fp);
  17096. } else {
  17097. ShowError("Failed to write '%s'.\n", packet_txt);
  17098. // Dump on console instead
  17099. if( sd ) {
  17100. 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);
  17101. } else {
  17102. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17103. }
  17104. ShowDump(RFIFOP(fd,0), packet_len);
  17105. }
  17106. }
  17107. #endif
  17108. /// Roulette System
  17109. /// Author: Yommy
  17110. /// Opens the roulette window
  17111. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17112. void clif_roulette_open( struct map_session_data* sd ){
  17113. nullpo_retv( sd );
  17114. struct packet_roulette_open_ack p;
  17115. p.PacketType = 0xa1a;
  17116. p.Result = 0; // result
  17117. p.Serial = 0; // serial
  17118. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17119. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17120. p.AdditionItemID = -1; //! TODO: Display bonus item
  17121. p.GoldPoint = sd->roulette_point.gold;
  17122. p.SilverPoint = sd->roulette_point.silver;
  17123. p.BronzePoint = sd->roulette_point.bronze;
  17124. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17125. }
  17126. /// Request to open the roulette window
  17127. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17128. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  17129. nullpo_retv(sd);
  17130. if (!battle_config.feature_roulette) {
  17131. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17132. return;
  17133. }
  17134. clif_roulette_open(sd);
  17135. }
  17136. /// Sends the info about the available roulette rewards to the client
  17137. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17138. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17139. void clif_roulette_info( struct map_session_data* sd ){
  17140. nullpo_retv(sd);
  17141. struct packet_roulette_info_ack p;
  17142. p.PacketType = rouletteinfoackType;
  17143. p.PacketLength = sizeof(p);
  17144. p.RouletteSerial = 1;
  17145. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17146. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17147. p.ItemInfo[count].Row = i;
  17148. p.ItemInfo[count].Position = j;
  17149. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17150. p.ItemInfo[count].Count = rd.qty[i][j];
  17151. #if PACKETVER >= 20180511
  17152. p.ItemInfo[count].unused = 0;
  17153. #endif
  17154. count++;
  17155. }
  17156. }
  17157. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17158. }
  17159. /// Request the roulette reward data
  17160. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17161. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  17162. nullpo_retv(sd);
  17163. if (!battle_config.feature_roulette) {
  17164. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17165. return;
  17166. }
  17167. clif_roulette_info(sd);
  17168. }
  17169. /// Notification of the client that the roulette window was closed
  17170. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17171. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  17172. nullpo_retv(sd);
  17173. if (!battle_config.feature_roulette) {
  17174. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17175. return;
  17176. }
  17177. // What do we need this for? (other than state tracking), game client closes the window without our response.
  17178. }
  17179. /// Response to a item reward request
  17180. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17181. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17182. #if PACKETVER >= 20141016
  17183. nullpo_retv(sd);
  17184. struct packet_roulette_itemrecv_ack p;
  17185. p.PacketType = roulettercvitemackType;
  17186. p.Result = type;
  17187. p.AdditionItemID = 0; //! TODO: Additional item
  17188. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17189. #endif
  17190. }
  17191. /**
  17192. * Claim roulette reward
  17193. * @param sd Player
  17194. * @return 0:Success
  17195. **/
  17196. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17197. struct item it;
  17198. uint8 res = 1;
  17199. nullpo_retr(1, sd);
  17200. if (sd->roulette.prizeIdx < 0)
  17201. return RECV_ITEM_FAILED;
  17202. memset(&it, 0, sizeof(it));
  17203. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17204. it.identify = 1;
  17205. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17206. ; // onSuccess
  17207. }
  17208. sd->roulette.claimPrize = false;
  17209. sd->roulette.prizeStage = 0;
  17210. sd->roulette.prizeIdx = -1;
  17211. sd->roulette.stage = 0;
  17212. return res;
  17213. }
  17214. /// Update Roulette window with current stats
  17215. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17216. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17217. nullpo_retv( sd );
  17218. struct packet_roulette_generate_ack p;
  17219. p.PacketType = roulettgenerateackType;
  17220. p.Result = result;
  17221. p.Step = stage;
  17222. p.Idx = prizeIdx;
  17223. p.AdditionItemID = bonusItemID;
  17224. p.RemainGold = sd->roulette_point.gold;
  17225. p.RemainSilver = sd->roulette_point.silver;
  17226. p.RemainBronze = sd->roulette_point.bronze;
  17227. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17228. }
  17229. /// Request to start the roulette
  17230. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17231. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17232. enum GENERATE_ROULETTE_ACK result;
  17233. nullpo_retv(sd);
  17234. if (!battle_config.feature_roulette) {
  17235. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17236. return;
  17237. }
  17238. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17239. return;
  17240. }
  17241. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17242. sd->roulette.stage = 0;
  17243. sd->roulette.claimPrize = false;
  17244. sd->roulette.prizeStage = 0;
  17245. sd->roulette.prizeIdx = -1;
  17246. }
  17247. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17248. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17249. }else{
  17250. if (!sd->roulette.stage) {
  17251. if (sd->roulette_point.bronze > 0) {
  17252. sd->roulette_point.bronze -= 1;
  17253. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17254. } else if (sd->roulette_point.silver > 9) {
  17255. sd->roulette_point.silver -= 10;
  17256. sd->roulette.stage = 2;
  17257. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17258. } else if (sd->roulette_point.gold > 9) {
  17259. sd->roulette_point.gold -= 10;
  17260. sd->roulette.stage = 4;
  17261. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17262. }
  17263. }
  17264. sd->roulette.prizeStage = sd->roulette.stage;
  17265. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17266. sd->roulette.claimPrize = true;
  17267. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17268. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17269. result = GENERATE_ROULETTE_LOSING;
  17270. sd->roulette.stage = 0;
  17271. }else{
  17272. result = GENERATE_ROULETTE_SUCCESS;
  17273. sd->roulette.stage++;
  17274. }
  17275. }
  17276. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17277. }
  17278. /// Request to claim a prize
  17279. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17280. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17281. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17282. nullpo_retv(sd);
  17283. if (!battle_config.feature_roulette) {
  17284. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17285. return;
  17286. }
  17287. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17288. return;
  17289. }
  17290. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17291. switch (clif_roulette_getitem(sd)) {
  17292. case ADDITEM_SUCCESS:
  17293. type = RECV_ITEM_SUCCESS;
  17294. break;
  17295. case ADDITEM_INVALID:
  17296. case ADDITEM_OVERITEM:
  17297. case ADDITEM_OVERAMOUNT:
  17298. type = RECV_ITEM_OVERCOUNT;
  17299. break;
  17300. case ADDITEM_OVERWEIGHT:
  17301. type = RECV_ITEM_OVERWEIGHT;
  17302. break;
  17303. case ADDITEM_STACKLIMIT:
  17304. default:
  17305. type = RECV_ITEM_FAILED;
  17306. break;
  17307. }
  17308. }
  17309. clif_roulette_recvitem_ack(sd,type);
  17310. }
  17311. /// MERGE ITEM
  17312. /**
  17313. * Acknowledge the client about item merger result
  17314. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17315. * @param fd
  17316. * @param sd
  17317. **/
  17318. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  17319. unsigned char buf[9];
  17320. struct s_packet_db *info = NULL;
  17321. short cmd = 0;
  17322. nullpo_retv(sd);
  17323. if (!clif_session_isValid(sd))
  17324. return;
  17325. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  17326. return;
  17327. if (!(info = &packet_db[cmd]) || info->len == 0)
  17328. return;
  17329. WBUFW(buf, 0) = cmd;
  17330. WBUFW(buf, info->pos[0]) = index;
  17331. WBUFW(buf, info->pos[1]) = count;
  17332. WBUFB(buf, info->pos[2]) = type;
  17333. clif_send(buf, info->len, &sd->bl, SELF);
  17334. }
  17335. /**
  17336. * Check if item has the pair to be merged
  17337. * @param sd
  17338. * @param it Item
  17339. * @return True if has pair, False if not
  17340. **/
  17341. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17342. struct item *it_;
  17343. unsigned short i;
  17344. nullpo_retr(false, sd);
  17345. 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);
  17346. if (i < MAX_INVENTORY)
  17347. return true;
  17348. return false;
  17349. }
  17350. /**
  17351. * Check if item can be merged
  17352. * @param id Item Data
  17353. * @param it Item
  17354. * @return True if can be merged, False if not
  17355. **/
  17356. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17357. if (!id || !it)
  17358. return false;
  17359. if (id->type == IT_CASH)
  17360. return false;
  17361. if (!itemdb_isstackable2(id))
  17362. return false;
  17363. if (itemdb_isspecial(it->card[0]))
  17364. return false;
  17365. if (!it->unique_id)
  17366. return false;
  17367. return true;
  17368. }
  17369. /**
  17370. * Open available item to be merged.
  17371. * Only show 1 item in 1 process.
  17372. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17373. * @param sd
  17374. **/
  17375. void clif_merge_item_open(struct map_session_data *sd) {
  17376. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17377. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17378. int len = 0;
  17379. struct s_packet_db *info = NULL;
  17380. struct item *it;
  17381. nullpo_retv(sd);
  17382. if (!clif_session_isValid(sd))
  17383. return;
  17384. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17385. return;
  17386. if (!(info = &packet_db[cmd]) || info->len == 0)
  17387. return;
  17388. // Get entries
  17389. for (i = 0; i < MAX_INVENTORY; i++) {
  17390. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17391. continue;
  17392. if (clif_merge_item_has_pair(sd, it))
  17393. indexes[n++] = i;
  17394. }
  17395. if (n < 2) { // No item need to be merged
  17396. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17397. return;
  17398. }
  17399. WBUFW(buf, 0) = cmd;
  17400. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17401. for (i = 0; i < n; i++) {
  17402. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17403. }
  17404. clif_send(buf, len, &sd->bl, SELF);
  17405. }
  17406. /**
  17407. * Process item merger
  17408. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17409. * @param fd
  17410. * @param sd
  17411. **/
  17412. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17413. struct s_packet_db *info = NULL;
  17414. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17415. unsigned int count = 0;
  17416. struct item_data *id = NULL;
  17417. nullpo_retv(sd);
  17418. if (!clif_session_isValid(sd))
  17419. return;
  17420. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17421. return;
  17422. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17423. if (n < 2) { // No item need to be merged
  17424. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17425. return;
  17426. }
  17427. for (i = 0, j = 0; i < n; i++) {
  17428. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  17429. if( idx < 0 || idx >= MAX_INVENTORY ){
  17430. return;
  17431. }
  17432. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17433. continue;
  17434. indexes[j] = idx;
  17435. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17436. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17437. return;
  17438. }
  17439. count += sd->inventory.u.items_inventory[idx].amount;
  17440. j++;
  17441. }
  17442. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17443. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17444. return;
  17445. }
  17446. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17447. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17448. return;
  17449. }
  17450. // Merrrrge!!!!
  17451. for (i = 1; i < n; i++) {
  17452. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17453. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17454. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17455. sd->inventory_data[idx] = NULL;
  17456. clif_delitem(sd, idx, amt, 0);
  17457. }
  17458. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17459. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17460. }
  17461. /**
  17462. * Cancel item merge
  17463. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17464. * @param fd
  17465. * @param sd
  17466. **/
  17467. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17468. return; // Nothing todo yet
  17469. }
  17470. /**
  17471. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17472. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17473. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17474. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17475. **/
  17476. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17477. char name[NAME_LENGTH];
  17478. if( battle_config.broadcast_hide_name ){
  17479. std::string dispname = std::string( char_name );
  17480. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17481. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17482. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17483. }else{
  17484. safestrncpy( name, char_name, sizeof( name ) );
  17485. }
  17486. switch( type ){
  17487. case ITEMOBTAIN_TYPE_BOXITEM:
  17488. {
  17489. struct packet_package_item_announce p;
  17490. p.PacketType = package_item_announceType;
  17491. p.type = type;
  17492. p.ItemID = client_nameid( nameid );
  17493. p.len = NAME_LENGTH;
  17494. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17495. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17496. p.BoxItemID = client_nameid( container );
  17497. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17498. p.PacketLength = 15 + p.len;
  17499. #else
  17500. p.PacketLength = 11 + p.len;
  17501. #endif
  17502. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17503. }
  17504. break;
  17505. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17506. case ITEMOBTAIN_TYPE_NPC:
  17507. {
  17508. struct packet_item_drop_announce p;
  17509. p.PacketType = item_drop_announceType;
  17510. p.type = type;
  17511. p.ItemID = client_nameid( nameid );
  17512. p.len = NAME_LENGTH;
  17513. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17514. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17515. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17516. p.monsterNameLen = NAME_LENGTH;
  17517. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17518. }else{
  17519. p.monsterNameLen = 0;
  17520. p.monsterName[0] = '\0';
  17521. }
  17522. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17523. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17524. #else
  17525. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17526. #endif
  17527. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17528. }
  17529. break;
  17530. }
  17531. }
  17532. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17533. /// 0A02 <view>.W
  17534. /// Value <flag> has the following effects:
  17535. /// 1: Open a Dress Room window.
  17536. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17537. #if PACKETVER >= 20150513
  17538. int fd = sd->fd;
  17539. nullpo_retv(sd);
  17540. WFIFOHEAD(fd, packet_len(0xa02));
  17541. WFIFOW(fd,0) = 0xa02;
  17542. WFIFOW(fd,2) = flag;
  17543. WFIFOSET(fd, packet_len(0xa02));
  17544. #endif
  17545. }
  17546. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17547. /// 0A35 <result>.W
  17548. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17549. #if PACKETVER >= 20150513
  17550. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17551. // Ignore the request
  17552. // - Invalid item index
  17553. // - Invalid item ID or item doesn't exist
  17554. // - Item is already identified
  17555. if (idx < 0 || idx >= MAX_INVENTORY ||
  17556. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17557. sd->inventory.u.items_inventory[idx].identify)
  17558. return;
  17559. // Ignore the request - No magnifiers in inventory
  17560. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17561. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17562. return;
  17563. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17564. return;
  17565. skill_identify(sd, idx);
  17566. #endif
  17567. }
  17568. /// Starts navigation to the given target on client side
  17569. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17570. #if PACKETVER >= 20111010
  17571. int fd = sd->fd;
  17572. WFIFOHEAD(fd,27);
  17573. WFIFOW(fd,0) = 0x08e2;
  17574. // How detailed will our navigation be?
  17575. if( mob_id > 0 ){
  17576. x = 0;
  17577. y = 0;
  17578. WFIFOB(fd,2) = 3; // monster with destination field
  17579. }else if( x > 0 && y > 0 ){
  17580. WFIFOB(fd,2) = 0; // with coordinates
  17581. }else{
  17582. x = 0;
  17583. y = 0;
  17584. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17585. }
  17586. // Which services can be used for transportation?
  17587. WFIFOB(fd,3) = flag;
  17588. // If this flag is set, the navigation window will not be opened up
  17589. WFIFOB(fd,4) = hideWindow;
  17590. // Target map
  17591. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17592. // Target x
  17593. WFIFOW(fd,21) = x;
  17594. // Target y
  17595. WFIFOW(fd,23) = y;
  17596. // Target monster ID
  17597. WFIFOW(fd,25) = mob_id;
  17598. WFIFOSET(fd,27);
  17599. #endif
  17600. }
  17601. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17602. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17603. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17604. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17605. struct map_session_data *tsd;
  17606. struct block_list* tbl;
  17607. if( target == SELF ){
  17608. tsd = BL_CAST(BL_PC,bl);
  17609. tbl = &sd->bl;
  17610. }else{
  17611. tsd = sd;
  17612. tbl = bl;
  17613. }
  17614. nullpo_retv( tsd );
  17615. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17616. return;
  17617. }
  17618. struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
  17619. p->packetType = HEADER_ZC_HAT_EFFECT;
  17620. p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17621. p->aid = tsd->bl.id;
  17622. p->status = 1;
  17623. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17624. p->effects[i] = tsd->hatEffects[i];
  17625. }
  17626. clif_send( p, p->packetLength, tbl, target );
  17627. #endif
  17628. }
  17629. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17630. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17631. nullpo_retv( sd );
  17632. struct PACKET_ZC_HAT_EFFECT* p = (struct PACKET_ZC_HAT_EFFECT*)packet_buffer;
  17633. p->packetType = HEADER_ZC_HAT_EFFECT;
  17634. p->packetLength = (int16)( sizeof( struct PACKET_ZC_HAT_EFFECT ) + sizeof( int16 ) );
  17635. p->aid = sd->bl.id;
  17636. p->status = enable;
  17637. p->effects[0] = effectId;
  17638. clif_send( p, p->packetLength, &sd->bl, AREA );
  17639. #endif
  17640. }
  17641. /// Notify the client that a sale has started
  17642. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17643. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17644. #if PACKETVER_SUPPORTS_SALES
  17645. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17646. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17647. p.itemId = client_nameid( sale_item->nameid );
  17648. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17649. clif_send( &p, sizeof( p ), bl, target );
  17650. #endif
  17651. }
  17652. /// Notify the client that a sale has ended
  17653. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17654. void clif_sale_end( 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_CLOSE p;
  17657. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17658. p.itemId = client_nameid( sale_item->nameid );
  17659. clif_send( &p, sizeof( p ), bl, target );
  17660. #endif
  17661. }
  17662. /// Update the remaining amount of a sale item.
  17663. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17664. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17665. #if PACKETVER_SUPPORTS_SALES
  17666. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17667. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17668. p.itemId = client_nameid( sale_item->nameid );
  17669. p.amount = sale_item->amount;
  17670. clif_send( &p, sizeof( p ), bl, target );
  17671. #endif
  17672. }
  17673. /// The client requested a refresh of the current remaining count of a sale item
  17674. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17675. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17676. #if PACKETVER_SUPPORTS_SALES
  17677. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17678. struct sale_item_data* sale;
  17679. if( p->AID != sd->status.account_id ){
  17680. return;
  17681. }
  17682. sale = sale_find_item( p->itemId, true );
  17683. if( sale == NULL ){
  17684. return;
  17685. }
  17686. clif_sale_amount(sale, &sd->bl, SELF);
  17687. #endif
  17688. }
  17689. /// Opens the sale administration window on the client
  17690. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17691. void clif_sale_open( struct map_session_data* sd ){
  17692. #if PACKETVER_SUPPORTS_SALES
  17693. nullpo_retv(sd);
  17694. if( sd->state.sale_open ){
  17695. return;
  17696. }
  17697. sd->state.sale_open = true;
  17698. int fd = sd->fd;
  17699. WFIFOHEAD(fd, 2);
  17700. WFIFOW(fd, 0) = 0x9b5;
  17701. WFIFOSET(fd, 2);
  17702. #endif
  17703. }
  17704. /// Client request to open the sale administration window.
  17705. /// This is sent by /limitedsale
  17706. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17707. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17708. #if PACKETVER_SUPPORTS_SALES
  17709. nullpo_retv(sd);
  17710. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17711. return;
  17712. }
  17713. char command[CHAT_SIZE_MAX];
  17714. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17715. is_atcommand(fd, sd, command, 1);
  17716. #endif
  17717. }
  17718. /// Closes the sale administration window on the client.
  17719. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17720. void clif_sale_close(struct map_session_data* sd) {
  17721. #if PACKETVER_SUPPORTS_SALES
  17722. nullpo_retv(sd);
  17723. if( !sd->state.sale_open ){
  17724. return;
  17725. }
  17726. sd->state.sale_open = false;
  17727. int fd = sd->fd;
  17728. WFIFOHEAD(fd, 2);
  17729. WFIFOW(fd, 0) = 0x9bd;
  17730. WFIFOSET(fd, 2);
  17731. #endif
  17732. }
  17733. /// Client request to close the sale administration window.
  17734. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17735. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17736. #if PACKETVER_SUPPORTS_SALES
  17737. nullpo_retv(sd);
  17738. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17739. return;
  17740. }
  17741. clif_sale_close(sd);
  17742. #endif
  17743. }
  17744. /// Reply to a item search request for item sale administration.
  17745. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17746. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17747. #if PACKETVER_SUPPORTS_SALES
  17748. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17749. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17750. if( item != NULL ){
  17751. p.result = 0;
  17752. p.itemId = client_nameid( item->nameid );
  17753. p.price = item->price;
  17754. }else{
  17755. p.result = 1;
  17756. p.itemId = 0;
  17757. p.price = 0;
  17758. }
  17759. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17760. #endif
  17761. }
  17762. /// Search request for an item sale administration.
  17763. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17764. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17765. #if PACKETVER_SUPPORTS_SALES
  17766. char item_name[ITEM_NAME_LENGTH];
  17767. nullpo_retv(sd);
  17768. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17769. return;
  17770. }
  17771. if( !sd->state.sale_open ){
  17772. return;
  17773. }
  17774. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17775. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17776. if( id ){
  17777. int i;
  17778. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17779. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17780. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17781. return;
  17782. }
  17783. }
  17784. }
  17785. // not found
  17786. clif_sale_search_reply( sd, NULL );
  17787. #endif
  17788. }
  17789. /// Reply if an item was successfully put on sale or not.
  17790. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17791. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17792. #if PACKETVER_SUPPORTS_SALES
  17793. int fd = sd->fd;
  17794. WFIFOHEAD(fd, 4);
  17795. WFIFOW(fd, 0) = 0x9af;
  17796. WFIFOW(fd, 2) = (uint16)result;
  17797. WFIFOSET(fd, 4);
  17798. #endif
  17799. }
  17800. /// A client request to put an item on sale.
  17801. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17802. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17803. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17804. #if PACKETVER_SUPPORTS_SALES
  17805. nullpo_retv( sd );
  17806. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17807. if( p->AID != sd->status.account_id ){
  17808. return;
  17809. }
  17810. if( !sd->state.sale_open ){
  17811. return;
  17812. }
  17813. time_t endTime = p->startTime + p->hours * 60 * 60;
  17814. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17815. #endif
  17816. }
  17817. /// Reply to an item removal from sale.
  17818. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17819. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17820. #if PACKETVER_SUPPORTS_SALES
  17821. int fd = sd->fd;
  17822. WFIFOHEAD(fd, 4);
  17823. WFIFOW(fd, 0) = 0x9b1;
  17824. WFIFOW(fd, 2) = failed;
  17825. WFIFOSET(fd, 4);
  17826. #endif
  17827. }
  17828. /// Request to remove an item from sale.
  17829. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17830. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17831. #if PACKETVER_SUPPORTS_SALES
  17832. nullpo_retv( sd );
  17833. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17834. if( p->AID != sd->status.account_id ){
  17835. return;
  17836. }
  17837. if( !sd->state.sale_open ){
  17838. return;
  17839. }
  17840. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17841. #endif
  17842. }
  17843. /// Achievement System
  17844. /// Author: Luxuri, Aleos
  17845. /**
  17846. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17847. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17848. */
  17849. void clif_achievement_list_all(struct map_session_data *sd)
  17850. {
  17851. nullpo_retv(sd);
  17852. if (!battle_config.feature_achievement) {
  17853. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17854. return;
  17855. }
  17856. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17857. if (count == 0)
  17858. return;
  17859. int len = (50 * count) + 22;
  17860. int fd = sd->fd;
  17861. int *info = achievement_level(sd, true);
  17862. WFIFOHEAD(fd,len);
  17863. WFIFOW(fd, 0) = 0xa23;
  17864. WFIFOW(fd, 2) = len;
  17865. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17866. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17867. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17868. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17869. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17870. for (int i = 0; i < count; i++) {
  17871. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17872. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17873. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17874. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17875. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17876. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17877. }
  17878. WFIFOSET(fd, len);
  17879. }
  17880. /**
  17881. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17882. * 0a24 <ACHPoint>.L
  17883. */
  17884. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17885. {
  17886. nullpo_retv(sd);
  17887. if (!battle_config.feature_achievement) {
  17888. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17889. return;
  17890. }
  17891. int fd = sd->fd;
  17892. int *info = achievement_level(sd, true);
  17893. WFIFOHEAD(fd, packet_len(0xa24));
  17894. WFIFOW(fd, 0) = 0xa24;
  17895. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17896. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17897. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17898. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17899. if (ach) {
  17900. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17901. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17902. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17903. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17904. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17905. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17906. } else
  17907. memset(WFIFOP(fd, 16), 0, 40);
  17908. WFIFOSET(fd, packet_len(0xa24));
  17909. }
  17910. /**
  17911. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17912. * 0a25 <achievementID>.L
  17913. */
  17914. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17915. {
  17916. nullpo_retv(sd);
  17917. if( sd->achievement_data.save )
  17918. intif_achievement_save(sd);
  17919. achievement_check_reward(sd, RFIFOL(fd,2));
  17920. }
  17921. /**
  17922. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17923. * 0a26 <result>.W <achievementID>.L
  17924. */
  17925. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17926. {
  17927. WFIFOHEAD(fd, packet_len(0xa26));
  17928. WFIFOW(fd, 0) = 0xa26;
  17929. WFIFOB(fd, 2) = result;
  17930. WFIFOL(fd, 3) = achievement_id;
  17931. WFIFOSET(fd, packet_len(0xa26));
  17932. }
  17933. /// Process the pet evolution request
  17934. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17935. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17936. #if PACKETVER >= 20141008
  17937. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17938. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17939. if (!pet) {
  17940. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17941. return;
  17942. }
  17943. pet_evolution(sd, pet->class_);
  17944. #endif
  17945. }
  17946. /// Sends the result of the evolution to the client.
  17947. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17948. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17949. #if PACKETVER >= 20141008
  17950. int fd = sd->fd;
  17951. WFIFOHEAD(fd, packet_len(0x9fc));
  17952. WFIFOW(fd, 0) = 0x9fc;
  17953. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17954. WFIFOSET(fd, packet_len(0x9fc));
  17955. #endif
  17956. }
  17957. /*
  17958. * This packet is sent by /changedress or /nocosplay
  17959. *
  17960. * 0ae8
  17961. */
  17962. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17963. #if PACKETVER >= 20180103
  17964. char command[CHAT_SIZE_MAX];
  17965. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17966. is_atcommand( fd, sd, command, 1 );
  17967. #endif
  17968. }
  17969. /// Opens an UI window of the given type and initializes it with the given data
  17970. /// 0AE2 <type>.B <data>.L
  17971. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17972. nullpo_retv(sd);
  17973. // If the UI requires state tracking
  17974. switch( ui_type ){
  17975. case OUT_UI_STYLIST:
  17976. sd->state.stylist_open = true;
  17977. break;
  17978. }
  17979. int fd = sd->fd;
  17980. WFIFOHEAD(fd,packet_len(0xae2));
  17981. WFIFOW(fd,0) = 0xae2;
  17982. WFIFOB(fd,2) = ui_type;
  17983. WFIFOL(fd,3) = data;
  17984. WFIFOSET(fd,packet_len(0xae2));
  17985. }
  17986. /// Request to open an UI window of the given type
  17987. /// 0A68 <type>.B
  17988. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17989. switch( RFIFOB(fd,2) ){
  17990. case IN_UI_ATTENDANCE:
  17991. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17992. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17993. }else if( pc_attendance_enabled() ){
  17994. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17995. }else{
  17996. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17997. }
  17998. break;
  17999. }
  18000. }
  18001. /// Response for attedance request
  18002. /// 0AF0 <unknown>.L <data>.L
  18003. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  18004. nullpo_retv(sd);
  18005. int fd = sd->fd;
  18006. WFIFOHEAD(fd,packet_len(0xAF0));
  18007. WFIFOW(fd,0) = 0xAF0;
  18008. WFIFOL(fd,2) = 0;
  18009. WFIFOL(fd,6) = data;
  18010. WFIFOSET(fd,packet_len(0xAF0));
  18011. }
  18012. /// Request from the client to retrieve today's attendance reward
  18013. /// 0AEF
  18014. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  18015. pc_attendance_claim_reward(sd);
  18016. }
  18017. /// Send out the percentage of weight that causes it to be displayed in red.
  18018. /// 0ADE <percentage>.L
  18019. void clif_weight_limit( struct map_session_data* sd ){
  18020. #if PACKETVER >= 20171025
  18021. nullpo_retv(sd);
  18022. int fd = sd->fd;
  18023. WFIFOHEAD(fd, packet_len(0xADE));
  18024. WFIFOW(fd, 0) = 0xADE;
  18025. #ifdef RENEWAL
  18026. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18027. #else
  18028. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18029. #endif
  18030. WFIFOSET(fd, packet_len(0xADE));
  18031. #endif
  18032. }
  18033. enum e_private_airship_response : uint32{
  18034. PRIVATEAIRSHIP_OK,
  18035. PRIVATEAIRSHIP_RETRY,
  18036. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18037. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18038. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18039. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18040. };
  18041. /// Send out the response to a private airship request
  18042. /// 0A4A <response>.L
  18043. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  18044. #if PACKETVER >= 20180321
  18045. nullpo_retv( sd );
  18046. int fd = sd->fd;
  18047. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18048. WFIFOW( fd, 0 ) = 0xA4A;
  18049. WFIFOL( fd, 2 ) = response;
  18050. WFIFOSET( fd, packet_len( 0xA4A ) );
  18051. #endif
  18052. }
  18053. /// Parses a request for a private airship
  18054. /// 0A49 <mapname>.16B <itemid>.W
  18055. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  18056. #if PACKETVER >= 20180321
  18057. // Check if the feature is enabled
  18058. if( !battle_config.feature_privateairship ){
  18059. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18060. return;
  18061. }
  18062. // Check if the player is allowed to warp from the source map
  18063. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18064. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18065. return;
  18066. }
  18067. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18068. char mapname[MAP_NAME_LENGTH_EXT];
  18069. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18070. int16 mapindex = mapindex_name2id( mapname );
  18071. // Check if we know the mapname
  18072. if( mapindex < 0 ){
  18073. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18074. return;
  18075. }
  18076. int16 mapid = map_mapindex2mapid( mapindex );
  18077. // Check if the map is available on this server
  18078. if( mapid < 0 ){
  18079. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18080. return;
  18081. }
  18082. // Check if the player tried to warp to the map he is on
  18083. if( sd->bl.m == mapid ){
  18084. // This is blocked by the client, but just to be sure
  18085. return;
  18086. }
  18087. // This can only be a hack, so we prevent it
  18088. if( map_getmapdata( mapid )->instance_id ){
  18089. // Ignore requests to warp directly into a running instance
  18090. return;
  18091. }
  18092. // Check if the player is allowed to warp to the target map
  18093. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18094. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18095. return;
  18096. }
  18097. t_itemid item_id = p->ItemID;
  18098. // Check if the item sent by the client is known to us
  18099. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18100. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18101. return;
  18102. }
  18103. int idx = pc_search_inventory( sd, item_id );
  18104. // Check if the player has the item at all
  18105. if( idx < 0 ){
  18106. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18107. return;
  18108. }
  18109. // Delete the chosen item
  18110. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18111. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18112. return;
  18113. }
  18114. // Warp the player to a random spot on the destination map
  18115. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18116. #endif
  18117. }
  18118. /// Sends out the usage history of the guild storage
  18119. /// 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
  18120. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18121. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18122. #if PACKETVER >= 20140205
  18123. nullpo_retv( sd );
  18124. int fd = sd->fd;
  18125. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18126. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18127. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18128. }else{
  18129. log.clear();
  18130. }
  18131. WFIFOHEAD( fd, size );
  18132. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18133. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18134. p->PacketLength = size;
  18135. p->result = result;
  18136. p->amount = (uint16)log.size();
  18137. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18138. for( int i = 0; i < log.size(); i++ ){
  18139. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18140. struct guild_log_entry& entry = log[i];
  18141. item->id = entry.id;
  18142. item->itemId = client_nameid( entry.item.nameid );
  18143. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18144. item->action = entry.amount > 0; // action = true(put), false(get)
  18145. item->refine = entry.item.refine;
  18146. item->uniqueId = entry.item.unique_id;
  18147. item->IsIdentified = entry.item.identify;
  18148. item->itemType = itemtype( entry.item.nameid );
  18149. clif_addcards( &item->slot, &entry.item );
  18150. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18151. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18152. item->attribute = entry.item.attribute;
  18153. }
  18154. }
  18155. WFIFOSET( fd, p->PacketLength );
  18156. #endif
  18157. }
  18158. /// Activates the client camera info or updates the client camera with the given values.
  18159. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18160. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18161. #if PACKETVER >= 20160525
  18162. int fd = sd->fd;
  18163. WFIFOHEAD(fd, packet_len(0xa78));
  18164. WFIFOW(fd, 0) = 0xa78;
  18165. WFIFOB(fd, 2) = show;
  18166. WFIFOF(fd, 3) = range;
  18167. WFIFOF(fd, 7) = rotation;
  18168. WFIFOF(fd, 11) = latitude;
  18169. WFIFOSET(fd, packet_len(0xa78));
  18170. #endif
  18171. }
  18172. /// Activates or deactives the client camera info or updates the camera settings.
  18173. /// This packet is triggered by /viewpointvalue or /setcamera
  18174. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18175. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18176. char command[CHAT_SIZE_MAX];
  18177. // /viewpointvalue
  18178. if( RFIFOB( fd, 2 ) == 1 ){
  18179. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18180. // /setcamera
  18181. }else{
  18182. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18183. }
  18184. is_atcommand( fd, sd, command, 1 );
  18185. }
  18186. /// Send the full list of items in the equip switch window
  18187. /// 0a9b <length>.W { <index>.W <position>.L }*
  18188. void clif_equipswitch_list( struct map_session_data* sd ){
  18189. #if PACKETVER >= 20170208
  18190. int fd = sd->fd;
  18191. int offset, i, position;
  18192. WFIFOW(fd, 0) = 0xa9b;
  18193. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18194. short index = sd->equip_switch_index[i];
  18195. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18196. WFIFOW(fd, offset) = index + 2;
  18197. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18198. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18199. offset += 6;
  18200. }
  18201. }
  18202. WFIFOW(fd, 2) = offset;
  18203. WFIFOSET(fd, offset);
  18204. #endif
  18205. }
  18206. /// Acknowledgement for removing an equip to the equip switch window
  18207. /// 0a9a <index>.W <position.>.L <failure>.W
  18208. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18209. #if PACKETVER >= 20170208
  18210. int fd = sd->fd;
  18211. WFIFOHEAD(fd, packet_len(0xa9a));
  18212. WFIFOW(fd, 0) = 0xa9a;
  18213. WFIFOW(fd, 2) = index + 2;
  18214. WFIFOL(fd, 4) = pos;
  18215. WFIFOW(fd, 8) = failed;
  18216. WFIFOSET(fd, packet_len(0xa9a));
  18217. #endif
  18218. }
  18219. /// Request to remove an equip from the equip switch window
  18220. /// 0a99 <index>.W <position>.L <= 20170502
  18221. /// 0a99 <index>.W
  18222. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18223. #if PACKETVER >= 20170208
  18224. uint16 index = RFIFOW(fd, 2) - 2;
  18225. bool removed = false;
  18226. if( !battle_config.feature_equipswitch ){
  18227. return;
  18228. }
  18229. // Check if the index is valid
  18230. if( index >= MAX_INVENTORY ){
  18231. return;
  18232. }
  18233. pc_equipswitch_remove( sd, index );
  18234. #endif
  18235. }
  18236. /// Acknowledgement for adding an equip to the equip switch window
  18237. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18238. /// 0a98 <index>.W <position.>.L <flag>.W
  18239. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18240. #if PACKETVER >= 20170208
  18241. int fd = sd->fd;
  18242. WFIFOHEAD(fd, packet_len(0xa98));
  18243. WFIFOW(fd, 0) = 0xa98;
  18244. WFIFOW(fd, 2) = index + 2;
  18245. WFIFOL(fd, 4) = pos;
  18246. #if PACKETVER <= 20170502
  18247. WFIFOL(fd, 8) = flag;
  18248. #else
  18249. WFIFOW(fd, 8) = flag;
  18250. #endif
  18251. WFIFOSET(fd,packet_len(0xa98));
  18252. #endif
  18253. }
  18254. /// Request to add an equip to the equip switch window
  18255. /// 0a97 <index>.W <position>.L
  18256. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18257. #if PACKETVER >= 20170208
  18258. uint16 index = RFIFOW(fd, 2) - 2;
  18259. uint32 position = RFIFOL(fd, 4);
  18260. if( !battle_config.feature_equipswitch ){
  18261. return;
  18262. }
  18263. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18264. return;
  18265. }
  18266. if( sd->state.trading || sd->npc_shopid ){
  18267. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18268. return;
  18269. }
  18270. if( sd->inventory_data[index]->type == IT_AMMO ){
  18271. position = EQP_AMMO;
  18272. }
  18273. pc_equipitem( sd, index, position, true );
  18274. #endif
  18275. }
  18276. /// Acknowledgement packet for the full equip switch
  18277. /// 0a9d <failed>.W
  18278. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18279. #if PACKETVER >= 20170208
  18280. int fd = sd->fd;
  18281. WFIFOHEAD(fd, packet_len(0xa9d));
  18282. WFIFOW(fd, 0) = 0xa9d;
  18283. WFIFOW(fd, 2) = failed;
  18284. WFIFOSET(fd, packet_len(0xa9d));
  18285. #endif
  18286. }
  18287. /// Request to do a full equip switch
  18288. /// 0a9c
  18289. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18290. #if PACKETVER >= 20170208
  18291. int i;
  18292. t_tick tick = gettick();
  18293. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18294. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18295. // Client will not let you send a request
  18296. return;
  18297. }
  18298. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18299. if( !battle_config.feature_equipswitch ){
  18300. return;
  18301. }
  18302. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18303. if( i == EQI_MAX ){
  18304. // client will show: "There is no item to replace." and should not even come here
  18305. clif_equipswitch_reply( sd, false );
  18306. return;
  18307. }
  18308. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18309. return;
  18310. }
  18311. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18312. #endif
  18313. }
  18314. /// Request to do a single equip switch
  18315. /// 0ace <index>.W
  18316. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18317. #if PACKETVER >= 20170502
  18318. uint16 index = RFIFOW(fd, 2) - 2;
  18319. if( !battle_config.feature_equipswitch ){
  18320. return;
  18321. }
  18322. // Check if the index is valid
  18323. if( index >= MAX_INVENTORY ){
  18324. return;
  18325. }
  18326. // Check if the item exists
  18327. if (sd->inventory_data[index] == nullptr)
  18328. return;
  18329. // Check if the item was already added to equip switch
  18330. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18331. if( sd->npc_id ){
  18332. #ifdef RENEWAL
  18333. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18334. clif_msg( sd, WORK_IN_PROGRESS );
  18335. return;
  18336. }
  18337. #endif
  18338. if( !sd->npc_item_flag ){
  18339. return;
  18340. }
  18341. }
  18342. pc_equipswitch( sd, index );
  18343. return;
  18344. }
  18345. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18346. #endif
  18347. }
  18348. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18349. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18350. const struct PACKET_CZ_START_USE_SKILL *p = (struct PACKET_CZ_START_USE_SKILL *)RFIFOP( fd, 0 );
  18351. // Only rolling cutter is supported for now
  18352. if( p->skillId != GC_ROLLINGCUTTER ){
  18353. return;
  18354. }
  18355. // Already running - cant happen on officials, since only one skill is supported
  18356. if( sd->skill_keep_using.skill_id != 0 ){
  18357. return;
  18358. }
  18359. sd->skill_keep_using.tid = INVALID_TIMER;
  18360. sd->skill_keep_using.skill_id = p->skillId;
  18361. sd->skill_keep_using.level = p->skillLv;
  18362. sd->skill_keep_using.target = p->targetId;
  18363. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18364. #endif
  18365. }
  18366. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18367. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18368. const struct PACKET_CZ_STOP_USE_SKILL *p = (struct PACKET_CZ_STOP_USE_SKILL *)RFIFOP( fd, 0 );
  18369. // Not running
  18370. if( sd->skill_keep_using.skill_id == 0 ){
  18371. return;
  18372. }
  18373. #if 0
  18374. // Hack
  18375. if( p->skillId != sd->skill_keep_using.skill_id ){
  18376. return;
  18377. }
  18378. #endif
  18379. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18380. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18381. sd->skill_keep_using.tid = INVALID_TIMER;
  18382. }
  18383. sd->skill_keep_using.skill_id = 0;
  18384. sd->skill_keep_using.level = 0;
  18385. sd->skill_keep_using.target = 0;
  18386. #endif
  18387. }
  18388. void clif_ping( struct map_session_data* sd ){
  18389. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18390. nullpo_retv( sd );
  18391. int fd = sd->fd;
  18392. if( !session_isActive( fd ) ){
  18393. return;
  18394. }
  18395. struct PACKET_ZC_PING p;
  18396. p.packetType = HEADER_ZC_PING;
  18397. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18398. #endif
  18399. }
  18400. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18401. nullpo_ret( sd );
  18402. int fd = sd->fd;
  18403. if( !session_isActive( fd ) ){
  18404. return 0;
  18405. }
  18406. t_tick tick = va_arg( ap, t_tick );
  18407. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18408. clif_ping( sd );
  18409. }
  18410. return 0;
  18411. }
  18412. TIMER_FUNC( clif_ping_timer ){
  18413. map_foreachpc( clif_ping_timer_sub, gettick() );
  18414. return 0;
  18415. }
  18416. /**
  18417. * Opens the refine UI on the designated client.
  18418. * 0aa0
  18419. */
  18420. void clif_refineui_open( struct map_session_data* sd ){
  18421. #if PACKETVER >= 20161012
  18422. nullpo_retv( sd );
  18423. struct PACKET_ZC_REFINE_OPEN_WINDOW p;
  18424. p.packetType = HEADER_ZC_REFINE_OPEN_WINDOW;
  18425. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18426. sd->state.refineui_open = true;
  18427. #endif
  18428. }
  18429. /**
  18430. * Parses cancel/close of the refine UI on client side.
  18431. * 0aa4
  18432. */
  18433. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18434. #if PACKETVER >= 20161012
  18435. sd->state.refineui_open = false;
  18436. #endif
  18437. }
  18438. /**
  18439. * Adds the selected item into the refine UI and sends the possible materials
  18440. * to the client.
  18441. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18442. */
  18443. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18444. #if PACKETVER >= 20161012
  18445. int fd = sd->fd;
  18446. // Get the item db reference
  18447. struct item_data* id = sd->inventory_data[index];
  18448. // No item data was found
  18449. if( id == NULL ){
  18450. return;
  18451. }
  18452. // Check the inventory
  18453. struct item* item = &sd->inventory.u.items_inventory[index];
  18454. // No item was found at the given index
  18455. if( item == NULL ){
  18456. return;
  18457. }
  18458. // Check if the item is identified
  18459. if( !item->identify ){
  18460. return;
  18461. }
  18462. // Check if the item is broken
  18463. if( item->attribute ){
  18464. return;
  18465. }
  18466. struct PACKET_ZC_REFINE_ADD_ITEM* p = (struct PACKET_ZC_REFINE_ADD_ITEM*)packet_buffer;
  18467. p->packetType = HEADER_ZC_REFINE_ADD_ITEM;
  18468. p->packtLength = sizeof( struct PACKET_ZC_REFINE_ADD_ITEM );
  18469. p->itemIndex = client_index( index );
  18470. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18471. // No possibilities were found
  18472. if( info == nullptr ){
  18473. p->blacksmithBlessing = 0;
  18474. }else{
  18475. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18476. uint16 count = 0;
  18477. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18478. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18479. if( cost != nullptr ){
  18480. p->req[count].itemId = client_nameid( cost->nameid );
  18481. p->req[count].chance = (uint8)( cost->chance / 100 );
  18482. p->req[count].zeny = cost->zeny;
  18483. p->packtLength += sizeof( struct PACKET_ZC_REFINE_ADD_ITEM_SUB );
  18484. count++;
  18485. }
  18486. }
  18487. }
  18488. clif_send( p, p->packtLength, &sd->bl, SELF );
  18489. #endif
  18490. }
  18491. /**
  18492. * Client request to add an item to the refine UI.
  18493. * 0aa1 <index>.W
  18494. */
  18495. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18496. #if PACKETVER >= 20161012
  18497. struct PACKET_CZ_REFINE_ADD_ITEM* p = (struct PACKET_CZ_REFINE_ADD_ITEM*)RFIFOP( fd, 0 );
  18498. uint16 index = server_index( p->index );
  18499. // Check if the refine UI is open
  18500. if( !sd->state.refineui_open ){
  18501. return;
  18502. }
  18503. // Check if the index is valid
  18504. if( index >= MAX_INVENTORY ){
  18505. return;
  18506. }
  18507. // Send out the requirements for the refine process
  18508. clif_refineui_info( sd, index );
  18509. #endif
  18510. }
  18511. /**
  18512. * Client requests to try to refine an item.
  18513. * 0aa3 <index>.W <material>.W <catalyst>.B
  18514. */
  18515. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18516. #if PACKETVER >= 20161012
  18517. struct PACKET_CZ_REFINE_ITEM_REQUEST* p = (struct PACKET_CZ_REFINE_ITEM_REQUEST*)RFIFOP( fd, 0 );
  18518. uint16 index = server_index( p->index );
  18519. t_itemid material = p->itemId;
  18520. int16 j;
  18521. // Check if the refine UI is open
  18522. if( !sd->state.refineui_open ){
  18523. return;
  18524. }
  18525. // Check if the index is valid
  18526. if( index >= MAX_INVENTORY ){
  18527. return;
  18528. }
  18529. // Get the item db reference
  18530. struct item_data* id = sd->inventory_data[index];
  18531. // No item data was found
  18532. if( id == NULL ){
  18533. return;
  18534. }
  18535. // Check the inventory
  18536. struct item* item = &sd->inventory.u.items_inventory[index];
  18537. // No item was found at the given index
  18538. if( item == NULL ){
  18539. return;
  18540. }
  18541. // Check if the item is identified
  18542. if( !item->identify ){
  18543. return;
  18544. }
  18545. // Check if the item is broken
  18546. if( item->attribute ){
  18547. return;
  18548. }
  18549. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18550. // No refine possible
  18551. if( info == nullptr ){
  18552. return;
  18553. }
  18554. // No possibilities were found
  18555. if( info->costs.empty() ){
  18556. return;
  18557. }
  18558. // Check if the player has the selected material
  18559. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18560. return;
  18561. }
  18562. int16 blacksmith_index = -1;
  18563. uint16 blacksmith_amount = 0;
  18564. // Check if the player has enough blacksmith blessings
  18565. if( p->blacksmithBlessing != 0 ){
  18566. blacksmith_amount = info->blessing_amount;
  18567. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18568. if( blacksmith_amount == 0 ){
  18569. return;
  18570. }
  18571. // Check if the player has blacksmith blessings
  18572. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18573. return;
  18574. }
  18575. // Check if the player has enough blacksmith blessings
  18576. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18577. return;
  18578. }
  18579. }
  18580. std::shared_ptr<s_refine_cost> cost = nullptr;
  18581. for( const auto& pair : info->costs ){
  18582. if( pair.second->nameid == material ){
  18583. cost = pair.second;
  18584. break;
  18585. }
  18586. }
  18587. // The material was not in the list of possible materials
  18588. if( cost == nullptr ){
  18589. return;
  18590. }
  18591. // Try to pay for the refine
  18592. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18593. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18594. return;
  18595. }
  18596. // Delete the required material
  18597. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18598. return;
  18599. }
  18600. // Delete the required blacksmith blessings
  18601. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18602. return;
  18603. }
  18604. // Try to refine the item
  18605. if( cost->chance >= ( rnd() % 10000 ) ){
  18606. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18607. // Success
  18608. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18609. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18610. clif_misceffect( &sd->bl, 3 );
  18611. clif_refine( fd, 0, index, item->refine );
  18612. if( id->type == IT_WEAPON ){
  18613. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18614. }
  18615. clif_refineui_info( sd, index );
  18616. }else{
  18617. // Failure
  18618. // Blacksmith blessings were used to prevent breaking and downgrading
  18619. if( blacksmith_amount > 0 ){
  18620. clif_refine( fd, 3, index, item->refine );
  18621. clif_refineui_info( sd, index );
  18622. // Delete the item if it is breakable
  18623. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18624. clif_refine( fd, 1, index, item->refine );
  18625. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18626. // Downgrade the item if necessary
  18627. }else if( cost->downgrade_amount > 0 ){
  18628. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18629. clif_refine( fd, 2, index, item->refine );
  18630. clif_refineui_info(sd, index);
  18631. // Only show failure, but dont do anything
  18632. }else{
  18633. clif_refine( fd, 3, index, item->refine );
  18634. clif_refineui_info( sd, index );
  18635. }
  18636. clif_misceffect( &sd->bl, 2 );
  18637. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18638. }
  18639. #endif
  18640. }
  18641. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18642. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18643. struct PACKET_ZC_TAKEOFF_EQUIP_ALL_ACK p = {};
  18644. p.PacketType = HEADER_ZC_TAKEOFF_EQUIP_ALL_ACK;
  18645. p.result = failed;
  18646. clif_send( &p, sizeof( struct PACKET_ZC_TAKEOFF_EQUIP_ALL_ACK ), &sd->bl, SELF );
  18647. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18648. }
  18649. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18650. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18651. if( pc_cant_act( sd ) ){
  18652. clif_unequipall_reply( sd, true );
  18653. return;
  18654. }
  18655. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18656. if( sd->equip_index[i] >= 0 ){
  18657. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18658. }
  18659. }
  18660. clif_unequipall_reply( sd, false );
  18661. #endif
  18662. }
  18663. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18664. #if PACKETVER >= 20151104
  18665. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18666. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18667. p.flag = failed;
  18668. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18669. if( !failed ){
  18670. sd->state.stylist_open = false;
  18671. }
  18672. #endif
  18673. }
  18674. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18675. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18676. if( list == nullptr ){
  18677. return false;
  18678. }
  18679. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18680. if( entry == nullptr ){
  18681. return false;
  18682. }
  18683. std::shared_ptr<s_stylist_costs> costs;
  18684. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18685. costs = entry->doram;
  18686. }else{
  18687. costs = entry->human;
  18688. }
  18689. if( costs == nullptr ){
  18690. return false;
  18691. }
  18692. if( sd->status.zeny < costs->price ){
  18693. return false;
  18694. }
  18695. int16 inventoryIndex = -1;
  18696. if( costs->requiredItem != 0 ){
  18697. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18698. if( inventoryIndex < 0 ){
  18699. // No other option
  18700. if( costs->requiredItemBox == 0 ){
  18701. return false;
  18702. }
  18703. // Check if the box that contains the item is in the inventory
  18704. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18705. // The box containing the item also does not exist
  18706. if( inventoryIndex < 0 ){
  18707. return false;
  18708. }
  18709. }
  18710. }else if( costs->requiredItemBox != 0 ){
  18711. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18712. if( inventoryIndex < 0 ){
  18713. return false;
  18714. }
  18715. }
  18716. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18717. return false;
  18718. }
  18719. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18720. return false;
  18721. }
  18722. switch( look ){
  18723. case LOOK_HAIR:
  18724. case LOOK_HAIR_COLOR:
  18725. case LOOK_CLOTHES_COLOR:
  18726. case LOOK_BODY2:
  18727. pc_changelook( sd, look, entry->value );
  18728. break;
  18729. case LOOK_HEAD_BOTTOM:
  18730. case LOOK_HEAD_MID:
  18731. case LOOK_HEAD_TOP: {
  18732. struct mail_message msg = {};
  18733. msg.dest_id = sd->status.char_id;
  18734. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18735. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18736. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18737. msg.item[0].nameid = entry->value;
  18738. msg.item[0].identify = 1;
  18739. msg.item[0].amount = 1;
  18740. msg.status = MAIL_NEW;
  18741. msg.type = MAIL_INBOX_NORMAL;
  18742. msg.timestamp = time( nullptr );
  18743. intif_Mail_send( 0, &msg );
  18744. } break;
  18745. }
  18746. return true;
  18747. }
  18748. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18749. #if PACKETVER >= 20151104
  18750. #if PACKETVER >= 20180516
  18751. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18752. #else
  18753. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18754. #endif
  18755. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18756. clif_stylist_response( sd, true );
  18757. return;
  18758. }
  18759. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18760. clif_stylist_response( sd, true );
  18761. return;
  18762. }
  18763. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18764. clif_stylist_response( sd, true );
  18765. return;
  18766. }
  18767. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18768. clif_stylist_response( sd, true );
  18769. return;
  18770. }
  18771. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18772. clif_stylist_response( sd, true );
  18773. return;
  18774. }
  18775. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18776. clif_stylist_response( sd, true );
  18777. return;
  18778. }
  18779. #if PACKETVER >= 20180516
  18780. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18781. clif_stylist_response( sd, true );
  18782. return;
  18783. }
  18784. #endif
  18785. clif_stylist_response( sd, false );
  18786. #endif
  18787. }
  18788. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18789. #if PACKETVER >= 20151104
  18790. sd->state.stylist_open = false;
  18791. #endif
  18792. }
  18793. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18794. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18795. nullpo_retv( sd );
  18796. struct PACKET_ZC_INVENTORY_EXPANSION_INFO p = {};
  18797. p.packetType = HEADER_ZC_INVENTORY_EXPANSION_INFO;
  18798. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18799. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18800. #endif
  18801. }
  18802. enum class e_inventory_expansion_response : uint8{
  18803. ASK_CONFIRMATION = 0,
  18804. FAILED,
  18805. BUSY,
  18806. MISSING_ITEM,
  18807. MAXIMUM_REACHED
  18808. };
  18809. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18810. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18811. nullpo_retv( sd );
  18812. struct PACKET_ZC_ACK_INVENTORY_EXPAND p = {};
  18813. p.packetType = HEADER_ZC_ACK_INVENTORY_EXPAND;
  18814. p.result = (uint8)response;
  18815. p.itemId = sd->state.inventory_expansion_confirmation;
  18816. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18817. #endif
  18818. }
  18819. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18820. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18821. // Check if player is dead or busy with other stuff
  18822. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18823. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18824. return;
  18825. }
  18826. // Check if the player already reached the maximum
  18827. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18828. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18829. return;
  18830. }
  18831. static std::map<t_itemid, uint16> items = {
  18832. // The order of entries in this list defines which will be used first
  18833. // This order and the usable items are hardcoded into the client
  18834. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18835. { ITEMID_INVENTORY_EX_EVT, 10 },
  18836. { ITEMID_INVENTORY_EX_DIS, 10 },
  18837. { ITEMID_INVENTORY_EX, 10 },
  18838. };
  18839. int16 index = -1;
  18840. bool found_over_limit = false;
  18841. for( const auto& entry : items ){
  18842. // Check if the player has the required item
  18843. index = pc_search_inventory( sd, entry.first );
  18844. // Found an item
  18845. if( index >= 0 ){
  18846. // Check if the player would exceed the maximum
  18847. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18848. found_over_limit = true;
  18849. }else{
  18850. found_over_limit = false;
  18851. sd->state.inventory_expansion_confirmation = entry.first;
  18852. sd->state.inventory_expansion_amount = entry.second;
  18853. break;
  18854. }
  18855. }
  18856. }
  18857. // Check if an item was found
  18858. if( sd->state.inventory_expansion_confirmation == 0 ){
  18859. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18860. return;
  18861. }
  18862. // Check if an item would have been found, but the player would exceed the maximum
  18863. if( found_over_limit ){
  18864. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18865. return;
  18866. }
  18867. // The player met all requirements => ask him for confirmation
  18868. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18869. #endif
  18870. }
  18871. enum class e_inventory_expansion_result : uint8{
  18872. SUCCESS = 0,
  18873. FAILED,
  18874. BUSY,
  18875. MISSING_ITEM,
  18876. MAXIMUM_REACHED
  18877. };
  18878. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18879. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18880. nullpo_retv( sd );
  18881. struct PACKET_ZC_ACK_INVENTORY_EXPAND_RESULT p = {};
  18882. p.packetType = HEADER_ZC_ACK_INVENTORY_EXPAND_RESULT;
  18883. p.result = (uint8)result;
  18884. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18885. // Reset the state tracking
  18886. sd->state.inventory_expansion_confirmation = 0;
  18887. sd->state.inventory_expansion_amount = 0;
  18888. #endif
  18889. }
  18890. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18891. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18892. if( sd->state.inventory_expansion_confirmation == 0 ){
  18893. return;
  18894. }
  18895. // Check if player is dead
  18896. if( pc_isdead( sd ) ){
  18897. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18898. return;
  18899. }
  18900. // Check if the player already reached the maximum
  18901. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18902. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18903. return;
  18904. }
  18905. // Check if the player has the required item
  18906. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18907. // The player did not have the item anymore
  18908. if( index < 0 ){
  18909. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18910. return;
  18911. }
  18912. // Check if the player would exceed the maximum
  18913. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18914. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18915. return;
  18916. }
  18917. // Delete the required item
  18918. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18919. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18920. return;
  18921. }
  18922. // Increase the slots
  18923. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18924. // Save player data (slots) and inventory data (removed item)
  18925. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18926. // Inform the player of success
  18927. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18928. clif_inventory_expansion_info( sd );
  18929. #endif
  18930. }
  18931. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18932. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18933. sd->state.inventory_expansion_confirmation = 0;
  18934. sd->state.inventory_expansion_amount = 0;
  18935. #endif
  18936. }
  18937. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  18938. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  18939. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18940. return;
  18941. }
  18942. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18943. if( barter == nullptr ){
  18944. return;
  18945. }
  18946. sd.state.barter_open = true;
  18947. struct PACKET_ZC_NPC_BARTER_OPEN* p = (struct PACKET_ZC_NPC_BARTER_OPEN*)packet_buffer;
  18948. p->packetType = HEADER_ZC_NPC_BARTER_OPEN;
  18949. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_OPEN );
  18950. int16 count = 0;
  18951. for( const auto& itemPair : barter->items ){
  18952. struct PACKET_ZC_NPC_BARTER_OPEN_sub* item = &p->list[count];
  18953. struct item_data* id = itemdb_exists( itemPair.second->nameid );
  18954. item->nameid = client_nameid( id->nameid );
  18955. item->type = itemtype( id->nameid );
  18956. if( itemPair.second->stockLimited ){
  18957. item->amount = itemPair.second->stock;
  18958. }else{
  18959. item->amount = -1;
  18960. }
  18961. item->weight = id->weight;
  18962. item->index = itemPair.second->index;
  18963. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18964. item->viewSprite = id->look;
  18965. item->location = pc_equippoint_sub( &sd, id );
  18966. #endif
  18967. // Use a loop if someone did not start with index 0
  18968. for( const auto& requirementPair : itemPair.second->requirements ){
  18969. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18970. item->currencyNameid = client_nameid( requirement->nameid );
  18971. item->currencyAmount = requirement->amount;
  18972. // It is a normal barter, cancel after first entry
  18973. break;
  18974. }
  18975. p->packetLength += (int16)( sizeof( *item ) );
  18976. count++;
  18977. }
  18978. clif_send( p, p->packetLength, &sd.bl, SELF );
  18979. #endif
  18980. }
  18981. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  18982. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  18983. if( sd->state.barter_open ){
  18984. sd->npc_shopid = 0;
  18985. sd->state.barter_open = false;
  18986. }
  18987. #endif
  18988. }
  18989. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  18990. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  18991. // No shop open
  18992. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18993. return;
  18994. }
  18995. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18996. // Unknown shop
  18997. if( nd == nullptr ){
  18998. return;
  18999. }
  19000. // Not a barter
  19001. if( nd->subtype != NPCTYPE_BARTER ){
  19002. return;
  19003. }
  19004. // It is an extended barter
  19005. if( nd->u.barter.extended ){
  19006. return;
  19007. }
  19008. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19009. if( barter == nullptr ){
  19010. return;
  19011. }
  19012. struct PACKET_CZ_NPC_BARTER_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_PURCHASE*)RFIFOP( fd, 0 );
  19013. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_PURCHASE_sub );
  19014. // Empty purchase list
  19015. if( entries == 0 ){
  19016. return;
  19017. }
  19018. std::vector<s_barter_purchase> purchases;
  19019. purchases.reserve( entries );
  19020. // Make sure each shop index and target item id is only used once
  19021. for( int i = 0; i < entries; i++ ){
  19022. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19023. // Invalid shop index
  19024. if( item == nullptr ){
  19025. return;
  19026. }
  19027. for( int j = i + 1; j < entries; j++ ){
  19028. // Same shop index
  19029. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19030. return;
  19031. }
  19032. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19033. // Invalid shop index
  19034. if( item2 == nullptr ){
  19035. return;
  19036. }
  19037. // Same target item id
  19038. if( item->nameid == item2->nameid ){
  19039. return;
  19040. }
  19041. }
  19042. s_barter_purchase purchase = {};
  19043. purchase.item = item;
  19044. purchase.amount = p->list[i].amount;
  19045. purchases.push_back( purchase );
  19046. }
  19047. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19048. #endif
  19049. }
  19050. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  19051. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19052. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19053. return;
  19054. }
  19055. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19056. if( barter == nullptr ){
  19057. return;
  19058. }
  19059. sd.state.barter_extended_open = true;
  19060. struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN*)packet_buffer;
  19061. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_OPEN;
  19062. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN );
  19063. p->items_count = 0;
  19064. for( const auto& itemPair : barter->items ){
  19065. // Needs dynamic calculation, because of variable currencies
  19066. struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub*)( ( (uint8*)p ) + p->packetLength );
  19067. struct item_data* id = itemdb_exists( itemPair.second->nameid );
  19068. item->nameid = client_nameid( id->nameid );
  19069. item->type = itemtype( id->nameid );
  19070. if( itemPair.second->stockLimited ){
  19071. item->amount = itemPair.second->stock;
  19072. }else{
  19073. item->amount = -1;
  19074. }
  19075. item->weight = id->weight;
  19076. item->index = itemPair.second->index;
  19077. item->zeny = itemPair.second->price;
  19078. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19079. item->viewSprite = id->look;
  19080. item->location = pc_equippoint_sub( &sd, id );
  19081. #endif
  19082. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19083. p->items_count++;
  19084. item->currency_count = 0;
  19085. for( const auto& requirementPair : itemPair.second->requirements ){
  19086. // Needs dynamic calculation, because of variable currencies
  19087. struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_OPEN_sub2*)( ( (uint8*)p ) + p->packetLength );
  19088. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19089. req->nameid = requirement->nameid;
  19090. if( requirement->refine >= 0 ){
  19091. req->refine_level = requirement->refine;
  19092. }else{
  19093. req->refine_level = 0;
  19094. }
  19095. req->amount = requirement->amount;
  19096. req->type = itemtype( requirement->nameid );
  19097. p->packetLength += (int16)( sizeof( *req ) );
  19098. item->currency_count++;
  19099. }
  19100. }
  19101. clif_send( p, p->packetLength, &sd.bl, SELF );
  19102. #endif
  19103. }
  19104. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  19105. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19106. if( sd->state.barter_extended_open ){
  19107. sd->npc_shopid = 0;
  19108. sd->state.barter_extended_open = false;
  19109. }
  19110. #endif
  19111. }
  19112. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  19113. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19114. // No shop open
  19115. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19116. return;
  19117. }
  19118. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19119. // Unknown shop
  19120. if( nd == nullptr ){
  19121. return;
  19122. }
  19123. // Not a barter
  19124. if( nd->subtype != NPCTYPE_BARTER ){
  19125. return;
  19126. }
  19127. // Not an extended barter
  19128. if( !nd->u.barter.extended ){
  19129. return;
  19130. }
  19131. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19132. if( barter == nullptr ){
  19133. return;
  19134. }
  19135. struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE*)RFIFOP( fd, 0 );
  19136. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_PURCHASE_sub );
  19137. // Empty purchase list
  19138. if( entries == 0 ){
  19139. return;
  19140. }
  19141. std::vector<s_barter_purchase> purchases;
  19142. purchases.reserve( entries );
  19143. // Make sure each shop index and target item id is only used once
  19144. for( int i = 0; i < entries; i++ ){
  19145. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19146. // Invalid shop index
  19147. if( item == nullptr ){
  19148. return;
  19149. }
  19150. for( int j = i + 1; j < entries; j++ ){
  19151. // Same shop index
  19152. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19153. return;
  19154. }
  19155. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19156. // Invalid shop index
  19157. if( item2 == nullptr ){
  19158. return;
  19159. }
  19160. // Same target item id
  19161. if( item->nameid == item2->nameid ){
  19162. return;
  19163. }
  19164. }
  19165. s_barter_purchase purchase = {};
  19166. purchase.item = item;
  19167. purchase.amount = p->list[i].amount;
  19168. purchases.push_back( purchase );
  19169. }
  19170. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19171. #endif
  19172. }
  19173. /*==========================================
  19174. * Main client packet processing function
  19175. *------------------------------------------*/
  19176. static int clif_parse(int fd)
  19177. {
  19178. int cmd, packet_len;
  19179. TBL_PC* sd;
  19180. int pnum;
  19181. #ifdef PACKET_OBFUSCATION
  19182. int cmd2;
  19183. #endif
  19184. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  19185. // Note: "click masters" can do 80+ clicks in 10 seconds
  19186. 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]
  19187. { // begin main client packet processing loop
  19188. sd = (TBL_PC *)session[fd]->session_data;
  19189. if (session[fd]->flag.eof) {
  19190. if (sd) {
  19191. if (sd->state.autotrade) {
  19192. //Disassociate character from the socket connection.
  19193. session[fd]->session_data = NULL;
  19194. sd->fd = 0;
  19195. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  19196. } else
  19197. if (sd->state.active) {
  19198. // Player logout display [Valaris]
  19199. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  19200. clif_quitsave(fd, sd);
  19201. } else {
  19202. //Unusual logout (during log on/off/map-changer procedure)
  19203. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  19204. map_quit(sd);
  19205. }
  19206. } else {
  19207. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  19208. }
  19209. do_close(fd);
  19210. return 0;
  19211. }
  19212. if (RFIFOREST(fd) < 2)
  19213. return 0;
  19214. cmd = RFIFOW(fd, 0);
  19215. #ifdef PACKET_OBFUSCATION
  19216. // Check if it is a player that tries to connect to the map server.
  19217. if( sd ){
  19218. // Decrypt the current packet ID with the last key stored in the session.
  19219. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  19220. }else{
  19221. // Store the original value for checking
  19222. cmd2 = cmd;
  19223. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  19224. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  19225. }
  19226. #endif
  19227. // filter out invalid / unsupported packets
  19228. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  19229. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  19230. #ifdef DUMP_INVALID_PACKET
  19231. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  19232. #endif
  19233. #ifdef PACKET_OBFUSCATION_WARN
  19234. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  19235. if( !sd ){
  19236. #ifdef PACKET_OBFUSCATION
  19237. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  19238. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  19239. }
  19240. #else
  19241. // Try to use the initial keys for the decryption of the packet ID.
  19242. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  19243. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  19244. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  19245. }
  19246. #endif
  19247. }
  19248. #endif
  19249. set_eof(fd);
  19250. return 0;
  19251. }
  19252. // determine real packet length
  19253. packet_len = packet_db[cmd].len;
  19254. if (packet_len == -1) { // variable-length packet
  19255. if (RFIFOREST(fd) < 4)
  19256. return 0;
  19257. packet_len = RFIFOW(fd,2);
  19258. if (packet_len < 4 || packet_len > 32768) {
  19259. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  19260. #ifdef DUMP_INVALID_PACKET
  19261. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  19262. #endif
  19263. set_eof(fd);
  19264. return 0;
  19265. }
  19266. }
  19267. if ((int)RFIFOREST(fd) < packet_len){
  19268. 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 );
  19269. #ifdef DUMP_INVALID_PACKET
  19270. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  19271. #endif
  19272. set_eof( fd );
  19273. return 0; // not enough data received to form the packet
  19274. }
  19275. #ifdef PACKET_OBFUSCATION
  19276. RFIFOW(fd, 0) = cmd;
  19277. if (sd)
  19278. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  19279. #endif
  19280. if( packet_db[cmd].func == clif_parse_debug )
  19281. packet_db[cmd].func(fd, sd);
  19282. else if( packet_db[cmd].func != NULL ) {
  19283. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  19284. ; //Only valid packet when there is no session
  19285. else
  19286. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  19287. ; //Only valid packet when player is not on a map
  19288. else
  19289. packet_db[cmd].func(fd, sd);
  19290. }
  19291. #ifdef DUMP_UNKNOWN_PACKET
  19292. else DumpUnknown(fd,sd,cmd,packet_len);
  19293. #endif
  19294. RFIFOSKIP(fd, packet_len);
  19295. }; // main loop end
  19296. return 0;
  19297. }
  19298. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  19299. va_list argp;
  19300. int i;
  19301. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  19302. return;
  19303. packet_db[cmd].len = length;
  19304. packet_db[cmd].func = func;
  19305. va_start(argp, func);
  19306. for( i = 0; i < MAX_PACKET_POS; i++ ){
  19307. int offset = va_arg(argp, int);
  19308. if( offset == 0 ){
  19309. break;
  19310. }
  19311. packet_db[cmd].pos[i] = offset;
  19312. }
  19313. if( i == MAX_PACKET_POS ){
  19314. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  19315. }
  19316. va_end(argp);
  19317. }
  19318. /*==========================================
  19319. * Reads packets and setups its array reference
  19320. *------------------------------------------*/
  19321. void packetdb_readdb(){
  19322. memset(packet_db,0,sizeof(packet_db));
  19323. memset(packet_db_ack,0,sizeof(packet_db_ack));
  19324. #include "clif_packetdb.hpp"
  19325. #include "clif_shuffle.hpp"
  19326. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  19327. #ifdef PACKET_OBFUSCATION
  19328. 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]);
  19329. #else
  19330. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  19331. #endif
  19332. }
  19333. /*==========================================
  19334. *
  19335. *------------------------------------------*/
  19336. void do_init_clif(void) {
  19337. const char* colors[COLOR_MAX] = {
  19338. "0x00FF00",
  19339. "0xFF0000",
  19340. "0xFFFFFF",
  19341. "0xFFFF00",
  19342. "0x00FFFF",
  19343. "0xB5FFB5",
  19344. };
  19345. int i;
  19346. /**
  19347. * Setup Color Table (saves unnecessary load of strtoul on every call)
  19348. **/
  19349. for(i = 0; i < COLOR_MAX; i++) {
  19350. color_table[i] = strtoul(colors[i],NULL,0);
  19351. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  19352. }
  19353. packetdb_readdb();
  19354. set_defaultparse(clif_parse);
  19355. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  19356. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  19357. exit(EXIT_FAILURE);
  19358. }
  19359. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  19360. add_timer_func_list(clif_delayquit, "clif_delayquit");
  19361. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  19362. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  19363. if( battle_config.ping_timer_interval > 0 ){
  19364. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  19365. }
  19366. #endif
  19367. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  19368. }
  19369. void do_final_clif(void) {
  19370. ers_destroy(delay_clearunit_ers);
  19371. }