clif.cpp 698 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // Copyright (c) Hercules Dev Team - Licensed under GNU GPL
  3. // For more information, see LICENCE in the main folder
  4. #include "clif.hpp"
  5. #include <cstdarg>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include "../common/cbasetypes.hpp"
  11. #include "../common/conf.hpp"
  12. #include "../common/ers.hpp"
  13. #include "../common/grfio.hpp"
  14. #include "../common/malloc.hpp"
  15. #include "../common/nullpo.hpp"
  16. #include "../common/random.hpp"
  17. #include "../common/showmsg.hpp"
  18. #include "../common/socket.hpp"
  19. #include "../common/strlib.hpp"
  20. #include "../common/timer.hpp"
  21. #include "../common/utilities.hpp"
  22. #include "../common/utils.hpp"
  23. #include "achievement.hpp"
  24. #include "atcommand.hpp"
  25. #include "battle.hpp"
  26. #include "battleground.hpp"
  27. #include "cashshop.hpp"
  28. #include "channel.hpp"
  29. #include "chat.hpp"
  30. #include "chrif.hpp"
  31. #include "clan.hpp"
  32. #include "clif.hpp"
  33. #include "elemental.hpp"
  34. #include "guild.hpp"
  35. #include "homunculus.hpp"
  36. #include "instance.hpp"
  37. #include "intif.hpp"
  38. #include "itemdb.hpp"
  39. #include "log.hpp"
  40. #include "mail.hpp"
  41. #include "map.hpp"
  42. #include "mercenary.hpp"
  43. #include "mob.hpp"
  44. #include "npc.hpp"
  45. #include "party.hpp"
  46. #include "pc.hpp"
  47. #include "pc_groups.hpp"
  48. #include "pet.hpp"
  49. #include "quest.hpp"
  50. #include "script.hpp"
  51. #include "skill.hpp"
  52. #include "status.hpp"
  53. #include "storage.hpp"
  54. #include "trade.hpp"
  55. #include "unit.hpp"
  56. #include "vending.hpp"
  57. using namespace rathena;
  58. static inline uint32 client_tick( t_tick tick ){
  59. return (uint32)tick;
  60. }
  61. #if PACKETVER >= 20170830
  62. static inline int64 client_exp(t_exp exp) {
  63. return (int64)u64min(exp, MAX_EXP);
  64. }
  65. #else
  66. static inline int32 client_exp(t_exp exp) {
  67. return (int32)u64min(exp, MAX_EXP);
  68. }
  69. #endif
  70. /* for clif_clearunit_delayed */
  71. static struct eri *delay_clearunit_ers;
  72. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  73. int packet_db_ack[MAX_ACK_FUNC + 1];
  74. // Reuseable global packet buffer to prevent too many allocations
  75. // Take socket.cpp::socket_max_client_packet into consideration
  76. static int8 packet_buffer[UINT16_MAX];
  77. unsigned long color_table[COLOR_MAX];
  78. #include "clif_obfuscation.hpp"
  79. static bool clif_session_isValid(struct map_session_data *sd);
  80. static void clif_loadConfirm( struct map_session_data *sd );
  81. #if PACKETVER >= 20150513
  82. enum mail_type {
  83. MAIL_TYPE_TEXT = 0x0,
  84. MAIL_TYPE_ZENY = 0x2,
  85. MAIL_TYPE_ITEM = 0x4,
  86. MAIL_TYPE_NPC = 0x8
  87. };
  88. #endif
  89. enum e_inventory_type{
  90. INVTYPE_INVENTORY = 0,
  91. INVTYPE_CART = 1,
  92. INVTYPE_STORAGE = 2,
  93. INVTYPE_GUILD_STORAGE = 3,
  94. };
  95. /** Converts item type to display it on client if necessary.
  96. * @param nameid: Item ID
  97. * @return item type. For IT_PETEGG will be displayed as IT_ARMOR. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  98. */
  99. static inline int itemtype(t_itemid nameid) {
  100. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  101. int type = id->type;
  102. if( type == IT_SHADOWGEAR ) {
  103. if( id->equip&EQP_SHADOW_WEAPON )
  104. return IT_WEAPON;
  105. else
  106. return IT_ARMOR;
  107. }
  108. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  109. }
  110. // TODO: doc
  111. static inline uint16 client_index( uint16 server_index ){
  112. return server_index + 2;
  113. }
  114. static inline uint16 server_index( uint16 client_index ){
  115. return client_index - 2;
  116. }
  117. static inline uint16 client_storage_index( uint16 server_index ){
  118. return server_index + 1;
  119. }
  120. static inline uint16 server_storage_index( uint16 client_index ){
  121. return client_index - 1;
  122. }
  123. static inline uint32 disguised_bl_id( uint32 bl_id ){
  124. // Casting to prevent a compiler warning
  125. return -((int32)bl_id);
  126. }
  127. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  128. static inline uint32 client_nameid( t_itemid server_nameid ){
  129. t_itemid view = itemdb_viewid( server_nameid );
  130. if( view > 0 ){
  131. return view;
  132. }else{
  133. return server_nameid;
  134. }
  135. }
  136. #else
  137. static inline uint16 client_nameid( t_itemid server_nameid ){
  138. t_itemid view = itemdb_viewid( server_nameid );
  139. if( view > 0 ){
  140. if( view > UINT16_MAX ){
  141. return (uint16)UNKNOWN_ITEM_ID;
  142. }
  143. return (uint16)view;
  144. }else{
  145. if( server_nameid > UINT16_MAX ){
  146. return (uint16)UNKNOWN_ITEM_ID;
  147. }
  148. return (uint16)server_nameid;
  149. }
  150. }
  151. #endif
  152. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  153. p += pos;
  154. p[0] = (uint8)(x>>2);
  155. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  156. p[2] = (uint8)((y<<4) | (dir&0xf));
  157. }
  158. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  159. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  160. p += pos;
  161. p[0] = (uint8)(x0>>2);
  162. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  163. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  164. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  165. p[4] = (uint8)y1;
  166. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  167. }
  168. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  169. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  170. }
  171. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  172. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  173. }
  174. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  175. p += pos;
  176. if( x ) {
  177. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  178. }
  179. if( y ) {
  180. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  181. }
  182. if( dir ) {
  183. dir[0] = ( p[2] & 0x0f );
  184. }
  185. }
  186. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  187. p += pos;
  188. if( x0 ) {
  189. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  190. }
  191. if( y0 ) {
  192. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  193. }
  194. if( x1 ) {
  195. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  196. }
  197. if( y1 ) {
  198. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  199. }
  200. if( sx0 ) {
  201. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  202. }
  203. if( sy0 ) {
  204. sy0[0] = ( p[5] & 0x0f ) >> 0;
  205. }
  206. }
  207. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  208. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  209. }
  210. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  211. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  212. }
  213. //To idenfity disguised characters.
  214. static inline bool disguised(struct block_list* bl) {
  215. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  216. }
  217. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  218. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  219. if( len > max )
  220. len = max;
  221. mes[len-1] = '\0';
  222. return len;
  223. }
  224. static char map_ip_str[128];
  225. static uint32 map_ip;
  226. static uint32 bind_ip = INADDR_ANY;
  227. static uint16 map_port = 5121;
  228. static bool clif_ally_only = false;
  229. int map_fd;
  230. static int clif_parse (int fd);
  231. /*==========================================
  232. * Ip setting of map-server
  233. *------------------------------------------*/
  234. int clif_setip(const char* ip) {
  235. char ip_str[16];
  236. map_ip = host2ip(ip);
  237. if (!map_ip) {
  238. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  239. return 0;
  240. }
  241. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  242. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  243. return 1;
  244. }
  245. void clif_setbindip(const char* ip)
  246. {
  247. bind_ip = host2ip(ip);
  248. if (bind_ip) {
  249. char ip_str[16];
  250. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  251. } else {
  252. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  253. }
  254. }
  255. /*==========================================
  256. * Sets map port to 'port'
  257. * is run from map.cpp upon loading map server configuration
  258. *------------------------------------------*/
  259. void clif_setport(uint16 port)
  260. {
  261. map_port = port;
  262. }
  263. /*==========================================
  264. * Returns map server IP
  265. *------------------------------------------*/
  266. uint32 clif_getip(void)
  267. {
  268. return map_ip;
  269. }
  270. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  271. uint32 clif_refresh_ip(void)
  272. {
  273. uint32 new_ip;
  274. new_ip = host2ip(map_ip_str);
  275. if (new_ip && new_ip != map_ip) {
  276. map_ip = new_ip;
  277. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  278. return map_ip;
  279. }
  280. return 0;
  281. }
  282. /*==========================================
  283. * Returns map port which is set by clif_setport()
  284. *------------------------------------------*/
  285. uint16 clif_getport(void)
  286. {
  287. return map_port;
  288. }
  289. #if PACKETVER >= 20071106
  290. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  291. switch (bl->type) {
  292. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  293. case BL_ITEM: return 0x2; //ITEM_TYPE
  294. case BL_SKILL: return 0x3; //SKILL_TYPE
  295. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  296. case BL_MOB:
  297. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  298. return 0x0; //PC_TYPE
  299. }else{
  300. switch( ( (mob_data*)bl )->special_state.ai ){
  301. case AI_ABR:
  302. return 0xd; //NPC_ABR_TYPE
  303. case AI_BIONIC:
  304. return 0xe; //NPC_BIONIC_TYPE
  305. default:
  306. return 0x5; //NPC_MOB_TYPE
  307. }
  308. }
  309. case BL_NPC:
  310. // From 2017-07-26 on NPC type units can also use player sprites.
  311. // There is one exception and this is if they are walking.
  312. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  313. #if PACKETVER >= 20170726
  314. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0xC; // New walking NPC type
  315. #else
  316. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  317. #endif
  318. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  319. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  320. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  321. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  322. default: return 0x1; //NPC_TYPE
  323. }
  324. }
  325. #endif
  326. static bool clif_session_isValid(struct map_session_data *sd) {
  327. return ( sd != nullptr && session_isActive(sd->fd) );
  328. }
  329. /*==========================================
  330. * sub process of clif_send
  331. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  332. * In order to send area-wise packets, such as:
  333. * - AREA : everyone nearby your area
  334. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  335. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  336. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  337. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  338. *------------------------------------------*/
  339. static int clif_send_sub(struct block_list *bl, va_list ap)
  340. {
  341. struct block_list *src_bl;
  342. struct map_session_data *sd;
  343. unsigned char *buf;
  344. int len, type, fd;
  345. nullpo_ret(bl);
  346. nullpo_ret(sd = (struct map_session_data *)bl);
  347. // Don't send to disconnected clients.
  348. if( !session_isActive( fd = sd->fd ) ){
  349. return 0;
  350. }
  351. buf = va_arg(ap,unsigned char*);
  352. len = va_arg(ap,int);
  353. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  354. type = va_arg(ap,int);
  355. switch(type) {
  356. case AREA_WOS:
  357. if (bl == src_bl)
  358. return 0;
  359. break;
  360. case AREA_WOC:
  361. if (sd->chatID || bl == src_bl)
  362. return 0;
  363. break;
  364. case AREA_WOSC:
  365. {
  366. if(src_bl->type == BL_PC) {
  367. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  368. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  369. return 0;
  370. }
  371. else if(src_bl->type == BL_NPC) {
  372. struct npc_data *nd = (struct npc_data *)src_bl;
  373. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  374. return 0;
  375. }
  376. }
  377. break;
  378. }
  379. /* unless visible, hold it here */
  380. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  381. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  382. return 0;
  383. WFIFOHEAD(fd, len);
  384. if (WFIFOP(fd,0) == buf) {
  385. ShowError("WARNING: Invalid use of clif_send function\n");
  386. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  387. ShowError(" Please correct your code.\n");
  388. // don't send to not move the pointer of the packet for next sessions in the loop
  389. //WFIFOSET(fd,0);//## TODO is this ok?
  390. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  391. return 0;
  392. }
  393. memcpy(WFIFOP(fd,0), buf, len);
  394. WFIFOSET(fd,len);
  395. return 0;
  396. }
  397. /*==========================================
  398. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  399. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  400. *------------------------------------------*/
  401. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  402. {
  403. int i;
  404. struct map_session_data *sd, *tsd;
  405. struct party_data *p = NULL;
  406. struct guild *g = NULL;
  407. std::shared_ptr<s_battleground_data> bg;
  408. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  409. struct s_mapiterator* iter;
  410. if( type != ALL_CLIENT )
  411. nullpo_ret(bl);
  412. sd = BL_CAST(BL_PC, bl);
  413. switch(type) {
  414. case ALL_CLIENT: //All player clients.
  415. iter = mapit_getallusers();
  416. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  417. if( session_isActive( fd = tsd->fd ) ){
  418. WFIFOHEAD( fd, len );
  419. memcpy( WFIFOP( fd, 0 ), buf, len );
  420. WFIFOSET( fd, len );
  421. }
  422. }
  423. mapit_free(iter);
  424. break;
  425. case ALL_SAMEMAP: //All players on the same map
  426. iter = mapit_getallusers();
  427. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  428. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  429. WFIFOHEAD( fd, len );
  430. memcpy( WFIFOP( fd, 0 ), buf, len );
  431. WFIFOSET( fd, len );
  432. }
  433. }
  434. mapit_free(iter);
  435. break;
  436. case AREA:
  437. case AREA_WOSC:
  438. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  439. clif_send (buf, len, bl, SELF);
  440. case AREA_WOC:
  441. case AREA_WOS:
  442. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  443. BL_PC, buf, len, bl, type);
  444. break;
  445. case AREA_CHAT_WOC:
  446. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  447. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  448. break;
  449. case CHAT:
  450. case CHAT_WOS:
  451. {
  452. struct chat_data *cd;
  453. if (sd) {
  454. cd = (struct chat_data*)map_id2bl(sd->chatID);
  455. } else if (bl->type == BL_CHAT) {
  456. cd = (struct chat_data*)bl;
  457. } else break;
  458. if (cd == NULL)
  459. break;
  460. for(i = 0; i < cd->users; i++) {
  461. if (type == CHAT_WOS && cd->usersd[i] == sd)
  462. continue;
  463. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  464. WFIFOHEAD(fd,len);
  465. memcpy(WFIFOP(fd,0), buf, len);
  466. WFIFOSET(fd,len);
  467. }
  468. }
  469. }
  470. break;
  471. case PARTY_AREA:
  472. case PARTY_AREA_WOS:
  473. x0 = bl->x - AREA_SIZE;
  474. y0 = bl->y - AREA_SIZE;
  475. x1 = bl->x + AREA_SIZE;
  476. y1 = bl->y + AREA_SIZE;
  477. case PARTY:
  478. case PARTY_WOS:
  479. case PARTY_SAMEMAP:
  480. case PARTY_SAMEMAP_WOS:
  481. if (sd && sd->status.party_id)
  482. p = party_search(sd->status.party_id);
  483. if (p) {
  484. for(i=0;i<MAX_PARTY;i++){
  485. if( (sd = p->data[i].sd) == NULL )
  486. continue;
  487. if( !session_isActive( fd = sd->fd ) )
  488. continue;
  489. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  490. continue;
  491. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  492. continue;
  493. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  494. continue;
  495. WFIFOHEAD(fd, len);
  496. memcpy(WFIFOP(fd, 0), buf, len);
  497. WFIFOSET(fd, len);
  498. }
  499. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  500. break;
  501. iter = mapit_getallusers();
  502. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  503. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  504. WFIFOHEAD( fd, len );
  505. memcpy( WFIFOP( fd, 0 ), buf, len );
  506. WFIFOSET( tsd->fd, len );
  507. }
  508. }
  509. mapit_free(iter);
  510. }
  511. break;
  512. case DUEL:
  513. case DUEL_WOS:
  514. if (!sd || !sd->duel_group) break; //Invalid usage.
  515. iter = mapit_getallusers();
  516. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  517. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  518. continue;
  519. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  520. WFIFOHEAD( fd, len );
  521. memcpy( WFIFOP( fd, 0 ), buf, len );
  522. WFIFOSET( fd, len );
  523. }
  524. }
  525. mapit_free(iter);
  526. break;
  527. case SELF:
  528. if( clif_session_isValid(sd) ){
  529. fd = sd->fd;
  530. WFIFOHEAD(fd,len);
  531. memcpy(WFIFOP(fd,0), buf, len);
  532. WFIFOSET(fd,len);
  533. }
  534. break;
  535. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  536. case GUILD_AREA:
  537. case GUILD_AREA_WOS:
  538. x0 = bl->x - AREA_SIZE;
  539. y0 = bl->y - AREA_SIZE;
  540. x1 = bl->x + AREA_SIZE;
  541. y1 = bl->y + AREA_SIZE;
  542. case GUILD_SAMEMAP:
  543. case GUILD_SAMEMAP_WOS:
  544. case GUILD:
  545. case GUILD_WOS:
  546. case GUILD_NOBG:
  547. if (sd && sd->status.guild_id)
  548. g = sd->guild;
  549. if (g) {
  550. for(i = 0; i < g->max_member; i++) {
  551. if( (sd = g->member[i].sd) != nullptr ){
  552. if( !session_isActive( fd = sd->fd ) )
  553. continue;
  554. if( type == GUILD_NOBG && sd->bg_id )
  555. continue;
  556. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  557. continue;
  558. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  559. continue;
  560. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  561. continue;
  562. WFIFOHEAD(fd,len);
  563. memcpy(WFIFOP(fd,0), buf, len);
  564. WFIFOSET(fd,len);
  565. }
  566. }
  567. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  568. break;
  569. iter = mapit_getallusers();
  570. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  571. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  572. WFIFOHEAD( fd, len );
  573. memcpy( WFIFOP( fd, 0 ), buf, len );
  574. WFIFOSET( fd, len );
  575. }
  576. }
  577. mapit_free(iter);
  578. }
  579. break;
  580. case BG_AREA:
  581. case BG_AREA_WOS:
  582. x0 = bl->x - AREA_SIZE;
  583. y0 = bl->y - AREA_SIZE;
  584. x1 = bl->x + AREA_SIZE;
  585. y1 = bl->y + AREA_SIZE;
  586. case BG_SAMEMAP:
  587. case BG_SAMEMAP_WOS:
  588. case BG:
  589. case BG_WOS:
  590. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  591. {
  592. for (const auto &member : bg->members) {
  593. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  594. continue;
  595. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  596. continue;
  597. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  598. continue;
  599. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  600. continue;
  601. WFIFOHEAD(fd,len);
  602. memcpy(WFIFOP(fd,0), buf, len);
  603. WFIFOSET(fd,len);
  604. }
  605. }
  606. break;
  607. case CLAN:
  608. if( sd && sd->clan ){
  609. struct clan* clan = sd->clan;
  610. for( i = 0; i < clan->max_member; i++ ){
  611. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  612. continue;
  613. }
  614. WFIFOHEAD(fd,len);
  615. memcpy(WFIFOP(fd,0), buf, len);
  616. WFIFOSET(fd,len);
  617. }
  618. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  619. break;
  620. iter = mapit_getallusers();
  621. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  622. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  623. WFIFOHEAD(fd, len);
  624. memcpy(WFIFOP(fd, 0), buf, len);
  625. WFIFOSET(fd, len);
  626. }
  627. }
  628. mapit_free(iter);
  629. }
  630. break;
  631. default:
  632. ShowError("clif_send: Unrecognized type %d\n",type);
  633. return -1;
  634. }
  635. return 0;
  636. }
  637. /// Notifies the client, that it's connection attempt was accepted.
  638. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  639. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  640. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  641. void clif_authok(struct map_session_data *sd)
  642. {
  643. #if PACKETVER < 20080102
  644. const int cmd = 0x73;
  645. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  646. const int cmd = 0x2eb;
  647. #else
  648. const int cmd = 0xa18;
  649. #endif
  650. int fd = sd->fd;
  651. WFIFOHEAD(fd,packet_len(cmd));
  652. WFIFOW(fd, 0) = cmd;
  653. WFIFOL(fd, 2) = client_tick(gettick());
  654. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  655. WFIFOB(fd, 9) = 5; // ignored
  656. WFIFOB(fd,10) = 5; // ignored
  657. #if PACKETVER >= 20080102
  658. WFIFOW(fd,11) = sd->status.font;
  659. #endif
  660. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  661. WFIFOB(fd,13) = sd->status.sex;
  662. #endif
  663. WFIFOSET(fd,packet_len(cmd));
  664. }
  665. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  666. /// 0074 <error code>.B
  667. /// error code:
  668. /// 0 = client type mismatch
  669. /// 1 = ID mismatch
  670. /// 2 = mobile - out of available time
  671. /// 3 = mobile - already logged in
  672. /// 4 = mobile - waiting state
  673. void clif_authrefuse(int fd, uint8 error_code)
  674. {
  675. WFIFOHEAD(fd,packet_len(0x74));
  676. WFIFOW(fd,0) = 0x74;
  677. WFIFOB(fd,2) = error_code;
  678. WFIFOSET(fd,packet_len(0x74));
  679. }
  680. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  681. /// 0081 <error code>.B
  682. /// error code:
  683. /// 0 = BAN_UNFAIR
  684. /// 1 = server closed -> MsgStringTable[4]
  685. /// 2 = ID already logged in -> MsgStringTable[5]
  686. /// 3 = timeout/too much lag -> MsgStringTable[241]
  687. /// 4 = server full -> MsgStringTable[264]
  688. /// 5 = underaged -> MsgStringTable[305]
  689. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  690. /// 9 = too many connections from this ip -> MsgStringTable[529]
  691. /// 10 = out of available time paid for -> MsgStringTable[530]
  692. /// 11 = BAN_PAY_SUSPEND
  693. /// 12 = BAN_PAY_CHANGE
  694. /// 13 = BAN_PAY_WRONGIP
  695. /// 14 = BAN_PAY_PNGAMEROOM
  696. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  697. /// 16 = BAN_JAPAN_REFUSE1
  698. /// 17 = BAN_JAPAN_REFUSE2
  699. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  700. /// 100 = BAN_PC_IP_UNFAIR
  701. /// 101 = BAN_PC_IP_COUNT_ALL
  702. /// 102 = BAN_PC_IP_COUNT
  703. /// 103 = BAN_GRAVITY_MEM_AGREE
  704. /// 104 = BAN_GAME_MEM_AGREE
  705. /// 105 = BAN_HAN_VALID
  706. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  707. /// 107 = BAN_OVER_CHARACTER_LIST
  708. /// 108 = BAN_IP_BLOCK
  709. /// 109 = BAN_INVALID_PWD_CNT
  710. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  711. /// ? = disconnected -> MsgStringTable[3]
  712. void clif_authfail_fd(int fd, int type)
  713. {
  714. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  715. return;
  716. WFIFOHEAD(fd, packet_len(0x81));
  717. WFIFOW(fd,0) = 0x81;
  718. WFIFOB(fd,2) = type;
  719. WFIFOSET(fd,packet_len(0x81));
  720. set_eof(fd);
  721. }
  722. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  723. /// 00b3 <type>.B
  724. /// type:
  725. /// 1 = disconnect, char-select
  726. /// ? = nothing
  727. void clif_charselectok(int id, uint8 ok)
  728. {
  729. struct map_session_data* sd;
  730. int fd;
  731. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  732. return;
  733. fd = sd->fd;
  734. WFIFOHEAD(fd,packet_len(0xb3));
  735. WFIFOW(fd,0) = 0xb3;
  736. WFIFOB(fd,2) = ok;
  737. WFIFOSET(fd,packet_len(0xb3));
  738. }
  739. /// Makes an item appear on the ground.
  740. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  741. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  742. /// 0ADD <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W <show drop effect>.B <drop effect mode>.W (ZC_ITEM_FALL_ENTRY5)
  743. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  744. nullpo_retv(fitem);
  745. if( fitem->item.nameid == 0 ){
  746. return;
  747. }
  748. struct packet_dropflooritem p;
  749. p.PacketType = dropflooritemType;
  750. p.ITAID = fitem->bl.id;
  751. p.ITID = client_nameid( fitem->item.nameid );
  752. #if PACKETVER >= 20130000 /* not sure date */
  753. p.type = itemtype( fitem->item.nameid );
  754. #endif
  755. p.IsIdentified = fitem->item.identify ? 1 : 0;
  756. p.xPos = fitem->bl.x;
  757. p.yPos = fitem->bl.y;
  758. p.subX = fitem->subx;
  759. p.subY = fitem->suby;
  760. p.count = fitem->item.amount;
  761. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  762. if( canShowEffect ){
  763. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  764. if( dropEffect > 0 ){
  765. p.showdropeffect = 1;
  766. p.dropeffectmode = dropEffect - 1;
  767. }else if (battle_config.rndopt_drop_pillar != 0){
  768. uint8 optionCount = 0;
  769. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  770. if (fitem->item.option[i].id != 0) {
  771. optionCount++;
  772. }
  773. }
  774. if (optionCount > 0) {
  775. p.showdropeffect = 1;
  776. if (optionCount == 1)
  777. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  778. else if (optionCount == 2)
  779. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  780. else
  781. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  782. } else {
  783. p.showdropeffect = 0;
  784. p.dropeffectmode = DROPEFFECT_NONE;
  785. }
  786. } else {
  787. p.showdropeffect = 0;
  788. p.dropeffectmode = DROPEFFECT_NONE;
  789. }
  790. }else{
  791. p.showdropeffect = 0;
  792. p.dropeffectmode = DROPEFFECT_NONE;
  793. }
  794. #endif
  795. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  796. }
  797. /// Makes an item disappear from the ground.
  798. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  799. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  800. {
  801. unsigned char buf[16];
  802. nullpo_retv(fitem);
  803. WBUFW(buf,0) = 0xa1;
  804. WBUFL(buf,2) = fitem->bl.id;
  805. if ( !session_isActive( fd ) ){
  806. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  807. } else {
  808. WFIFOHEAD(fd,packet_len(0xa1));
  809. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  810. WFIFOSET(fd,packet_len(0xa1));
  811. }
  812. }
  813. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  814. /// 0080 <id>.L <type>.B
  815. /// type:
  816. /// 0 = out of sight
  817. /// 1 = died
  818. /// 2 = logged out
  819. /// 3 = teleport
  820. /// 4 = trickdead
  821. void clif_clearunit_single(int id, clr_type type, int fd)
  822. {
  823. WFIFOHEAD(fd, packet_len(0x80));
  824. WFIFOW(fd,0) = 0x80;
  825. WFIFOL(fd,2) = id;
  826. WFIFOB(fd,6) = type;
  827. WFIFOSET(fd, packet_len(0x80));
  828. }
  829. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  830. /// 0080 <id>.L <type>.B
  831. /// type:
  832. /// 0 = out of sight
  833. /// 1 = died
  834. /// 2 = logged out
  835. /// 3 = teleport
  836. /// 4 = trickdead
  837. void clif_clearunit_area(struct block_list* bl, clr_type type)
  838. {
  839. unsigned char buf[8];
  840. nullpo_retv(bl);
  841. WBUFW(buf,0) = 0x80;
  842. WBUFL(buf,2) = bl->id;
  843. WBUFB(buf,6) = type;
  844. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  845. if(disguised(bl)) {
  846. WBUFL(buf,2) = disguised_bl_id( bl->id );
  847. clif_send(buf, packet_len(0x80), bl, SELF);
  848. }
  849. }
  850. /// Used to make monsters with player-sprites disappear after dying
  851. /// like normal monsters, because the client does not remove those
  852. /// automatically.
  853. static TIMER_FUNC(clif_clearunit_delayed_sub){
  854. struct block_list *bl = (struct block_list *)data;
  855. clif_clearunit_area(bl, (clr_type) id);
  856. ers_free(delay_clearunit_ers,bl);
  857. return 0;
  858. }
  859. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  860. {
  861. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  862. memcpy (tbl, bl, sizeof (struct block_list));
  863. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  864. }
  865. void clif_get_weapon_view(struct map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  866. {
  867. if(sd->sc.option&OPTION_COSTUME)
  868. {
  869. *rhand = *lhand = 0;
  870. return;
  871. }
  872. #if PACKETVER < 4
  873. *rhand = sd->status.weapon;
  874. *lhand = sd->status.shield;
  875. #else
  876. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  877. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  878. {
  879. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  880. if (id->view_id > 0)
  881. *rhand = id->view_id;
  882. else
  883. *rhand = id->nameid;
  884. } else
  885. *rhand = 0;
  886. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  887. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  888. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  889. {
  890. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  891. if (id->view_id > 0)
  892. *lhand = id->view_id;
  893. else
  894. *lhand = id->nameid;
  895. } else
  896. *lhand = 0;
  897. #endif
  898. }
  899. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  900. static int clif_setlevel_sub(int lv) {
  901. if( lv < battle_config.max_lv ) {
  902. ;
  903. } else if( lv < battle_config.aura_lv ) {
  904. lv = battle_config.max_lv - 1;
  905. } else {
  906. lv = battle_config.max_lv;
  907. }
  908. return lv;
  909. }
  910. static int clif_setlevel(struct block_list* bl) {
  911. int lv = status_get_lv(bl);
  912. if( battle_config.client_limit_unit_lv&bl->type )
  913. return clif_setlevel_sub(lv);
  914. switch( bl->type ) {
  915. case BL_NPC:
  916. case BL_PET:
  917. // npcs and pets do not have level
  918. return 0;
  919. }
  920. return lv;
  921. }
  922. /*==========================================
  923. * Prepares 'unit standing/spawning' packet
  924. *------------------------------------------*/
  925. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  926. nullpo_retv( bl );
  927. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  928. struct status_change* sc = status_get_sc( bl );
  929. struct view_data* vd = status_get_viewdata( bl );
  930. int g_id = status_get_guild_id( bl );
  931. #if PACKETVER < 20091103
  932. if( !pcdb_checkid( vd->class_ ) ){
  933. struct packet_idle_unit2 p;
  934. p.PacketType = idle_unit2Type;
  935. #if PACKETVER >= 20071106
  936. p.objecttype = clif_bl_type( bl, walking );
  937. #endif
  938. p.GID = bl->id;
  939. p.speed = status_get_speed( bl );
  940. p.bodyState = ( sc ) ? sc->opt1 : 0;
  941. p.healthState = ( sc ) ? sc->opt2 : 0;
  942. p.effectState = ( sc ) ? sc->option : 0;
  943. p.job = vd->class_;
  944. p.head = vd->hair_style;
  945. p.weapon = vd->weapon;
  946. p.accessory = vd->head_bottom;
  947. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  948. // The hell, why flags work like this?
  949. p.shield = status_get_emblem_id( bl );
  950. p.accessory2 = GetWord( g_id, 1 );
  951. p.accessory3 = GetWord( g_id, 0 );
  952. }else{
  953. p.shield = vd->shield;
  954. p.accessory2 = vd->head_top;
  955. p.accessory3 = vd->head_mid;
  956. }
  957. p.headpalette = vd->hair_color;
  958. p.bodypalette = vd->cloth_color;
  959. p.headDir = ( sd )? sd->head_dir : 0;
  960. p.GUID = g_id;
  961. p.GEmblemVer = status_get_emblem_id( bl );
  962. p.honor = ( sd ) ? sd->status.manner : 0;
  963. p.virtue = ( sc ) ? sc->opt3 : 0;
  964. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  965. p.sex = vd->sex;
  966. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  967. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  968. p.state = vd->dead_sit;
  969. p.clevel = clif_setlevel( bl );
  970. clif_send( &p, sizeof( p ), tbl, target );
  971. return;
  972. }
  973. #endif
  974. struct packet_idle_unit p;
  975. p.PacketType = idle_unitType;
  976. #if PACKETVER >= 20091103
  977. p.PacketLength = sizeof(p);
  978. p.objecttype = clif_bl_type( bl, walking );
  979. #endif
  980. #if PACKETVER >= 20131223
  981. p.AID = bl->id;
  982. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  983. #else
  984. p.GID = bl->id;
  985. #endif
  986. p.speed = status_get_speed(bl);
  987. p.bodyState = (sc) ? sc->opt1 : 0;
  988. p.healthState = (sc) ? sc->opt2 : 0;
  989. // npc option changed?
  990. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  991. struct map_session_data* sd = (struct map_session_data*)tbl;
  992. struct npc_data* nd = (struct npc_data*)bl;
  993. int option = (sc) ? sc->option : 0;
  994. if( !nd->vd.dead_sit ){
  995. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  996. option ^= OPTION_CLOAK;
  997. }
  998. }
  999. p.effectState = option;
  1000. }else{
  1001. p.effectState = (sc) ? sc->option : 0;
  1002. }
  1003. p.job = vd->class_;
  1004. p.head = vd->hair_style;
  1005. p.weapon = vd->weapon;
  1006. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1007. p.shield = vd->shield;
  1008. #endif
  1009. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1010. // The hell, why flags work like this?
  1011. p.accessory = status_get_emblem_id( bl );
  1012. p.accessory2 = GetWord( g_id, 1 );
  1013. p.accessory3 = GetWord( g_id, 0 );
  1014. }else{
  1015. p.accessory = vd->head_bottom;
  1016. p.accessory2 = vd->head_top;
  1017. p.accessory3 = vd->head_mid;
  1018. }
  1019. p.headpalette = vd->hair_color;
  1020. p.bodypalette = vd->cloth_color;
  1021. p.headDir = (sd)? sd->head_dir : 0;
  1022. #if PACKETVER >= 20101124
  1023. p.robe = vd->robe;
  1024. #endif
  1025. p.GUID = g_id;
  1026. p.GEmblemVer = status_get_emblem_id( bl );
  1027. p.honor = (sd) ? sd->status.manner : 0;
  1028. p.virtue = (sc) ? sc->opt3 : 0;
  1029. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1030. p.sex = vd->sex;
  1031. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1032. p.xSize = p.ySize = (sd) ? 5 : 0;
  1033. p.state = vd->dead_sit;
  1034. p.clevel = clif_setlevel( bl );
  1035. #if PACKETVER >= 20080102
  1036. p.font = (sd) ? sd->status.font : 0;
  1037. #endif
  1038. #if PACKETVER >= 20120221
  1039. if( battle_config.monster_hp_bars_info && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && bl->type == BL_MOB && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1040. p.maxHP = status_get_max_hp(bl);
  1041. p.HP = status_get_hp(bl);
  1042. }else{
  1043. p.maxHP = -1;
  1044. p.HP = -1;
  1045. }
  1046. if( bl->type == BL_MOB ){
  1047. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1048. }else if( bl->type == BL_PET ){
  1049. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1050. }else{
  1051. p.isBoss = BOSSTYPE_NONE;
  1052. }
  1053. #endif
  1054. #if PACKETVER >= 20150513
  1055. p.body = vd->body_style;
  1056. #endif
  1057. /* Might be earlier, this is when the named item bug began */
  1058. #if PACKETVER >= 20131223
  1059. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1060. #endif
  1061. clif_send( &p, sizeof( p ), tbl, target );
  1062. // if disguised, send to self
  1063. if( disguised( bl ) ){
  1064. #if PACKETVER >= 20091103
  1065. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1066. #if PACKETVER >= 20131223
  1067. p.AID = disguised_bl_id( bl->id );
  1068. #else
  1069. p.GID = disguised_bl_id( bl->id );
  1070. #endif
  1071. #else
  1072. p.GID = disguised_bl_id( bl->id );
  1073. #endif
  1074. clif_send(&p, sizeof(p), bl, SELF);
  1075. }
  1076. }
  1077. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1078. nullpo_retv( bl );
  1079. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1080. struct status_change* sc = status_get_sc( bl );
  1081. struct view_data* vd = status_get_viewdata( bl );
  1082. int g_id = status_get_guild_id( bl );
  1083. #if PACKETVER < 20091103
  1084. if( !pcdb_checkid( vd->class_ ) ){
  1085. struct packet_spawn_unit2 p;
  1086. p.PacketType = spawn_unit2Type;
  1087. #if PACKETVER >= 20071106
  1088. p.objecttype = clif_bl_type( bl, false );
  1089. #endif
  1090. p.GID = bl->id;
  1091. p.speed = status_get_speed( bl );
  1092. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1093. p.healthState = ( sc ) ? sc->opt2 : 0;
  1094. p.effectState = ( sc ) ? sc->option : 0;
  1095. p.head = vd->hair_style;
  1096. p.weapon = vd->weapon;
  1097. p.accessory = vd->head_bottom;
  1098. p.job = vd->class_;
  1099. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1100. // The hell, why flags work like this?
  1101. p.shield = status_get_emblem_id( bl );
  1102. p.accessory2 = GetWord( g_id, 1 );
  1103. p.accessory3 = GetWord( g_id, 0 );
  1104. }else{
  1105. p.shield = vd->shield;
  1106. p.accessory2 = vd->head_top;
  1107. p.accessory3 = vd->head_mid;
  1108. }
  1109. p.headpalette = vd->hair_color;
  1110. p.bodypalette = vd->cloth_color;
  1111. p.headDir = ( sd ) ? sd->head_dir : 0;
  1112. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1113. p.sex = vd->sex;
  1114. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1115. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1116. clif_send( &p, sizeof( p ), bl, target );
  1117. return;
  1118. }
  1119. #endif
  1120. struct packet_spawn_unit p;
  1121. p.PacketType = spawn_unitType;
  1122. #if PACKETVER >= 20091103
  1123. p.PacketLength = sizeof(p);
  1124. p.objecttype = clif_bl_type( bl, false );
  1125. #endif
  1126. #if PACKETVER >= 20131223
  1127. p.AID = bl->id;
  1128. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1129. #else
  1130. p.GID = bl->id;
  1131. #endif
  1132. p.speed = status_get_speed( bl );
  1133. p.bodyState = (sc) ? sc->opt1 : 0;
  1134. p.healthState = (sc) ? sc->opt2 : 0;
  1135. p.effectState = (sc) ? sc->option : 0;
  1136. p.job = vd->class_;
  1137. p.head = vd->hair_style;
  1138. p.weapon = vd->weapon;
  1139. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1140. p.shield = vd->shield;
  1141. #endif
  1142. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1143. // The hell, why flags work like this?
  1144. p.accessory = status_get_emblem_id( bl );
  1145. p.accessory2 = GetWord( g_id, 1 );
  1146. p.accessory3 = GetWord( g_id, 0 );
  1147. }else{
  1148. p.accessory = vd->head_bottom;
  1149. p.accessory2 = vd->head_top;
  1150. p.accessory3 = vd->head_mid;
  1151. }
  1152. p.headpalette = vd->hair_color;
  1153. p.bodypalette = vd->cloth_color;
  1154. p.headDir = (sd)? sd->head_dir : 0;
  1155. #if PACKETVER >= 20101124
  1156. p.robe = vd->robe;
  1157. #endif
  1158. p.GUID = g_id;
  1159. p.GEmblemVer = status_get_emblem_id( bl );
  1160. p.honor = (sd) ? sd->status.manner : 0;
  1161. p.virtue = (sc) ? sc->opt3 : 0;
  1162. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1163. p.sex = vd->sex;
  1164. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1165. p.xSize = p.ySize = (sd) ? 5 : 0;
  1166. p.clevel = clif_setlevel( bl );
  1167. #if PACKETVER >= 20080102
  1168. p.font = (sd) ? sd->status.font : 0;
  1169. #endif
  1170. #if PACKETVER >= 20120221
  1171. if( battle_config.monster_hp_bars_info && bl->type == BL_MOB && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1172. p.maxHP = status_get_max_hp( bl );
  1173. p.HP = status_get_hp( bl );
  1174. }else{
  1175. p.maxHP = -1;
  1176. p.HP = -1;
  1177. }
  1178. if( bl->type == BL_MOB ){
  1179. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1180. }else if( bl->type == BL_PET ){
  1181. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1182. }else{
  1183. p.isBoss = BOSSTYPE_NONE;
  1184. }
  1185. #endif
  1186. #if PACKETVER >= 20150513
  1187. p.body = vd->body_style;
  1188. #endif
  1189. /* Might be earlier, this is when the named item bug began */
  1190. #if PACKETVER >= 20131223
  1191. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1192. #endif
  1193. if( disguised( bl ) ){
  1194. nullpo_retv( sd );
  1195. if( sd->status.class_ != sd->disguise ){
  1196. clif_send( &p, sizeof( p ), bl, target );
  1197. }
  1198. #if PACKETVER >= 20091103
  1199. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1200. #if PACKETVER >= 20131223
  1201. p.AID = disguised_bl_id( bl->id );
  1202. #else
  1203. p.GID = disguised_bl_id( bl->id );
  1204. #endif
  1205. #else
  1206. p.GID = disguised_bl_id( bl->id );
  1207. #endif
  1208. clif_send( &p, sizeof( p ), bl, SELF );
  1209. }else{
  1210. clif_send( &p, sizeof( p ), bl, target );
  1211. }
  1212. }
  1213. /*==========================================
  1214. * Prepares 'unit walking' packet
  1215. *------------------------------------------*/
  1216. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1217. nullpo_retv( bl );
  1218. nullpo_retv( ud );
  1219. struct map_session_data* sd;
  1220. struct status_change* sc = status_get_sc( bl );
  1221. struct view_data* vd = status_get_viewdata( bl );
  1222. struct packet_unit_walking p;
  1223. int g_id = status_get_guild_id(bl);
  1224. sd = BL_CAST(BL_PC, bl);
  1225. p.PacketType = unit_walkingType;
  1226. #if PACKETVER >= 20091103
  1227. p.PacketLength = sizeof(p);
  1228. #endif
  1229. #if PACKETVER >= 20071106
  1230. p.objecttype = clif_bl_type( bl, true );
  1231. #endif
  1232. #if PACKETVER >= 20131223
  1233. p.AID = bl->id;
  1234. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1235. #else
  1236. p.GID = bl->id;
  1237. #endif
  1238. p.speed = status_get_speed(bl);
  1239. p.bodyState = (sc) ? sc->opt1 : 0;
  1240. p.healthState = (sc) ? sc->opt2 : 0;
  1241. p.effectState = (sc) ? sc->option : 0;
  1242. p.job = vd->class_;
  1243. p.head = vd->hair_style;
  1244. p.weapon = vd->weapon;
  1245. p.accessory = vd->head_bottom;
  1246. p.moveStartTime = client_tick(gettick());
  1247. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1248. p.shield = vd->shield;
  1249. #endif
  1250. p.accessory2 = vd->head_top;
  1251. p.accessory3 = vd->head_mid;
  1252. p.headpalette = vd->hair_color;
  1253. p.bodypalette = vd->cloth_color;
  1254. p.headDir = (sd) ? sd->head_dir : 0;
  1255. #if PACKETVER >= 20101124
  1256. p.robe = vd->robe;
  1257. #endif
  1258. p.GUID = g_id;
  1259. p.GEmblemVer = status_get_emblem_id(bl);
  1260. p.honor = (sd) ? sd->status.manner : 0;
  1261. p.virtue = (sc) ? sc->opt3 : 0;
  1262. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1263. p.sex = vd->sex;
  1264. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1265. p.xSize = p.ySize = (sd) ? 5 : 0;
  1266. p.clevel = clif_setlevel(bl);
  1267. #if PACKETVER >= 20080102
  1268. p.font = (sd) ? sd->status.font : 0;
  1269. #endif
  1270. #if PACKETVER >= 20120221
  1271. if( battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp( bl ) ) ){
  1272. p.maxHP = status_get_max_hp(bl);
  1273. p.HP = status_get_hp(bl);
  1274. } else {
  1275. p.maxHP = -1;
  1276. p.HP = -1;
  1277. }
  1278. if( bl->type == BL_MOB ){
  1279. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1280. }else if( bl->type == BL_PET ){
  1281. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1282. }else{
  1283. p.isBoss = BOSSTYPE_NONE;
  1284. }
  1285. #endif
  1286. #if PACKETVER >= 20150513
  1287. p.body = vd->body_style;
  1288. #endif
  1289. /* Might be earlier, this is when the named item bug began */
  1290. #if PACKETVER >= 20131223
  1291. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1292. #endif
  1293. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1294. // if disguised, send the info to self
  1295. if( disguised( bl ) ){
  1296. #if PACKETVER >= 20091103
  1297. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1298. #if PACKETVER >= 20131223
  1299. p.AID = disguised_bl_id( bl->id );
  1300. #else
  1301. p.GID = disguised_bl_id( bl->id );
  1302. #endif
  1303. #else
  1304. p.GID = disguised_bl_id( bl->id );
  1305. #endif
  1306. clif_send(&p,sizeof(p),bl,SELF);
  1307. }
  1308. }
  1309. //Modifies the buffer for disguise characters and sends it to self.
  1310. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1311. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1312. {
  1313. #if PACKETVER >= 20091103
  1314. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1315. WBUFL(buf,5)=-bl->id;
  1316. #elif PACKETVER >= 20071106
  1317. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1318. WBUFL(buf,3)=-bl->id;
  1319. #else
  1320. WBUFL(buf,2)=-bl->id;
  1321. #endif
  1322. clif_send(buf, len, bl, SELF);
  1323. }
  1324. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1325. /// 01b0 <id>.L <type>.B <value>.L
  1326. /// type:
  1327. /// unused
  1328. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1329. {
  1330. nullpo_retv(bl);
  1331. if(!pcdb_checkid(class_))
  1332. {// player classes yield missing sprites
  1333. unsigned char buf[16];
  1334. WBUFW(buf,0)=0x1b0;
  1335. WBUFL(buf,2)=bl->id;
  1336. WBUFB(buf,6)=type;
  1337. WBUFL(buf,7)=class_;
  1338. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1339. }
  1340. }
  1341. void clif_servantball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1342. struct PACKET_ZC_SPIRITS p = {};
  1343. p.packetType = HEADER_ZC_SPIRITS;
  1344. p.GID = sd.bl.id;
  1345. p.amount = sd.servantball;
  1346. if( target == nullptr ){
  1347. target = &sd.bl;
  1348. }
  1349. clif_send( &p, sizeof( p ), target, send_target );
  1350. }
  1351. void clif_abyssball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1352. struct PACKET_ZC_SPIRITS p = {};
  1353. p.packetType = HEADER_ZC_SPIRITS;
  1354. p.GID = sd.bl.id;
  1355. p.amount = sd.abyssball;
  1356. if( target == nullptr ){
  1357. target = &sd.bl;
  1358. }
  1359. clif_send( &p, sizeof( p ), target, send_target );
  1360. }
  1361. /// Notifies the client of an object's Millenium Shields.
  1362. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1363. {
  1364. nullpo_retv(sd);
  1365. if (sd->sc.data[SC_MILLENNIUMSHIELD] == nullptr)
  1366. return;
  1367. WFIFOHEAD(fd, packet_len(0x440));
  1368. WFIFOW(fd, 0) = 0x440;
  1369. WFIFOL(fd, 2) = sd->bl.id;
  1370. WFIFOW(fd, 6) = sd->sc.data[SC_MILLENNIUMSHIELD]->val2;
  1371. WFIFOW(fd, 8) = 0;
  1372. WFIFOSET(fd, packet_len(0x440));
  1373. }
  1374. /*==========================================
  1375. * Kagerou/Oboro amulet spirit
  1376. *------------------------------------------*/
  1377. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1378. {
  1379. WFIFOHEAD(fd, packet_len(0x08cf));
  1380. WFIFOW(fd,0)=0x08cf;
  1381. WFIFOL(fd,2)=sd->bl.id;
  1382. WFIFOW(fd,6)=sd->spiritcharm_type;
  1383. WFIFOW(fd,8)=sd->spiritcharm;
  1384. WFIFOSET(fd, packet_len(0x08cf));
  1385. }
  1386. /*==========================================
  1387. * Run when player changes map / refreshes
  1388. * Tells its client to display all weather settings being used by this map
  1389. *------------------------------------------*/
  1390. static void clif_weather_check(struct map_session_data *sd)
  1391. {
  1392. int16 m = sd->bl.m;
  1393. int fd = sd->fd;
  1394. if (map_getmapflag(m, MF_SNOW)
  1395. || map_getmapflag(m, MF_CLOUDS)
  1396. || map_getmapflag(m, MF_FOG)
  1397. || map_getmapflag(m, MF_FIREWORKS)
  1398. || map_getmapflag(m, MF_SAKURA)
  1399. || map_getmapflag(m, MF_LEAVES)
  1400. || map_getmapflag(m, MF_CLOUDS2))
  1401. {
  1402. if (map_getmapflag(m, MF_SNOW))
  1403. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1404. if (map_getmapflag(m, MF_CLOUDS))
  1405. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1406. if (map_getmapflag(m, MF_CLOUDS2))
  1407. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1408. if (map_getmapflag(m, MF_FOG))
  1409. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1410. if (map_getmapflag(m, MF_FIREWORKS)) {
  1411. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1412. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1413. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1414. }
  1415. if (map_getmapflag(m, MF_SAKURA))
  1416. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1417. if (map_getmapflag(m, MF_LEAVES))
  1418. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1419. }
  1420. }
  1421. /**
  1422. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1423. **/
  1424. void clif_weather(int16 m)
  1425. {
  1426. struct s_mapiterator* iter;
  1427. struct map_session_data *sd=NULL;
  1428. iter = mapit_getallusers();
  1429. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1430. {
  1431. if( sd->bl.m == m )
  1432. clif_weather_check(sd);
  1433. }
  1434. mapit_free(iter);
  1435. }
  1436. /**
  1437. * Hide a NPC from the effects of Maya Purple card.
  1438. * @param bl: Block data
  1439. * @return True if NPC is disabled or false otherwise
  1440. */
  1441. static inline bool clif_npc_mayapurple(block_list *bl) {
  1442. nullpo_retr(false, bl);
  1443. if (bl->type == BL_NPC) {
  1444. npc_data *nd = map_id2nd(bl->id);
  1445. // TODO: Confirm if waitingroom cause any special cases
  1446. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1447. return true;
  1448. }
  1449. return false;
  1450. }
  1451. /**
  1452. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1453. **/
  1454. int clif_spawn( struct block_list *bl, bool walking ){
  1455. struct view_data *vd;
  1456. vd = status_get_viewdata(bl);
  1457. if( !vd || vd->class_ == JT_INVISIBLE )
  1458. return 0;
  1459. // Hide NPC from Maya Purple card
  1460. if (clif_npc_mayapurple(bl))
  1461. return 0;
  1462. if( bl->type == BL_NPC && !vd->dead_sit ){
  1463. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1464. }else{
  1465. clif_spawn_unit( bl, AREA_WOS );
  1466. }
  1467. if (vd->cloth_color)
  1468. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1469. if (vd->body_style)
  1470. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1471. switch (bl->type)
  1472. {
  1473. case BL_PC:
  1474. {
  1475. TBL_PC *sd = ((TBL_PC*)bl);
  1476. if (sd->spiritball > 0)
  1477. clif_spiritball(&sd->bl);
  1478. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  1479. clif_millenniumshield(&sd->bl, sd->sc.data[SC_MILLENNIUMSHIELD]->val2);
  1480. if (sd->soulball > 0)
  1481. clif_soulball(sd);
  1482. if (sd->servantball > 0)
  1483. clif_servantball( *sd );
  1484. if (sd->abyssball > 0)
  1485. clif_abyssball( *sd );
  1486. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1487. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1488. else if(sd->state.size==SZ_MEDIUM)
  1489. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1490. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1491. clif_sendbgemblem_area(sd);
  1492. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1493. clif_spiritcharm(sd);
  1494. if (sd->status.robe)
  1495. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1496. clif_efst_status_change_sub(bl, bl, AREA);
  1497. clif_hat_effects(sd,bl,AREA);
  1498. }
  1499. break;
  1500. case BL_MOB:
  1501. {
  1502. TBL_MOB *md = ((TBL_MOB*)bl);
  1503. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1504. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1505. else if(md->special_state.size==SZ_MEDIUM)
  1506. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1507. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1508. clif_summon_init(*md);
  1509. }
  1510. break;
  1511. case BL_NPC:
  1512. {
  1513. TBL_NPC *nd = ((TBL_NPC*)bl);
  1514. if( nd->size == SZ_BIG )
  1515. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1516. else if( nd->size == SZ_MEDIUM )
  1517. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1518. clif_efst_status_change_sub(bl, bl, AREA);
  1519. clif_progressbar_npc_area(nd);
  1520. }
  1521. break;
  1522. case BL_PET:
  1523. if (vd->head_bottom)
  1524. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1525. break;
  1526. }
  1527. return 0;
  1528. }
  1529. /// Sends information about owned homunculus to the client . [orn]
  1530. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN)
  1531. /// 09f7 <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.L <max hp>.L <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN_2)
  1532. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1533. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1534. nullpo_retv( sd );
  1535. nullpo_retv( hd );
  1536. struct status_data *status = &hd->battle_status;
  1537. struct PACKET_ZC_PROPERTY_HOMUN p;
  1538. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1539. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1540. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1541. p.flags = ( !battle_config.hom_rename && hd->homunculus.rename_flag ? 0x1 : 0x0 ) | ( hd->homunculus.vaporize == HOM_ST_REST ? 0x2 : 0 ) | ( hd->homunculus.hp > 0 ? 0x4 : 0 );
  1542. p.level = hd->homunculus.level;
  1543. p.hunger = hd->homunculus.hunger;
  1544. p.intimacy = hd->homunculus.intimacy / 100;
  1545. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1546. p.itemId = 0; // equip id
  1547. #endif
  1548. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1549. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1550. p.hit = status->hit;
  1551. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1552. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1553. }else{
  1554. p.crit = status->cri / 10;
  1555. }
  1556. #ifdef RENEWAL
  1557. p.def = status->def + status->def2;
  1558. p.mdef = status->mdef + status->mdef2;
  1559. #else
  1560. p.def = status->def + status->vit;
  1561. p.mdef = status->mdef;
  1562. #endif
  1563. p.flee = status->flee;
  1564. p.amotion = (flag) ? 0 : status->amotion;
  1565. #if PACKETVER >= 20141016
  1566. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1567. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1568. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1569. p.hp = status->hp / ( status->max_hp / 100 );
  1570. p.maxHp = 100;
  1571. }else{
  1572. p.hp = status->hp;
  1573. p.maxHp = status->max_hp;
  1574. }
  1575. #else
  1576. if( status->max_hp > INT16_MAX ){
  1577. p.hp = status->hp / ( status->max_hp / 100 );
  1578. p.maxHp = 100;
  1579. }else{
  1580. p.hp = status->hp;
  1581. p.maxHp = status->max_hp;
  1582. }
  1583. #endif
  1584. if( status->max_sp > INT16_MAX ){
  1585. p.sp = status->sp / ( status->max_sp / 100 );
  1586. p.maxSp = 100;
  1587. }else{
  1588. p.sp = status->sp;
  1589. p.maxSp = status->max_sp;
  1590. }
  1591. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1592. p.exp = hd->homunculus.exp;
  1593. p.expNext = hd->exp_next;
  1594. #else
  1595. p.exp = (uint32)hd->homunculus.exp;
  1596. p.expNext = (uint32)hd->exp_next;
  1597. #endif
  1598. switch( hom_class2type( hd->homunculus.class_ ) ){
  1599. case HT_REG:
  1600. case HT_EVO:
  1601. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1602. p.expNext = 0;
  1603. }
  1604. break;
  1605. case HT_S:
  1606. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1607. p.expNext = 0;
  1608. }
  1609. break;
  1610. }
  1611. p.skillPoints = hd->homunculus.skillpts;
  1612. p.range = status_get_range( &hd->bl );
  1613. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1614. #endif
  1615. }
  1616. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1617. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1618. /// type:
  1619. /// unused
  1620. /// state:
  1621. /// 0 = pre-init
  1622. /// 1 = intimacy
  1623. /// 2 = hunger
  1624. /// 3 = accessory?
  1625. /// ? = ignored
  1626. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1627. { //[orn]
  1628. int fd = sd->fd;
  1629. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1630. hom_calc_skilltree(sd->hd, 0);
  1631. WFIFOHEAD(fd, packet_len(0x230));
  1632. WFIFOW(fd,0)=0x230;
  1633. WFIFOB(fd,2)=0;
  1634. WFIFOB(fd,3)=state;
  1635. WFIFOL(fd,4)=sd->hd->bl.id;
  1636. WFIFOL(fd,8)=param;
  1637. WFIFOSET(fd,packet_len(0x230));
  1638. }
  1639. int clif_homskillinfoblock(struct map_session_data *sd)
  1640. { //[orn]
  1641. struct homun_data *hd;
  1642. int fd = sd->fd;
  1643. int i, len=4;
  1644. nullpo_ret(sd);
  1645. hd = sd->hd;
  1646. if ( !hd )
  1647. return 0 ;
  1648. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1649. WFIFOW(fd,0)=0x235;
  1650. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1651. int id = hd->homunculus.hskill[i].id;
  1652. if( id != 0 ){
  1653. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1654. short idx = hom_skill_get_index(id);
  1655. if (idx == -1)
  1656. continue;
  1657. WFIFOW(fd,len ) = id;
  1658. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1659. WFIFOW(fd,len+4) = 0;
  1660. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1661. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1662. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1663. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1664. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1665. len+=37;
  1666. }
  1667. }
  1668. WFIFOW(fd,2)=len;
  1669. WFIFOSET(fd,len);
  1670. return 0;
  1671. }
  1672. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1673. { //[orn]
  1674. struct homun_data *hd;
  1675. int fd;
  1676. short idx = -1;
  1677. nullpo_retv(sd);
  1678. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1679. return;
  1680. fd = sd->fd;
  1681. hd = sd->hd;
  1682. WFIFOHEAD(fd, packet_len(0x239));
  1683. WFIFOW(fd,0) = 0x239;
  1684. WFIFOW(fd,2) = skill_id;
  1685. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1686. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1687. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1688. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1689. WFIFOSET(fd,packet_len(0x239));
  1690. }
  1691. /// Result of request to feed a homun/merc.
  1692. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1693. /// result:
  1694. /// 0 = failure
  1695. /// 1 = success
  1696. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1697. nullpo_retv( sd );
  1698. struct PACKET_ZC_FEED_MER p;
  1699. p.packetType = 0x22f;
  1700. p.result = fail;
  1701. p.itemId = client_nameid( foodid );
  1702. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1703. }
  1704. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1705. /// 0087 <walk start time>.L <walk data>.6B
  1706. void clif_walkok(struct map_session_data *sd)
  1707. {
  1708. int fd=sd->fd;
  1709. WFIFOHEAD(fd, packet_len(0x87));
  1710. WFIFOW(fd,0)=0x87;
  1711. WFIFOL(fd,2)=client_tick(gettick());
  1712. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1713. WFIFOSET(fd,packet_len(0x87));
  1714. }
  1715. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1716. struct status_change *sc = NULL;
  1717. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1718. clif_ally_only = true;
  1719. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1720. if(vd->cloth_color)
  1721. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1722. if(vd->body_style)
  1723. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1724. switch(bl->type) {
  1725. case BL_PC:
  1726. {
  1727. TBL_PC *sd = ((TBL_PC*)bl);
  1728. // clif_movepc(sd);
  1729. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1730. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1731. else if(sd->state.size==SZ_MEDIUM)
  1732. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1733. if (sd->status.robe)
  1734. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1735. }
  1736. break;
  1737. case BL_MOB:
  1738. {
  1739. TBL_MOB *md = ((TBL_MOB*)bl);
  1740. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1741. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1742. else if(md->special_state.size==SZ_MEDIUM)
  1743. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1744. }
  1745. break;
  1746. case BL_PET:
  1747. if(vd->head_bottom) // needed to display pet equip properly
  1748. clif_pet_equip_area((TBL_PET*)bl);
  1749. break;
  1750. }
  1751. clif_ally_only = false;
  1752. }
  1753. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1754. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1755. /// Note: unit must not be self
  1756. void clif_move(struct unit_data *ud)
  1757. {
  1758. unsigned char buf[16];
  1759. struct view_data* vd;
  1760. struct block_list* bl = ud->bl;
  1761. struct status_change *sc = NULL;
  1762. vd = status_get_viewdata(bl);
  1763. if (!vd )
  1764. return;
  1765. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1766. else if( vd->class_ == JT_INVISIBLE ){
  1767. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1768. if(disguised(bl)) {
  1769. WBUFW(buf,0)=0x86;
  1770. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1771. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1772. WBUFL(buf,12)=client_tick(gettick());
  1773. clif_send(buf, packet_len(0x86), bl, SELF);
  1774. }
  1775. return;
  1776. }
  1777. // Hide NPC from Maya Purple card
  1778. if (clif_npc_mayapurple(bl))
  1779. return;
  1780. if (ud->state.speed_changed) {
  1781. // Since we don't know how to update the speed of other objects,
  1782. // use the old walk packet to update the data.
  1783. ud->state.speed_changed = 0;
  1784. clif_move2(bl, vd, ud);
  1785. return;
  1786. }
  1787. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1788. clif_ally_only = true;
  1789. WBUFW(buf,0)=0x86;
  1790. WBUFL(buf,2)=bl->id;
  1791. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1792. WBUFL(buf,12)=client_tick(gettick());
  1793. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1794. if (disguised(bl)) {
  1795. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1796. clif_send(buf, packet_len(0x86), bl, SELF);
  1797. }
  1798. clif_ally_only = false;
  1799. }
  1800. /*==========================================
  1801. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1802. *------------------------------------------*/
  1803. static TIMER_FUNC(clif_delayquit){
  1804. struct map_session_data *sd = NULL;
  1805. //Remove player from map server
  1806. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1807. map_quit(sd);
  1808. return 0;
  1809. }
  1810. /*==========================================
  1811. *
  1812. *------------------------------------------*/
  1813. void clif_quitsave(int fd,struct map_session_data *sd) {
  1814. if (!battle_config.prevent_logout ||
  1815. sd->canlog_tick == 0 ||
  1816. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1817. map_quit(sd);
  1818. else if (session_isValid(sd->fd)) {
  1819. //Disassociate session from player (session is deleted after this function was called)
  1820. //And set a timer to make him quit later.
  1821. session[sd->fd]->session_data = NULL;
  1822. sd->fd = 0;
  1823. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1824. }
  1825. }
  1826. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1827. /// 0091 <map name>.16B <x>.W <y>.W
  1828. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1829. {
  1830. nullpo_retv(sd);
  1831. int fd = sd->fd;
  1832. WFIFOHEAD(fd,packet_len(0x91));
  1833. WFIFOW(fd,0) = 0x91;
  1834. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1835. WFIFOW(fd,18) = x;
  1836. WFIFOW(fd,20) = y;
  1837. WFIFOSET(fd,packet_len(0x91));
  1838. }
  1839. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1840. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1841. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1842. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1843. {
  1844. int fd;
  1845. #if PACKETVER >= 20170315
  1846. int cmd = 0xac7;
  1847. #else
  1848. int cmd = 0x92;
  1849. #endif
  1850. nullpo_retv(sd);
  1851. fd = sd->fd;
  1852. WFIFOHEAD(fd,packet_len(cmd));
  1853. WFIFOW(fd,0) = cmd;
  1854. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1855. WFIFOW(fd,18) = x;
  1856. WFIFOW(fd,20) = y;
  1857. WFIFOL(fd,22) = htonl(ip);
  1858. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1859. #if PACKETVER >= 20170315
  1860. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1861. #endif
  1862. WFIFOSET(fd,packet_len(cmd));
  1863. }
  1864. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1865. /// This function combines both calls and allows to simplify the calling code
  1866. void clif_blown(struct block_list *bl)
  1867. {
  1868. clif_slide(bl, bl->x, bl->y);
  1869. clif_fixpos(bl);
  1870. }
  1871. /// Visually moves(slides) a character to x,y. If the target cell
  1872. /// isn't walkable, the char doesn't move at all. If the char is
  1873. /// sitting it will stand up (ZC_STOPMOVE).
  1874. /// 0088 <id>.L <x>.W <y>.W
  1875. void clif_fixpos(struct block_list *bl)
  1876. {
  1877. unsigned char buf[10];
  1878. nullpo_retv(bl);
  1879. WBUFW(buf,0) = 0x88;
  1880. WBUFL(buf,2) = bl->id;
  1881. WBUFW(buf,6) = bl->x;
  1882. WBUFW(buf,8) = bl->y;
  1883. clif_send(buf, packet_len(0x88), bl, AREA);
  1884. if( disguised(bl) ) {
  1885. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1886. clif_send(buf, packet_len(0x88), bl, SELF);
  1887. }
  1888. }
  1889. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1890. /// 00c4 <shop id>.L
  1891. void clif_npcbuysell(struct map_session_data* sd, int id)
  1892. {
  1893. int fd;
  1894. nullpo_retv(sd);
  1895. fd=sd->fd;
  1896. WFIFOHEAD(fd, packet_len(0xc4));
  1897. WFIFOW(fd,0)=0xc4;
  1898. WFIFOL(fd,2)=id;
  1899. WFIFOSET(fd,packet_len(0xc4));
  1900. }
  1901. /// Presents list of items, that can be bought in an NPC shop.
  1902. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1903. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1904. nullpo_retv( sd );
  1905. nullpo_retv( nd );
  1906. int fd = sd->fd;
  1907. if( !session_isActive( fd ) ){
  1908. return;
  1909. }
  1910. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1911. WFIFOHEAD( fd, len );
  1912. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1913. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1914. int count = 0;
  1915. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1916. int val = nd->u.shop.shop_item[i].value;
  1917. p->items[count].price = val;
  1918. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1919. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1920. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1921. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1922. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1923. p->items[count].viewSprite = id->look;
  1924. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1925. #endif
  1926. count++;
  1927. }
  1928. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1929. WFIFOSET( fd, p->packetLength );
  1930. }
  1931. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1932. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1933. void clif_selllist(struct map_session_data *sd)
  1934. {
  1935. int fd,i,c=0,val;
  1936. struct npc_data *nd;
  1937. nullpo_retv(sd);
  1938. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1939. return;
  1940. fd=sd->fd;
  1941. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1942. WFIFOW(fd,0)=0xc7;
  1943. for( i = 0; i < MAX_INVENTORY; i++ )
  1944. {
  1945. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1946. {
  1947. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1948. continue;
  1949. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1950. val = 0;
  1951. else {
  1952. val = sd->inventory_data[i]->value_sell;
  1953. if( val < 0 )
  1954. continue;
  1955. }
  1956. WFIFOW(fd,4+c*10)=i+2;
  1957. WFIFOL(fd,6+c*10)=val;
  1958. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1959. c++;
  1960. }
  1961. }
  1962. WFIFOW(fd,2)=c*10+4;
  1963. WFIFOSET(fd,WFIFOW(fd,2));
  1964. }
  1965. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1966. /// 09d4
  1967. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1968. // TODO: State tracking?
  1969. sd->npc_shopid = 0;
  1970. }
  1971. /**
  1972. * Presents list of items, that can be sold to a Market shop.
  1973. * @author: Ind and Yommy
  1974. **/
  1975. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1976. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1977. #if PACKETVER >= 20131223
  1978. nullpo_retv( sd );
  1979. nullpo_retv( nd );
  1980. if( sd->state.trading ){
  1981. return;
  1982. }
  1983. int fd = sd->fd;
  1984. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1985. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1986. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1987. int count = 0;
  1988. for( int i = 0; i < nd->u.shop.count; i++ ){
  1989. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1990. if( !item->nameid ){
  1991. continue;
  1992. }
  1993. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  1994. if( !id ){
  1995. continue;
  1996. }
  1997. // Out of stock
  1998. if( item->qty == 0 ){
  1999. continue;
  2000. }
  2001. p->list[count].nameid = client_nameid( item->nameid );
  2002. p->list[count].type = itemtype( item->nameid );
  2003. p->list[count].price = item->value;
  2004. p->list[count].qty = item->qty;
  2005. p->list[count].weight = id->weight;
  2006. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2007. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2008. #endif
  2009. count++;
  2010. }
  2011. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2012. WFIFOSET( fd, p->packetLength );
  2013. sd->state.trading = 1;
  2014. #endif
  2015. }
  2016. /// Closes the Market shop window.
  2017. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  2018. nullpo_retv(sd);
  2019. sd->npc_shopid = 0;
  2020. sd->state.trading = 0;
  2021. }
  2022. /// Purchase item from Market shop.
  2023. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2024. void clif_npc_market_purchase_ack( struct map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2025. #if PACKETVER >= 20131223
  2026. nullpo_retv( sd );
  2027. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2028. nullpo_retv( nd );
  2029. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2030. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2031. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2032. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2033. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2034. #else
  2035. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2036. #endif
  2037. if( p->result ){
  2038. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2039. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2040. // Not found
  2041. if( j == nd->u.shop.count ){
  2042. continue;
  2043. }
  2044. p->list[count].ITID = client_nameid( list[i].nameid );
  2045. p->list[count].qty = list[i].qty;
  2046. p->list[count].price = nd->u.shop.shop_item[j].value;
  2047. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2048. count++;
  2049. }
  2050. }
  2051. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2052. #endif
  2053. }
  2054. /// Purchase item from Market shop.
  2055. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2056. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  2057. #if PACKETVER >= 20131223
  2058. nullpo_retv( sd );
  2059. if( !sd->npc_shopid ){
  2060. return;
  2061. }
  2062. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2063. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2064. std::vector<s_npc_buy_list> items;
  2065. items.reserve( count );
  2066. for( int i = 0; i < count; i++ ){
  2067. s_npc_buy_list item = {};
  2068. item.nameid = p->list[i].ITID;
  2069. item.qty = p->list[i].qty;
  2070. items.push_back( item );
  2071. }
  2072. e_purchase_result res = npc_buylist( sd, items );
  2073. clif_npc_market_purchase_ack( sd, res, items );
  2074. #endif
  2075. }
  2076. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2077. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2078. /// Client behavior (dialog window):
  2079. /// - disable mouse targeting
  2080. /// - open the dialog window
  2081. /// - set npcid of dialog window (0 by default)
  2082. /// - if set to clear on next mes, clear contents
  2083. /// - append this text
  2084. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  2085. {
  2086. int fd = sd->fd;
  2087. int slen = strlen(mes) + 9;
  2088. WFIFOHEAD(fd, slen);
  2089. WFIFOW(fd,0)=0xb4;
  2090. WFIFOW(fd,2)=slen;
  2091. WFIFOL(fd,4)=npcid;
  2092. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2093. WFIFOSET(fd,WFIFOW(fd,2));
  2094. }
  2095. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2096. /// 00b5 <npc id>.L
  2097. /// Client behavior (dialog window):
  2098. /// - disable mouse targeting
  2099. /// - open the dialog window
  2100. /// - add 'next' button
  2101. /// When 'next' is pressed:
  2102. /// - 00B9 <npcid of dialog window>.L
  2103. /// - set to clear on next mes
  2104. /// - remove 'next' button
  2105. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2106. {
  2107. int fd;
  2108. nullpo_retv(sd);
  2109. fd=sd->fd;
  2110. WFIFOHEAD(fd, packet_len(0xb5));
  2111. WFIFOW(fd,0)=0xb5;
  2112. WFIFOL(fd,2)=npcid;
  2113. WFIFOSET(fd,packet_len(0xb5));
  2114. }
  2115. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2116. /// 00b6 <npc id>.L
  2117. /// Client behavior:
  2118. /// - if dialog window is open:
  2119. /// - remove 'next' button
  2120. /// - add 'close' button
  2121. /// - else:
  2122. /// - enable mouse targeting
  2123. /// - close the dialog window
  2124. /// - close the menu window
  2125. /// When 'close' is pressed:
  2126. /// - enable mouse targeting
  2127. /// - close the dialog window
  2128. /// - close the menu window
  2129. /// - 0146 <npcid of dialog window>.L
  2130. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2131. {
  2132. int fd;
  2133. nullpo_retv(sd);
  2134. fd=sd->fd;
  2135. WFIFOHEAD(fd, packet_len(0xb6));
  2136. WFIFOW(fd,0)=0xb6;
  2137. WFIFOL(fd,2)=npcid;
  2138. WFIFOSET(fd,packet_len(0xb6));
  2139. }
  2140. /**
  2141. * Close script when player is idle
  2142. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2143. * @author [Ind/Hercules]
  2144. * @param sd : player pointer
  2145. * @param npcid : npc gid to close
  2146. */
  2147. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2148. {
  2149. struct s_packet_db* info;
  2150. int16 len;
  2151. int cmd = 0;
  2152. int fd;
  2153. nullpo_retv(sd);
  2154. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2155. if(!cmd) cmd = 0x8d6; //default
  2156. info = &packet_db[cmd];
  2157. len = info->len;
  2158. fd = sd->fd;
  2159. WFIFOHEAD(fd, len);
  2160. WFIFOW(fd,0)=0x8d6;
  2161. WFIFOL(fd,info->pos[0])=npcid;
  2162. WFIFOSET(fd,len);
  2163. }
  2164. /*==========================================
  2165. *
  2166. *------------------------------------------*/
  2167. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2168. unsigned char *buf;
  2169. int fd = sd->fd;
  2170. sd->state.using_fake_npc = 1;
  2171. WFIFOHEAD(fd, packet_len(0x78));
  2172. buf = WFIFOP(fd,0);
  2173. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2174. WBUFW(buf,0)=0x78;
  2175. #if PACKETVER >= 20071106
  2176. WBUFB(buf,2) = 0; // object type
  2177. buf = WFIFOP(fd,1);
  2178. #endif
  2179. WBUFL(buf,2)=npcid;
  2180. WBUFW(buf,14)=111;
  2181. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2182. WBUFB(buf,49)=5;
  2183. WBUFB(buf,50)=5;
  2184. WFIFOSET(fd, packet_len(0x78));
  2185. }
  2186. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2187. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2188. /// Client behavior:
  2189. /// - disable mouse targeting
  2190. /// - close the menu window
  2191. /// - open the menu window
  2192. /// - add options to the menu (separated in the text by ":")
  2193. /// - set npcid of menu window
  2194. /// - if dialog window is open:
  2195. /// - remove 'next' button
  2196. /// When 'ok' is pressed:
  2197. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2198. /// - close the menu window
  2199. /// When 'cancel' is pressed:
  2200. /// - 00B8 <npcid of menu window>.L <-1>.B
  2201. /// - enable mouse targeting
  2202. /// - close a bunch of windows...
  2203. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2204. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2205. /// TODO investigate behavior of other windows [FlavioJS]
  2206. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2207. {
  2208. int fd = sd->fd;
  2209. int slen = strlen(mes) + 9;
  2210. struct block_list *bl = NULL;
  2211. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2212. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2213. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2214. clif_sendfakenpc(sd, npcid);
  2215. WFIFOHEAD(fd, slen);
  2216. WFIFOW(fd,0)=0xb7;
  2217. WFIFOW(fd,2)=slen;
  2218. WFIFOL(fd,4)=npcid;
  2219. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2220. WFIFOSET(fd,WFIFOW(fd,2));
  2221. }
  2222. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2223. /// 0142 <npc id>.L
  2224. /// Client behavior (inputnum window):
  2225. /// - if npcid exists in the client:
  2226. /// - open the inputnum window
  2227. /// - set npcid of inputnum window
  2228. /// When 'ok' is pressed:
  2229. /// - if inputnum window has text:
  2230. /// - if npcid exists in the client:
  2231. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2232. /// - close inputnum window
  2233. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2234. {
  2235. int fd;
  2236. struct block_list *bl = NULL;
  2237. nullpo_retv(sd);
  2238. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2239. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2240. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2241. clif_sendfakenpc(sd, npcid);
  2242. fd=sd->fd;
  2243. WFIFOHEAD(fd, packet_len(0x142));
  2244. WFIFOW(fd,0)=0x142;
  2245. WFIFOL(fd,2)=npcid;
  2246. WFIFOSET(fd,packet_len(0x142));
  2247. }
  2248. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2249. /// 01d4 <npc id>.L
  2250. /// Client behavior (inputstr window):
  2251. /// - if npcid is 0 or npcid exists in the client:
  2252. /// - open the inputstr window
  2253. /// - set npcid of inputstr window
  2254. /// When 'ok' is pressed:
  2255. /// - if inputstr window has text and isn't an insult(manner.txt):
  2256. /// - if npcid is 0 or npcid exists in the client:
  2257. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2258. /// - close inputstr window
  2259. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2260. {
  2261. int fd;
  2262. struct block_list *bl = NULL;
  2263. nullpo_retv(sd);
  2264. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2265. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2266. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2267. clif_sendfakenpc(sd, npcid);
  2268. fd=sd->fd;
  2269. WFIFOHEAD(fd, packet_len(0x1d4));
  2270. WFIFOW(fd,0)=0x1d4;
  2271. WFIFOL(fd,2)=npcid;
  2272. WFIFOSET(fd,packet_len(0x1d4));
  2273. }
  2274. /// Marks a position on client's minimap (ZC_COMPASS).
  2275. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2276. /// npc id:
  2277. /// is ignored in the client
  2278. /// type:
  2279. /// 0 = display mark for 15 seconds
  2280. /// 1 = display mark until dead or teleported
  2281. /// 2 = remove mark
  2282. /// color:
  2283. /// 0x00RRGGBB
  2284. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2285. {
  2286. int fd;
  2287. nullpo_retv(sd);
  2288. fd=sd->fd;
  2289. WFIFOHEAD(fd, packet_len(0x144));
  2290. WFIFOW(fd,0)=0x144;
  2291. WFIFOL(fd,2)=npc_id;
  2292. WFIFOL(fd,6)=type;
  2293. WFIFOL(fd,10)=x;
  2294. WFIFOL(fd,14)=y;
  2295. WFIFOB(fd,18)=id;
  2296. WFIFOL(fd,19)=color;
  2297. WFIFOSET(fd,packet_len(0x144));
  2298. }
  2299. /// Displays an illustration image.
  2300. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2301. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2302. /// type:
  2303. /// 0 = bottom left corner
  2304. /// 1 = bottom middle
  2305. /// 2 = bottom right corner
  2306. /// 3 = middle of screen, inside a movable window
  2307. /// 4 = middle of screen, movable with a close button, chrome-less
  2308. /// 255 = clear all displayed cutins
  2309. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2310. {
  2311. int fd;
  2312. nullpo_retv(sd);
  2313. fd=sd->fd;
  2314. WFIFOHEAD(fd, packet_len(0x1b3));
  2315. WFIFOW(fd,0)=0x1b3;
  2316. strncpy(WFIFOCP(fd,2),image,64);
  2317. WFIFOB(fd,66)=type;
  2318. WFIFOSET(fd,packet_len(0x1b3));
  2319. }
  2320. /*==========================================
  2321. * Fills in card data from the given item and into the buffer. [Skotlex]
  2322. *------------------------------------------*/
  2323. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2324. nullpo_retv( buf );
  2325. // Blank data
  2326. if( item == nullptr ){
  2327. buf->card[0] = 0;
  2328. buf->card[1] = 0;
  2329. buf->card[2] = 0;
  2330. buf->card[3] = 0;
  2331. return;
  2332. }
  2333. // Pet eggs
  2334. if( item->card[0] == CARD0_PET ){
  2335. buf->card[0] = 0;
  2336. buf->card[1] = 0;
  2337. // Pet intimacy
  2338. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2339. buf->card[2] = item->card[3] >> 1;
  2340. // Pet renamed flag
  2341. buf->card[3] = item->card[3] & 1;
  2342. return;
  2343. }
  2344. // Forged/created items
  2345. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2346. buf->card[0] = item->card[0];
  2347. buf->card[1] = item->card[1];
  2348. buf->card[2] = item->card[2];
  2349. buf->card[3] = item->card[3];
  2350. return;
  2351. }
  2352. int i = 0, j;
  2353. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2354. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2355. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2356. }
  2357. // Normal items.
  2358. for( int k = 0; k < 4; k++, i++ ){
  2359. if( item->card[i] > 0 ){
  2360. buf->card[k] = client_nameid( item->card[i] );
  2361. }else{
  2362. buf->card[k] = 0;
  2363. }
  2364. }
  2365. }
  2366. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2367. /// A maximum of 5 random options can be supported.
  2368. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2369. nullpo_retr( 0, it );
  2370. uint8 count = 0;
  2371. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2372. if( it->option[i].id ){
  2373. buf[i].index = it->option[i].id; // OptIndex
  2374. buf[i].value = it->option[i].value; // Value
  2375. buf[i].param = it->option[i].param; // Param1
  2376. count++;
  2377. }else{
  2378. buf[i].index = 0;
  2379. buf[i].value = 0;
  2380. buf[i].param = 0;
  2381. }
  2382. }
  2383. #if MAX_ITEM_RDM_OPT < 5
  2384. for( ; i < 5; i++ ){
  2385. buf[i].index = 0; // OptIndex
  2386. buf[i].value = 0; // Value
  2387. buf[i].param = 0; // Param1
  2388. }
  2389. #endif
  2390. return count;
  2391. }
  2392. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2393. /// 00a0 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B (ZC_ITEM_PICKUP_ACK)
  2394. /// 029a <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L (ZC_ITEM_PICKUP_ACK2)
  2395. /// 02d4 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK3)
  2396. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  2397. /// 0a0c <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ITEM_PICKUP_ACK_V6)
  2398. /// 0a37 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W { <option id>.W <option value>.W <option param>.B }*5 <favorite>.B <view id>.W (ZC_ITEM_PICKUP_ACK_V7)
  2399. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2400. nullpo_retv( sd );
  2401. int fd = sd->fd;
  2402. if( !session_isActive( fd ) ){
  2403. return;
  2404. }
  2405. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2406. if( fail ){
  2407. p = {};
  2408. }else{
  2409. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2410. return;
  2411. }
  2412. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2413. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2414. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2415. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2416. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2417. p.location = pc_equippoint(sd,n);
  2418. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2419. #if PACKETVER >= 20061218
  2420. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2421. #if PACKETVER >= 20071002
  2422. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2423. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2424. */
  2425. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2426. #if PACKETVER >= 20150226
  2427. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2428. #if PACKETVER >= 20160921
  2429. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2430. p.look = sd->inventory_data[n]->look;
  2431. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2432. p.enchantgrade = sd->inventory.u.items_inventory[n].enchantgrade;
  2433. #endif
  2434. #endif
  2435. #endif
  2436. #endif
  2437. #endif
  2438. }
  2439. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2440. p.Index = client_index( n );
  2441. p.count = amount;
  2442. p.result = fail;
  2443. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2444. }
  2445. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2446. /// 00af <index>.W <amount>.W
  2447. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2448. {
  2449. int fd;
  2450. nullpo_retv(sd);
  2451. fd=sd->fd;
  2452. WFIFOHEAD(fd, packet_len(0xaf));
  2453. WFIFOW(fd,0)=0xaf;
  2454. WFIFOW(fd,2)=n+2;
  2455. WFIFOW(fd,4)=amount;
  2456. WFIFOSET(fd,packet_len(0xaf));
  2457. }
  2458. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2459. /// 07fa <delete type>.W <index>.W <amount>.W
  2460. /// delete type:
  2461. /// 0 = Normal
  2462. /// 1 = Item used for a skill
  2463. /// 2 = Refine failed
  2464. /// 3 = Material changed
  2465. /// 4 = Moved to storage
  2466. /// 5 = Moved to cart
  2467. /// 6 = Item sold
  2468. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2469. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2470. {
  2471. #if PACKETVER < 20091117
  2472. clif_dropitem(sd,n,amount);
  2473. #else
  2474. int fd;
  2475. nullpo_retv(sd);
  2476. fd=sd->fd;
  2477. WFIFOHEAD(fd, packet_len(0x7fa));
  2478. WFIFOW(fd,0)=0x7fa;
  2479. WFIFOW(fd,2)=reason;
  2480. WFIFOW(fd,4)=n+2;
  2481. WFIFOW(fd,6)=amount;
  2482. WFIFOSET(fd,packet_len(0x7fa));
  2483. #endif
  2484. }
  2485. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2486. nullpo_retv( p );
  2487. nullpo_retv( it );
  2488. nullpo_retv( id );
  2489. p->index = idx;
  2490. p->ITID = client_nameid( it->nameid );
  2491. p->type = itemtype( it->nameid );
  2492. #if PACKETVER < 20120925
  2493. p->IsIdentified = it->identify ? 1 : 0;
  2494. #endif
  2495. p->location = eqp_pos;
  2496. p->WearState = it->equip;
  2497. #if PACKETVER < 20120925
  2498. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2499. #endif
  2500. p->RefiningLevel = it->refine;
  2501. clif_addcards( &p->slot, it );
  2502. #if PACKETVER >= 20071002
  2503. p->HireExpireDate = it->expire_time;
  2504. #endif
  2505. #if PACKETVER >= 20080102
  2506. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2507. #endif
  2508. #if PACKETVER >= 20100629
  2509. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2510. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2511. #endif
  2512. #if PACKETVER >= 20120925
  2513. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2514. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2515. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2516. p->Flag.SpareBits = 0;
  2517. #endif
  2518. #if PACKETVER >= 20150226
  2519. p->option_count = clif_add_random_options( p->option_data, it );
  2520. #endif
  2521. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2522. p->enchantgrade = it->enchantgrade;
  2523. #endif
  2524. }
  2525. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2526. nullpo_retv(p);
  2527. nullpo_retv(i);
  2528. nullpo_retv(id);
  2529. p->index = idx;
  2530. p->ITID = client_nameid( i->nameid );
  2531. p->type = itemtype( i->nameid );
  2532. #if PACKETVER < 20120925
  2533. p->IsIdentified = i->identify ? 1 : 0;
  2534. #endif
  2535. p->count = i->amount;
  2536. p->WearState = id->equip;
  2537. #if PACKETVER >= 5
  2538. clif_addcards( &p->slot, i );
  2539. #endif
  2540. #if PACKETVER >= 20080102
  2541. p->HireExpireDate = i->expire_time;
  2542. #endif
  2543. #if PACKETVER >= 20120925
  2544. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2545. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2546. p->Flag.SpareBits = 0;
  2547. #endif
  2548. }
  2549. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2550. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2551. nullpo_retv(sd);
  2552. nullpo_retv(name);
  2553. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2554. memset(buf, 0, sizeof(buf));
  2555. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2556. p->packetType = HEADER_ZC_INVENTORY_START;
  2557. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2558. p->invType = type;
  2559. #endif
  2560. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2561. int strLen = (int)safestrnlen(name, 24) + 1;
  2562. if (strLen > 24)
  2563. strLen = 24;
  2564. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2565. p->packetLength = len;
  2566. safestrncpy(p->name, name, strLen);
  2567. #else
  2568. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2569. safestrncpy(p->name, name, NAME_LENGTH);
  2570. #endif
  2571. clif_send( p, len, &sd->bl, SELF );
  2572. #endif
  2573. }
  2574. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2575. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2576. nullpo_retv(sd);
  2577. struct PACKET_ZC_INVENTORY_END p;
  2578. p.packetType = HEADER_ZC_INVENTORY_END;
  2579. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2580. p.invType = type;
  2581. #endif
  2582. p.flag = 0;
  2583. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2584. #endif
  2585. }
  2586. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2587. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2588. void clif_inventorylist( struct map_session_data *sd ){
  2589. nullpo_retv( sd );
  2590. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2591. e_inventory_type type = INVTYPE_INVENTORY;
  2592. clif_inventoryStart( sd, type, "" );
  2593. #endif
  2594. static struct packet_itemlist_normal itemlist_normal;
  2595. static struct packet_itemlist_equip itemlist_equip;
  2596. int equip = 0;
  2597. int normal = 0;
  2598. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2599. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2600. continue;
  2601. }
  2602. // Non-stackable (Equippable)
  2603. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2604. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2605. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2606. itemlist_equip.PacketType = inventorylistequipType;
  2607. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2608. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2609. itemlist_equip.invType = type;
  2610. #endif
  2611. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2612. equip = 0;
  2613. }
  2614. // Stackable (Normal)
  2615. }else{
  2616. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2617. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2618. itemlist_normal.PacketType = inventorylistnormalType;
  2619. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2620. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2621. itemlist_normal.invType = type;
  2622. #endif
  2623. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2624. normal = 0;
  2625. }
  2626. }
  2627. }
  2628. if( normal ){
  2629. itemlist_normal.PacketType = inventorylistnormalType;
  2630. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2631. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2632. itemlist_normal.invType = type;
  2633. #endif
  2634. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2635. }
  2636. if( sd->equip_index[EQI_AMMO] >= 0 )
  2637. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2638. if( equip ) {
  2639. itemlist_equip.PacketType = inventorylistequipType;
  2640. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2641. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2642. itemlist_equip.invType = type;
  2643. #endif
  2644. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2645. }
  2646. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2647. clif_inventoryEnd( sd, type );
  2648. #endif
  2649. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2650. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2651. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2652. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2653. continue;
  2654. if ( sd->inventory.u.items_inventory[i].favorite )
  2655. clif_favorite_item(sd, i);
  2656. }
  2657. #endif
  2658. }
  2659. //Required when items break/get-repaired. Only sends equippable item list.
  2660. void clif_equiplist( struct map_session_data *sd ){
  2661. // TODO: implement again => only send equip part
  2662. clif_inventorylist( sd );
  2663. }
  2664. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2665. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2666. e_inventory_type type = INVTYPE_STORAGE;
  2667. clif_inventoryStart( sd, type, storename );
  2668. #endif
  2669. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2670. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2671. int equip = 0;
  2672. int normal = 0;
  2673. for( int i = 0; i < items_length; i++ ){
  2674. if( items[i].nameid == 0 ){
  2675. continue;
  2676. }
  2677. struct item_data* id = itemdb_search( items[i].nameid );
  2678. // Non-stackable (Equippable)
  2679. if( !itemdb_isstackable2( id ) ){
  2680. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2681. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2682. storage_itemlist_equip.PacketType = storageListEquipType;
  2683. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2684. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2685. storage_itemlist_equip.invType = type;
  2686. #elif PACKETVER >= 20120925
  2687. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2688. #endif
  2689. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2690. equip = 0;
  2691. }
  2692. // Stackable (Normal)
  2693. }else{
  2694. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2695. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2696. storage_itemlist_normal.PacketType = storageListNormalType;
  2697. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2698. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2699. storage_itemlist_normal.invType = type;
  2700. #elif PACKETVER >= 20120925
  2701. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2702. #endif
  2703. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2704. normal = 0;
  2705. }
  2706. }
  2707. }
  2708. if( normal ){
  2709. storage_itemlist_normal.PacketType = storageListNormalType;
  2710. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2711. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2712. storage_itemlist_normal.invType = type;
  2713. #elif PACKETVER >= 20120925
  2714. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2715. #endif
  2716. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2717. }
  2718. if( equip ) {
  2719. storage_itemlist_equip.PacketType = storageListEquipType;
  2720. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2721. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2722. storage_itemlist_equip.invType = type;
  2723. #elif PACKETVER >= 20120925
  2724. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2725. #endif
  2726. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2727. }
  2728. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2729. clif_inventoryEnd( sd, type );
  2730. #endif
  2731. }
  2732. void clif_cartlist( struct map_session_data *sd ){
  2733. nullpo_retv( sd );
  2734. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2735. e_inventory_type type = INVTYPE_CART;
  2736. clif_inventoryStart( sd, type, "" );
  2737. #endif
  2738. static struct packet_itemlist_normal itemlist_normal;
  2739. static struct packet_itemlist_equip itemlist_equip;
  2740. int normal = 0;
  2741. int equip = 0;
  2742. for( int i = 0; i < MAX_CART; i++ ){
  2743. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2744. continue;
  2745. }
  2746. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2747. // Non-stackable (Equippable)
  2748. if( !itemdb_isstackable2(id) ){
  2749. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2750. // Stackable (Normal)
  2751. }else{
  2752. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2753. }
  2754. }
  2755. if( normal ){
  2756. itemlist_normal.PacketType = cartlistnormalType;
  2757. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2758. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2759. itemlist_normal.invType = type;
  2760. #endif
  2761. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2762. }
  2763. if( equip ){
  2764. itemlist_equip.PacketType = cartlistequipType;
  2765. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2766. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2767. itemlist_equip.invType = type;
  2768. #endif
  2769. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2770. }
  2771. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2772. clif_inventoryEnd( sd, type );
  2773. #endif
  2774. }
  2775. /// Removes cart (ZC_CARTOFF).
  2776. /// 012b
  2777. /// Client behaviour:
  2778. /// Closes the cart storage and removes all it's items from memory.
  2779. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2780. void clif_clearcart(int fd)
  2781. {
  2782. WFIFOHEAD(fd, packet_len(0x12b));
  2783. WFIFOW(fd,0) = 0x12b;
  2784. WFIFOSET(fd, packet_len(0x12b));
  2785. }
  2786. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2787. /// 01eb <account id>.L <x>.W <y>.W
  2788. void clif_guild_xy(struct map_session_data *sd)
  2789. {
  2790. unsigned char buf[10];
  2791. nullpo_retv(sd);
  2792. WBUFW(buf,0)=0x1eb;
  2793. WBUFL(buf,2)=sd->status.account_id;
  2794. WBUFW(buf,6)=sd->bl.x;
  2795. WBUFW(buf,8)=sd->bl.y;
  2796. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2797. }
  2798. /*==========================================
  2799. * Sends x/y dot to a single fd. [Skotlex]
  2800. *------------------------------------------*/
  2801. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2802. {
  2803. if( sd->bg_id )
  2804. return;
  2805. WFIFOHEAD(fd,packet_len(0x1eb));
  2806. WFIFOW(fd,0)=0x1eb;
  2807. WFIFOL(fd,2)=sd->status.account_id;
  2808. WFIFOW(fd,6)=sd->bl.x;
  2809. WFIFOW(fd,8)=sd->bl.y;
  2810. WFIFOSET(fd,packet_len(0x1eb));
  2811. }
  2812. // Guild XY locators [Valaris]
  2813. void clif_guild_xy_remove(struct map_session_data *sd)
  2814. {
  2815. unsigned char buf[10];
  2816. nullpo_retv(sd);
  2817. WBUFW(buf,0)=0x1eb;
  2818. WBUFL(buf,2)=sd->status.account_id;
  2819. WBUFW(buf,6)=-1;
  2820. WBUFW(buf,8)=-1;
  2821. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2822. }
  2823. /*==========================================
  2824. *
  2825. *------------------------------------------*/
  2826. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2827. {
  2828. struct map_session_data *sd, *tsd;
  2829. #if PACKETVER < 20100126
  2830. const int cmd = 0x106;
  2831. #else
  2832. const int cmd = 0x80e;
  2833. #endif
  2834. sd = va_arg(ap, struct map_session_data *);
  2835. tsd = (TBL_PC *)bl;
  2836. nullpo_ret(sd);
  2837. nullpo_ret(tsd);
  2838. if( !session_isActive(tsd->fd) || tsd == sd )
  2839. return 0;
  2840. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2841. return 0;
  2842. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2843. WFIFOW(tsd->fd,0) = cmd;
  2844. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2845. #if PACKETVER < 20100126
  2846. if( sd->battle_status.max_hp > INT16_MAX )
  2847. { //To correctly display the %hp bar. [Skotlex]
  2848. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2849. WFIFOW(tsd->fd,8) = 100;
  2850. } else {
  2851. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2852. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2853. }
  2854. #else
  2855. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2856. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2857. #endif
  2858. WFIFOSET(tsd->fd,packet_len(cmd));
  2859. return 0;
  2860. }
  2861. /*==========================================
  2862. * Server tells all players that are allowed to view HP bars
  2863. * and are nearby 'sd' that 'sd' hp bar was updated.
  2864. *------------------------------------------*/
  2865. static int clif_hpmeter(struct map_session_data *sd)
  2866. {
  2867. nullpo_ret(sd);
  2868. map_foreachinallarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2869. return 0;
  2870. }
  2871. /**
  2872. * Send HP bar update to others.
  2873. * @param sd: Player invoking update
  2874. */
  2875. void clif_update_hp(map_session_data &sd) {
  2876. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2877. clif_hpmeter(&sd);
  2878. if (!battle_config.party_hp_mode && sd.status.party_id)
  2879. clif_party_hp(&sd);
  2880. if (sd.bg_id)
  2881. clif_bg_hp(&sd);
  2882. }
  2883. /// Notifies client of a character parameter change.
  2884. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2885. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2886. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2887. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2888. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2889. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2890. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2891. /// TODO: Extract individual packets.
  2892. /// FIXME: Packet lengths from packet_len(cmd)
  2893. void clif_updatestatus(struct map_session_data *sd,int type)
  2894. {
  2895. int fd,len=8;
  2896. nullpo_retv(sd);
  2897. fd=sd->fd;
  2898. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2899. return;
  2900. WFIFOHEAD(fd, 14);
  2901. WFIFOW(fd,0)=0xb0;
  2902. WFIFOW(fd,2)=type;
  2903. switch(type){
  2904. // 00b0
  2905. case SP_WEIGHT:
  2906. pc_updateweightstatus(sd);
  2907. WFIFOHEAD(fd,14);
  2908. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2909. WFIFOW(fd,2)=type;
  2910. WFIFOL(fd,4)=sd->weight;
  2911. break;
  2912. case SP_MAXWEIGHT:
  2913. WFIFOL(fd,4)=sd->max_weight;
  2914. break;
  2915. case SP_SPEED:
  2916. WFIFOL(fd,4)=sd->battle_status.speed;
  2917. break;
  2918. case SP_BASELEVEL:
  2919. WFIFOL(fd,4)=sd->status.base_level;
  2920. break;
  2921. case SP_JOBLEVEL:
  2922. WFIFOL(fd,4)=sd->status.job_level;
  2923. break;
  2924. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2925. WFIFOL(fd,4)=sd->status.karma;
  2926. break;
  2927. case SP_MANNER:
  2928. WFIFOL(fd,4)=sd->status.manner;
  2929. break;
  2930. case SP_STATUSPOINT:
  2931. WFIFOL(fd,4)=sd->status.status_point;
  2932. break;
  2933. case SP_SKILLPOINT:
  2934. WFIFOL(fd,4)=sd->status.skill_point;
  2935. break;
  2936. case SP_HIT:
  2937. WFIFOL(fd,4)=sd->battle_status.hit;
  2938. break;
  2939. case SP_FLEE1:
  2940. WFIFOL(fd,4)=sd->battle_status.flee;
  2941. break;
  2942. case SP_FLEE2:
  2943. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2944. break;
  2945. case SP_MAXHP:
  2946. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2947. break;
  2948. case SP_MAXSP:
  2949. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2950. break;
  2951. case SP_HP:
  2952. // On officials the HP never go below 1, even if you die [Lemongrass]
  2953. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2954. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2955. break;
  2956. case SP_SP:
  2957. WFIFOL(fd,4)=sd->battle_status.sp;
  2958. break;
  2959. case SP_ASPD:
  2960. WFIFOL(fd,4)=sd->battle_status.amotion;
  2961. break;
  2962. case SP_ATK1:
  2963. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2964. break;
  2965. case SP_DEF1:
  2966. WFIFOL(fd,4)=pc_leftside_def(sd);
  2967. break;
  2968. case SP_MDEF1:
  2969. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2970. break;
  2971. case SP_ATK2:
  2972. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2973. break;
  2974. case SP_DEF2:
  2975. WFIFOL(fd,4)=pc_rightside_def(sd);
  2976. break;
  2977. case SP_MDEF2: {
  2978. //negative check (in case you have something like Berserk active)
  2979. int mdef2 = pc_rightside_mdef(sd);
  2980. WFIFOL(fd,4)=
  2981. #ifndef RENEWAL
  2982. ( mdef2 < 0 ) ? 0 :
  2983. #endif
  2984. mdef2;
  2985. }
  2986. break;
  2987. case SP_CRITICAL:
  2988. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2989. break;
  2990. case SP_MATK1:
  2991. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2992. break;
  2993. case SP_MATK2:
  2994. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2995. break;
  2996. case SP_ZENY:
  2997. WFIFOW(fd,0)=0xb1;
  2998. WFIFOL(fd,4)=sd->status.zeny;
  2999. break;
  3000. #if PACKETVER >= 20170830
  3001. case SP_BASEEXP:
  3002. WFIFOW(fd,0)=0xacb;
  3003. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  3004. len = packet_len(0xacb);
  3005. break;
  3006. case SP_JOBEXP:
  3007. WFIFOW(fd,0)=0xacb;
  3008. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  3009. len = packet_len(0xacb);
  3010. break;
  3011. case SP_NEXTBASEEXP:
  3012. WFIFOW(fd,0)=0xacb;
  3013. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3014. len = packet_len(0xacb);
  3015. break;
  3016. case SP_NEXTJOBEXP:
  3017. WFIFOW(fd,0)=0xacb;
  3018. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3019. len = packet_len(0xacb);
  3020. break;
  3021. #else
  3022. case SP_BASEEXP:
  3023. WFIFOW(fd,0)=0xb1;
  3024. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3025. break;
  3026. case SP_JOBEXP:
  3027. WFIFOW(fd,0)=0xb1;
  3028. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3029. break;
  3030. case SP_NEXTBASEEXP:
  3031. WFIFOW(fd,0)=0xb1;
  3032. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3033. break;
  3034. case SP_NEXTJOBEXP:
  3035. WFIFOW(fd,0)=0xb1;
  3036. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3037. break;
  3038. #endif
  3039. /**
  3040. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3041. **/
  3042. case SP_USTR:
  3043. case SP_UAGI:
  3044. case SP_UVIT:
  3045. case SP_UINT:
  3046. case SP_UDEX:
  3047. case SP_ULUK:
  3048. WFIFOW(fd,0)=0xbe;
  3049. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3050. len=5;
  3051. break;
  3052. /**
  3053. * Tells the client how far it is allowed to attack (weapon range)
  3054. **/
  3055. case SP_ATTACKRANGE:
  3056. WFIFOW(fd,0)=0x13a;
  3057. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3058. len=4;
  3059. break;
  3060. case SP_STR:
  3061. WFIFOW(fd,0)=0x141;
  3062. WFIFOL(fd,2)=type;
  3063. WFIFOL(fd,6)=sd->status.str;
  3064. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3065. len=14;
  3066. break;
  3067. case SP_AGI:
  3068. WFIFOW(fd,0)=0x141;
  3069. WFIFOL(fd,2)=type;
  3070. WFIFOL(fd,6)=sd->status.agi;
  3071. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3072. len=14;
  3073. break;
  3074. case SP_VIT:
  3075. WFIFOW(fd,0)=0x141;
  3076. WFIFOL(fd,2)=type;
  3077. WFIFOL(fd,6)=sd->status.vit;
  3078. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3079. len=14;
  3080. break;
  3081. case SP_INT:
  3082. WFIFOW(fd,0)=0x141;
  3083. WFIFOL(fd,2)=type;
  3084. WFIFOL(fd,6)=sd->status.int_;
  3085. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3086. len=14;
  3087. break;
  3088. case SP_DEX:
  3089. WFIFOW(fd,0)=0x141;
  3090. WFIFOL(fd,2)=type;
  3091. WFIFOL(fd,6)=sd->status.dex;
  3092. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3093. len=14;
  3094. break;
  3095. case SP_LUK:
  3096. WFIFOW(fd,0)=0x141;
  3097. WFIFOL(fd,2)=type;
  3098. WFIFOL(fd,6)=sd->status.luk;
  3099. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3100. len=14;
  3101. break;
  3102. case SP_CARTINFO:
  3103. WFIFOW(fd,0)=0x121;
  3104. WFIFOW(fd,2)=sd->cart_num;
  3105. WFIFOW(fd,4)=MAX_CART;
  3106. WFIFOL(fd,6)=sd->cart_weight;
  3107. WFIFOL(fd,10)=sd->cart_weight_max;
  3108. len=14;
  3109. break;
  3110. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3111. case SP_AP:
  3112. WFIFOL(fd, 4) = sd->battle_status.ap;
  3113. break;
  3114. case SP_TRAITPOINT:
  3115. WFIFOL(fd, 4) = sd->status.trait_point;
  3116. break;
  3117. case SP_MAXAP:
  3118. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3119. break;
  3120. case SP_POW:
  3121. WFIFOW(fd, 0) = 0x141;
  3122. WFIFOL(fd, 2) = type;
  3123. WFIFOL(fd, 6) = sd->status.pow;
  3124. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3125. len = 14;
  3126. break;
  3127. case SP_STA:
  3128. WFIFOW(fd, 0) = 0x141;
  3129. WFIFOL(fd, 2) = type;
  3130. WFIFOL(fd, 6) = sd->status.sta;
  3131. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3132. len = 14;
  3133. break;
  3134. case SP_WIS:
  3135. WFIFOW(fd, 0) = 0x141;
  3136. WFIFOL(fd, 2) = type;
  3137. WFIFOL(fd, 6) = sd->status.wis;
  3138. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3139. len = 14;
  3140. break;
  3141. case SP_SPL:
  3142. WFIFOW(fd, 0) = 0x141;
  3143. WFIFOL(fd, 2) = type;
  3144. WFIFOL(fd, 6) = sd->status.spl;
  3145. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3146. len = 14;
  3147. break;
  3148. case SP_CON:
  3149. WFIFOW(fd, 0) = 0x141;
  3150. WFIFOL(fd, 2) = type;
  3151. WFIFOL(fd, 6) = sd->status.con;
  3152. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3153. len = 14;
  3154. break;
  3155. case SP_CRT:
  3156. WFIFOW(fd, 0) = 0x141;
  3157. WFIFOL(fd, 2) = type;
  3158. WFIFOL(fd, 6) = sd->status.crt;
  3159. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3160. len = 14;
  3161. break;
  3162. case SP_UPOW:
  3163. case SP_USTA:
  3164. case SP_UWIS:
  3165. case SP_USPL:
  3166. case SP_UCON:
  3167. case SP_UCRT:
  3168. WFIFOW(fd, 0) = 0xbe;
  3169. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3170. len = 5;
  3171. break;
  3172. case SP_PATK:
  3173. WFIFOL(fd, 4) = sd->battle_status.patk;
  3174. break;
  3175. case SP_SMATK:
  3176. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3177. break;
  3178. case SP_RES:
  3179. WFIFOL(fd, 4) = sd->battle_status.res;
  3180. break;
  3181. case SP_MRES:
  3182. WFIFOL(fd, 4) = sd->battle_status.mres;
  3183. break;
  3184. case SP_HPLUS:
  3185. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3186. break;
  3187. case SP_CRATE:
  3188. WFIFOL(fd, 4) = sd->battle_status.crate;
  3189. break;
  3190. #else
  3191. case SP_AP:
  3192. case SP_TRAITPOINT:
  3193. case SP_MAXAP:
  3194. case SP_POW:
  3195. case SP_STA:
  3196. case SP_WIS:
  3197. case SP_SPL:
  3198. case SP_CON:
  3199. case SP_CRT:
  3200. case SP_UPOW:
  3201. case SP_USTA:
  3202. case SP_UWIS:
  3203. case SP_USPL:
  3204. case SP_UCON:
  3205. case SP_UCRT:
  3206. case SP_PATK:
  3207. case SP_SMATK:
  3208. case SP_RES:
  3209. case SP_MRES:
  3210. case SP_HPLUS:
  3211. case SP_CRATE:
  3212. // 4th job status are not supported by older clients
  3213. return;
  3214. #endif
  3215. default:
  3216. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3217. return;
  3218. }
  3219. WFIFOSET(fd,len);
  3220. // Additional update packets that should be sent right after
  3221. switch( type ){
  3222. case SP_BASELEVEL:
  3223. if( sd->status.party_id ){
  3224. struct party_data* p;
  3225. int i;
  3226. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3227. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3228. if( i < MAX_PARTY ){
  3229. p->party.member[i].lv = sd->status.base_level;
  3230. clif_party_job_and_level(sd);
  3231. }
  3232. }
  3233. }
  3234. break;
  3235. case SP_HP:
  3236. clif_update_hp(*sd);
  3237. break;
  3238. }
  3239. }
  3240. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3241. /// 01ab <account id>.L <var id>.W <value>.L
  3242. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3243. {
  3244. unsigned char buf[12];
  3245. nullpo_retv(sd);
  3246. WBUFW(buf,0)=0x1ab;
  3247. WBUFL(buf,2)=sd->bl.id;
  3248. WBUFW(buf,6)=type;
  3249. switch(type)
  3250. {
  3251. case SP_MANNER:
  3252. WBUFL(buf,8)=val;
  3253. break;
  3254. default:
  3255. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3256. return;
  3257. }
  3258. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3259. }
  3260. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3261. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3262. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3263. struct PACKET_ZC_SPRITE_CHANGE p;
  3264. p.packetType = sendLookType;
  3265. p.AID = id;
  3266. p.type = type;
  3267. p.val = val;
  3268. #if PACKETVER >= 4
  3269. p.val2 = val2;
  3270. #endif
  3271. clif_send( &p, sizeof( p ), bl, target );
  3272. }
  3273. /// Updates sprite/style properties of an object.
  3274. void clif_changelook(struct block_list *bl, int type, int val) {
  3275. struct map_session_data* sd;
  3276. struct status_change* sc;
  3277. struct view_data* vd;
  3278. enum send_target target = AREA;
  3279. int val2 = 0;
  3280. nullpo_retv(bl);
  3281. sd = BL_CAST(BL_PC, bl);
  3282. sc = status_get_sc(bl);
  3283. vd = status_get_viewdata(bl);
  3284. if( vd ) //temp hack to let Warp Portal change appearance
  3285. switch(type) {
  3286. case LOOK_WEAPON:
  3287. if (sd) {
  3288. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3289. val = vd->weapon;
  3290. }
  3291. else
  3292. vd->weapon = val;
  3293. break;
  3294. case LOOK_SHIELD:
  3295. if (sd) {
  3296. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3297. val = vd->shield;
  3298. }
  3299. else
  3300. vd->shield = val;
  3301. break;
  3302. case LOOK_BASE:
  3303. if (!sd)
  3304. break;
  3305. if ( val == JT_INVISIBLE )
  3306. return;
  3307. if (sd->sc.option&OPTION_COSTUME)
  3308. vd->weapon = vd->shield = 0;
  3309. if (!vd->cloth_color)
  3310. break;
  3311. if (sd) {
  3312. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3313. vd->cloth_color = 0;
  3314. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3315. vd->cloth_color = 0;
  3316. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3317. vd->cloth_color = 0;
  3318. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3319. vd->cloth_color = 0;
  3320. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3321. vd->cloth_color = 0;
  3322. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3323. vd->body_style = 0;
  3324. }
  3325. break;
  3326. case LOOK_HAIR:
  3327. vd->hair_style = val;
  3328. break;
  3329. case LOOK_HEAD_BOTTOM:
  3330. vd->head_bottom = val;
  3331. break;
  3332. case LOOK_HEAD_TOP:
  3333. vd->head_top = val;
  3334. break;
  3335. case LOOK_HEAD_MID:
  3336. vd->head_mid = val;
  3337. break;
  3338. case LOOK_HAIR_COLOR:
  3339. vd->hair_color = val;
  3340. break;
  3341. case LOOK_CLOTHES_COLOR:
  3342. if (val && sd) {
  3343. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3344. val = 0;
  3345. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3346. val = 0;
  3347. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3348. val = 0;
  3349. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3350. val = 0;
  3351. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3352. val = 0;
  3353. }
  3354. vd->cloth_color = val;
  3355. break;
  3356. case LOOK_SHOES:
  3357. #if PACKETVER > 3
  3358. if (sd) {
  3359. int n;
  3360. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3361. if(sd->inventory_data[n]->view_id > 0)
  3362. val = sd->inventory_data[n]->view_id;
  3363. else
  3364. val = sd->inventory.u.items_inventory[n].nameid;
  3365. } else
  3366. val = 0;
  3367. }
  3368. #endif
  3369. //Shoes? No packet uses this....
  3370. break;
  3371. case LOOK_BODY:
  3372. // unknown purpose
  3373. break;
  3374. case LOOK_ROBE:
  3375. #if PACKETVER < 20110111
  3376. return;
  3377. #else
  3378. vd->robe = val;
  3379. #endif
  3380. break;
  3381. case LOOK_BODY2:
  3382. #if PACKETVER < 20150513
  3383. return;
  3384. #else
  3385. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3386. val = 0;
  3387. vd->body_style = val;
  3388. #endif
  3389. break;
  3390. }
  3391. // prevent leaking the presence of GM-hidden objects
  3392. if( sc && sc->option&OPTION_INVISIBLE )
  3393. target = SELF;
  3394. #if PACKETVER < 4
  3395. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3396. #else
  3397. if (bl->type != BL_NPC) {
  3398. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3399. type = LOOK_WEAPON;
  3400. val = (vd ? vd->weapon : 0);
  3401. val2 = (vd ? vd->shield : 0);
  3402. }
  3403. if (disguised(bl)) {
  3404. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3405. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3406. } else
  3407. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3408. } else
  3409. unit_refresh(bl);
  3410. #endif
  3411. }
  3412. //Sends a change-base-look packet required for traps as they are triggered.
  3413. void clif_changetraplook(struct block_list *bl,int val) {
  3414. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3415. }
  3416. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3417. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3418. clif_sprite_change(bl, id, type, val, 0, target);
  3419. }
  3420. /// Character status (ZC_STATUS).
  3421. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3422. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3423. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3424. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3425. void clif_initialstatus(struct map_session_data *sd) {
  3426. int fd, mdef2;
  3427. unsigned char *buf;
  3428. nullpo_retv(sd);
  3429. fd=sd->fd;
  3430. WFIFOHEAD(fd, packet_len(0xbd));
  3431. buf = WFIFOP(fd,0);
  3432. WBUFW(buf,0) = 0xbd;
  3433. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3434. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3435. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3436. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3437. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3438. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3439. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3440. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3441. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3442. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3443. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3444. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3445. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3446. WBUFW(buf,16) = pc_leftside_atk(sd);
  3447. WBUFW(buf,18) = pc_rightside_atk(sd);
  3448. WBUFW(buf,20) = pc_rightside_matk(sd);
  3449. WBUFW(buf,22) = pc_leftside_matk(sd);
  3450. WBUFW(buf,24) = pc_leftside_def(sd);
  3451. WBUFW(buf,26) = pc_rightside_def(sd);
  3452. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3453. mdef2 = pc_rightside_mdef(sd);
  3454. WBUFW(buf,30) =
  3455. #ifndef RENEWAL
  3456. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3457. #endif
  3458. mdef2;
  3459. WBUFW(buf,32) = sd->battle_status.hit;
  3460. WBUFW(buf,34) = sd->battle_status.flee;
  3461. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3462. WBUFW(buf,38) = sd->battle_status.cri/10;
  3463. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3464. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3465. WFIFOSET(fd, packet_len(0xbd));
  3466. clif_updatestatus(sd, SP_STR);
  3467. clif_updatestatus(sd, SP_AGI);
  3468. clif_updatestatus(sd, SP_VIT);
  3469. clif_updatestatus(sd, SP_INT);
  3470. clif_updatestatus(sd, SP_DEX);
  3471. clif_updatestatus(sd, SP_LUK);
  3472. clif_updatestatus(sd, SP_ATTACKRANGE);
  3473. clif_updatestatus(sd, SP_ASPD);
  3474. #ifdef RENEWAL
  3475. clif_updatestatus(sd, SP_POW);
  3476. clif_updatestatus(sd, SP_STA);
  3477. clif_updatestatus(sd, SP_WIS);
  3478. clif_updatestatus(sd, SP_SPL);
  3479. clif_updatestatus(sd, SP_CON);
  3480. clif_updatestatus(sd, SP_CRT);
  3481. clif_updatestatus(sd, SP_PATK);
  3482. clif_updatestatus(sd, SP_SMATK);
  3483. clif_updatestatus(sd, SP_RES);
  3484. clif_updatestatus(sd, SP_MRES);
  3485. clif_updatestatus(sd, SP_HPLUS);
  3486. clif_updatestatus(sd, SP_CRATE);
  3487. clif_updatestatus(sd, SP_TRAITPOINT);
  3488. clif_updatestatus(sd, SP_AP);
  3489. clif_updatestatus(sd, SP_MAXAP);
  3490. clif_updatestatus(sd, SP_UPOW);
  3491. clif_updatestatus(sd, SP_USTA);
  3492. clif_updatestatus(sd, SP_UWIS);
  3493. clif_updatestatus(sd, SP_USPL);
  3494. clif_updatestatus(sd, SP_UCON);
  3495. clif_updatestatus(sd, SP_UCRT);
  3496. #endif
  3497. }
  3498. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3499. /// 013c <index>.W
  3500. void clif_arrowequip(struct map_session_data *sd,int val) {
  3501. int fd;
  3502. nullpo_retv(sd);
  3503. #if PACKETVER >= 20121128
  3504. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3505. #endif
  3506. fd=sd->fd;
  3507. WFIFOHEAD(fd, packet_len(0x013c));
  3508. WFIFOW(fd,0) = 0x013c;
  3509. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3510. WFIFOSET(fd, packet_len(0x013c));
  3511. }
  3512. /// Ammunition action message (ZC_ACTION_FAILURE).
  3513. /// 013b <type>.W
  3514. /// type:
  3515. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3516. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3517. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3518. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3519. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3520. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3521. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3522. int fd;
  3523. nullpo_retv(sd);
  3524. fd=sd->fd;
  3525. WFIFOHEAD(fd, packet_len(0x013b));
  3526. WFIFOW(fd,0) = 0x013b;
  3527. WFIFOW(fd,2) = type;
  3528. WFIFOSET(fd, packet_len(0x013b));
  3529. }
  3530. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3531. /// 01ad <packet len>.W { <name id>.W }*
  3532. void clif_arrow_create_list( struct map_session_data *sd ){
  3533. nullpo_retv( sd );
  3534. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3535. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3536. int count = 0;
  3537. for (const auto &it : skill_arrow_db) {
  3538. t_itemid nameid = it.second->nameid;
  3539. if( !item_db.exists( nameid ) ){
  3540. continue;
  3541. }
  3542. int index = pc_search_inventory( sd, nameid );
  3543. if( index < 0 ){
  3544. continue;
  3545. }
  3546. if( sd->inventory.u.items_inventory[index].equip ){
  3547. continue;
  3548. }
  3549. if( !sd->inventory.u.items_inventory[index].identify ){
  3550. continue;
  3551. }
  3552. p->items[count].itemId = client_nameid( nameid );
  3553. count++;
  3554. }
  3555. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3556. clif_send( p, p->packetLength, &sd->bl, SELF );
  3557. if( count > 0 ){
  3558. sd->menuskill_id = AC_MAKINGARROW;
  3559. sd->menuskill_val = count;
  3560. }
  3561. }
  3562. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3563. /// 00bc <status id>.W <result>.B <value>.B
  3564. /// status id:
  3565. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3566. /// result:
  3567. /// 0 = failure
  3568. /// 1 = success
  3569. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3570. int fd;
  3571. nullpo_retv(sd);
  3572. fd=sd->fd;
  3573. WFIFOHEAD(fd, packet_len(0xbc));
  3574. WFIFOW(fd,0) = 0xbc;
  3575. WFIFOW(fd,2) = type;
  3576. WFIFOB(fd,4) = ok;
  3577. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3578. WFIFOSET(fd, packet_len(0xbc));
  3579. }
  3580. /// Notifies the client about the result of a request to equip an item.
  3581. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3582. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3583. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3584. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3585. /// @ok: //inversed forv2 v5
  3586. /// 0 = failure
  3587. /// 1 = success
  3588. /// 2 = failure due to low level
  3589. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3590. {
  3591. int fd = 0, cmd = 0, look = 0;
  3592. struct s_packet_db *info = NULL;
  3593. nullpo_retv(sd);
  3594. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3595. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3596. return;
  3597. fd = sd->fd;
  3598. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3599. look = sd->inventory_data[n]->look;
  3600. WFIFOHEAD(fd, info->len);
  3601. WFIFOW(fd, 0) = cmd;
  3602. WFIFOW(fd, info->pos[0]) = n+2;
  3603. switch (cmd) {
  3604. case 0xaa:
  3605. WFIFOW(fd, info->pos[1]) = pos;
  3606. #if PACKETVER < 20100629
  3607. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3608. #else
  3609. WFIFOL(fd, info->pos[2]) = look;
  3610. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3611. #endif
  3612. break;
  3613. case 0x8d0:
  3614. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3615. flag = 1;
  3616. case 0x999:
  3617. if (cmd == 0x999)
  3618. WFIFOL(fd, info->pos[1]) = pos;
  3619. else
  3620. WFIFOW(fd, info->pos[1]) = pos;
  3621. WFIFOL(fd, info->pos[2]) = look;
  3622. WFIFOW(fd, info->pos[3]) = flag;
  3623. break;
  3624. }
  3625. WFIFOSET(fd, info->len);
  3626. }
  3627. /// Notifies the client about the result of a request to take off an item.
  3628. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3629. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3630. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3631. /// @ok : //inversed for v2 v5
  3632. /// 0 = failure
  3633. /// 1 = success
  3634. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3635. {
  3636. int fd, header, offs = 0;
  3637. #if PACKETVER >= 20130000
  3638. header = 0x99a;
  3639. ok = ok ? 0 : 1;
  3640. #elif PACKETVER >= 20110824
  3641. header = 0x8d1;
  3642. ok = ok ? 0 : 1;
  3643. #else
  3644. header = 0xac;
  3645. #endif
  3646. nullpo_retv(sd);
  3647. fd=sd->fd;
  3648. WFIFOHEAD(fd, packet_len(header));
  3649. WFIFOW(fd,offs+0) = header;
  3650. WFIFOW(fd,offs+2) = n+2;
  3651. #if PACKETVER >= 20130000
  3652. WFIFOL(fd,offs+4) = pos;
  3653. offs += 2;
  3654. #else
  3655. WFIFOW(fd,offs+4) = pos;
  3656. #endif
  3657. WFIFOB(fd,offs+6) = ok;
  3658. WFIFOSET(fd, packet_len(header));
  3659. }
  3660. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3661. /// 019b <id>.L <effect id>.L
  3662. /// effect id:
  3663. /// 0 = base level up
  3664. /// 1 = job level up
  3665. /// 2 = refine failure
  3666. /// 3 = refine success
  3667. /// 4 = game over
  3668. /// 5 = pharmacy success
  3669. /// 6 = pharmacy failure
  3670. /// 7 = base level up (super novice)
  3671. /// 8 = job level up (super novice)
  3672. /// 9 = base level up (taekwon)
  3673. void clif_misceffect(struct block_list* bl,int type)
  3674. {
  3675. unsigned char buf[32];
  3676. nullpo_retv(bl);
  3677. WBUFW(buf,0) = 0x19b;
  3678. WBUFL(buf,2) = bl->id;
  3679. WBUFL(buf,6) = type;
  3680. clif_send(buf,packet_len(0x19b),bl,AREA);
  3681. }
  3682. /// Notifies clients in the area of a state change.
  3683. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3684. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3685. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3686. nullpo_retv( bl );
  3687. struct status_change* sc = status_get_sc( bl );
  3688. //How can an option change if there's no sc?
  3689. if( sc == nullptr ){
  3690. return;
  3691. }
  3692. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3693. struct PACKET_ZC_STATE_CHANGE p;
  3694. p.packetType = HEADER_ZC_STATE_CHANGE;
  3695. p.AID = bl->id;
  3696. p.bodyState = sc->opt1;
  3697. p.healthState = sc->opt2;
  3698. p.effectState = sc->option;
  3699. p.isPKModeON = sd ? sd->status.karma : false;
  3700. if( target == nullptr ){
  3701. if( disguised( bl ) ){
  3702. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3703. p.AID = disguised_bl_id( p.AID );
  3704. clif_send( &p, sizeof( p ), bl, SELF );
  3705. p.AID = disguised_bl_id( p.AID );
  3706. p.effectState = OPTION_INVISIBLE;
  3707. clif_send( &p, sizeof( p ), bl, SELF );
  3708. }else{
  3709. clif_send( &p, sizeof( p ), bl, AREA );
  3710. }
  3711. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3712. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3713. if( sc->data[SC_PROVOKE] ){
  3714. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3715. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3716. }
  3717. }else{
  3718. if( disguised( bl ) ){
  3719. p.AID = disguised_bl_id( p.AID );
  3720. clif_send( &p, sizeof( p ), target, SELF );
  3721. p.AID = disguised_bl_id( p.AID );
  3722. p.effectState = OPTION_INVISIBLE;
  3723. clif_send( &p, sizeof( p ), target, SELF );
  3724. }else{
  3725. clif_send( &p, sizeof( p ), target, SELF );
  3726. }
  3727. }
  3728. }
  3729. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3730. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3731. void clif_changeoption2(struct block_list* bl)
  3732. {
  3733. unsigned char buf[20];
  3734. struct status_change *sc;
  3735. sc = status_get_sc(bl);
  3736. if (!sc) return; //How can an option change if there's no sc?
  3737. WBUFW(buf,0) = 0x28a;
  3738. WBUFL(buf,2) = bl->id;
  3739. WBUFL(buf,6) = sc->option;
  3740. WBUFL(buf,10) = clif_setlevel(bl);
  3741. WBUFL(buf,14) = sc->opt3;
  3742. if(disguised(bl)) {
  3743. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3744. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3745. clif_send(buf,packet_len(0x28a),bl,SELF);
  3746. WBUFL(buf,2) = bl->id;
  3747. WBUFL(buf,6) = OPTION_INVISIBLE;
  3748. clif_send(buf,packet_len(0x28a),bl,SELF);
  3749. } else
  3750. clif_send(buf,packet_len(0x28a),bl,AREA);
  3751. }
  3752. /// Notifies the client about the result of an item use request.
  3753. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3754. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3755. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3756. nullpo_retv( sd );
  3757. int fd = sd->fd;
  3758. if( !session_isActive( fd ) ){
  3759. return;
  3760. }
  3761. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3762. return;
  3763. }
  3764. struct PACKET_ZC_USE_ITEM_ACK p;
  3765. p.packetType = useItemAckType;
  3766. p.index = index + 2;
  3767. #if PACKETVER > 3
  3768. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3769. p.AID = sd->bl.id;
  3770. #endif
  3771. p.amount = amount;
  3772. p.result = ok;
  3773. if( !ok ){
  3774. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3775. }else{
  3776. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3777. }
  3778. }
  3779. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3780. /// 00d6 <flag>.B
  3781. /// flag:
  3782. /// 0 = Room has been successfully created (opens chat room)
  3783. /// 1 = Room limit exceeded
  3784. /// 2 = Same room already exists
  3785. void clif_createchat(struct map_session_data* sd, int flag)
  3786. {
  3787. int fd;
  3788. nullpo_retv(sd);
  3789. fd = sd->fd;
  3790. WFIFOHEAD(fd,packet_len(0xd6));
  3791. WFIFOW(fd,0) = 0xd6;
  3792. WFIFOB(fd,2) = flag;
  3793. WFIFOSET(fd,packet_len(0xd6));
  3794. }
  3795. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3796. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3797. /// type:
  3798. /// 0 = private (password protected)
  3799. /// 1 = public
  3800. /// 2 = arena (npc waiting room)
  3801. /// 3 = PK zone (non-clickable)
  3802. void clif_dispchat(struct chat_data* cd, int fd)
  3803. {
  3804. unsigned char buf[128];
  3805. uint8 type;
  3806. if( cd == NULL || cd->owner == NULL )
  3807. return;
  3808. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3809. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3810. : 1;
  3811. WBUFW(buf, 0) = 0xd7;
  3812. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3813. WBUFL(buf, 4) = cd->owner->id;
  3814. WBUFL(buf, 8) = cd->bl.id;
  3815. WBUFW(buf,12) = cd->limit;
  3816. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3817. WBUFB(buf,16) = type;
  3818. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3819. if( session_isActive(fd) ) {
  3820. WFIFOHEAD(fd,WBUFW(buf,2));
  3821. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3822. WFIFOSET(fd,WBUFW(buf,2));
  3823. } else {
  3824. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3825. }
  3826. }
  3827. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3828. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3829. /// type:
  3830. /// 0 = private (password protected)
  3831. /// 1 = public
  3832. /// 2 = arena (npc waiting room)
  3833. /// 3 = PK zone (non-clickable)
  3834. void clif_changechatstatus(struct chat_data* cd)
  3835. {
  3836. unsigned char buf[128];
  3837. uint8 type;
  3838. if( cd == NULL || cd->usersd[0] == NULL )
  3839. return;
  3840. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3841. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3842. : 1;
  3843. WBUFW(buf, 0) = 0xdf;
  3844. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3845. WBUFL(buf, 4) = cd->owner->id;
  3846. WBUFL(buf, 8) = cd->bl.id;
  3847. WBUFW(buf,12) = cd->limit;
  3848. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3849. WBUFB(buf,16) = type;
  3850. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3851. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3852. }
  3853. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3854. /// 00d8 <chat id>.L
  3855. void clif_clearchat(struct chat_data *cd,int fd)
  3856. {
  3857. unsigned char buf[32];
  3858. nullpo_retv(cd);
  3859. WBUFW(buf,0) = 0xd8;
  3860. WBUFL(buf,2) = cd->bl.id;
  3861. if( session_isActive(fd) ) {
  3862. WFIFOHEAD(fd,packet_len(0xd8));
  3863. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3864. WFIFOSET(fd,packet_len(0xd8));
  3865. } else {
  3866. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3867. }
  3868. }
  3869. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3870. /// 00da <result>.B
  3871. /// result:
  3872. /// 0 = room full
  3873. /// 1 = wrong password
  3874. /// 2 = kicked
  3875. /// 3 = success (no message)
  3876. /// 4 = no enough zeny
  3877. /// 5 = too low level
  3878. /// 6 = too high level
  3879. /// 7 = unsuitable job class
  3880. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3881. {
  3882. int fd;
  3883. nullpo_retv(sd);
  3884. fd = sd->fd;
  3885. WFIFOHEAD(fd,packet_len(0xda));
  3886. WFIFOW(fd,0) = 0xda;
  3887. WFIFOB(fd,2) = flag;
  3888. WFIFOSET(fd,packet_len(0xda));
  3889. }
  3890. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3891. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3892. /// role:
  3893. /// 0 = owner (menu)
  3894. /// 1 = normal
  3895. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3896. {
  3897. int fd;
  3898. int i,t;
  3899. nullpo_retv(sd);
  3900. nullpo_retv(cd);
  3901. fd = sd->fd;
  3902. if (!session_isActive(fd))
  3903. return;
  3904. t = (int)(cd->owner->type == BL_NPC);
  3905. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3906. WFIFOW(fd, 0) = 0xdb;
  3907. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3908. WFIFOL(fd, 4) = cd->bl.id;
  3909. if(cd->owner->type == BL_NPC){
  3910. WFIFOL(fd, 30) = 1;
  3911. WFIFOL(fd, 8) = 0;
  3912. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3913. for (i = 0; i < cd->users; i++) {
  3914. WFIFOL(fd, 8+(i+1)*28) = 1;
  3915. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3916. }
  3917. }else{
  3918. for (i = 0; i < cd->users; i++) {
  3919. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3920. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3921. }
  3922. }
  3923. WFIFOSET(fd, WFIFOW(fd, 2));
  3924. }
  3925. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3926. /// 00dc <users>.W <name>.24B
  3927. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3928. {
  3929. unsigned char buf[29];
  3930. nullpo_retv(sd);
  3931. nullpo_retv(cd);
  3932. WBUFW(buf, 0) = 0xdc;
  3933. WBUFW(buf, 2) = cd->users;
  3934. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3935. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3936. }
  3937. /// Announce the new owner (ZC_ROLE_CHANGE).
  3938. /// 00e1 <role>.L <nick>.24B
  3939. /// role:
  3940. /// 0 = owner (menu)
  3941. /// 1 = normal
  3942. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3943. {
  3944. unsigned char buf[64];
  3945. nullpo_retv(sd);
  3946. nullpo_retv(cd);
  3947. WBUFW(buf, 0) = 0xe1;
  3948. WBUFL(buf, 2) = 1;
  3949. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3950. WBUFW(buf,30) = 0xe1;
  3951. WBUFL(buf,32) = 0;
  3952. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3953. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3954. }
  3955. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3956. /// 00dd <users>.W <nick>.24B <flag>.B
  3957. /// flag:
  3958. /// 0 = left
  3959. /// 1 = kicked
  3960. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3961. {
  3962. unsigned char buf[32];
  3963. nullpo_retv(sd);
  3964. nullpo_retv(cd);
  3965. WBUFW(buf, 0) = 0xdd;
  3966. WBUFW(buf, 2) = cd->users-1;
  3967. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3968. WBUFB(buf,28) = flag;
  3969. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3970. }
  3971. /// Opens a trade request window from char 'name'.
  3972. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3973. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3974. void clif_traderequest(struct map_session_data* sd, const char* name)
  3975. {
  3976. int fd = sd->fd;
  3977. #if PACKETVER < 6
  3978. WFIFOHEAD(fd,packet_len(0xe5));
  3979. WFIFOW(fd,0) = 0xe5;
  3980. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3981. WFIFOSET(fd,packet_len(0xe5));
  3982. #else
  3983. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3984. if( !tsd ) return;
  3985. WFIFOHEAD(fd,packet_len(0x1f4));
  3986. WFIFOW(fd,0) = 0x1f4;
  3987. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3988. WFIFOL(fd,26) = tsd->status.char_id;
  3989. WFIFOW(fd,30) = tsd->status.base_level;
  3990. WFIFOSET(fd,packet_len(0x1f4));
  3991. #endif
  3992. }
  3993. /// Reply to a trade-request.
  3994. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3995. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3996. /// result:
  3997. /// 0 = Char is too far
  3998. /// 1 = Character does not exist
  3999. /// 2 = Trade failed
  4000. /// 3 = Accept
  4001. /// 4 = Cancel
  4002. /// 5 = Busy
  4003. void clif_tradestart(struct map_session_data* sd, uint8 type)
  4004. {
  4005. int fd = sd->fd;
  4006. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  4007. if( PACKETVER < 6 || !tsd ) {
  4008. WFIFOHEAD(fd,packet_len(0xe7));
  4009. WFIFOW(fd,0) = 0xe7;
  4010. WFIFOB(fd,2) = type;
  4011. WFIFOSET(fd,packet_len(0xe7));
  4012. } else {
  4013. WFIFOHEAD(fd,packet_len(0x1f5));
  4014. WFIFOW(fd,0) = 0x1f5;
  4015. WFIFOB(fd,2) = type;
  4016. WFIFOL(fd,3) = tsd->status.char_id;
  4017. WFIFOW(fd,7) = tsd->status.base_level;
  4018. WFIFOSET(fd,packet_len(0x1f5));
  4019. }
  4020. }
  4021. /// Notifies the client about an item from other player in current trade.
  4022. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4023. /// 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)
  4024. /// 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)
  4025. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  4026. nullpo_retv( sd );
  4027. nullpo_retv( tsd );
  4028. int fd = tsd->fd;
  4029. if( !session_isActive( fd ) ){
  4030. return;
  4031. }
  4032. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4033. if( index ){
  4034. index = server_index( index );
  4035. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4036. return;
  4037. }
  4038. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4039. #if PACKETVER >= 20100223
  4040. p.itemType = sd->inventory_data[index]->type;
  4041. #endif
  4042. p.identified = sd->inventory.u.items_inventory[index].identify;
  4043. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4044. p.refine = sd->inventory.u.items_inventory[index].refine;
  4045. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4046. #if PACKETVER >= 20150226
  4047. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  4048. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4049. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4050. p.look = sd->inventory_data[index]->look;
  4051. p.enchantgrade = sd->inventory.u.items_inventory[index].enchantgrade;
  4052. #endif
  4053. #endif
  4054. }else{
  4055. p = {};
  4056. }
  4057. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4058. p.amount = amount;
  4059. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4060. }
  4061. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4062. /// 00ea <index>.W <result>.B
  4063. /// result:
  4064. /// 0 = success
  4065. /// 1 = overweight
  4066. /// 2 = trade canceled
  4067. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  4068. {
  4069. int fd;
  4070. nullpo_retv(sd);
  4071. fd = sd->fd;
  4072. WFIFOHEAD(fd,packet_len(0xea));
  4073. WFIFOW(fd,0) = 0xea;
  4074. WFIFOW(fd,2) = index;
  4075. WFIFOB(fd,4) = fail;
  4076. WFIFOSET(fd,packet_len(0xea));
  4077. }
  4078. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4079. /// 00ec <who>.B
  4080. /// who:
  4081. /// 0 = self
  4082. /// 1 = other player
  4083. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4084. {
  4085. int fd;
  4086. nullpo_retv(sd);
  4087. fd = sd->fd;
  4088. WFIFOHEAD(fd,packet_len(0xec));
  4089. WFIFOW(fd,0) = 0xec;
  4090. WFIFOB(fd,2) = fail;
  4091. WFIFOSET(fd,packet_len(0xec));
  4092. }
  4093. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4094. /// 00ee
  4095. void clif_tradecancelled(struct map_session_data* sd)
  4096. {
  4097. int fd;
  4098. nullpo_retv(sd);
  4099. fd = sd->fd;
  4100. WFIFOHEAD(fd,packet_len(0xee));
  4101. WFIFOW(fd,0) = 0xee;
  4102. WFIFOSET(fd,packet_len(0xee));
  4103. }
  4104. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4105. /// 00f0 <result>.B
  4106. /// result:
  4107. /// 0 = success
  4108. /// 1 = failure
  4109. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4110. {
  4111. int fd;
  4112. nullpo_retv(sd);
  4113. fd = sd->fd;
  4114. WFIFOHEAD(fd,packet_len(0xf0));
  4115. WFIFOW(fd,0) = 0xf0;
  4116. WFIFOB(fd,2) = fail;
  4117. WFIFOSET(fd,packet_len(0xf0));
  4118. }
  4119. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4120. /// 00f1
  4121. /// NOTE: Unknown purpose. Items are not removed until the window is
  4122. /// refreshed (ex. by putting another item in there).
  4123. void clif_tradeundo(struct map_session_data* sd)
  4124. {
  4125. int fd = sd->fd;
  4126. WFIFOHEAD(fd,packet_len(0xf1));
  4127. WFIFOW(fd,0) = 0xf1;
  4128. WFIFOSET(fd,packet_len(0xf1));
  4129. }
  4130. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4131. /// 00f2 <current count>.W <max count>.W
  4132. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4133. {
  4134. int fd;
  4135. nullpo_retv(sd);
  4136. fd=sd->fd;
  4137. WFIFOHEAD(fd,packet_len(0xf2));
  4138. WFIFOW(fd,0) = 0xf2;
  4139. WFIFOW(fd,2) = amount;
  4140. WFIFOW(fd,4) = max_amount;
  4141. WFIFOSET(fd,packet_len(0xf2));
  4142. }
  4143. /// Notifies the client of an item being added to the storage.
  4144. /// 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)
  4145. /// 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)
  4146. /// 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)
  4147. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4148. nullpo_retv( sd );
  4149. nullpo_retv( i );
  4150. int fd = sd->fd;
  4151. if( !session_isActive( fd ) ){
  4152. return;
  4153. }
  4154. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4155. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4156. p.index = client_storage_index( index ); // index
  4157. p.amount = amount; // amount
  4158. p.itemId = client_nameid( i->nameid ); // id
  4159. #if PACKETVER >= 5
  4160. p.itemType = itemtype( i->nameid ); //type
  4161. #endif
  4162. p.identified = i->identify; //identify flag
  4163. p.damaged = i->attribute; // attribute
  4164. p.refine = i->refine; //refine
  4165. clif_addcards( &p.slot, i );
  4166. #if PACKETVER >= 20150226
  4167. clif_add_random_options( p.option_data, i );
  4168. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4169. p.enchantgrade = i->enchantgrade;
  4170. #endif
  4171. #endif
  4172. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4173. }
  4174. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4175. /// 00f6 <index>.W <amount>.L
  4176. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4177. {
  4178. int fd;
  4179. nullpo_retv(sd);
  4180. fd=sd->fd;
  4181. WFIFOHEAD(fd,packet_len(0xf6));
  4182. WFIFOW(fd,0)=0xf6; // Storage item removed
  4183. WFIFOW(fd,2)=client_storage_index(index);
  4184. WFIFOL(fd,4)=amount;
  4185. WFIFOSET(fd,packet_len(0xf6));
  4186. }
  4187. /// Closes storage (ZC_CLOSE_STORE).
  4188. /// 00f8
  4189. void clif_storageclose(struct map_session_data* sd)
  4190. {
  4191. int fd;
  4192. nullpo_retv(sd);
  4193. fd=sd->fd;
  4194. WFIFOHEAD(fd,packet_len(0xf8));
  4195. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4196. WFIFOSET(fd,packet_len(0xf8));
  4197. }
  4198. /// Notifies clients in an area of a player's souls.
  4199. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4200. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4201. /// 0b73 <id>.L <amount>.W
  4202. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4203. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4204. struct PACKET_ZC_UNCONFIRMED_SPIRITS3 p = {};
  4205. p.packetType = HEADER_ZC_UNCONFIRMED_SPIRITS3;
  4206. #else
  4207. struct PACKET_ZC_SPIRITS p = {};
  4208. p.packetType = HEADER_ZC_SPIRITS;
  4209. #endif
  4210. p.GID = sd->bl.id;
  4211. p.amount = sd->soulball;
  4212. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4213. }
  4214. /*==========================================
  4215. * Server tells 'sd' player client the abouts of 'dstsd' player
  4216. *------------------------------------------*/
  4217. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4218. {
  4219. struct block_list *d_bl;
  4220. int i;
  4221. if( dstsd->chatID ) {
  4222. struct chat_data *cd = NULL;
  4223. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4224. clif_dispchat(cd,sd->fd);
  4225. } else if( dstsd->state.vending )
  4226. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4227. else if( dstsd->state.buyingstore )
  4228. clif_buyingstore_entry_single(sd, dstsd);
  4229. if(dstsd->spiritball > 0)
  4230. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4231. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4232. clif_millenniumshield_single(sd->fd, dstsd);
  4233. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4234. clif_spiritcharm_single(sd->fd, dstsd);
  4235. if (dstsd->soulball > 0)
  4236. clif_soulball( dstsd, &sd->bl, SELF );
  4237. if (dstsd->servantball > 0)
  4238. clif_servantball( *dstsd, &sd->bl, SELF );
  4239. if (dstsd->abyssball > 0)
  4240. clif_abyssball( *dstsd, &sd->bl, SELF );
  4241. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4242. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4243. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4244. )
  4245. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4246. // display link (sd - dstsd) to sd
  4247. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4248. if( i < MAX_DEVOTION )
  4249. clif_devotion(&sd->bl, sd);
  4250. // display links (dstsd - devotees) to sd
  4251. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4252. if( i < MAX_DEVOTION )
  4253. clif_devotion(&dstsd->bl, sd);
  4254. // display link (dstsd - crusader) to sd
  4255. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4256. clif_devotion(d_bl, sd);
  4257. }
  4258. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4259. struct unit_data *ud;
  4260. struct view_data *vd;
  4261. bool option = false;
  4262. unsigned int option_val = 0;
  4263. vd = status_get_viewdata(bl);
  4264. if (!vd || vd->class_ == JT_INVISIBLE)
  4265. return;
  4266. // Hide NPC from Maya Purple card
  4267. if (clif_npc_mayapurple(bl))
  4268. return;
  4269. ud = unit_bl2ud(bl);
  4270. if( ud && ud->walktimer != INVALID_TIMER ){
  4271. clif_set_unit_walking( bl, sd, ud, SELF );
  4272. }else{
  4273. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4274. }
  4275. if (vd->cloth_color)
  4276. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4277. if (vd->body_style)
  4278. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4279. switch (bl->type)
  4280. {
  4281. case BL_PC:
  4282. {
  4283. TBL_PC* tsd = (TBL_PC*)bl;
  4284. clif_getareachar_pc(sd, tsd);
  4285. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4286. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4287. else if(tsd->state.size==SZ_MEDIUM)
  4288. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4289. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4290. clif_sendbgemblem_single(sd->fd,tsd);
  4291. if ( tsd->status.robe )
  4292. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4293. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4294. clif_hat_effects(sd,bl,SELF);
  4295. }
  4296. break;
  4297. case BL_MER: // Devotion Effects
  4298. if( ((TBL_MER*)bl)->devotion_flag )
  4299. clif_devotion(bl, sd);
  4300. break;
  4301. case BL_NPC:
  4302. {
  4303. TBL_NPC* nd = (TBL_NPC*)bl;
  4304. if( nd->chat_id )
  4305. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4306. if( nd->size == SZ_BIG )
  4307. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4308. else if( nd->size == SZ_MEDIUM )
  4309. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4310. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4311. clif_progressbar_npc(nd, sd);
  4312. }
  4313. break;
  4314. case BL_MOB:
  4315. {
  4316. TBL_MOB* md = (TBL_MOB*)bl;
  4317. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4318. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4319. else if(md->special_state.size==SZ_MEDIUM)
  4320. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4321. #if PACKETVER >= 20120404
  4322. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4323. int i;
  4324. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4325. if( md->dmglog[i].id == sd->status.char_id )
  4326. clif_monster_hp_bar(md, sd->fd);
  4327. }
  4328. #endif
  4329. }
  4330. break;
  4331. case BL_PET:
  4332. if (vd->head_bottom)
  4333. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4334. break;
  4335. }
  4336. }
  4337. //Modifies the type of damage according to status changes [Skotlex]
  4338. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4339. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4340. {
  4341. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4342. }
  4343. /*==========================================
  4344. * Estimates walk delay based on the damage criteria. [Skotlex]
  4345. *------------------------------------------*/
  4346. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4347. {
  4348. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4349. return 0;
  4350. if (bl->type == BL_PC) {
  4351. if (battle_config.pc_walk_delay_rate != 100)
  4352. delay = delay*battle_config.pc_walk_delay_rate/100;
  4353. } else
  4354. if (battle_config.walk_delay_rate != 100)
  4355. delay = delay*battle_config.walk_delay_rate/100;
  4356. if (div_ > 1) //Multi-hit skills mean higher delays.
  4357. delay += battle_config.multihit_delay*(div_-1);
  4358. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4359. }
  4360. /*========================================== [Playtester]
  4361. * Returns hallucination damage the client displays
  4362. *------------------------------------------*/
  4363. static int clif_hallucination_damage()
  4364. {
  4365. int digit = rnd() % 5 + 1;
  4366. switch (digit)
  4367. {
  4368. case 1:
  4369. return (rnd() % 10);
  4370. case 2:
  4371. return (rnd() % 100);
  4372. case 3:
  4373. return (rnd() % 1000);
  4374. case 4:
  4375. return (rnd() % 10000);
  4376. }
  4377. return (rnd() % 32767);
  4378. }
  4379. /// Sends a 'damage' packet (src performs action on dst)
  4380. /// 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)
  4381. /// 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)
  4382. /// 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)
  4383. /// type:
  4384. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4385. /// 1 = pick up item
  4386. /// 2 = sit down
  4387. /// 3 = stand up
  4388. /// 4 = damage (endure)
  4389. /// 5 = (splash?)
  4390. /// 6 = (skill?)
  4391. /// 7 = (repeat damage?)
  4392. /// 8 = multi-hit damage
  4393. /// 9 = multi-hit damage (endure)
  4394. /// 10 = critical hit
  4395. /// 11 = lucky dodge
  4396. /// 12 = (touch skill?)
  4397. /// 13 = multi-hit critical
  4398. 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)
  4399. {
  4400. unsigned char buf[34];
  4401. struct status_change *sc;
  4402. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4403. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4404. #if PACKETVER < 20071113
  4405. const int cmd = 0x8a;
  4406. int offset = 0;
  4407. #elif PACKETVER < 20131223
  4408. const int cmd = 0x2e1;
  4409. int offset = 2;
  4410. #else
  4411. const int cmd = 0x8c8;
  4412. int offset = 3;
  4413. #endif
  4414. nullpo_ret(src);
  4415. nullpo_ret(dst);
  4416. if (type != DMG_MULTI_HIT_CRITICAL)
  4417. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4418. sc = status_get_sc(dst);
  4419. if(sc && sc->count) {
  4420. if(sc->data[SC_HALLUCINATION]) {
  4421. damage = clif_hallucination_damage();
  4422. if(damage2) damage2 = clif_hallucination_damage();
  4423. }
  4424. }
  4425. WBUFW(buf,0) = cmd;
  4426. WBUFL(buf,2) = src->id;
  4427. WBUFL(buf,6) = dst->id;
  4428. WBUFL(buf,10) = client_tick(tick);
  4429. WBUFL(buf,14) = sdelay;
  4430. WBUFL(buf,18) = ddelay;
  4431. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4432. #if PACKETVER < 20071113
  4433. WBUFW(buf,22) = damage ? div : 0;
  4434. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4435. #else
  4436. WBUFL(buf, 22) = damage ? div : 0;
  4437. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4438. #endif
  4439. } else {
  4440. #if PACKETVER < 20071113
  4441. WBUFW(buf,22) = min(damage, INT16_MAX);
  4442. WBUFW(buf,27+offset) = damage2;
  4443. #else
  4444. WBUFL(buf,22) = damage;
  4445. WBUFL(buf,27+offset) = damage2;
  4446. #endif
  4447. }
  4448. #if PACKETVER >= 20131223
  4449. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4450. #endif
  4451. WBUFW(buf,24+offset) = div;
  4452. WBUFB(buf,26+offset) = type;
  4453. if(disguised(dst)) {
  4454. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4455. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4456. clif_send(buf, packet_len(cmd), dst, SELF);
  4457. } else
  4458. clif_send(buf, packet_len(cmd), dst, AREA);
  4459. if(disguised(src)) {
  4460. WBUFL(buf,2) = disguised_bl_id( src->id );
  4461. if (disguised(dst))
  4462. WBUFL(buf,6) = dst->id;
  4463. #if PACKETVER < 20071113
  4464. if(damage > 0) WBUFW(buf,22) = -1;
  4465. if(damage2 > 0) WBUFW(buf,27) = -1;
  4466. #else
  4467. if(damage > 0) WBUFL(buf,22) = -1;
  4468. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4469. #endif
  4470. clif_send(buf,packet_len(cmd),src,SELF);
  4471. }
  4472. if(src == dst) {
  4473. unit_setdir(src, unit_getdir(src));
  4474. }
  4475. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4476. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4477. //Return adjusted can't walk delay for further processing.
  4478. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4479. }
  4480. /*==========================================
  4481. * src picks up dst
  4482. *------------------------------------------*/
  4483. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4484. {
  4485. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4486. unsigned char buf[32];
  4487. nullpo_retv(src);
  4488. nullpo_retv(dst);
  4489. WBUFW(buf, 0) = 0x8a;
  4490. WBUFL(buf, 2) = src->id;
  4491. WBUFL(buf, 6) = dst->id;
  4492. WBUFB(buf,26) = 1;
  4493. clif_send(buf, packet_len(0x8a), src, AREA);
  4494. }
  4495. /*==========================================
  4496. * inform clients in area that `bl` is sitting
  4497. *------------------------------------------*/
  4498. void clif_sitting(struct block_list* bl)
  4499. {
  4500. unsigned char buf[32];
  4501. nullpo_retv(bl);
  4502. WBUFW(buf, 0) = 0x8a;
  4503. WBUFL(buf, 2) = bl->id;
  4504. WBUFB(buf,26) = 2;
  4505. clif_send(buf, packet_len(0x8a), bl, AREA);
  4506. if(disguised(bl)) {
  4507. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4508. clif_send(buf, packet_len(0x8a), bl, SELF);
  4509. }
  4510. }
  4511. /*==========================================
  4512. * inform clients in area that `bl` is standing
  4513. *------------------------------------------*/
  4514. void clif_standing(struct block_list* bl)
  4515. {
  4516. unsigned char buf[32];
  4517. nullpo_retv(bl);
  4518. WBUFW(buf, 0) = 0x8a;
  4519. WBUFL(buf, 2) = bl->id;
  4520. WBUFB(buf,26) = 3;
  4521. clif_send(buf, packet_len(0x8a), bl, AREA);
  4522. if(disguised(bl)) {
  4523. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4524. clif_send(buf, packet_len(0x8a), bl, SELF);
  4525. }
  4526. }
  4527. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4528. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4529. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4530. {
  4531. unsigned char buf[32];
  4532. WBUFW(buf,0) = 0x192;
  4533. WBUFW(buf,2) = x;
  4534. WBUFW(buf,4) = y;
  4535. WBUFW(buf,6) = type;
  4536. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4537. if( session_isActive(fd) )
  4538. {
  4539. WFIFOHEAD(fd,packet_len(0x192));
  4540. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4541. WFIFOSET(fd,packet_len(0x192));
  4542. }
  4543. else
  4544. {
  4545. struct block_list dummy_bl;
  4546. dummy_bl.type = BL_NUL;
  4547. dummy_bl.x = x;
  4548. dummy_bl.y = y;
  4549. dummy_bl.m = m;
  4550. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4551. }
  4552. }
  4553. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4554. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4555. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4556. nullpo_retv( sd );
  4557. nullpo_retv( fitem );
  4558. struct PACKET_ZC_ITEM_ENTRY p;
  4559. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4560. p.AID = fitem->bl.id;
  4561. p.itemId = client_nameid( fitem->item.nameid );
  4562. p.identify = fitem->item.identify;
  4563. p.x = fitem->bl.x;
  4564. p.y = fitem->bl.y;
  4565. p.amount = fitem->item.amount;
  4566. p.subX = fitem->subx;
  4567. p.subY = fitem->suby;
  4568. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4569. }
  4570. /// Notifes client about Graffiti
  4571. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4572. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4573. unsigned char buf[128];
  4574. nullpo_retv(bl);
  4575. nullpo_retv(unit);
  4576. WBUFW(buf, 0) = 0x1c9;
  4577. WBUFL(buf, 2) = unit->bl.id;
  4578. WBUFL(buf, 6) = unit->group->src_id;
  4579. WBUFW(buf,10) = unit->bl.x;
  4580. WBUFW(buf,12) = unit->bl.y;
  4581. WBUFB(buf,14) = unit->group->unit_id;
  4582. WBUFB(buf,15) = 1;
  4583. WBUFB(buf,16) = 1;
  4584. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4585. clif_send(buf,packet_len(0x1c9),bl,target);
  4586. }
  4587. /// Notifies the client of a skill unit.
  4588. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4589. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4590. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4591. /// 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)
  4592. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4593. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4594. unsigned char buf[128];
  4595. nullpo_retv(bl);
  4596. nullpo_retv(unit);
  4597. if (bl->type == BL_PC)
  4598. fd = ((TBL_PC*)bl)->fd;
  4599. if (unit->group->state.guildaura)
  4600. return;
  4601. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4602. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4603. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4604. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4605. else
  4606. unit_id = unit->group->unit_id;
  4607. if (!visible)
  4608. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4609. #if PACKETVER >= 3
  4610. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4611. clif_graffiti(bl, unit, target);
  4612. return;
  4613. }
  4614. #endif
  4615. #if PACKETVER <= 20120702
  4616. header = 0x011f;
  4617. //#if PACKETVER < 20110718
  4618. // header = 0x011f;
  4619. //#elif PACKETVER < 20121212
  4620. // header = 0x08c7;
  4621. #elif PACKETVER < 20130731
  4622. header = 0x099f;
  4623. #else
  4624. header = 0x09ca;
  4625. #endif
  4626. len = packet_len(header);
  4627. WBUFW(buf,pos) = header;
  4628. if (header != 0x011f) {
  4629. WBUFW(buf, pos+2) = len;
  4630. pos += 2;
  4631. }
  4632. WBUFL(buf,pos+2) = unit->bl.id;
  4633. WBUFL(buf,pos+6) = unit->group->src_id;
  4634. WBUFW(buf,pos+10) = unit->bl.x;
  4635. WBUFW(buf,pos+12) = unit->bl.y;
  4636. switch (header) {
  4637. case 0x011f:
  4638. WBUFB(buf,pos+14) = unit_id;
  4639. WBUFB(buf,pos+15) = visible;
  4640. break;
  4641. case 0x08c7:
  4642. WBUFB(buf,pos+14) = unit_id;
  4643. WBUFW(buf,pos+15) = unit->range;
  4644. WBUFB(buf,pos+17) = visible;
  4645. break;
  4646. case 0x099f:
  4647. WBUFL(buf,pos+14) = unit_id;
  4648. WBUFW(buf,pos+18) = unit->range;
  4649. WBUFB(buf,pos+20) = visible;
  4650. break;
  4651. case 0x09ca:
  4652. WBUFL(buf,pos+14) = unit_id;
  4653. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4654. WBUFB(buf,pos+19) = visible;
  4655. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4656. break;
  4657. }
  4658. clif_send(buf, len, bl, target);
  4659. if (unit->group->skill_id == WZ_ICEWALL)
  4660. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4661. }
  4662. /// 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)
  4663. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4664. unsigned char buf[128];
  4665. nullpo_retv(bl);
  4666. WBUFW(buf, 0) = 0x09ca;
  4667. WBUFW(buf, 2) = packet_len(0x09ca);
  4668. WBUFL(buf, 4) = 1000;
  4669. WBUFL(buf, 8) = 2000;
  4670. WBUFW(buf, 12) = x;
  4671. WBUFW(buf, 14) = y;
  4672. WBUFL(buf, 16) = unit_id;
  4673. WBUFB(buf, 20) = (unsigned char)range;
  4674. WBUFB(buf, 21) = 1;
  4675. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4676. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4677. }
  4678. /*==========================================
  4679. * Server tells client to remove unit of id 'unit->bl.id'
  4680. *------------------------------------------*/
  4681. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4682. {
  4683. nullpo_retv(unit);
  4684. WFIFOHEAD(fd,packet_len(0x120));
  4685. WFIFOW(fd, 0)=0x120;
  4686. WFIFOL(fd, 2)=unit->bl.id;
  4687. WFIFOSET(fd,packet_len(0x120));
  4688. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4689. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4690. }
  4691. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4692. /// 0120 <id>.L
  4693. void clif_skill_delunit(struct skill_unit *unit)
  4694. {
  4695. unsigned char buf[16];
  4696. nullpo_retv(unit);
  4697. WBUFW(buf, 0)=0x120;
  4698. WBUFL(buf, 2)=unit->bl.id;
  4699. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4700. }
  4701. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4702. /// 01ac <id>.L
  4703. /// Only affects units with class [139,153] client-side.
  4704. void clif_skillunit_update(struct block_list* bl)
  4705. {
  4706. unsigned char buf[6];
  4707. nullpo_retv(bl);
  4708. WBUFW(buf,0) = 0x1ac;
  4709. WBUFL(buf,2) = bl->id;
  4710. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4711. }
  4712. /*==========================================
  4713. *
  4714. *------------------------------------------*/
  4715. static int clif_getareachar(struct block_list* bl,va_list ap)
  4716. {
  4717. struct map_session_data *sd;
  4718. nullpo_ret(bl);
  4719. sd=va_arg(ap,struct map_session_data*);
  4720. if (!clif_session_isValid(sd))
  4721. return 0;
  4722. switch(bl->type){
  4723. case BL_ITEM:
  4724. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4725. break;
  4726. case BL_SKILL:
  4727. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4728. break;
  4729. default:
  4730. if(&sd->bl == bl)
  4731. break;
  4732. clif_getareachar_unit(sd,bl);
  4733. break;
  4734. }
  4735. return 0;
  4736. }
  4737. /*==========================================
  4738. * tbl has gone out of view-size of bl
  4739. *------------------------------------------*/
  4740. int clif_outsight(struct block_list *bl,va_list ap)
  4741. {
  4742. struct block_list *tbl;
  4743. struct view_data *vd;
  4744. TBL_PC *sd, *tsd;
  4745. tbl=va_arg(ap,struct block_list*);
  4746. if(bl == tbl) return 0;
  4747. sd = BL_CAST(BL_PC, bl);
  4748. tsd = BL_CAST(BL_PC, tbl);
  4749. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4750. nullpo_ret(bl);
  4751. switch(bl->type){
  4752. case BL_PC:
  4753. if(sd->vd.class_ != JT_INVISIBLE)
  4754. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4755. if(sd->chatID){
  4756. struct chat_data *cd;
  4757. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4758. if(cd->usersd[0]==sd)
  4759. clif_dispchat(cd,tsd->fd);
  4760. }
  4761. if(sd->state.vending)
  4762. clif_closevendingboard(bl,tsd->fd);
  4763. if(sd->state.buyingstore)
  4764. clif_buyingstore_disappear_entry_single(tsd, sd);
  4765. break;
  4766. case BL_ITEM:
  4767. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4768. break;
  4769. case BL_SKILL:
  4770. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4771. break;
  4772. case BL_NPC:
  4773. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4774. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4775. break;
  4776. default:
  4777. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4778. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4779. break;
  4780. }
  4781. }
  4782. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4783. nullpo_ret(tbl);
  4784. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4785. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4786. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4787. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4788. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4789. }
  4790. return 0;
  4791. }
  4792. /*==========================================
  4793. * tbl has come into view of bl
  4794. *------------------------------------------*/
  4795. int clif_insight(struct block_list *bl,va_list ap)
  4796. {
  4797. struct block_list *tbl;
  4798. TBL_PC *sd, *tsd;
  4799. tbl=va_arg(ap,struct block_list*);
  4800. if (bl == tbl) return 0;
  4801. sd = BL_CAST(BL_PC, bl);
  4802. tsd = BL_CAST(BL_PC, tbl);
  4803. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4804. switch(bl->type){
  4805. case BL_ITEM:
  4806. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4807. break;
  4808. case BL_SKILL:
  4809. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4810. break;
  4811. default:
  4812. clif_getareachar_unit(tsd,bl);
  4813. break;
  4814. }
  4815. }
  4816. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4817. clif_getareachar_unit(sd,tbl);
  4818. }
  4819. return 0;
  4820. }
  4821. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4822. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4823. void clif_skillinfoblock(struct map_session_data *sd)
  4824. {
  4825. int fd;
  4826. int i,len,id;
  4827. nullpo_retv(sd);
  4828. fd = sd->fd;
  4829. if (!session_isActive(fd))
  4830. return;
  4831. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4832. WFIFOW(fd,0) = 0x10f;
  4833. bool haveCallPartnerSkill = false;
  4834. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4835. {
  4836. if( (id = sd->status.skill[i].id) != 0 )
  4837. {
  4838. // workaround for bugreport:5348
  4839. if (len + 37 > 8192)
  4840. break;
  4841. // skip WE_CALLPARTNER and send it in special way
  4842. if (id == WE_CALLPARTNER) {
  4843. haveCallPartnerSkill = true;
  4844. continue;
  4845. }
  4846. WFIFOW(fd,len) = id;
  4847. WFIFOL(fd,len+2) = skill_get_inf(id);
  4848. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4849. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4850. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4851. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4852. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4853. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4854. else
  4855. WFIFOB(fd,len+36) = 0;
  4856. len += 37;
  4857. }
  4858. }
  4859. WFIFOW(fd,2)=len;
  4860. WFIFOSET(fd,len);
  4861. // adoption fix
  4862. if (haveCallPartnerSkill) {
  4863. clif_addskill(sd, WE_CALLPARTNER);
  4864. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4865. }
  4866. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4867. for ( ; i < MAX_SKILL; i++)
  4868. {
  4869. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4870. {
  4871. clif_addskill(sd, id);
  4872. clif_skillinfo(sd, id, 0);
  4873. }
  4874. }
  4875. }
  4876. /**
  4877. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4878. **/
  4879. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4880. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4881. void clif_addskill(struct map_session_data *sd, int skill_id)
  4882. {
  4883. nullpo_retv(sd);
  4884. int fd = sd->fd;
  4885. uint16 idx = skill_get_index(skill_id);
  4886. if (!session_isActive(fd) || !idx)
  4887. return;
  4888. if( sd->status.skill[idx].id <= 0 )
  4889. return;
  4890. WFIFOHEAD(fd, packet_len(0x111));
  4891. WFIFOW(fd,0) = 0x111;
  4892. WFIFOW(fd,2) = skill_id;
  4893. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4894. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4895. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4896. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4897. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4898. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4899. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4900. else
  4901. WFIFOB(fd,38) = 0;
  4902. WFIFOSET(fd,packet_len(0x111));
  4903. }
  4904. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4905. /// 0441 <skill id>.W
  4906. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4907. {
  4908. #if PACKETVER >= 20081217
  4909. nullpo_retv(sd);
  4910. int fd = sd->fd;
  4911. uint16 idx = skill_get_index(skill_id);
  4912. if (!session_isActive(fd) || !idx)
  4913. return;
  4914. WFIFOHEAD(fd,packet_len(0x441));
  4915. WFIFOW(fd,0) = 0x441;
  4916. WFIFOW(fd,2) = skill_id;
  4917. WFIFOSET(fd,packet_len(0x441));
  4918. #endif
  4919. clif_skillinfoblock(sd);
  4920. }
  4921. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4922. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4923. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4924. nullpo_retv(sd);
  4925. int fd = sd->fd;
  4926. uint16 idx = skill_get_index(skill_id);
  4927. if (!session_isActive(fd) || !idx)
  4928. return;
  4929. WFIFOHEAD(fd, packet_len(0x10e));
  4930. WFIFOW(fd, 0) = 0x10e;
  4931. WFIFOW(fd, 2) = skill_id;
  4932. WFIFOW(fd, 4) = lv;
  4933. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4934. WFIFOW(fd, 8) = range;
  4935. WFIFOB(fd, 10) = upgradable;
  4936. WFIFOSET(fd, packet_len(0x10e));
  4937. }
  4938. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4939. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4940. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4941. {
  4942. nullpo_retv(sd);
  4943. const int fd = sd->fd;
  4944. uint16 idx = skill_get_index(skill_id);
  4945. if (!session_isActive(fd) || !idx)
  4946. return;
  4947. WFIFOHEAD(fd,packet_len(0x7e1));
  4948. WFIFOW(fd,0) = 0x7e1;
  4949. WFIFOW(fd,2) = skill_id;
  4950. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4951. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4952. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4953. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4954. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4955. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4956. else
  4957. WFIFOB(fd,14) = 0;
  4958. WFIFOSET(fd,packet_len(0x7e1));
  4959. }
  4960. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4961. #if PACKETVER >= 20151223
  4962. if( !battle_config.show_skill_scale ){
  4963. return;
  4964. }
  4965. struct PACKET_ZC_SKILL_SCALE p;
  4966. p.PacketType = skillscale;
  4967. p.AID = src_id;
  4968. p.skill_id = skill_id;
  4969. p.skill_lv = skill_lv;
  4970. p.x = x;
  4971. p.y = y;
  4972. p.casttime = casttime;
  4973. if( disguised( bl ) ){
  4974. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4975. p.AID = disguised_bl_id( bl->id );
  4976. clif_send( &p, sizeof( p ), bl, SELF );
  4977. }else{
  4978. clif_send( &p, sizeof( p ), bl, AREA );
  4979. }
  4980. #endif
  4981. }
  4982. /// Notifies clients in area, that an object is about to use a skill.
  4983. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4984. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4985. /// property:
  4986. /// 0 = Yellow cast aura
  4987. /// 1 = Water elemental cast aura
  4988. /// 2 = Earth elemental cast aura
  4989. /// 3 = Fire elemental cast aura
  4990. /// 4 = Wind elemental cast aura
  4991. /// 5 = Poison elemental cast aura
  4992. /// 6 = Holy elemental cast aura
  4993. /// ? = like 0
  4994. /// is disposable:
  4995. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4996. /// 1 = no text
  4997. 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)
  4998. {
  4999. #if PACKETVER < 20091124
  5000. const int cmd = 0x13e;
  5001. #else
  5002. const int cmd = 0x7fb;
  5003. #endif
  5004. unsigned char buf[32];
  5005. WBUFW(buf,0) = cmd;
  5006. WBUFL(buf,2) = src_id;
  5007. WBUFL(buf,6) = dst_id;
  5008. WBUFW(buf,10) = dst_x;
  5009. WBUFW(buf,12) = dst_y;
  5010. WBUFW(buf,14) = skill_id;
  5011. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5012. WBUFL(buf,20) = casttime;
  5013. #if PACKETVER >= 20091124
  5014. WBUFB(buf,24) = 0; // isDisposable
  5015. #endif
  5016. if (disguised(bl)) {
  5017. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5018. WBUFL(buf,2) = disguised_bl_id( src_id );
  5019. clif_send(buf,packet_len(cmd), bl, SELF);
  5020. } else
  5021. clif_send(buf,packet_len(cmd), bl, AREA);
  5022. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5023. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5024. }
  5025. }
  5026. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5027. /// 01b9 <id>.L
  5028. void clif_skillcastcancel(struct block_list* bl)
  5029. {
  5030. unsigned char buf[16];
  5031. nullpo_retv(bl);
  5032. WBUFW(buf,0) = 0x1b9;
  5033. WBUFL(buf,2) = bl->id;
  5034. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5035. }
  5036. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5037. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5038. /// num (only used when skill id = NV_BASIC and cause = 0):
  5039. /// 0 = "skill failed" MsgStringTable[159]
  5040. /// 1 = "no emotions" MsgStringTable[160]
  5041. /// 2 = "no sit" MsgStringTable[161]
  5042. /// 3 = "no chat" MsgStringTable[162]
  5043. /// 4 = "no party" MsgStringTable[163]
  5044. /// 5 = "no shout" MsgStringTable[164]
  5045. /// 6 = "no PKing" MsgStringTable[165]
  5046. /// 7 = "no alligning" MsgStringTable[383]
  5047. /// ? = ignored
  5048. /// cause:
  5049. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5050. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5051. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5052. /// "skill failed" MsgStringTable[204] (otherwise)
  5053. /// ... = @see enum useskill_fail_cause
  5054. /// ? = ignored
  5055. ///
  5056. /// if(result!=0) doesn't display any of the previous messages
  5057. /// Note: when this packet is received an unknown flag is always set to 0,
  5058. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5059. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5060. nullpo_retv( sd );
  5061. int fd = sd->fd;
  5062. if( !session_isActive( fd ) ){
  5063. return;
  5064. }
  5065. if(battle_config.display_skill_fail&1)
  5066. return; //Disable all skill failed messages
  5067. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5068. return; //Disable delay failed messages
  5069. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5070. return;
  5071. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5072. return;
  5073. struct PACKET_ZC_ACK_TOUSESKILL p;
  5074. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5075. p.skillId = skill_id;
  5076. p.btype = btype;
  5077. p.itemId = itemId;
  5078. p.flag = 0; // 0 - failed
  5079. p.cause = cause;
  5080. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5081. }
  5082. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5083. /// 043d <skill ID>.W <tick>.L
  5084. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5085. {
  5086. #if PACKETVER>=20081112
  5087. int fd;
  5088. nullpo_retv(sd);
  5089. fd=sd->fd;
  5090. WFIFOHEAD(fd,packet_len(0x43d));
  5091. WFIFOW(fd,0) = 0x43d;
  5092. WFIFOW(fd,2) = skill_id;
  5093. WFIFOL(fd,4) = client_tick(tick);
  5094. WFIFOSET(fd,packet_len(0x43d));
  5095. #endif
  5096. }
  5097. /// Skill attack effect and damage.
  5098. /// 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)
  5099. /// 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)
  5100. 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)
  5101. {
  5102. unsigned char buf[64];
  5103. struct status_change *sc;
  5104. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5105. nullpo_ret(src);
  5106. nullpo_ret(dst);
  5107. type = clif_calc_delay(type,div,damage,ddelay);
  5108. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5109. if(sc->data[SC_HALLUCINATION] && damage)
  5110. damage = clif_hallucination_damage();
  5111. }
  5112. #if PACKETVER < 3
  5113. WBUFW(buf,0)=0x114;
  5114. WBUFW(buf,2)=skill_id;
  5115. WBUFL(buf,4)=src->id;
  5116. WBUFL(buf,8)=dst->id;
  5117. WBUFL(buf,12)=client_tick(tick);
  5118. WBUFL(buf,16)=sdelay;
  5119. WBUFL(buf,20)=ddelay;
  5120. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5121. WBUFW(buf,24)=damage?div:0;
  5122. } else {
  5123. WBUFW(buf,24)=damage;
  5124. }
  5125. WBUFW(buf,26)=skill_lv;
  5126. WBUFW(buf,28)=div;
  5127. WBUFB(buf,30)=type;
  5128. if (disguised(dst)) {
  5129. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5130. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5131. clif_send(buf,packet_len(0x114),dst,SELF);
  5132. } else
  5133. clif_send(buf,packet_len(0x114),dst,AREA);
  5134. if(disguised(src)) {
  5135. WBUFL(buf,4)=disguised_bl_id(src->id);
  5136. if (disguised(dst))
  5137. WBUFL(buf,8)=dst->id;
  5138. if(damage > 0)
  5139. WBUFW(buf,24)=-1;
  5140. clif_send(buf,packet_len(0x114),src,SELF);
  5141. }
  5142. #else
  5143. WBUFW(buf,0)=0x1de;
  5144. WBUFW(buf,2)=skill_id;
  5145. WBUFL(buf,4)=src->id;
  5146. WBUFL(buf,8)=dst->id;
  5147. WBUFL(buf,12)=client_tick(tick);
  5148. WBUFL(buf,16)=sdelay;
  5149. WBUFL(buf,20)=ddelay;
  5150. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5151. WBUFL(buf,24)=damage?div:0;
  5152. } else {
  5153. WBUFL(buf,24)=damage;
  5154. }
  5155. WBUFW(buf,28)=skill_lv;
  5156. WBUFW(buf,30)=div;
  5157. // For some reason, late 2013 and newer clients have
  5158. // a issue that causes players and monsters to endure
  5159. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5160. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5161. #if PACKETVER < 20131223
  5162. WBUFB(buf,32)=type;
  5163. #else
  5164. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5165. #endif
  5166. if (disguised(dst)) {
  5167. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5168. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5169. clif_send(buf,packet_len(0x1de),dst,SELF);
  5170. } else
  5171. clif_send(buf,packet_len(0x1de),dst,AREA);
  5172. if(disguised(src)) {
  5173. WBUFL(buf,4)=disguised_bl_id(src->id);
  5174. if (disguised(dst))
  5175. WBUFL(buf,8)=dst->id;
  5176. if(damage > 0)
  5177. WBUFL(buf,24)=-1;
  5178. clif_send(buf,packet_len(0x1de),src,SELF);
  5179. }
  5180. #endif
  5181. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5182. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5183. }
  5184. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5185. /// 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
  5186. /*
  5187. 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)
  5188. {
  5189. unsigned char buf[64];
  5190. struct status_change *sc;
  5191. nullpo_ret(src);
  5192. nullpo_ret(dst);
  5193. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5194. type = clif_calc_delay(type,div,damage,ddelay);
  5195. sc = status_get_sc(dst);
  5196. if(sc && sc->count) {
  5197. if(sc->data[SC_HALLUCINATION] && damage)
  5198. damage = clif_hallucination_damage();
  5199. }
  5200. WBUFW(buf,0)=0x115;
  5201. WBUFW(buf,2)=skill_id;
  5202. WBUFL(buf,4)=src->id;
  5203. WBUFL(buf,8)=dst->id;
  5204. WBUFL(buf,12)=client_tick(tick);
  5205. WBUFL(buf,16)=sdelay;
  5206. WBUFL(buf,20)=ddelay;
  5207. WBUFW(buf,24)=dst->x;
  5208. WBUFW(buf,26)=dst->y;
  5209. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5210. WBUFW(buf,28)=damage?div:0;
  5211. } else {
  5212. WBUFW(buf,28)=damage;
  5213. }
  5214. WBUFW(buf,30)=skill_lv;
  5215. WBUFW(buf,32)=div;
  5216. WBUFB(buf,34)=type;
  5217. clif_send(buf,packet_len(0x115),src,AREA);
  5218. if(disguised(src)) {
  5219. WBUFL(buf,4)=disguised_bl_id(src->id);
  5220. if(damage > 0)
  5221. WBUFW(buf,28)=-1;
  5222. clif_send(buf,packet_len(0x115),src,SELF);
  5223. }
  5224. if (disguised(dst)) {
  5225. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5226. if (disguised(src))
  5227. WBUFL(buf,4)=src->id;
  5228. else if(damage > 0)
  5229. WBUFW(buf,28)=-1;
  5230. clif_send(buf,packet_len(0x115),dst,SELF);
  5231. }
  5232. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5233. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5234. }
  5235. */
  5236. /// Non-damaging skill effect
  5237. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5238. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5239. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5240. {
  5241. unsigned char buf[17];
  5242. #if PACKETVER < 20130731
  5243. const int cmd = 0x11a;
  5244. #else
  5245. const int cmd = 0x9cb;
  5246. #endif
  5247. int offset = 0;
  5248. bool success = ( tick != 0 );
  5249. nullpo_ret(dst);
  5250. WBUFW(buf,0) = cmd;
  5251. WBUFW(buf,2) = skill_id;
  5252. #if PACKETVER < 20130731
  5253. WBUFW(buf,4) = min(heal, INT16_MAX);
  5254. #else
  5255. WBUFL(buf,4) = min(heal, INT32_MAX);
  5256. offset += 2;
  5257. #endif
  5258. WBUFL(buf,6+offset) = dst->id;
  5259. WBUFL(buf,10+offset) = src ? src->id : 0;
  5260. WBUFB(buf,14+offset) = success;
  5261. if (disguised(dst)) {
  5262. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5263. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5264. clif_send(buf, packet_len(cmd), dst, SELF);
  5265. } else
  5266. clif_send(buf, packet_len(cmd), dst, AREA);
  5267. if(src && disguised(src)) {
  5268. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5269. if (disguised(dst))
  5270. WBUFL(buf,6+offset) = dst->id;
  5271. clif_send(buf, packet_len(cmd), src, SELF);
  5272. }
  5273. return success;
  5274. }
  5275. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5276. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5277. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5278. {
  5279. unsigned char buf[32];
  5280. nullpo_retv(src);
  5281. WBUFW(buf,0)=0x117;
  5282. WBUFW(buf,2)=skill_id;
  5283. WBUFL(buf,4)=src->id;
  5284. WBUFW(buf,8)=val;
  5285. WBUFW(buf,10)=x;
  5286. WBUFW(buf,12)=y;
  5287. WBUFL(buf,14)=client_tick(tick);
  5288. if(disguised(src)) {
  5289. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5290. WBUFL(buf,4)=disguised_bl_id(src->id);
  5291. clif_send(buf,packet_len(0x117),src,SELF);
  5292. } else
  5293. clif_send(buf,packet_len(0x117),src,AREA);
  5294. }
  5295. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5296. /// 011c <skill id>.W { <map name>.16B }*4
  5297. 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)
  5298. {
  5299. int fd;
  5300. nullpo_retv(sd);
  5301. fd = sd->fd;
  5302. WFIFOHEAD(fd,packet_len(0x11c));
  5303. WFIFOW(fd,0) = 0x11c;
  5304. WFIFOW(fd,2) = skill_id;
  5305. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5306. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5307. else // normal map name
  5308. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5309. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5310. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5311. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5312. WFIFOSET(fd,packet_len(0x11c));
  5313. sd->menuskill_id = skill_id;
  5314. if (skill_id == AL_WARP) {
  5315. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5316. sd->state.workinprogress = WIP_DISABLE_ALL;
  5317. } else
  5318. sd->menuskill_val = skill_lv;
  5319. }
  5320. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5321. /// 011e <type>.B
  5322. /// type:
  5323. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5324. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5325. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5326. ///
  5327. /// @param sd Who receives the message
  5328. /// @param type What message
  5329. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5330. {
  5331. int fd;
  5332. nullpo_retv(sd);
  5333. fd=sd->fd;
  5334. WFIFOHEAD(fd,packet_len(0x11e));
  5335. WFIFOW(fd,0)=0x11e;
  5336. WFIFOB(fd,2)=type;
  5337. WFIFOSET(fd,packet_len(0x11e));
  5338. }
  5339. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5340. /// 0189 <type>.W
  5341. /// type:
  5342. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5343. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5344. ///
  5345. /// @param sd Who receives the message
  5346. /// @param type What message
  5347. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5348. {
  5349. int fd;
  5350. nullpo_retv(sd);
  5351. fd=sd->fd;
  5352. WFIFOHEAD(fd,packet_len(0x189));
  5353. WFIFOW(fd,0)=0x189;
  5354. WFIFOW(fd,2)=type;
  5355. WFIFOSET(fd,packet_len(0x189));
  5356. }
  5357. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5358. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5359. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5360. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5361. {
  5362. struct status_data *status;
  5363. unsigned char buf[64];
  5364. int i, fix;
  5365. nullpo_retv(sd);
  5366. nullpo_retv(dst);
  5367. if( dst->type != BL_MOB )
  5368. return;
  5369. status = status_get_status_data(dst);
  5370. WBUFW(buf, 0)=0x18c;
  5371. WBUFW(buf, 2)=status_get_class(dst);
  5372. WBUFW(buf, 4)=status_get_lv(dst);
  5373. WBUFW(buf, 6)=status->size;
  5374. WBUFL(buf, 8)=status->hp;
  5375. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5376. +(battle_config.estimation_type&2?status->def2:0);
  5377. WBUFW(buf,14)=status->race;
  5378. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5379. +(battle_config.estimation_type&2?status->mdef2:0);
  5380. WBUFW(buf,18)= status->def_ele;
  5381. for(i=0;i<9;i++)
  5382. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5383. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5384. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5385. }
  5386. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5387. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5388. /// material id:
  5389. /// unused by the client
  5390. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5391. nullpo_retv(sd);
  5392. int fd = sd->fd;
  5393. if( !session_isActive( fd ) ){
  5394. return;
  5395. }
  5396. if (sd->menuskill_id == skill_id)
  5397. return; //Avoid resending the menu twice or more times...
  5398. if (skill_id == GC_CREATENEWPOISON)
  5399. skill_id = GC_RESEARCHNEWPOISON;
  5400. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5401. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5402. p->packetType = 0x18d;
  5403. int count = 0;
  5404. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5405. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5406. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5407. )
  5408. {
  5409. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5410. p->items[count].material[0] = 0;
  5411. p->items[count].material[1] = 0;
  5412. p->items[count].material[2] = 0;
  5413. count++;
  5414. }
  5415. }
  5416. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5417. WFIFOSET( fd, p->packetLength );
  5418. if( count > 0 ){
  5419. sd->menuskill_id = skill_id;
  5420. sd->menuskill_val = trigger;
  5421. return;
  5422. }
  5423. }
  5424. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5425. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5426. /// mk type:
  5427. /// 1 = cooking
  5428. /// 2 = arrow
  5429. /// 3 = elemental
  5430. /// 4 = GN_MIX_COOKING
  5431. /// 5 = GN_MAKEBOMB
  5432. /// 6 = GN_S_PHARMACY
  5433. /// 7 = MT_M_MACHINE - Unconfirmed
  5434. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5435. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5436. nullpo_retv( sd );
  5437. // Avoid resending the menu twice or more times...
  5438. if( sd->menuskill_id == skill_id ){
  5439. return;
  5440. }
  5441. int fd = sd->fd;
  5442. if( !session_isActive( fd ) ){
  5443. return;
  5444. }
  5445. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5446. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5447. p->packetType = 0x25a;
  5448. p->makeItem = list_type; // list type
  5449. int count = 0;
  5450. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5451. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5452. continue;
  5453. }
  5454. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5455. count++;
  5456. }
  5457. if( count > 0 || skill_id == AM_PHARMACY ){
  5458. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5459. WFIFOSET( fd, p->packetLength );
  5460. sd->menuskill_id = skill_id;
  5461. sd->menuskill_val = trigger;
  5462. sd->menuskill_val2 = qty; // amount.
  5463. }else{
  5464. clif_menuskill_clear(sd);
  5465. #if PACKETVER >= 20090922
  5466. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5467. #else
  5468. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5469. WFIFOSET( fd, p->packetLength );
  5470. #endif
  5471. }
  5472. }
  5473. /// Notifies clients of a status change.
  5474. /// 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)]
  5475. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5476. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5477. /// @param bl Sends packet to clients around this object
  5478. /// @param id ID of object that has this effect
  5479. /// @param type Status icon see enum efst_type
  5480. /// @param flag 1:Active, 0:Deactive
  5481. /// @param tick Duration in ms
  5482. /// @param val1
  5483. /// @param val2
  5484. /// @param val3
  5485. 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)
  5486. {
  5487. unsigned char buf[32];
  5488. if (type == EFST_BLANK) //It shows nothing on the client...
  5489. return;
  5490. if (type == EFST_POSTDELAY && tick == 0)
  5491. return;
  5492. nullpo_retv(bl);
  5493. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5494. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5495. tick = 200;
  5496. #if PACKETVER >= 20120618
  5497. if (flag && battle_config.display_status_timers)
  5498. WBUFW(buf,0) = 0x983;
  5499. else
  5500. #elif PACKETVER >= 20090121
  5501. if (flag && battle_config.display_status_timers)
  5502. WBUFW(buf,0) = 0x43f;
  5503. else
  5504. #endif
  5505. WBUFW(buf,0) = 0x196;
  5506. WBUFW(buf,2) = type;
  5507. WBUFL(buf,4) = id;
  5508. WBUFB(buf,8) = flag;
  5509. #if PACKETVER >= 20120618
  5510. if (flag && battle_config.display_status_timers) {
  5511. if (tick <= 0)
  5512. tick = 9999; // this is indeed what official servers do
  5513. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5514. WBUFL(buf,13) = client_tick(tick);
  5515. WBUFL(buf,17) = val1;
  5516. WBUFL(buf,21) = val2;
  5517. WBUFL(buf,25) = val3;
  5518. }
  5519. #elif PACKETVER >= 20090121
  5520. if (flag && battle_config.display_status_timers) {
  5521. if (tick <= 0)
  5522. tick = 9999; // this is indeed what official servers do
  5523. WBUFL(buf,9) = client_tick(tick);
  5524. WBUFL(buf,13) = val1;
  5525. WBUFL(buf,17) = val2;
  5526. WBUFL(buf,21) = val3;
  5527. }
  5528. #endif
  5529. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5530. }
  5531. /* Sends status effect to clients around the bl
  5532. * @param bl Object that has the effect
  5533. * @param type Status icon see enum efst_type
  5534. * @param flag 1:Active, 0:Deactive
  5535. * @param tick Duration in ms
  5536. * @param val1
  5537. * @param val2
  5538. * @param val3
  5539. */
  5540. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5541. struct map_session_data *sd = NULL;
  5542. if (type == EFST_BLANK) //It shows nothing on the client...
  5543. return;
  5544. if (type == EFST_POSTDELAY && tick == 0)
  5545. return;
  5546. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5547. return;
  5548. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5549. // Older clients display normal riding icon.
  5550. if (type == EFST_MADOGEAR)
  5551. type = EFST_RIDING;
  5552. #endif
  5553. nullpo_retv(bl);
  5554. sd = BL_CAST(BL_PC, bl);
  5555. if (!(status_efst_get_bl_type((efst_type)type)&bl->type)) // only send status changes that actually matter to the client
  5556. return;
  5557. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5558. }
  5559. /**
  5560. * Send any active EFST to those around.
  5561. * @param tbl: Unit to send the packet to
  5562. * @param bl: Objects walking into view
  5563. * @param target: Client send type
  5564. */
  5565. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5566. unsigned char i;
  5567. struct sc_display_entry **sc_display;
  5568. unsigned char sc_display_count;
  5569. bool spheres_sent;
  5570. nullpo_retv(bl);
  5571. switch( bl->type ){
  5572. case BL_PC: {
  5573. struct map_session_data* sd = (struct map_session_data*)bl;
  5574. sc_display = sd->sc_display;
  5575. sc_display_count = sd->sc_display_count;
  5576. spheres_sent = !sd->state.connect_new;
  5577. }
  5578. break;
  5579. case BL_NPC: {
  5580. struct npc_data* nd = (struct npc_data*)bl;
  5581. sc_display = nd->sc_display;
  5582. sc_display_count = nd->sc_display_count;
  5583. spheres_sent = true;
  5584. }
  5585. break;
  5586. default:
  5587. return;
  5588. }
  5589. for (i = 0; i < sc_display_count; i++) {
  5590. enum sc_type type = sc_display[i]->type;
  5591. struct status_change *sc = status_get_sc(bl);
  5592. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5593. t_tick tick = 0;
  5594. if (td)
  5595. tick = DIFF_TICK(td->tick, gettick());
  5596. // Status changes that need special handling
  5597. switch( type ){
  5598. case SC_SPHERE_1:
  5599. case SC_SPHERE_2:
  5600. case SC_SPHERE_3:
  5601. case SC_SPHERE_4:
  5602. case SC_SPHERE_5:
  5603. if( spheres_sent ){
  5604. target = AREA_WOS;
  5605. }
  5606. break;
  5607. case SC_HELLS_PLANT:
  5608. if( sc && sc->data[type] ){
  5609. tick = sc->data[type]->val4;
  5610. }
  5611. break;
  5612. }
  5613. #if PACKETVER > 20120418
  5614. clif_efst_status_change(tbl, bl->id, target, status_db.getIcon(type), tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5615. #else
  5616. clif_status_change_sub(tbl, bl->id, status_db.getIcon(type), 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5617. #endif
  5618. }
  5619. }
  5620. /// Notifies the client when a player enters the screen with an active EFST.
  5621. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5622. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5623. 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) {
  5624. #if PACKETVER >= 20111108
  5625. unsigned char buf[32];
  5626. #if PACKETVER >= 20120618
  5627. const int cmd = 0x984;
  5628. #elif PACKETVER >= 20111108
  5629. const int cmd = 0x8ff;
  5630. #endif
  5631. int offset = 0;
  5632. if (type == EFST_BLANK)
  5633. return;
  5634. nullpo_retv(bl);
  5635. if (tick <= 0)
  5636. tick = 9999;
  5637. WBUFW(buf,offset + 0) = cmd;
  5638. WBUFL(buf,offset + 2) = tid;
  5639. WBUFW(buf,offset + 6) = type;
  5640. #if PACKETVER >= 20111108
  5641. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5642. #if PACKETVER >= 20120618
  5643. WBUFL(buf,offset + 12) = client_tick(tick);
  5644. offset += 4;
  5645. #endif
  5646. WBUFL(buf,offset + 12) = val1;
  5647. WBUFL(buf,offset + 16) = val2;
  5648. WBUFL(buf,offset + 20) = val3;
  5649. #endif
  5650. clif_send(buf,packet_len(cmd),bl,target);
  5651. #endif
  5652. }
  5653. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5654. /// 008e <packet len>.W <message>.?B
  5655. void clif_displaymessage(const int fd, const char* mes)
  5656. {
  5657. nullpo_retv(mes);
  5658. if( session_isActive( fd ) ){
  5659. char *message, *line;
  5660. message = aStrdup(mes);
  5661. line = strtok(message, "\n");
  5662. while(line != NULL) {
  5663. #if PACKETVER == 20141022
  5664. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5665. /** so we redirect to ZC_NPC_CHAT **/
  5666. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5667. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5668. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5669. if (len > 0) {
  5670. WFIFOHEAD(fd, 13 + len);
  5671. WFIFOW(fd, 0) = 0x2C1;
  5672. WFIFOW(fd, 2) = 13 + len;
  5673. WFIFOL(fd, 4) = 0;
  5674. WFIFOL(fd, 8) = color;
  5675. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5676. WFIFOSET(fd, WFIFOW(fd, 2));
  5677. }
  5678. #else
  5679. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5680. int len = strnlen(line, CHAT_SIZE_MAX);
  5681. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5682. WFIFOHEAD(fd, 5 + len);
  5683. WFIFOW(fd,0) = 0x8e;
  5684. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5685. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5686. WFIFOSET(fd, 5 + len);
  5687. }
  5688. #endif
  5689. line = strtok(NULL, "\n");
  5690. }
  5691. aFree(message);
  5692. }
  5693. }
  5694. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5695. /// 009a <packet len>.W <message>.?B
  5696. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5697. {
  5698. nullpo_retv(mes);
  5699. if (len < 2)
  5700. return;
  5701. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5702. p->packetType = HEADER_ZC_BROADCAST;
  5703. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5704. if( ( type&BC_BLUE ) != 0 ){
  5705. const char* color = "blue";
  5706. int16 length = (int16)strlen( color );
  5707. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5708. strcpy( p->message, color );
  5709. strncpy( &p->message[length], mes, len );
  5710. p->PacketLength += length;
  5711. }else if( ( type&BC_WOE ) != 0 ){
  5712. const char* color = "ssss";
  5713. int16 length = (int16)strlen( color );
  5714. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5715. strcpy( p->message, color );
  5716. strncpy( &p->message[length], mes, len );
  5717. p->PacketLength += length;
  5718. }else{
  5719. strncpy( p->message, mes, len );
  5720. }
  5721. clif_send( p, p->PacketLength, bl, target );
  5722. }
  5723. /*==========================================
  5724. * Displays a message on a 'bl' to all it's nearby clients
  5725. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5726. *------------------------------------------*/
  5727. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5728. nullpo_retv(bl);
  5729. nullpo_retv(message);
  5730. int16 len = (int16)( strlen( message ) + 1 );
  5731. if( len > CHAT_SIZE_MAX ) {
  5732. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5733. len = CHAT_SIZE_MAX;
  5734. }
  5735. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5736. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5737. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5738. p->GID = bl->id;
  5739. safestrncpy( p->Message, message, len );
  5740. clif_send( p, p->PacketLength, bl, target );
  5741. }
  5742. /// Send broadcast message with font formatting.
  5743. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5744. 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)
  5745. {
  5746. nullpo_retv(mes);
  5747. if (len < 2)
  5748. return;
  5749. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5750. p->packetType = HEADER_ZC_BROADCAST2;
  5751. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5752. p->fontColor = fontColor;
  5753. p->fontType = fontType;
  5754. p->fontSize = fontSize;
  5755. p->fontAlign = fontAlign;
  5756. p->fontY = fontY;
  5757. strncpy( p->message, mes, len );
  5758. clif_send( p, p->PacketLength, bl, target );
  5759. }
  5760. /*
  5761. * Display *msg to all *users in channel
  5762. */
  5763. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5764. DBIterator *iter;
  5765. struct map_session_data *user;
  5766. unsigned short msg_len = 0, len = 0;
  5767. unsigned char buf[CHAT_SIZE_MAX];
  5768. if (!channel || !msg)
  5769. return;
  5770. msg_len = (unsigned short)(strlen(msg) + 1);
  5771. if( msg_len > sizeof(buf)-12 ) {
  5772. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5773. msg_len = sizeof(buf)-12;
  5774. }
  5775. WBUFW(buf,0) = 0x2C1;
  5776. WBUFW(buf,2) = (len = msg_len + 12);
  5777. WBUFL(buf,4) = 0;
  5778. WBUFL(buf,8) = color;
  5779. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5780. iter = db_iterator(channel->users);
  5781. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5782. clif_send(buf, len, &user->bl, SELF);
  5783. }
  5784. dbi_destroy(iter);
  5785. }
  5786. /// Displays heal effect.
  5787. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5788. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5789. /// var id:
  5790. /// 5 = HP (SP_HP)
  5791. /// 7 = SP (SP_SP)
  5792. /// ? = ignored
  5793. void clif_heal(int fd,int type,int val) {
  5794. #if PACKETVER < 20141022
  5795. const int cmd = 0x13d;
  5796. #else
  5797. const int cmd = 0xa27;
  5798. #endif
  5799. WFIFOHEAD(fd, packet_len(cmd));
  5800. WFIFOW(fd,0) = cmd;
  5801. WFIFOW(fd,2) = type;
  5802. #if PACKETVER < 20141022
  5803. WFIFOW(fd,4) = min(val, INT16_MAX);
  5804. #else
  5805. WFIFOL(fd,4) = min(val, INT32_MAX);
  5806. #endif
  5807. WFIFOSET(fd, packet_len(cmd));
  5808. }
  5809. /// Displays resurrection effect (ZC_RESURRECTION).
  5810. /// 0148 <id>.L <type>.W
  5811. /// type:
  5812. /// ignored
  5813. void clif_resurrection(struct block_list *bl,int type)
  5814. {
  5815. unsigned char buf[16];
  5816. nullpo_retv(bl);
  5817. WBUFW(buf,0)=0x148;
  5818. WBUFL(buf,2)=bl->id;
  5819. WBUFW(buf,6)=0;
  5820. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5821. if (disguised(bl))
  5822. clif_spawn(bl);
  5823. }
  5824. /// Sets the map property
  5825. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5826. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5827. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5828. {
  5829. #if PACKETVER >= 20121010
  5830. short cmd = 0x99b;
  5831. unsigned char buf[8];
  5832. #else
  5833. short cmd = 0x199;
  5834. unsigned char buf[4];
  5835. #endif
  5836. WBUFW(buf,0)=cmd;
  5837. WBUFW(buf,2)=property;
  5838. #if PACKETVER >= 20121010
  5839. struct map_data *mapdata = map_getmapdata(bl->m);
  5840. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  5841. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5842. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5843. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5844. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5845. ((mapdata->flag[MF_NOLOCKON] || mapdata_flag_vs(mapdata) || (sd && sd->duel_group > 0))<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5846. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5847. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5848. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5849. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5850. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5851. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5852. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5853. #endif
  5854. clif_send(buf,packet_len(cmd),bl,t);
  5855. }
  5856. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5857. /// 01d6 <type>.W
  5858. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5859. {
  5860. int fd;
  5861. nullpo_retv(sd);
  5862. fd=sd->fd;
  5863. WFIFOHEAD(fd,packet_len(0x1D6));
  5864. WFIFOW(fd,0)=0x1D6;
  5865. WFIFOW(fd,2)=type;
  5866. WFIFOSET(fd,packet_len(0x1D6));
  5867. }
  5868. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5869. /// 019a <id>.L <ranking>.L <total>.L
  5870. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5871. {
  5872. if(type == 2) {
  5873. int fd = sd->fd;
  5874. WFIFOHEAD(fd,packet_len(0x19a));
  5875. WFIFOW(fd,0) = 0x19a;
  5876. WFIFOL(fd,2) = sd->bl.id;
  5877. WFIFOL(fd,6) = pvprank;
  5878. WFIFOL(fd,10) = pvpnum;
  5879. WFIFOSET(fd,packet_len(0x19a));
  5880. } else {
  5881. unsigned char buf[32];
  5882. WBUFW(buf,0) = 0x19a;
  5883. WBUFL(buf,2) = sd->bl.id;
  5884. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5885. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5886. else
  5887. WBUFL(buf,6) = pvprank;
  5888. WBUFL(buf,10) = pvpnum;
  5889. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5890. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5891. else if(!type)
  5892. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5893. else
  5894. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5895. }
  5896. }
  5897. /*==========================================
  5898. *
  5899. *------------------------------------------*/
  5900. void clif_map_property_mapall(int map_idx, enum map_property property)
  5901. {
  5902. struct block_list bl;
  5903. bl.id = 0;
  5904. bl.type = BL_NUL;
  5905. bl.m = map_idx;
  5906. clif_map_property( &bl, property, ALL_SAMEMAP );
  5907. }
  5908. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5909. /// 0188 <result>.W <index>.W <refine>.W
  5910. /// result:
  5911. /// 0 = success
  5912. /// 1 = failure
  5913. /// 2 = downgrade
  5914. void clif_refine(int fd, int fail, int index, int val)
  5915. {
  5916. WFIFOHEAD(fd,packet_len(0x188));
  5917. WFIFOW(fd,0)=0x188;
  5918. WFIFOW(fd,2)=fail;
  5919. WFIFOW(fd,4)=index+2;
  5920. WFIFOW(fd,6)=val;
  5921. WFIFOSET(fd,packet_len(0x188));
  5922. }
  5923. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5924. /// 0223 <result>.L <nameid>.W
  5925. /// result:
  5926. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5927. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5928. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5929. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5930. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5931. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5932. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5933. p.result = result;
  5934. p.itemId = client_nameid( item_id );
  5935. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5936. }
  5937. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5938. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5939. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5940. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5941. int fd;
  5942. nullpo_retv(sd);
  5943. fd = sd->fd;
  5944. #if PACKETVER < 20091104
  5945. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5946. WFIFOW(fd,0) = 0x97;
  5947. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5948. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5949. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5950. WFIFOSET(fd,WFIFOW(fd,2));
  5951. #else
  5952. struct map_session_data *ssd = map_nick2sd(nick,false);
  5953. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5954. WFIFOW(fd,0) = 0x97;
  5955. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5956. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5957. // If it is not a message from the server or a player from another map-server
  5958. if( ssd ){
  5959. gmlvl = pc_get_group_level(ssd);
  5960. }
  5961. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5962. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5963. WFIFOSET(fd,WFIFOW(fd,2));
  5964. #endif
  5965. }
  5966. /// Inform the player about the result of his whisper action
  5967. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5968. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5969. /// result:
  5970. /// 0 = success to send wisper
  5971. /// 1 = target character is not loged in
  5972. /// 2 = ignored by target
  5973. /// 3 = everyone ignored by target
  5974. void clif_wis_end(int fd, int result)
  5975. {
  5976. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5977. #if PACKETVER < 20131223
  5978. const int cmd = 0x98;
  5979. #else
  5980. const int cmd = 0x9df;
  5981. #endif
  5982. if (!sd)
  5983. return;
  5984. WFIFOHEAD(fd,packet_len(cmd));
  5985. WFIFOW(fd,0) = cmd;
  5986. WFIFOB(fd,2) = (char)result;
  5987. #if PACKETVER >= 20131223
  5988. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5989. #endif
  5990. WFIFOSET(fd,packet_len(cmd));
  5991. }
  5992. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5993. /// 0194 <char id>.L <name>.24B
  5994. /// 0af7 <flag>.W <char id>.L <name>.24B
  5995. void clif_solved_charname(int fd, int charid, const char* name)
  5996. {
  5997. #if PACKETVER >= 20180221
  5998. WFIFOHEAD(fd,packet_len(0xaf7));
  5999. WFIFOW(fd,0) = 0xaf7;
  6000. WFIFOW(fd,2) = name[0] ? 3 : 2;
  6001. WFIFOL(fd,4) = charid;
  6002. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  6003. WFIFOSET(fd,packet_len(0x0af7));
  6004. #else
  6005. WFIFOHEAD(fd,packet_len(0x194));
  6006. WFIFOW(fd,0)=0x194;
  6007. WFIFOL(fd,2)=charid;
  6008. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  6009. WFIFOSET(fd,packet_len(0x194));
  6010. #endif
  6011. }
  6012. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6013. /// 017b <packet len>.W { <name id>.W }*
  6014. void clif_use_card(struct map_session_data *sd,int idx)
  6015. {
  6016. int i,c,ep;
  6017. int fd=sd->fd;
  6018. nullpo_retv(sd);
  6019. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6020. return;
  6021. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6022. return; //Avoid parsing invalid item indexes (no card/no item)
  6023. ep=sd->inventory_data[idx]->equip;
  6024. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6025. WFIFOW(fd,0)=0x17b;
  6026. for(i=c=0;i<MAX_INVENTORY;i++){
  6027. int j;
  6028. if(sd->inventory_data[i] == NULL)
  6029. continue;
  6030. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6031. continue;
  6032. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6033. continue;
  6034. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6035. continue;
  6036. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6037. continue;
  6038. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6039. continue;
  6040. 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.
  6041. continue;
  6042. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6043. if( j == sd->inventory_data[i]->slots ) // No room
  6044. continue;
  6045. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6046. continue;
  6047. WFIFOW(fd,4+c*2)=i+2;
  6048. c++;
  6049. }
  6050. if( !c ) return; // no item is available for card insertion
  6051. WFIFOW(fd,2)=4+c*2;
  6052. WFIFOSET(fd,WFIFOW(fd,2));
  6053. }
  6054. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6055. /// 017d <equip index>.W <card index>.W <result>.B
  6056. /// result:
  6057. /// 0 = success
  6058. /// 1 = failure
  6059. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  6060. {
  6061. int fd;
  6062. nullpo_retv(sd);
  6063. fd=sd->fd;
  6064. WFIFOHEAD(fd,packet_len(0x17d));
  6065. WFIFOW(fd,0)=0x17d;
  6066. WFIFOW(fd,2)=idx_equip+2;
  6067. WFIFOW(fd,4)=idx_card+2;
  6068. WFIFOB(fd,6)=flag;
  6069. WFIFOSET(fd,packet_len(0x17d));
  6070. }
  6071. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6072. /// 0177 <packet len>.W { <index>.W }*
  6073. void clif_item_identify_list(struct map_session_data *sd)
  6074. {
  6075. int i,c;
  6076. int fd;
  6077. nullpo_retv(sd);
  6078. fd=sd->fd;
  6079. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6080. WFIFOW(fd,0)=0x177;
  6081. for(i=c=0;i<MAX_INVENTORY;i++){
  6082. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6083. WFIFOW(fd,c*2+4)=client_index(i);
  6084. c++;
  6085. }
  6086. }
  6087. if(c > 0) {
  6088. WFIFOW(fd,2)=c*2+4;
  6089. WFIFOSET(fd,WFIFOW(fd,2));
  6090. sd->menuskill_id = MC_IDENTIFY;
  6091. sd->menuskill_val = c;
  6092. sd->state.workinprogress = WIP_DISABLE_ALL;
  6093. }
  6094. }
  6095. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6096. /// 0179 <index>.W <result>.B
  6097. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6098. {
  6099. int fd;
  6100. nullpo_retv(sd);
  6101. fd=sd->fd;
  6102. WFIFOHEAD(fd,packet_len(0x179));
  6103. WFIFOW(fd, 0)=0x179;
  6104. WFIFOW(fd, 2)=idx+2;
  6105. WFIFOB(fd, 4)=flag;
  6106. WFIFOSET(fd,packet_len(0x179));
  6107. }
  6108. /// Presents a list of items that can be repaired.
  6109. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6110. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6111. nullpo_retv( sd );
  6112. nullpo_retv( dstsd );
  6113. int fd = sd->fd;
  6114. if( !session_isActive( fd ) ){
  6115. return;
  6116. }
  6117. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6118. // Preallocate the maximum size
  6119. WFIFOHEAD( fd, len );
  6120. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6121. int c = 0;
  6122. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6123. 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)){
  6124. p->items[c].index = i;
  6125. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6126. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6127. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6128. c++;
  6129. }
  6130. }
  6131. if( c > 0 ){
  6132. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6133. // Recalculate real length
  6134. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6135. p->packetLength = len;
  6136. WFIFOSET( fd, len );
  6137. sd->menuskill_id = BS_REPAIRWEAPON;
  6138. sd->menuskill_val = dstsd->bl.id;
  6139. sd->menuskill_val2 = lv;
  6140. }else{
  6141. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6142. }
  6143. }
  6144. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6145. /// 01fe <index>.W <result>.B
  6146. /// index:
  6147. /// ignored (inventory index)
  6148. /// result:
  6149. /// 0 = Item repair success.
  6150. /// 1 = Item repair failure.
  6151. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6152. {
  6153. int fd;
  6154. nullpo_retv(sd);
  6155. fd = sd->fd;
  6156. WFIFOHEAD(fd,packet_len(0x1fe));
  6157. WFIFOW(fd, 0)=0x1fe;
  6158. WFIFOW(fd, 2)=idx+2;
  6159. WFIFOB(fd, 4)=flag;
  6160. WFIFOSET(fd,packet_len(0x1fe));
  6161. }
  6162. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6163. /// 02bb <equip location>.W <account id>.L
  6164. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6165. {
  6166. int fd = sd->fd;
  6167. WFIFOHEAD(fd,packet_len(0x2bb));
  6168. WFIFOW(fd,0) = 0x2bb;
  6169. WFIFOW(fd,2) = position;
  6170. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6171. WFIFOSET(fd,packet_len(0x2bb));
  6172. }
  6173. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6174. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6175. void clif_item_refine_list( struct map_session_data *sd ){
  6176. nullpo_retv( sd );
  6177. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6178. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6179. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6180. int refine_item[MAX_WEAPON_LEVEL];
  6181. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6182. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6183. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6184. #ifdef RENEWAL
  6185. refine_item[4] = -1;
  6186. #endif
  6187. int count = 0;
  6188. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6189. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6190. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6191. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6192. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6193. p->items[count].index = client_index( i );
  6194. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6195. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6196. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6197. count++;
  6198. }
  6199. }
  6200. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6201. clif_send( p, p->packetLength, &sd->bl, SELF );
  6202. if( count > 0 ){
  6203. sd->menuskill_id = WS_WEAPONREFINE;
  6204. sd->menuskill_val = skill_lv;
  6205. }
  6206. }
  6207. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6208. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6209. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6210. nullpo_retv( sd );
  6211. struct PACKET_ZC_AUTORUN_SKILL p;
  6212. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6213. p.skill_id = skill_id;
  6214. p.skill_type = skill_get_inf( skill_id );
  6215. p.skill_lv = skill_lv;
  6216. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6217. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6218. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6219. p.up_flag = false;
  6220. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6221. }
  6222. /// Adds an item to character's cart.
  6223. /// 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)
  6224. /// 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)
  6225. /// 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)
  6226. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6227. nullpo_retv( sd );
  6228. int fd = sd->fd;
  6229. if( !session_isActive( fd ) ){
  6230. return;
  6231. }
  6232. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6233. return;
  6234. }
  6235. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6236. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6237. p.index = client_index( n );
  6238. p.amount = amount;
  6239. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6240. #if PACKETVER >= 5
  6241. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6242. #endif
  6243. p.identified = sd->cart.u.items_cart[n].identify;
  6244. p.damaged = sd->cart.u.items_cart[n].attribute;
  6245. p.refine = sd->cart.u.items_cart[n].refine;
  6246. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6247. #if PACKETVER >= 20150226
  6248. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6249. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6250. p.enchantgrade = sd->cart.u.items_cart[n].enchantgrade;
  6251. #endif
  6252. #endif
  6253. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6254. }
  6255. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6256. /* Acknowledge an item have been added to cart
  6257. * 012c <result>B
  6258. * result :
  6259. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6260. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6261. */
  6262. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6263. {
  6264. int fd;
  6265. unsigned char *buf;
  6266. nullpo_retv(sd);
  6267. fd = sd->fd;
  6268. buf = WFIFOP(fd,0);
  6269. WBUFW(buf,0) = 0x12c;
  6270. WBUFB(buf,2) = flag;
  6271. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6272. }
  6273. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6274. void clif_bank_open(struct map_session_data *sd){
  6275. int fd;
  6276. nullpo_retv(sd);
  6277. fd = sd->fd;
  6278. WFIFOHEAD(fd,4);
  6279. WFIFOW(fd,0) = 0x09b7;
  6280. WFIFOW(fd,2) = 0;
  6281. WFIFOSET(fd,4);
  6282. }
  6283. /*
  6284. * Request to Open the banking system
  6285. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6286. */
  6287. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6288. //TODO check if preventing trade or stuff like that
  6289. //also mark something in case char ain't available for saving, should we check now ?
  6290. nullpo_retv(sd);
  6291. if( !battle_config.feature_banking ) {
  6292. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6293. return;
  6294. }
  6295. else {
  6296. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6297. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6298. if(sd->status.account_id == aid){
  6299. sd->state.banking = 1;
  6300. //request save ?
  6301. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6302. //on succes open bank ?
  6303. clif_bank_open(sd);
  6304. }
  6305. }
  6306. }
  6307. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6308. void clif_bank_close(struct map_session_data *sd){
  6309. int fd;
  6310. nullpo_retv(sd);
  6311. fd = sd->fd;
  6312. WFIFOHEAD(fd,4);
  6313. WFIFOW(fd,0) = 0x09B9;
  6314. WFIFOW(fd,2) = 0;
  6315. WFIFOSET(fd,4);
  6316. }
  6317. /*
  6318. * Request to close the banking system
  6319. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6320. */
  6321. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6322. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6323. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6324. nullpo_retv(sd);
  6325. if( !battle_config.feature_banking ) {
  6326. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6327. //still allow to go trough to not stuck player if we have disable it while they was in
  6328. }
  6329. if(sd->status.account_id == aid){
  6330. sd->state.banking = 0;
  6331. clif_bank_close(sd);
  6332. }
  6333. }
  6334. /*
  6335. * Display how much we got in bank (I suppose)
  6336. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6337. */
  6338. void clif_Bank_Check(struct map_session_data* sd) {
  6339. unsigned char buf[13];
  6340. struct s_packet_db* info;
  6341. int16 len;
  6342. int cmd = 0;
  6343. nullpo_retv(sd);
  6344. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6345. if(!cmd) cmd = 0x09A6; //default
  6346. info = &packet_db[cmd];
  6347. len = info->len;
  6348. if(!len) return; //version as packet disable
  6349. // sd->state.banking = 1; //mark opening and closing
  6350. WBUFW(buf,0) = cmd;
  6351. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6352. WBUFW(buf,info->pos[1]) = 0; //reason
  6353. clif_send(buf,len,&sd->bl,SELF);
  6354. }
  6355. /*
  6356. * Requesting the data in bank
  6357. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6358. */
  6359. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6360. nullpo_retv(sd);
  6361. if( !battle_config.feature_banking ) {
  6362. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6363. return;
  6364. }
  6365. else {
  6366. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6367. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6368. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6369. clif_Bank_Check(sd);
  6370. }
  6371. }
  6372. /*
  6373. * Acknowledge of deposit some money in bank
  6374. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6375. */
  6376. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6377. unsigned char buf[17];
  6378. struct s_packet_db* info;
  6379. int16 len;
  6380. int cmd =0;
  6381. nullpo_retv(sd);
  6382. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6383. if(!cmd) cmd = 0x09A8;
  6384. info = &packet_db[cmd];
  6385. len = info->len;
  6386. if(!len) return; //version as packet disable
  6387. WBUFW(buf,0) = cmd;
  6388. WBUFW(buf,info->pos[0]) = (short)reason;
  6389. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6390. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6391. clif_send(buf,len,&sd->bl,SELF);
  6392. }
  6393. /*
  6394. * Request saving some money in bank
  6395. * @author : original [Yommy/Hercules]
  6396. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6397. */
  6398. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6399. nullpo_retv(sd);
  6400. if( !battle_config.feature_banking ) {
  6401. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6402. return;
  6403. }
  6404. else {
  6405. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6406. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6407. int money = RFIFOL(fd,info->pos[1]);
  6408. if(sd->status.account_id == aid){
  6409. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6410. clif_bank_deposit(sd,reason);
  6411. }
  6412. }
  6413. }
  6414. /*
  6415. * Acknowledge of withdrawing some money from bank
  6416. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6417. */
  6418. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6419. unsigned char buf[17];
  6420. struct s_packet_db* info;
  6421. int16 len;
  6422. int cmd;
  6423. nullpo_retv(sd);
  6424. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6425. if(!cmd) cmd = 0x09AA;
  6426. info = &packet_db[cmd];
  6427. len = info->len;
  6428. if(!len) return; //version as packet disable
  6429. WBUFW(buf,0) = cmd;
  6430. WBUFW(buf,info->pos[0]) = (short)reason;
  6431. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6432. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6433. clif_send(buf,len,&sd->bl,SELF);
  6434. }
  6435. /*
  6436. * Request Withdrawing some money from bank
  6437. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6438. */
  6439. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6440. nullpo_retv(sd);
  6441. if( !battle_config.feature_banking ) {
  6442. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6443. return;
  6444. }
  6445. else {
  6446. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6447. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6448. int money = RFIFOL(fd,info->pos[1]);
  6449. if(sd->status.account_id == aid){
  6450. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6451. clif_bank_withdraw(sd,reason);
  6452. }
  6453. }
  6454. }
  6455. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6456. /// 0125 <index>.W <amount>.L
  6457. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6458. {
  6459. int fd;
  6460. nullpo_retv(sd);
  6461. fd=sd->fd;
  6462. WFIFOHEAD(fd,packet_len(0x125));
  6463. WFIFOW(fd,0)=0x125;
  6464. WFIFOW(fd,2)=n+2;
  6465. WFIFOL(fd,4)=amount;
  6466. WFIFOSET(fd,packet_len(0x125));
  6467. }
  6468. /// Opens the shop creation menu (ZC_OPENSTORE).
  6469. /// 012d <num>.W
  6470. /// num:
  6471. /// number of allowed item slots
  6472. void clif_openvendingreq(struct map_session_data* sd, int num)
  6473. {
  6474. int fd;
  6475. nullpo_retv(sd);
  6476. fd = sd->fd;
  6477. WFIFOHEAD(fd,packet_len(0x12d));
  6478. WFIFOW(fd,0) = 0x12d;
  6479. WFIFOW(fd,2) = num;
  6480. WFIFOSET(fd,packet_len(0x12d));
  6481. }
  6482. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6483. /// 0131 <owner id>.L <message>.80B
  6484. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6485. {
  6486. unsigned char buf[128];
  6487. nullpo_retv(bl);
  6488. WBUFW(buf,0) = 0x131;
  6489. WBUFL(buf,2) = bl->id;
  6490. safestrncpy(WBUFCP(buf,6), message, 80);
  6491. if( session_isActive(fd) ) {
  6492. WFIFOHEAD(fd,packet_len(0x131));
  6493. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6494. WFIFOSET(fd,packet_len(0x131));
  6495. } else {
  6496. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6497. }
  6498. }
  6499. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6500. /// 0132 <owner id>.L
  6501. void clif_closevendingboard(struct block_list* bl, int fd)
  6502. {
  6503. unsigned char buf[16];
  6504. nullpo_retv(bl);
  6505. WBUFW(buf,0) = 0x132;
  6506. WBUFL(buf,2) = bl->id;
  6507. if( session_isActive(fd) ) {
  6508. WFIFOHEAD(fd,packet_len(0x132));
  6509. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6510. WFIFOSET(fd,packet_len(0x132));
  6511. } else {
  6512. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6513. }
  6514. }
  6515. /// Sends a list of items in a shop.
  6516. /// 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)
  6517. /// 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)
  6518. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6519. nullpo_retv( sd );
  6520. nullpo_retv( vsd );
  6521. nullpo_retv( vsd->vending );
  6522. int fd = sd->fd;
  6523. if( !session_isActive( fd ) ){
  6524. return;
  6525. }
  6526. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6527. WFIFOHEAD( fd, len );
  6528. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6529. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6530. p->packetLength = len;
  6531. p->AID = vsd->status.account_id;
  6532. #if PACKETVER >= 20100105
  6533. p->venderId = vsd->vender_id;
  6534. #endif
  6535. for( int i = 0; i < vsd->vend_num; i++ ){
  6536. int index = vsd->vending[i].index;
  6537. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6538. p->items[i].price = vsd->vending[i].value;
  6539. p->items[i].amount = vsd->vending[i].amount;
  6540. p->items[i].index = client_index( index );
  6541. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6542. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6543. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6544. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6545. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6546. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6547. #if PACKETVER >= 20150226
  6548. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6549. #if PACKETVER >= 20160921
  6550. p->items[i].location = pc_equippoint_sub( sd, data );
  6551. p->items[i].viewSprite = data->look;
  6552. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6553. p->items[i].enchantgrade = vsd->cart.u.items_cart[index].enchantgrade;
  6554. #endif
  6555. #endif
  6556. #endif
  6557. }
  6558. WFIFOSET( fd, len );
  6559. }
  6560. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6561. /// 0135 <index>.W <amount>.W <result>.B
  6562. /// result:
  6563. /// 0 = success
  6564. /// 1 = not enough zeny
  6565. /// 2 = overweight
  6566. /// 4 = out of stock
  6567. /// 5 = "cannot use an npc shop while in a trade"
  6568. /// 6 = Because the store information was incorrect the item was not purchased.
  6569. /// 7 = No sales information.
  6570. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6571. {
  6572. int fd;
  6573. nullpo_retv(sd);
  6574. fd = sd->fd;
  6575. WFIFOHEAD(fd,packet_len(0x135));
  6576. WFIFOW(fd,0) = 0x135;
  6577. WFIFOW(fd,2) = index+2;
  6578. WFIFOW(fd,4) = amount;
  6579. WFIFOB(fd,6) = fail;
  6580. WFIFOSET(fd,packet_len(0x135));
  6581. }
  6582. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6583. /// 0a28 <Result>.B
  6584. /// result:
  6585. /// 0 = Successed
  6586. /// 1 = Failed
  6587. void clif_openvending_ack(struct map_session_data* sd, int result)
  6588. {
  6589. int fd;
  6590. nullpo_retv(sd);
  6591. fd = sd->fd;
  6592. WFIFOHEAD(fd, 3);
  6593. WFIFOW(fd,0) = 0xa28;
  6594. WFIFOB(fd,2) = result;
  6595. WFIFOSET(fd, 3);
  6596. }
  6597. /// Shop creation success.
  6598. /// 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)
  6599. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6600. nullpo_retv( sd );
  6601. nullpo_retv( vending );
  6602. int fd = sd->fd;
  6603. if( !session_isActive( fd ) ){
  6604. return;
  6605. }
  6606. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6607. WFIFOHEAD( fd, len );
  6608. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6609. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6610. p->packetLength = len;
  6611. p->AID = id;
  6612. for( int i = 0; i < sd->vend_num; i++ ) {
  6613. int index = vending[i].index;
  6614. p->items[i].price = vending[i].value;
  6615. p->items[i].index = client_index( index );
  6616. p->items[i].amount = vending[i].amount;
  6617. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6618. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6619. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6620. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6621. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6622. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6623. #if PACKETVER >= 20150226
  6624. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6625. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6626. p->items[i].enchantgrade = sd->cart.u.items_cart[index].enchantgrade;
  6627. #endif
  6628. #endif
  6629. }
  6630. WFIFOSET( fd, len );
  6631. #if PACKETVER >= 20141022
  6632. /// 0 = Successed
  6633. /// 1 = Failed
  6634. clif_openvending_ack( sd, 0 );
  6635. #endif
  6636. }
  6637. /// Inform merchant that someone has bought an item.
  6638. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6639. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6640. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6641. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6642. const int cmd = 0x137;
  6643. #else
  6644. const int cmd = 0x9e5;
  6645. #endif
  6646. int fd = sd->fd;
  6647. nullpo_retv(sd);
  6648. WFIFOHEAD(fd,packet_len(cmd));
  6649. WFIFOW(fd,0) = cmd;
  6650. WFIFOW(fd,2) = index+2;
  6651. WFIFOW(fd,4) = amount;
  6652. #if PACKETVER >= 20141016
  6653. WFIFOL(fd,6) = char_id; // GID
  6654. WFIFOL(fd,10) = (int)time(NULL); // Date
  6655. WFIFOL(fd,14) = zeny; // zeny
  6656. #endif
  6657. WFIFOSET(fd,packet_len(cmd));
  6658. }
  6659. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6660. /// 00fa <result>.B
  6661. /// result:
  6662. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6663. /// 1 = MsgStringTable[78]="party name already exists"
  6664. /// 2 = MsgStringTable[79]="already in a party"
  6665. /// 3 = cannot organize parties on this map
  6666. /// ? = nothing
  6667. void clif_party_created(struct map_session_data *sd,int result)
  6668. {
  6669. int fd;
  6670. nullpo_retv(sd);
  6671. fd=sd->fd;
  6672. WFIFOHEAD(fd,packet_len(0xfa));
  6673. WFIFOW(fd,0)=0xfa;
  6674. WFIFOB(fd,2)=result;
  6675. WFIFOSET(fd,packet_len(0xfa));
  6676. }
  6677. /// Adds new member to a party.
  6678. /// 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)
  6679. /// 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)
  6680. /// 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)
  6681. /// role:
  6682. /// 0 = leader
  6683. /// 1 = normal
  6684. /// state:
  6685. /// 0 = connected
  6686. /// 1 = disconnected
  6687. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6688. {
  6689. int i;
  6690. #if PACKETVER < 20170502
  6691. unsigned char buf[81];
  6692. int cmd = 0x1e9;
  6693. int offset = 0;
  6694. #else
  6695. unsigned char buf[85];
  6696. int cmd = 0xa43;
  6697. int offset = 4;
  6698. #endif
  6699. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6700. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6701. } else {
  6702. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6703. }
  6704. if (i >= MAX_PARTY) return; //Should never happen...
  6705. sd = p->data[i].sd;
  6706. WBUFW(buf, 0) = cmd;
  6707. WBUFL(buf, 2) = sd->status.account_id;
  6708. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6709. #if PACKETVER >= 20170502
  6710. WBUFW(buf,10) = sd->status.class_;
  6711. WBUFW(buf,12) = sd->status.base_level;
  6712. #endif
  6713. WBUFW(buf,offset+10) = sd->bl.x;
  6714. WBUFW(buf,offset+12) = sd->bl.y;
  6715. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6716. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6717. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6718. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6719. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6720. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6721. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6722. }
  6723. /// Sends party information (ZC_GROUP_LIST).
  6724. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6725. /// role:
  6726. /// 0 = leader
  6727. /// 1 = normal
  6728. /// state:
  6729. /// 0 = connected
  6730. /// 1 = disconnected
  6731. /// 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
  6732. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6733. {
  6734. struct map_session_data* party_sd = NULL;
  6735. int i, c;
  6736. #if PACKETVER < 20170502
  6737. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6738. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6739. int cmd = 0xfb;
  6740. #else
  6741. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6742. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6743. int cmd = 0xa44;
  6744. #endif
  6745. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6746. nullpo_retv(p);
  6747. WBUFW(buf,0) = cmd;
  6748. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6749. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6750. {
  6751. struct party_member* m = &p->party.member[i];
  6752. if(!m->account_id) continue;
  6753. if(party_sd == NULL) party_sd = p->data[i].sd;
  6754. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6755. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6756. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6757. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6758. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6759. #if PACKETVER >= 20170502
  6760. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6761. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6762. #endif
  6763. c++;
  6764. }
  6765. #if PACKETVER < 20170502
  6766. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6767. #else
  6768. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6769. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6770. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6771. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6772. #endif
  6773. if(sd) { // send only to self
  6774. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6775. } else if (party_sd) { // send to whole party
  6776. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6777. }
  6778. }
  6779. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6780. /// 02c9 <flag>.B
  6781. /// flag:
  6782. /// 0 = allow party invites
  6783. /// 1 = auto-deny party invites
  6784. void clif_partyinvitationstate(struct map_session_data* sd)
  6785. {
  6786. int fd;
  6787. nullpo_retv(sd);
  6788. fd = sd->fd;
  6789. WFIFOHEAD(fd, packet_len(0x2c9));
  6790. WFIFOW(fd, 0) = 0x2c9;
  6791. WFIFOB(fd, 2) = 0; // not implemented
  6792. WFIFOSET(fd, packet_len(0x2c9));
  6793. }
  6794. /// Party invitation request.
  6795. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6796. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6797. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6798. {
  6799. #if PACKETVER < 20070821
  6800. const int cmd = 0xfe;
  6801. #else
  6802. const int cmd = 0x2c6;
  6803. #endif
  6804. int fd;
  6805. struct party_data *p;
  6806. nullpo_retv(sd);
  6807. nullpo_retv(tsd);
  6808. fd=tsd->fd;
  6809. if( (p=party_search(sd->status.party_id))==NULL )
  6810. return;
  6811. WFIFOHEAD(fd,packet_len(cmd));
  6812. WFIFOW(fd,0)=cmd;
  6813. WFIFOL(fd,2)=sd->status.party_id;
  6814. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6815. WFIFOSET(fd,packet_len(cmd));
  6816. }
  6817. /// Party invite result.
  6818. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6819. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6820. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6821. {
  6822. int fd;
  6823. nullpo_retv(sd);
  6824. fd=sd->fd;
  6825. #if PACKETVER < 20070904
  6826. if( reply == PARTY_REPLY_OFFLINE ) {
  6827. clif_displaymessage(fd, msg_txt(sd,3));
  6828. return;
  6829. }
  6830. #endif
  6831. #if PACKETVER < 20070821
  6832. WFIFOHEAD(fd,packet_len(0xfd));
  6833. WFIFOW(fd,0) = 0xfd;
  6834. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6835. WFIFOB(fd,26) = reply;
  6836. WFIFOSET(fd,packet_len(0xfd));
  6837. #else
  6838. WFIFOHEAD(fd,packet_len(0x2c5));
  6839. WFIFOW(fd,0) = 0x2c5;
  6840. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6841. WFIFOL(fd,26) = reply;
  6842. WFIFOSET(fd,packet_len(0x2c5));
  6843. #endif
  6844. }
  6845. /// Updates party settings.
  6846. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6847. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6848. /// exp option:
  6849. /// 0 = exp sharing disabled
  6850. /// 1 = exp sharing enabled
  6851. /// 2 = cannot change exp sharing
  6852. ///
  6853. /// flag:
  6854. /// 0 = send to party
  6855. /// 1 = send to sd
  6856. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6857. {
  6858. unsigned char buf[16];
  6859. #if PACKETVER < 20090603
  6860. const int cmd = 0x101;
  6861. #else
  6862. const int cmd = 0x7d8;
  6863. #endif
  6864. nullpo_retv(p);
  6865. if(!sd && flag==0){
  6866. int i;
  6867. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6868. if (i < MAX_PARTY)
  6869. sd = p->data[i].sd;
  6870. }
  6871. if(!sd) return;
  6872. WBUFW(buf,0)=cmd;
  6873. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6874. #if PACKETVER >= 20090603
  6875. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6876. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6877. #endif
  6878. if(flag==0)
  6879. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6880. else
  6881. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6882. }
  6883. /**
  6884. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6885. * @param sd Send the notification for this player
  6886. * @param account_id Account ID of kicked member
  6887. * @param name Name of kicked member
  6888. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6889. * @param target Send target
  6890. **/
  6891. 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) {
  6892. unsigned char buf[2+4+NAME_LENGTH+1];
  6893. if (!sd)
  6894. return;
  6895. WBUFW(buf,0) = 0x0105;
  6896. WBUFL(buf,2) = account_id;
  6897. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6898. WBUFB(buf,6+NAME_LENGTH) = result;
  6899. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6900. }
  6901. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6902. /// 0109 <packet len>.W <account id>.L <message>.?B
  6903. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6904. {
  6905. struct map_session_data *sd;
  6906. int i;
  6907. nullpo_retv(p);
  6908. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6909. if(i < MAX_PARTY){
  6910. unsigned char buf[1024];
  6911. if( len > sizeof(buf)-8 )
  6912. {
  6913. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6914. len = sizeof(buf)-8;
  6915. }
  6916. sd = p->data[i].sd;
  6917. WBUFW(buf,0)=0x109;
  6918. WBUFW(buf,2)=len+8;
  6919. WBUFL(buf,4)=account_id;
  6920. safestrncpy(WBUFCP(buf,8), mes, len);
  6921. clif_send(buf,len+8,&sd->bl,PARTY);
  6922. }
  6923. }
  6924. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6925. /// 0107 <account id>.L <x>.W <y>.W
  6926. void clif_party_xy(struct map_session_data *sd)
  6927. {
  6928. unsigned char buf[16];
  6929. nullpo_retv(sd);
  6930. WBUFW(buf,0)=0x107;
  6931. WBUFL(buf,2)=sd->status.account_id;
  6932. WBUFW(buf,6)=sd->bl.x;
  6933. WBUFW(buf,8)=sd->bl.y;
  6934. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6935. }
  6936. /*==========================================
  6937. * Sends x/y dot to a single fd. [Skotlex]
  6938. *------------------------------------------*/
  6939. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6940. {
  6941. WFIFOHEAD(fd,packet_len(0x107));
  6942. WFIFOW(fd,0)=0x107;
  6943. WFIFOL(fd,2)=sd->status.account_id;
  6944. WFIFOW(fd,6)=sd->bl.x;
  6945. WFIFOW(fd,8)=sd->bl.y;
  6946. WFIFOSET(fd,packet_len(0x107));
  6947. }
  6948. /// Updates HP bar of a party member.
  6949. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6950. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6951. void clif_party_hp(struct map_session_data *sd)
  6952. {
  6953. unsigned char buf[16];
  6954. #if PACKETVER < 20100126
  6955. const int cmd = 0x106;
  6956. #else
  6957. const int cmd = 0x80e;
  6958. #endif
  6959. nullpo_retv(sd);
  6960. WBUFW(buf,0)=cmd;
  6961. WBUFL(buf,2)=sd->status.account_id;
  6962. #if PACKETVER < 20100126
  6963. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6964. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6965. WBUFW(buf,8) = 100;
  6966. } else {
  6967. WBUFW(buf,6) = sd->battle_status.hp;
  6968. WBUFW(buf,8) = sd->battle_status.max_hp;
  6969. }
  6970. #else
  6971. WBUFL(buf,6) = sd->battle_status.hp;
  6972. WBUFL(buf,10) = sd->battle_status.max_hp;
  6973. #endif
  6974. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6975. }
  6976. /// Notifies the party members of a character's death or revival.
  6977. /// 0AB2 <GID>.L <dead>.B
  6978. void clif_party_dead( struct map_session_data *sd ){
  6979. #if PACKETVER >= 20170502
  6980. unsigned char buf[7];
  6981. nullpo_retv(sd);
  6982. WBUFW(buf, 0) = 0xab2;
  6983. WBUFL(buf, 2) = sd->status.account_id;
  6984. WBUFB(buf, 6) = pc_isdead(sd);
  6985. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6986. #endif
  6987. }
  6988. /// Updates the job and level of a party member
  6989. /// 0abd <account id>.L <job>.W <level>.W
  6990. void clif_party_job_and_level(struct map_session_data *sd){
  6991. #if PACKETVER >= 20170502
  6992. unsigned char buf[10];
  6993. nullpo_retv(sd);
  6994. WBUFW(buf, 0) = 0xabd;
  6995. WBUFL(buf, 2) = sd->status.account_id;
  6996. WBUFW(buf, 6) = sd->status.class_;
  6997. WBUFW(buf, 8) = sd->status.base_level;
  6998. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6999. #endif
  7000. }
  7001. /*==========================================
  7002. * Sends HP bar to a single fd. [Skotlex]
  7003. *------------------------------------------*/
  7004. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  7005. {
  7006. #if PACKETVER < 20100126
  7007. const int cmd = 0x106;
  7008. #else
  7009. const int cmd = 0x80e;
  7010. #endif
  7011. WFIFOHEAD(fd,packet_len(cmd));
  7012. WFIFOW(fd,0) = cmd;
  7013. WFIFOL(fd,2) = id;
  7014. #if PACKETVER < 20100126
  7015. if( maxhp > INT16_MAX )
  7016. {// To correctly display the %hp bar. [Skotlex]
  7017. WFIFOW(fd,6) = hp/(maxhp/100);
  7018. WFIFOW(fd,8) = 100;
  7019. } else {
  7020. WFIFOW(fd,6) = hp;
  7021. WFIFOW(fd,8) = maxhp;
  7022. }
  7023. #else
  7024. WFIFOL(fd,6) = hp;
  7025. WFIFOL(fd,10) = maxhp;
  7026. #endif
  7027. WFIFOSET(fd, packet_len(cmd));
  7028. }
  7029. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7030. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7031. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  7032. {
  7033. int fd;
  7034. nullpo_retv(sd);
  7035. nullpo_retv(bl);
  7036. fd=sd->fd;
  7037. WFIFOHEAD(fd,packet_len(0x139));
  7038. WFIFOW(fd, 0)=0x139;
  7039. WFIFOL(fd, 2)=bl->id;
  7040. WFIFOW(fd, 6)=bl->x;
  7041. WFIFOW(fd, 8)=bl->y;
  7042. WFIFOW(fd,10)=sd->bl.x;
  7043. WFIFOW(fd,12)=sd->bl.y;
  7044. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7045. WFIFOSET(fd,packet_len(0x139));
  7046. }
  7047. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7048. /// 018f <result>.W <name id>.W
  7049. /// result:
  7050. /// 0 = success
  7051. /// 1 = failure
  7052. /// 2 = success (alchemist)
  7053. /// 3 = failure (alchemist)
  7054. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  7055. nullpo_retv( sd );
  7056. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7057. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7058. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7059. p.result = flag;
  7060. p.itemId = client_nameid( nameid );
  7061. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7062. }
  7063. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7064. /// 019e
  7065. void clif_catch_process(struct map_session_data *sd)
  7066. {
  7067. int fd;
  7068. nullpo_retv(sd);
  7069. fd=sd->fd;
  7070. WFIFOHEAD(fd,packet_len(0x19e));
  7071. WFIFOW(fd,0)=0x19e;
  7072. WFIFOSET(fd,packet_len(0x19e));
  7073. }
  7074. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7075. /// 01a0 <result>.B
  7076. /// 0 = failure
  7077. /// 1 = success
  7078. void clif_pet_roulette(struct map_session_data *sd,int data)
  7079. {
  7080. int fd;
  7081. nullpo_retv(sd);
  7082. fd=sd->fd;
  7083. WFIFOHEAD(fd,packet_len(0x1a0));
  7084. WFIFOW(fd,0)=0x1a0;
  7085. WFIFOB(fd,2)=data;
  7086. WFIFOSET(fd,packet_len(0x1a0));
  7087. }
  7088. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7089. /// 01a6 <packet len>.W { <index>.W }*
  7090. void clif_sendegg(struct map_session_data *sd)
  7091. {
  7092. int i,n=0,fd;
  7093. nullpo_retv(sd);
  7094. fd=sd->fd;
  7095. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7096. clif_displaymessage(fd, msg_txt(sd,666));
  7097. return;
  7098. }
  7099. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7100. WFIFOW(fd,0)=0x1a6;
  7101. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7102. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7103. sd->inventory_data[i]->type != IT_PETEGG ||
  7104. sd->inventory.u.items_inventory[i].amount <= 0)
  7105. continue;
  7106. WFIFOW(fd,n*2+4)=client_index(i);
  7107. n++;
  7108. }
  7109. WFIFOW(fd,2)=4+n*2;
  7110. WFIFOSET(fd,WFIFOW(fd,2));
  7111. sd->menuskill_id = SA_TAMINGMONSTER;
  7112. sd->menuskill_val = -1;
  7113. }
  7114. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7115. /// 01a4 <type>.B <id>.L <data>.L
  7116. /// type:
  7117. /// 0 = pre-init (data = 0)
  7118. /// 1 = intimacy (data = 0~4)
  7119. /// 2 = hunger (data = 0~4)
  7120. /// 3 = accessory
  7121. /// 4 = performance (data = 1~3: normal, 4: special)
  7122. /// 5 = hairstyle
  7123. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7124. ///
  7125. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7126. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  7127. {
  7128. uint8 buf[16];
  7129. nullpo_retv(pd);
  7130. WBUFW(buf,0) = 0x1a4;
  7131. WBUFB(buf,2) = type;
  7132. WBUFL(buf,3) = pd->bl.id;
  7133. WBUFL(buf,7) = param;
  7134. if (sd)
  7135. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7136. else
  7137. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7138. }
  7139. /// Pet's base data (ZC_PROPERTY_PET).
  7140. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7141. void clif_send_petstatus(struct map_session_data *sd)
  7142. {
  7143. int fd;
  7144. struct s_pet *pet;
  7145. nullpo_retv(sd);
  7146. nullpo_retv(sd->pd);
  7147. fd=sd->fd;
  7148. pet = &sd->pd->pet;
  7149. WFIFOHEAD(fd,packet_len(0x1a2));
  7150. WFIFOW(fd,0)=0x1a2;
  7151. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7152. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7153. WFIFOW(fd,27)=pet->level;
  7154. WFIFOW(fd,29)=pet->hungry;
  7155. WFIFOW(fd,31)=pet->intimate;
  7156. WFIFOW(fd,33)=pet->equip;
  7157. #if PACKETVER >= 20081126
  7158. WFIFOW(fd,35)=pet->class_;
  7159. #endif
  7160. WFIFOSET(fd,packet_len(0x1a2));
  7161. }
  7162. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7163. /// 01aa <id>.L <data>.L
  7164. /// data:
  7165. /// @see CZ_PET_ACT.
  7166. void clif_pet_emotion(struct pet_data *pd,int param)
  7167. {
  7168. unsigned char buf[16];
  7169. nullpo_retv(pd);
  7170. memset(buf,0,packet_len(0x1aa));
  7171. WBUFW(buf,0)=0x1aa;
  7172. WBUFL(buf,2)=pd->bl.id;
  7173. WBUFL(buf,6)=param;
  7174. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7175. }
  7176. /// Result of request to feed a pet (ZC_FEED_PET).
  7177. /// 01a3 <result>.B <name id>.W
  7178. /// result:
  7179. /// 0 = failure
  7180. /// 1 = success
  7181. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7182. nullpo_retv( sd );
  7183. struct PACKET_ZC_FEED_PET p;
  7184. p.packetType = 0x1a3;
  7185. p.result = fail;
  7186. p.itemId = client_nameid( foodid );
  7187. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7188. }
  7189. /// Send pet auto feed info.
  7190. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7191. #if PACKETVER >= 20141008
  7192. nullpo_retv(sd);
  7193. if (force || battle_config.pet_autofeed_always) {
  7194. // Always send ON or OFF
  7195. if (sd->pd && battle_config.feature_pet_autofeed) {
  7196. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7197. }
  7198. else {
  7199. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7200. }
  7201. }
  7202. else {
  7203. // Only send when enabled
  7204. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7205. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7206. }
  7207. }
  7208. #endif
  7209. }
  7210. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7211. /// 01cd { <skill id>.L }*7
  7212. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7213. {
  7214. nullpo_retv(sd);
  7215. int fd = sd->fd;
  7216. #ifdef RENEWAL
  7217. uint16 autospell_skill[][2] = {
  7218. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7219. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7220. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7221. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7222. };
  7223. int count = 0;
  7224. WFIFOHEAD(fd, 2 * 6 + 4);
  7225. WFIFOW(fd, 0) = 0x442;
  7226. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7227. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7228. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7229. count++;
  7230. }
  7231. }
  7232. WFIFOW(fd, 2) = 8 + count * 2;
  7233. WFIFOL(fd, 4) = count;
  7234. WFIFOSET(fd, WFIFOW(fd, 2));
  7235. #else
  7236. WFIFOHEAD(fd,packet_len(0x1cd));
  7237. WFIFOW(fd, 0)=0x1cd;
  7238. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7239. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7240. else
  7241. WFIFOL(fd,2)= 0x00000000;
  7242. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7243. WFIFOL(fd,6)= MG_COLDBOLT;
  7244. else
  7245. WFIFOL(fd,6)= 0x00000000;
  7246. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7247. WFIFOL(fd,10)= MG_FIREBOLT;
  7248. else
  7249. WFIFOL(fd,10)= 0x00000000;
  7250. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7251. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7252. else
  7253. WFIFOL(fd,14)= 0x00000000;
  7254. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7255. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7256. else
  7257. WFIFOL(fd,18)= 0x00000000;
  7258. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7259. WFIFOL(fd,22)= MG_FIREBALL;
  7260. else
  7261. WFIFOL(fd,22)= 0x00000000;
  7262. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7263. WFIFOL(fd,26)= MG_FROSTDIVER;
  7264. else
  7265. WFIFOL(fd,26)= 0x00000000;
  7266. WFIFOSET(fd,packet_len(0x1cd));
  7267. #endif
  7268. sd->menuskill_id = SA_AUTOSPELL;
  7269. sd->menuskill_val = skill_lv;
  7270. }
  7271. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7272. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7273. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7274. {
  7275. unsigned char buf[56];
  7276. nullpo_retv(src);
  7277. memset(buf,0,packet_len(0x1cf));
  7278. WBUFW(buf,0) = 0x1cf;
  7279. WBUFL(buf,2) = src->id;
  7280. if( src->type == BL_MER )
  7281. {
  7282. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7283. if( md && md->master && md->devotion_flag )
  7284. WBUFL(buf,6) = md->master->bl.id;
  7285. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7286. }
  7287. else
  7288. {
  7289. int i;
  7290. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7291. if( sd == NULL )
  7292. return;
  7293. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7294. WBUFL(buf,6+4*i) = sd->devotion[i];
  7295. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7296. }
  7297. if( tsd )
  7298. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7299. else
  7300. clif_send(buf, packet_len(0x1cf), src, AREA);
  7301. }
  7302. /// Notifies the client of an object's spirits.
  7303. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7304. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7305. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7306. nullpo_retv( bl );
  7307. struct PACKET_ZC_SPIRITS p = {};
  7308. p.packetType = HEADER_ZC_SPIRITS;
  7309. p.GID = bl->id;
  7310. switch( bl->type ){
  7311. case BL_PC:
  7312. p.amount = ( (struct map_session_data*)bl )->spiritball;
  7313. break;
  7314. case BL_HOM:
  7315. p.amount = ( (struct homun_data*)bl )->homunculus.spiritball;
  7316. break;
  7317. }
  7318. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7319. }
  7320. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7321. /// 01d2 <account id>.L <delay>.L
  7322. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7323. {
  7324. unsigned char buf[32];
  7325. nullpo_retv(bl);
  7326. WBUFW(buf,0)=0x1d2;
  7327. WBUFL(buf,2)=bl->id;
  7328. WBUFL(buf,6)=client_tick(wait);
  7329. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7330. }
  7331. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7332. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7333. /// flag:
  7334. /// 0 = inactive
  7335. /// 1 = active
  7336. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7337. {
  7338. unsigned char buf[32];
  7339. nullpo_retv(src);
  7340. WBUFW(buf,0)=0x1d1;
  7341. WBUFL(buf,2)=src->id;
  7342. WBUFL(buf,6)=dst_id;
  7343. WBUFL(buf,10)=active;
  7344. clif_send(buf,packet_len(0x1d1),src,AREA);
  7345. }
  7346. /// MVP effect (ZC_MVP).
  7347. /// 010c <account id>.L
  7348. void clif_mvp_effect(struct map_session_data *sd)
  7349. {
  7350. unsigned char buf[16];
  7351. nullpo_retv(sd);
  7352. WBUFW(buf,0)=0x10c;
  7353. WBUFL(buf,2)=sd->bl.id;
  7354. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7355. }
  7356. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7357. /// 010a <name id>.W
  7358. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7359. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7360. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7361. p.itemId = client_nameid( nameid );
  7362. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7363. }
  7364. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7365. /// 010b <exp>.L
  7366. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7367. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7368. if (battle_config.mvp_exp_reward_message) {
  7369. char e_msg[CHAT_SIZE_MAX];
  7370. sprintf(e_msg, msg_txt(sd, 717), exp);
  7371. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7372. }
  7373. #else
  7374. int fd;
  7375. nullpo_retv(sd);
  7376. fd = sd->fd;
  7377. WFIFOHEAD(fd, packet_len(0x10b));
  7378. WFIFOW(fd,0) = 0x10b;
  7379. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7380. WFIFOSET(fd, packet_len(0x10b));
  7381. #endif
  7382. }
  7383. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7384. /// 010d
  7385. ///
  7386. /// "You are the MVP, but cannot obtain the reward because
  7387. /// you are overweight."
  7388. void clif_mvp_noitem(struct map_session_data* sd)
  7389. {
  7390. int fd = sd->fd;
  7391. WFIFOHEAD(fd,packet_len(0x10d));
  7392. WFIFOW(fd,0) = 0x10d;
  7393. WFIFOSET(fd,packet_len(0x10d));
  7394. }
  7395. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7396. /// 0167 <result>.B
  7397. /// result:
  7398. /// 0 = "Guild has been created."
  7399. /// 1 = "You are already in a Guild."
  7400. /// 2 = "That Guild Name already exists."
  7401. /// 3 = "You need the neccessary item to create a Guild."
  7402. void clif_guild_created(struct map_session_data *sd,int flag)
  7403. {
  7404. int fd;
  7405. nullpo_retv(sd);
  7406. fd=sd->fd;
  7407. WFIFOHEAD(fd,packet_len(0x167));
  7408. WFIFOW(fd,0)=0x167;
  7409. WFIFOB(fd,2)=flag;
  7410. WFIFOSET(fd,packet_len(0x167));
  7411. }
  7412. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7413. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7414. /// mode:
  7415. /// &0x01 = allow invite
  7416. /// &0x10 = allow expel
  7417. void clif_guild_belonginfo(struct map_session_data *sd)
  7418. {
  7419. int ps,fd;
  7420. struct guild* g;
  7421. nullpo_retv(sd);
  7422. nullpo_retv(g = sd->guild);
  7423. fd=sd->fd;
  7424. ps=guild_getposition(sd);
  7425. WFIFOHEAD(fd,packet_len(0x16c));
  7426. WFIFOW(fd,0)=0x16c;
  7427. WFIFOL(fd,2)=g->guild_id;
  7428. WFIFOL(fd,6)=g->emblem_id;
  7429. WFIFOL(fd,10)=g->position[ps].mode;
  7430. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7431. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7432. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7433. WFIFOSET(fd,packet_len(0x16c));
  7434. }
  7435. /// Guild member login notice.
  7436. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7437. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7438. /// status:
  7439. /// 0 = offline
  7440. /// 1 = online
  7441. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7442. {
  7443. unsigned char buf[64];
  7444. struct map_session_data* sd;
  7445. nullpo_retv(g);
  7446. WBUFW(buf, 0)=0x1f2;
  7447. WBUFL(buf, 2)=g->member[idx].account_id;
  7448. WBUFL(buf, 6)=g->member[idx].char_id;
  7449. WBUFL(buf,10)=flag;
  7450. if( ( sd = g->member[idx].sd ) != NULL )
  7451. {
  7452. WBUFW(buf,14) = sd->status.sex;
  7453. WBUFW(buf,16) = sd->status.hair;
  7454. WBUFW(buf,18) = sd->status.hair_color;
  7455. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7456. }
  7457. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7458. {
  7459. WBUFW(buf,14) = 0;
  7460. WBUFW(buf,16) = 0;
  7461. WBUFW(buf,18) = 0;
  7462. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7463. }
  7464. }
  7465. // Function `clif_guild_memberlogin_notice` sends info about
  7466. // logins and logouts of a guild member to the rest members.
  7467. // But at the 1st time (after a player login or map changing)
  7468. // the client won't show the message.
  7469. // So I suggest use this function for sending "first-time-info"
  7470. // to some player on entering the game or changing location.
  7471. // At next time the client would always show the message.
  7472. // The function sends all the statuses in the single packet
  7473. // to economize traffic. [LuzZza]
  7474. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7475. {
  7476. struct guild *g;
  7477. unsigned char buf[14*128];
  7478. int i, count=0, p_len;
  7479. nullpo_retv(sd);
  7480. p_len = packet_len(0x16d);
  7481. if(!(g = sd->guild))
  7482. return;
  7483. for(i=0; i<g->max_member; i++) {
  7484. if(g->member[i].account_id > 0 &&
  7485. g->member[i].account_id != sd->status.account_id) {
  7486. WBUFW(buf,count*p_len) = 0x16d;
  7487. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7488. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7489. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7490. count++;
  7491. }
  7492. }
  7493. clif_send(buf, p_len*count, &sd->bl, SELF);
  7494. }
  7495. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7496. /// 014e <menu flag>.L
  7497. /// menu flag:
  7498. /// 0x00 = Basic Info (always on)
  7499. /// &0x01 = Member manager
  7500. /// &0x02 = Positions
  7501. /// &0x04 = Skills
  7502. /// &0x10 = Expulsion list
  7503. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7504. /// &0x80 = Notice
  7505. void clif_guild_masterormember(struct map_session_data *sd)
  7506. {
  7507. int fd;
  7508. nullpo_retv(sd);
  7509. fd=sd->fd;
  7510. WFIFOHEAD(fd,packet_len(0x14e));
  7511. WFIFOW(fd,0) = 0x14e;
  7512. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7513. WFIFOSET(fd,packet_len(0x14e));
  7514. }
  7515. /// Guild basic information (Territories [Valaris])
  7516. /// 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)
  7517. /// 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)
  7518. /// 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)
  7519. void clif_guild_basicinfo(struct map_session_data *sd) {
  7520. int fd;
  7521. struct guild *g;
  7522. #if PACKETVER < 20160622
  7523. int cmd = 0x1b6;
  7524. int offset = NAME_LENGTH;
  7525. #else
  7526. int cmd = 0xa84;
  7527. int offset = 0;
  7528. #endif
  7529. nullpo_retv(sd);
  7530. fd = sd->fd;
  7531. if( (g = sd->guild) == NULL )
  7532. return;
  7533. WFIFOHEAD(fd,packet_len(cmd));
  7534. WFIFOW(fd, 0)=cmd;
  7535. WFIFOL(fd, 2)=g->guild_id;
  7536. WFIFOL(fd, 6)=g->guild_lv;
  7537. WFIFOL(fd,10)=g->connect_member;
  7538. WFIFOL(fd,14)=g->max_member;
  7539. WFIFOL(fd,18)=g->average_lv;
  7540. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7541. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7542. WFIFOL(fd,30)=0; // Tax Points
  7543. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7544. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7545. WFIFOL(fd,42)=g->emblem_id;
  7546. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7547. #if PACKETVER < 20160622
  7548. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7549. #endif
  7550. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7551. WFIFOL(fd,70+offset+16) = 0; // zeny
  7552. #if PACKETVER >= 20160622
  7553. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7554. #endif
  7555. WFIFOSET(fd,packet_len(cmd));
  7556. }
  7557. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7558. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7559. void clif_guild_allianceinfo(struct map_session_data *sd)
  7560. {
  7561. int fd,i,c;
  7562. struct guild *g;
  7563. nullpo_retv(sd);
  7564. if( (g = sd->guild) == NULL )
  7565. return;
  7566. fd = sd->fd;
  7567. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7568. WFIFOW(fd, 0)=0x14c;
  7569. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7570. struct guild_alliance *a=&g->alliance[i];
  7571. if(a->guild_id>0){
  7572. WFIFOL(fd,c*32+4)=a->opposition;
  7573. WFIFOL(fd,c*32+8)=a->guild_id;
  7574. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7575. c++;
  7576. }
  7577. }
  7578. WFIFOW(fd, 2)=c*32+4;
  7579. WFIFOSET(fd,WFIFOW(fd,2));
  7580. }
  7581. /// Guild member manager information
  7582. /// 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)
  7583. /// state:
  7584. /// 0 = offline
  7585. /// 1 = online
  7586. /// memo:
  7587. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7588. /// 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)
  7589. void clif_guild_memberlist(struct map_session_data *sd)
  7590. {
  7591. int fd;
  7592. int i,c;
  7593. struct guild *g;
  7594. #if PACKETVER < 20161026
  7595. int cmd = 0x154;
  7596. int size = 104;
  7597. #else
  7598. int cmd = 0xaa5;
  7599. int size = 34;
  7600. #endif
  7601. nullpo_retv(sd);
  7602. if( !session_isActive(fd = sd->fd) )
  7603. return;
  7604. if( (g = sd->guild) == NULL )
  7605. return;
  7606. WFIFOHEAD(fd, g->max_member * size + 4);
  7607. WFIFOW(fd, 0)=cmd;
  7608. for(i=0,c=0;i<g->max_member;i++){
  7609. struct guild_member *m=&g->member[i];
  7610. if(m->account_id==0)
  7611. continue;
  7612. WFIFOL(fd,c*size+ 4)=m->account_id;
  7613. WFIFOL(fd,c*size+ 8)=m->char_id;
  7614. WFIFOW(fd,c*size+12)=m->hair;
  7615. WFIFOW(fd,c*size+14)=m->hair_color;
  7616. WFIFOW(fd,c*size+16)=m->gender;
  7617. WFIFOW(fd,c*size+18)=m->class_;
  7618. WFIFOW(fd,c*size+20)=m->lv;
  7619. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7620. WFIFOL(fd,c*size+26)=m->online;
  7621. WFIFOL(fd,c*size+30)=m->position;
  7622. #if PACKETVER < 20161026
  7623. 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.
  7624. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7625. #else
  7626. WFIFOL(fd,c*size+34)=m->last_login;
  7627. #endif
  7628. c++;
  7629. }
  7630. WFIFOW(fd, 2)=c*size+4;
  7631. WFIFOSET(fd,WFIFOW(fd,2));
  7632. }
  7633. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7634. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7635. void clif_guild_positionnamelist(struct map_session_data *sd)
  7636. {
  7637. int i,fd;
  7638. struct guild *g;
  7639. nullpo_retv(sd);
  7640. if( (g = sd->guild) == NULL )
  7641. return;
  7642. fd = sd->fd;
  7643. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7644. WFIFOW(fd, 0)=0x166;
  7645. for(i=0;i<MAX_GUILDPOSITION;i++){
  7646. WFIFOL(fd,i*28+4)=i;
  7647. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7648. }
  7649. WFIFOW(fd,2)=i*28+4;
  7650. WFIFOSET(fd,WFIFOW(fd,2));
  7651. }
  7652. /// Guild position information (ZC_POSITION_INFO).
  7653. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7654. /// mode:
  7655. /// &0x01 = allow invite
  7656. /// &0x10 = allow expel
  7657. /// ranking:
  7658. /// TODO
  7659. void clif_guild_positioninfolist(struct map_session_data *sd)
  7660. {
  7661. int i,fd;
  7662. struct guild *g;
  7663. nullpo_retv(sd);
  7664. if( (g = sd->guild) == NULL )
  7665. return;
  7666. fd = sd->fd;
  7667. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7668. WFIFOW(fd, 0)=0x160;
  7669. for(i=0;i<MAX_GUILDPOSITION;i++){
  7670. struct guild_position *p=&g->position[i];
  7671. WFIFOL(fd,i*16+ 4)=i;
  7672. WFIFOL(fd,i*16+ 8)=p->mode;
  7673. WFIFOL(fd,i*16+12)=i;
  7674. WFIFOL(fd,i*16+16)=p->exp_mode;
  7675. }
  7676. WFIFOW(fd, 2)=i*16+4;
  7677. WFIFOSET(fd,WFIFOW(fd,2));
  7678. }
  7679. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7680. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7681. /// mode:
  7682. /// &0x01 = allow invite
  7683. /// &0x10 = allow expel
  7684. /// ranking:
  7685. /// TODO
  7686. void clif_guild_positionchanged(struct guild *g,int idx)
  7687. {
  7688. // FIXME: This packet is intended to update the clients after a
  7689. // commit of position info changes, not sending one packet per
  7690. // position.
  7691. struct map_session_data *sd;
  7692. unsigned char buf[128];
  7693. nullpo_retv(g);
  7694. WBUFW(buf, 0)=0x174;
  7695. WBUFW(buf, 2)=44; // packet len
  7696. // GUILD_REG_POSITION_INFO{
  7697. WBUFL(buf, 4)=idx;
  7698. WBUFL(buf, 8)=g->position[idx].mode;
  7699. WBUFL(buf,12)=idx;
  7700. WBUFL(buf,16)=g->position[idx].exp_mode;
  7701. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7702. // }*
  7703. if( (sd=guild_getavailablesd(g))!=NULL )
  7704. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7705. }
  7706. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7707. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7708. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7709. {
  7710. // FIXME: This packet is intended to update the clients after a
  7711. // commit of member position assignment changes, not sending one
  7712. // packet per position.
  7713. struct map_session_data *sd;
  7714. unsigned char buf[64];
  7715. nullpo_retv(g);
  7716. WBUFW(buf, 0)=0x156;
  7717. WBUFW(buf, 2)=16; // packet len
  7718. // MEMBER_POSITION_INFO{
  7719. WBUFL(buf, 4)=g->member[idx].account_id;
  7720. WBUFL(buf, 8)=g->member[idx].char_id;
  7721. WBUFL(buf,12)=g->member[idx].position;
  7722. // }*
  7723. if( (sd=guild_getavailablesd(g))!=NULL )
  7724. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7725. }
  7726. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7727. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7728. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7729. {
  7730. int fd;
  7731. nullpo_retv(sd);
  7732. nullpo_retv(g);
  7733. fd = sd->fd;
  7734. if( g->emblem_len <= 0 )
  7735. return;
  7736. WFIFOHEAD(fd,g->emblem_len+12);
  7737. WFIFOW(fd,0)=0x152;
  7738. WFIFOW(fd,2)=g->emblem_len+12;
  7739. WFIFOL(fd,4)=g->guild_id;
  7740. WFIFOL(fd,8)=g->emblem_id;
  7741. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7742. WFIFOSET(fd,WFIFOW(fd,2));
  7743. }
  7744. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7745. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7746. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7747. void clif_guild_emblem_area(struct block_list* bl)
  7748. {
  7749. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7750. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7751. PACKET_ZC_CHANGE_GUILD p{};
  7752. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7753. p.guild_id = status_get_guild_id(bl);
  7754. p.emblem_id = status_get_emblem_id(bl);
  7755. #if PACKETVER < 20190724
  7756. p.aid = bl->id;
  7757. #else
  7758. p.unknown = 0;
  7759. #endif
  7760. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7761. }
  7762. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7763. /// 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 }*
  7764. void clif_guild_skillinfo(struct map_session_data* sd)
  7765. {
  7766. int fd;
  7767. struct guild* g;
  7768. int i,c;
  7769. nullpo_retv(sd);
  7770. if( (g = sd->guild) == NULL )
  7771. return;
  7772. fd = sd->fd;
  7773. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7774. WFIFOW(fd,0) = 0x0162;
  7775. WFIFOW(fd,4) = g->skill_point;
  7776. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7777. {
  7778. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7779. {
  7780. int id = g->skill[i].id;
  7781. int p = 6 + c*37;
  7782. WFIFOW(fd,p+0) = id;
  7783. WFIFOL(fd,p+2) = skill_get_inf(id);
  7784. WFIFOW(fd,p+6) = g->skill[i].lv;
  7785. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7786. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7787. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7788. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7789. c++;
  7790. }
  7791. }
  7792. WFIFOW(fd,2) = 6 + c*37;
  7793. WFIFOSET(fd,WFIFOW(fd,2));
  7794. }
  7795. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7796. /// 016f <subject>.60B <notice>.120B
  7797. void clif_guild_notice(struct map_session_data* sd)
  7798. {
  7799. struct guild* g;
  7800. nullpo_retv(sd);
  7801. nullpo_retv(g = sd->guild);
  7802. int fd = sd->fd;
  7803. if ( !session_isActive(fd) )
  7804. return;
  7805. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7806. return;
  7807. WFIFOHEAD(fd,packet_len(0x16f));
  7808. WFIFOW(fd,0) = 0x16f;
  7809. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7810. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7811. WFIFOSET(fd,packet_len(0x16f));
  7812. }
  7813. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7814. /// 016a <guild id>.L <guild name>.24B
  7815. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7816. {
  7817. int fd;
  7818. nullpo_retv(sd);
  7819. nullpo_retv(g);
  7820. fd=sd->fd;
  7821. WFIFOHEAD(fd,packet_len(0x16a));
  7822. WFIFOW(fd,0)=0x16a;
  7823. WFIFOL(fd,2)=g->guild_id;
  7824. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7825. WFIFOSET(fd,packet_len(0x16a));
  7826. }
  7827. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7828. /// 0169 <answer>.B
  7829. /// answer:
  7830. /// 0 = Already in guild.
  7831. /// 1 = Offer rejected.
  7832. /// 2 = Offer accepted.
  7833. /// 3 = Guild full.
  7834. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7835. {
  7836. int fd;
  7837. nullpo_retv(sd);
  7838. fd=sd->fd;
  7839. WFIFOHEAD(fd,packet_len(0x169));
  7840. WFIFOW(fd,0)=0x169;
  7841. WFIFOB(fd,2)=flag;
  7842. WFIFOSET(fd,packet_len(0x169));
  7843. }
  7844. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7845. /// 015a <char name>.24B <reason>.40B
  7846. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7847. {
  7848. unsigned char buf[128];
  7849. nullpo_retv(sd);
  7850. WBUFW(buf, 0)=0x15a;
  7851. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7852. memcpy(WBUFP(buf,26),mes,40);
  7853. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7854. }
  7855. /// Notifies clients of a guild of an expelled member.
  7856. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7857. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7858. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7859. {
  7860. unsigned char buf[128];
  7861. #if PACKETVER < 20100803
  7862. const unsigned short cmd = 0x15c;
  7863. #else
  7864. const unsigned short cmd = 0x839;
  7865. #endif
  7866. nullpo_retv(sd);
  7867. WBUFW(buf,0) = cmd;
  7868. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7869. safestrncpy(WBUFCP(buf,26), mes, 40);
  7870. #if PACKETVER < 20100803
  7871. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7872. #endif
  7873. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7874. }
  7875. /// Guild expulsion list (ZC_BAN_LIST).
  7876. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7877. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7878. void clif_guild_expulsionlist(struct map_session_data* sd)
  7879. {
  7880. #if PACKETVER < 20100803
  7881. const int offset = NAME_LENGTH*2+40;
  7882. #else
  7883. const int offset = NAME_LENGTH+40;
  7884. #endif
  7885. int fd, i, c = 0;
  7886. struct guild* g;
  7887. nullpo_retv(sd);
  7888. if( (g = sd->guild) == NULL )
  7889. return;
  7890. fd = sd->fd;
  7891. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7892. WFIFOW(fd,0) = 0x163;
  7893. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7894. {
  7895. struct guild_expulsion* e = &g->expulsion[i];
  7896. if( e->account_id > 0 )
  7897. {
  7898. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7899. #if PACKETVER < 20100803
  7900. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7901. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7902. #else
  7903. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7904. #endif
  7905. c++;
  7906. }
  7907. }
  7908. WFIFOW(fd,2) = 4 + c*offset;
  7909. WFIFOSET(fd,WFIFOW(fd,2));
  7910. }
  7911. /// Guild chat message (ZC_GUILD_CHAT).
  7912. /// 017f <packet len>.W <message>.?B
  7913. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7914. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7915. struct map_session_data *sd;
  7916. uint8 buf[256];
  7917. if( len == 0 )
  7918. {
  7919. return;
  7920. }
  7921. else if( len > sizeof(buf)-5 )
  7922. {
  7923. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7924. len = sizeof(buf)-5;
  7925. }
  7926. WBUFW(buf, 0) = 0x17f;
  7927. WBUFW(buf, 2) = len + 5;
  7928. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7929. if ((sd = guild_getavailablesd(g)) != NULL)
  7930. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7931. }
  7932. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7933. /// 0171 <inviter account id>.L <guild name>.24B
  7934. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7935. {
  7936. int fd;
  7937. nullpo_retv(sd);
  7938. fd=sd->fd;
  7939. WFIFOHEAD(fd,packet_len(0x171));
  7940. WFIFOW(fd,0)=0x171;
  7941. WFIFOL(fd,2)=account_id;
  7942. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7943. WFIFOSET(fd,packet_len(0x171));
  7944. }
  7945. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7946. /// 0173 <answer>.B
  7947. /// answer:
  7948. /// 0 = Already allied.
  7949. /// 1 = You rejected the offer.
  7950. /// 2 = You accepted the offer.
  7951. /// 3 = They have too any alliances.
  7952. /// 4 = You have too many alliances.
  7953. /// 5 = Alliances are disabled.
  7954. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7955. {
  7956. int fd;
  7957. nullpo_retv(sd);
  7958. fd=sd->fd;
  7959. WFIFOHEAD(fd,packet_len(0x173));
  7960. WFIFOW(fd,0)=0x173;
  7961. WFIFOL(fd,2)=flag;
  7962. WFIFOSET(fd,packet_len(0x173));
  7963. }
  7964. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7965. /// 0184 <other guild id>.L <relation>.L
  7966. /// relation:
  7967. /// 0 = Ally
  7968. /// 1 = Enemy
  7969. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7970. {
  7971. nullpo_retv(sd);
  7972. int fd = sd->fd;
  7973. if ( !session_isActive(fd) )
  7974. return;
  7975. WFIFOHEAD(fd,packet_len(0x184));
  7976. WFIFOW(fd,0)=0x184;
  7977. WFIFOL(fd,2)=guild_id;
  7978. WFIFOL(fd,6)=flag;
  7979. WFIFOSET(fd,packet_len(0x184));
  7980. }
  7981. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7982. /// 0181 <result>.B
  7983. /// result:
  7984. /// 0 = Antagonist has been set.
  7985. /// 1 = Guild has too many Antagonists.
  7986. /// 2 = Already set as an Antagonist.
  7987. /// 3 = Antagonists are disabled.
  7988. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7989. {
  7990. int fd;
  7991. nullpo_retv(sd);
  7992. fd=sd->fd;
  7993. WFIFOHEAD(fd,packet_len(0x181));
  7994. WFIFOW(fd,0)=0x181;
  7995. WFIFOB(fd,2)=flag;
  7996. WFIFOSET(fd,packet_len(0x181));
  7997. }
  7998. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7999. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  8000. /*
  8001. void clif_guild_allianceadded(struct guild *g,int idx)
  8002. {
  8003. unsigned char buf[64];
  8004. WBUFW(buf,0)=0x185;
  8005. WBUFL(buf,2)=g->alliance[idx].opposition;
  8006. WBUFL(buf,6)=g->alliance[idx].guild_id;
  8007. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  8008. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  8009. }
  8010. */
  8011. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  8012. /// 015e <reason>.L
  8013. /// 0 = success
  8014. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  8015. /// 2 = there are still members in the guild
  8016. void clif_guild_broken(struct map_session_data *sd,int flag)
  8017. {
  8018. int fd;
  8019. nullpo_retv(sd);
  8020. fd=sd->fd;
  8021. WFIFOHEAD(fd,packet_len(0x15e));
  8022. WFIFOW(fd,0)=0x15e;
  8023. WFIFOL(fd,2)=flag;
  8024. WFIFOSET(fd,packet_len(0x15e));
  8025. }
  8026. /// Displays emotion on an object (ZC_EMOTION).
  8027. /// 00c0 <id>.L <type>.B
  8028. /// type:
  8029. /// enum emotion_type
  8030. void clif_emotion(struct block_list *bl,int type)
  8031. {
  8032. unsigned char buf[8];
  8033. nullpo_retv(bl);
  8034. WBUFW(buf,0)=0xc0;
  8035. WBUFL(buf,2)=bl->id;
  8036. WBUFB(buf,6)=type;
  8037. clif_send(buf,packet_len(0xc0),bl,AREA);
  8038. }
  8039. /// Displays the contents of a talkiebox trap.
  8040. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8041. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8042. nullpo_retv( bl );
  8043. nullpo_retv( talkie );
  8044. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8045. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8046. p.aid = bl->id;
  8047. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8048. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8049. }
  8050. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8051. /// 01ea <id>.L
  8052. void clif_wedding_effect(struct block_list *bl)
  8053. {
  8054. unsigned char buf[6];
  8055. nullpo_retv(bl);
  8056. WBUFW(buf,0) = 0x1ea;
  8057. WBUFL(buf,2) = bl->id;
  8058. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8059. }
  8060. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8061. /// 01e6 <partner name>.24B
  8062. void clif_callpartner(struct map_session_data *sd)
  8063. {
  8064. unsigned char buf[26];
  8065. nullpo_retv(sd);
  8066. WBUFW(buf,0) = 0x1e6;
  8067. if( sd->status.partner_id ) {
  8068. const char *p = map_charid2nick(sd->status.partner_id);
  8069. struct map_session_data *p_sd = pc_get_partner(sd);
  8070. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  8071. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  8072. else
  8073. WBUFB(buf,2) = 0;
  8074. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8075. WBUFB(buf,2) = 0;
  8076. }
  8077. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  8078. }
  8079. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8080. /// 01e4
  8081. /// This packet while still implemented by the client is no longer being officially used.
  8082. /*
  8083. void clif_marriage_process(struct map_session_data *sd)
  8084. {
  8085. int fd;
  8086. nullpo_retv(sd);
  8087. fd=sd->fd;
  8088. WFIFOHEAD(fd,packet_len(0x1e4));
  8089. WFIFOW(fd,0)=0x1e4;
  8090. WFIFOSET(fd,packet_len(0x1e4));
  8091. }
  8092. */
  8093. /// Notice of divorce (ZC_DIVORCE).
  8094. /// 0205 <partner name>.24B
  8095. void clif_divorced(struct map_session_data* sd, const char* name)
  8096. {
  8097. int fd;
  8098. nullpo_retv(sd);
  8099. fd=sd->fd;
  8100. WFIFOHEAD(fd,packet_len(0x205));
  8101. WFIFOW(fd,0)=0x205;
  8102. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8103. WFIFOSET(fd, packet_len(0x205));
  8104. }
  8105. /// Marriage proposal (ZC_REQ_COUPLE).
  8106. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8107. /// This packet while still implemented by the client is no longer being officially used.
  8108. /*
  8109. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  8110. {
  8111. nullpo_retv(sd);
  8112. WFIFOHEAD(fd,packet_len(0x1e2));
  8113. WFIFOW(fd,0) = 0x1e2;
  8114. WFIFOL(fd,2) = ssd->status.account_id;
  8115. WFIFOL(fd,6) = ssd->status.char_id;
  8116. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8117. WFIFOSET(fd, packet_len(0x1e2));
  8118. }
  8119. */
  8120. /*==========================================
  8121. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8122. *------------------------------------------*/
  8123. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8124. {
  8125. unsigned char buf[256];
  8126. if( len == 0 ) {
  8127. return;
  8128. } else if( len > sizeof(buf)-5 ) {
  8129. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8130. len = sizeof(buf)-5;
  8131. }
  8132. WBUFW(buf, 0) = 0x17f;
  8133. WBUFW(buf, 2) = len + 5;
  8134. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8135. clif_send(buf, WBUFW(buf,2), src, target);
  8136. }
  8137. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8138. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8139. /// 00cd <result>.B
  8140. /// result:
  8141. /// 0 = failure
  8142. /// 1 = success
  8143. void clif_GM_kickack(struct map_session_data *sd, int id)
  8144. {
  8145. int fd;
  8146. nullpo_retv(sd);
  8147. fd = sd->fd;
  8148. WFIFOHEAD(fd,packet_len(0xcd));
  8149. WFIFOW(fd,0) = 0xcd;
  8150. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8151. WFIFOSET(fd, packet_len(0xcd));
  8152. }
  8153. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  8154. {
  8155. nullpo_retv(tsd);
  8156. if (sd == NULL)
  8157. tsd->state.keepshop = true;
  8158. if (session_isActive(tsd->fd))
  8159. clif_authfail_fd(tsd->fd, 15);
  8160. else
  8161. map_quit(tsd);
  8162. if (sd)
  8163. clif_GM_kickack(sd, tsd->status.account_id);
  8164. }
  8165. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8166. /// 014a <result>.L
  8167. /// result:
  8168. /// 0 = "A manner point has been successfully aligned."
  8169. /// 1 = MP_FAILURE_EXHAUST
  8170. /// 2 = MP_FAILURE_ALREADY_GIVING
  8171. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8172. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8173. /// 5 = "You got a good point from %s."
  8174. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8175. {
  8176. int fd;
  8177. nullpo_retv(sd);
  8178. fd = sd->fd;
  8179. WFIFOHEAD(fd,packet_len(0x14a));
  8180. WFIFOW(fd,0) = 0x14a;
  8181. WFIFOL(fd,2) = type;
  8182. WFIFOSET(fd, packet_len(0x14a));
  8183. }
  8184. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8185. /// 014b <type>.B <GM name>.24B
  8186. /// type:
  8187. /// 0 = positive (unmute)
  8188. /// 1 = negative (mute)
  8189. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8190. {
  8191. int fd;
  8192. nullpo_retv(sd);
  8193. nullpo_retv(tsd);
  8194. fd = tsd->fd;
  8195. WFIFOHEAD(fd,packet_len(0x14b));
  8196. WFIFOW(fd,0) = 0x14b;
  8197. WFIFOB(fd,2) = type;
  8198. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8199. WFIFOSET(fd, packet_len(0x14b));
  8200. }
  8201. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8202. /// 00d1 <type>.B <result>.B
  8203. /// type:
  8204. /// 0 = /ex (deny)
  8205. /// 1 = /in (allow)
  8206. /// result:
  8207. /// 0 = success
  8208. /// 1 = failure
  8209. /// 2 = too many blocks
  8210. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8211. {
  8212. int fd;
  8213. nullpo_retv(sd);
  8214. fd=sd->fd;
  8215. WFIFOHEAD(fd,packet_len(0xd1));
  8216. WFIFOW(fd,0)=0xd1;
  8217. WFIFOB(fd,2)=type;
  8218. WFIFOB(fd,3)=flag;
  8219. WFIFOSET(fd,packet_len(0xd1));
  8220. }
  8221. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8222. /// 00d2 <type>.B <result>.B
  8223. /// type:
  8224. /// 0 = /exall (deny)
  8225. /// 1 = /inall (allow)
  8226. /// result:
  8227. /// 0 = success
  8228. /// 1 = failure
  8229. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8230. {
  8231. int fd;
  8232. nullpo_retv(sd);
  8233. fd=sd->fd;
  8234. WFIFOHEAD(fd,packet_len(0xd2));
  8235. WFIFOW(fd,0)=0xd2;
  8236. WFIFOB(fd,2)=type;
  8237. WFIFOB(fd,3)=flag;
  8238. WFIFOSET(fd,packet_len(0xd2));
  8239. }
  8240. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8241. /// 07fe <bgm>.24B
  8242. void clif_playBGM(struct map_session_data* sd, const char* name)
  8243. {
  8244. int fd;
  8245. nullpo_retv(sd);
  8246. fd = sd->fd;
  8247. WFIFOHEAD(fd,packet_len(0x7fe));
  8248. WFIFOW(fd,0) = 0x7fe;
  8249. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8250. WFIFOSET(fd,packet_len(0x7fe));
  8251. }
  8252. /// Plays/stops a wave sound (ZC_SOUND).
  8253. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8254. /// file name:
  8255. /// relative to data\wav
  8256. /// act:
  8257. /// 0 = play (once)
  8258. /// 1 = play (repeat, does not work)
  8259. /// 2 = stops all sound instances of file name (does not work)
  8260. /// term:
  8261. /// unknown purpose, only relevant to act = 1
  8262. /// npc id:
  8263. /// The accustic direction of the sound is determined by the
  8264. /// relative position of the NPC to the player (3D sound).
  8265. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8266. {
  8267. int fd;
  8268. nullpo_retv(sd);
  8269. nullpo_retv(bl);
  8270. fd = sd->fd;
  8271. WFIFOHEAD(fd,packet_len(0x1d3));
  8272. WFIFOW(fd,0) = 0x1d3;
  8273. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8274. WFIFOB(fd,26) = type;
  8275. WFIFOL(fd,27) = 0;
  8276. WFIFOL(fd,31) = bl->id;
  8277. WFIFOSET(fd,packet_len(0x1d3));
  8278. }
  8279. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8280. {
  8281. unsigned char buf[40];
  8282. nullpo_retv(bl);
  8283. WBUFW(buf,0) = 0x1d3;
  8284. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8285. WBUFB(buf,26) = type;
  8286. WBUFL(buf,27) = 0;
  8287. WBUFL(buf,31) = bl->id;
  8288. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8289. }
  8290. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8291. /// 01f3 <id>.L <effect id>.L
  8292. /// effect id:
  8293. /// @see doc/effect_list.txt
  8294. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8295. {
  8296. unsigned char buf[24];
  8297. nullpo_retv(bl);
  8298. memset(buf, 0, packet_len(0x1f3));
  8299. WBUFW(buf,0) = 0x1f3;
  8300. WBUFL(buf,2) = bl->id;
  8301. WBUFL(buf,6) = type;
  8302. clif_send(buf, packet_len(0x1f3), bl, target);
  8303. if (disguised(bl)) {
  8304. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8305. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8306. }
  8307. }
  8308. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8309. {
  8310. WFIFOHEAD(fd,10);
  8311. WFIFOW(fd,0) = 0x1f3;
  8312. WFIFOL(fd,2) = bl->id;
  8313. WFIFOL(fd,6) = type;
  8314. WFIFOSET(fd,10);
  8315. }
  8316. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8317. /// 0284 <id>.L <effect id>.L <num data>.L
  8318. /// effect id:
  8319. /// @see doc/effect_list.txt
  8320. /// num data:
  8321. /// effect-dependent value
  8322. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8323. {
  8324. uint8 buf[14];
  8325. WBUFW(buf,0) = 0x284;
  8326. WBUFL(buf,2) = bl->id;
  8327. WBUFL(buf,6) = effect_id;
  8328. WBUFL(buf,10) = num;
  8329. clif_send(buf, packet_len(0x284), bl, target);
  8330. if( disguised(bl) )
  8331. {
  8332. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8333. clif_send(buf, packet_len(0x284), bl, SELF);
  8334. }
  8335. }
  8336. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8337. {
  8338. #if PACKETVER >= 20181002
  8339. nullpo_retv( bl_src );
  8340. nullpo_retv( bl_target );
  8341. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8342. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8343. p.aid = bl_src->id;
  8344. p.effectId = effect;
  8345. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8346. if( disguised(bl_src) )
  8347. {
  8348. p.aid = disguised_bl_id( bl_src->id );
  8349. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8350. }
  8351. #endif
  8352. }
  8353. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8354. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8355. 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) {
  8356. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8357. uint8 buf[CHAT_SIZE_MAX];
  8358. nullpo_retv(bl);
  8359. if (msg_len > sizeof(buf) - 12) {
  8360. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8361. msg_len = sizeof(buf) - 12;
  8362. }
  8363. if (rgb2bgr)
  8364. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8365. WBUFW(buf,0) = 0x2C1;
  8366. WBUFW(buf,2) = msg_len + 12;
  8367. WBUFL(buf,4) = bl->id;
  8368. WBUFL(buf,8) = color;
  8369. memcpy(WBUFCP(buf,12), msg, msg_len);
  8370. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8371. }
  8372. /**
  8373. * Notifies the client that the storage window is still open
  8374. *
  8375. * Should only be used in cases where the client closed the
  8376. * storage window without server's consent
  8377. */
  8378. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8379. // Notify the client that the storage is open
  8380. if( sd->state.storage_flag == 1 ) {
  8381. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8382. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8383. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8384. }
  8385. // Notify the client that the gstorage is open otherwise it will
  8386. // remain locked forever and nobody will be able to access it
  8387. if( sd->state.storage_flag == 2 ) {
  8388. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8389. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8390. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8391. else {
  8392. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8393. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8394. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8395. }
  8396. }
  8397. // Notify the client that the premium storage is open
  8398. if (sd->state.storage_flag == 3) {
  8399. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8400. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8401. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8402. }
  8403. }
  8404. // refresh the client's screen, getting rid of any effects
  8405. void clif_refresh(struct map_session_data *sd)
  8406. {
  8407. nullpo_retv(sd);
  8408. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8409. clif_inventorylist(sd);
  8410. clif_equipswitch_list(sd);
  8411. if(pc_iscarton(sd)) {
  8412. clif_cartlist(sd);
  8413. clif_updatestatus(sd,SP_CARTINFO);
  8414. }
  8415. clif_updatestatus(sd,SP_WEIGHT);
  8416. clif_updatestatus(sd,SP_MAXWEIGHT);
  8417. clif_updatestatus(sd,SP_STR);
  8418. clif_updatestatus(sd,SP_AGI);
  8419. clif_updatestatus(sd,SP_VIT);
  8420. clif_updatestatus(sd,SP_INT);
  8421. clif_updatestatus(sd,SP_DEX);
  8422. clif_updatestatus(sd,SP_LUK);
  8423. #ifdef RENEWAL
  8424. clif_updatestatus(sd,SP_POW);
  8425. clif_updatestatus(sd,SP_STA);
  8426. clif_updatestatus(sd,SP_WIS);
  8427. clif_updatestatus(sd,SP_SPL);
  8428. clif_updatestatus(sd,SP_CON);
  8429. clif_updatestatus(sd,SP_CRT);
  8430. #endif
  8431. if (sd->spiritball)
  8432. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8433. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8434. clif_millenniumshield_single(sd->fd, sd);
  8435. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8436. clif_spiritcharm_single(sd->fd, sd);
  8437. if (sd->soulball)
  8438. clif_soulball( sd, &sd->bl, SELF );
  8439. if (sd->servantball)
  8440. clif_servantball( *sd, &sd->bl, SELF );
  8441. if (sd->abyssball)
  8442. clif_abyssball( *sd, &sd->bl, SELF );
  8443. if (sd->vd.cloth_color)
  8444. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8445. if (sd->vd.body_style)
  8446. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8447. if(hom_is_active(sd->hd))
  8448. clif_send_homdata(sd,SP_ACK,0);
  8449. if( sd->md ) {
  8450. clif_mercenary_info(sd);
  8451. clif_mercenary_skillblock(sd);
  8452. }
  8453. if( sd->ed )
  8454. clif_elemental_info(sd);
  8455. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8456. clif_weather_check(sd);
  8457. if( sd->chatID )
  8458. chat_leavechat(sd,0);
  8459. if( sd->state.vending )
  8460. clif_openvending(sd, sd->bl.id, sd->vending);
  8461. if( pc_issit(sd) )
  8462. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8463. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8464. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8465. else
  8466. clif_changed_dir(&sd->bl, SELF);
  8467. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8468. //Issue #2143
  8469. //Cancel Trading State
  8470. if (sd->state.trading)
  8471. trade_tradecancel(sd);
  8472. //Cancel Buying/Selling State
  8473. if (sd->state.buyingstore)
  8474. buyingstore_close(sd);
  8475. mail_clear(sd);
  8476. clif_loadConfirm( sd );
  8477. if( disguised(&sd->bl) ) {/* refresh-da */
  8478. short disguise = sd->disguise;
  8479. pc_disguise(sd, 0);
  8480. pc_disguise(sd, disguise);
  8481. }
  8482. clif_refresh_storagewindow(sd);
  8483. }
  8484. /// Updates the object's (bl) name on client.
  8485. /// Used to update when a char leaves a party/guild. [Skotlex]
  8486. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8487. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8488. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8489. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8490. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8491. nullpo_retv( src );
  8492. nullpo_retv( bl );
  8493. switch( bl->type ){
  8494. case BL_PC: {
  8495. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8496. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8497. packet.gid = bl->id;
  8498. map_session_data *sd = (map_session_data *)bl;
  8499. //Requesting your own "shadow" name. [Skotlex]
  8500. if( src == bl && target == SELF && sd->disguise ){
  8501. packet.gid = -bl->id;
  8502. }
  8503. if( sd->fakename[0] ) {
  8504. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8505. clif_send( &packet, sizeof(packet), src, target );
  8506. return;
  8507. }
  8508. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8509. party_data *p = nullptr;
  8510. if( sd->status.party_id ){
  8511. p = party_search( sd->status.party_id );
  8512. }
  8513. // do not display party unless the player is also in a guild
  8514. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8515. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8516. }
  8517. if( sd->guild ){
  8518. int position;
  8519. // Will get the position of the guild the player is in
  8520. position = guild_getposition( sd );
  8521. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8522. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8523. }else if( sd->clan ){
  8524. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8525. }
  8526. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8527. packet.title_id = sd->status.title_id; // Title ID
  8528. #endif
  8529. clif_send(&packet, sizeof(packet), src, target);
  8530. }
  8531. break;
  8532. //[blackhole89]
  8533. case BL_HOM:
  8534. case BL_MER:
  8535. case BL_PET:
  8536. case BL_NPC:
  8537. case BL_ELEM: {
  8538. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8539. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8540. packet.gid = bl->id;
  8541. switch (bl->type) {
  8542. case BL_HOM:
  8543. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8544. break;
  8545. case BL_MER:
  8546. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8547. break;
  8548. case BL_PET:
  8549. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8550. break;
  8551. case BL_NPC:
  8552. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8553. break;
  8554. case BL_ELEM:
  8555. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8556. break;
  8557. }
  8558. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8559. unit_data *ud = unit_bl2ud(bl);
  8560. if (ud != nullptr) {
  8561. memcpy(packet.title, ud->title, NAME_LENGTH);
  8562. packet.groupId = ud->group_id;
  8563. }
  8564. #endif
  8565. clif_send(&packet, sizeof(packet), src, target);
  8566. }
  8567. break;
  8568. case BL_MOB: {
  8569. mob_data *md = (mob_data *)bl;
  8570. if( md->guardian_data && md->guardian_data->guild_id ){
  8571. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8572. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8573. packet.gid = bl->id;
  8574. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8575. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8576. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8577. clif_send(&packet, sizeof(packet), src, target);
  8578. }else if( battle_config.show_mob_info ){
  8579. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8580. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8581. packet.gid = bl->id;
  8582. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8583. char mobhp[50], *str_p = mobhp;
  8584. if( battle_config.show_mob_info&4 ){
  8585. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8586. }
  8587. if( battle_config.show_mob_info&1 ){
  8588. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8589. }
  8590. if( battle_config.show_mob_info&2 ){
  8591. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8592. }
  8593. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8594. if( str_p != mobhp ){
  8595. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8596. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8597. }
  8598. clif_send(&packet, sizeof(packet), src, target);
  8599. } else {
  8600. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8601. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8602. packet.gid = bl->id;
  8603. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8604. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8605. unit_data *ud = unit_bl2ud(bl);
  8606. if (ud != nullptr) {
  8607. memcpy(packet.title, ud->title, NAME_LENGTH);
  8608. packet.groupId = ud->group_id;
  8609. }
  8610. #endif
  8611. clif_send(&packet, sizeof(packet), src, target);
  8612. }
  8613. }
  8614. break;
  8615. case BL_CHAT:
  8616. case BL_SKILL:
  8617. // Newer clients request this, but do not need an answer
  8618. return;
  8619. default:
  8620. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8621. return;
  8622. }
  8623. }
  8624. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8625. /// 01ff <id>.L <x>.W <y>.W
  8626. ///
  8627. /// Visually moves(instant) a character to x,y. The char moves even
  8628. /// when the target cell isn't walkable. If the char is sitting it
  8629. /// stays that way.
  8630. void clif_slide(struct block_list *bl, int x, int y)
  8631. {
  8632. unsigned char buf[10];
  8633. nullpo_retv(bl);
  8634. WBUFW(buf, 0) = 0x01ff;
  8635. WBUFL(buf, 2) = bl->id;
  8636. WBUFW(buf, 6) = x;
  8637. WBUFW(buf, 8) = y;
  8638. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8639. if( disguised(bl) )
  8640. {
  8641. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8642. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8643. }
  8644. }
  8645. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8646. /// 008d <packet len>.W <id>.L <message>.?B
  8647. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8648. {
  8649. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8650. int len_mes = strlen(mes)+1; //Account for \0
  8651. if (len_mes > sizeof(buf)-8) {
  8652. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8653. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8654. }
  8655. // send message to others
  8656. if (flag == AREA) {
  8657. WBUFW(buf,0) = 0x8d;
  8658. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8659. WBUFL(buf,4) = bl->id;
  8660. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8661. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8662. }
  8663. // send back message to the speaker
  8664. if( bl->type == BL_PC ) {
  8665. WBUFW(buf,0) = 0x8e;
  8666. WBUFW(buf, 2) = len_mes + 4;
  8667. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8668. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8669. }
  8670. }
  8671. /*==========================
  8672. * Minimap fix [Kevin]
  8673. * Remove dot from minimap
  8674. *--------------------------*/
  8675. void clif_party_xy_remove(struct map_session_data *sd)
  8676. {
  8677. unsigned char buf[16];
  8678. nullpo_retv(sd);
  8679. WBUFW(buf,0)=0x107;
  8680. WBUFL(buf,2)=sd->status.account_id;
  8681. WBUFW(buf,6)=-1;
  8682. WBUFW(buf,8)=-1;
  8683. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8684. }
  8685. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8686. /// 0215 <msg id>.L
  8687. /// msg id:
  8688. /// 0x15 = End all negative status (PA_GOSPEL)
  8689. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8690. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8691. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8692. /// 0x19 = All stats +20 (PA_GOSPEL)
  8693. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8694. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8695. /// 0x1e = DEF +25% (PA_GOSPEL)
  8696. /// 0x1f = ATK +100% (PA_GOSPEL)
  8697. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8698. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8699. /// ? = nothing
  8700. void clif_gospel_info(struct map_session_data *sd, int type)
  8701. {
  8702. int fd=sd->fd;
  8703. WFIFOHEAD(fd,packet_len(0x215));
  8704. WFIFOW(fd,0)=0x215;
  8705. WFIFOL(fd,2)=type;
  8706. WFIFOSET(fd, packet_len(0x215));
  8707. }
  8708. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8709. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8710. /// result:
  8711. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8712. /// star:
  8713. /// 0 = Place of the Sun
  8714. /// 1 = Place of the Moon
  8715. /// 2 = Place of the Stars
  8716. /// 1 = Star Gladiator %s's %s: <mapname>
  8717. /// star:
  8718. /// 0 = Place of the Sun
  8719. /// 1 = Place of the Moon
  8720. /// 2 = Place of the Stars
  8721. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8722. /// star:
  8723. /// 0 = Target of the Sun
  8724. /// 1 = Target of the Moon
  8725. /// 2 = Target of the Stars
  8726. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8727. /// star:
  8728. /// 0 = Monster of the Sun
  8729. /// 1 = Monster of the Moon
  8730. /// 2 = Monster of the Stars
  8731. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8732. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8733. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8734. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8735. /// 40 = Target HP : <monster_id used as HP>
  8736. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8737. {
  8738. int fd = sd->fd;
  8739. WFIFOHEAD(fd,packet_len(0x20e));
  8740. WFIFOW(fd,0) = 0x20e;
  8741. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8742. WFIFOL(fd,26) = monster_id;
  8743. WFIFOB(fd,30) = star;
  8744. WFIFOB(fd,31) = result;
  8745. WFIFOSET(fd,packet_len(0x20e));
  8746. }
  8747. /*==========================================
  8748. * Info about Star Glaldiator save map [Komurka]
  8749. * type: 1: Information, 0: Map registered
  8750. *------------------------------------------*/
  8751. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8752. {
  8753. char mapname[MAP_NAME_LENGTH_EXT];
  8754. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8755. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8756. }
  8757. /*==========================================
  8758. * Info about Star Glaldiator hate mob [Komurka]
  8759. * type: 1: Register mob, 0: Information.
  8760. *------------------------------------------*/
  8761. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8762. {
  8763. if( pcdb_checkid(class_) ) {
  8764. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8765. } else if( mobdb_checkid(class_) ) {
  8766. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8767. } else {
  8768. 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);
  8769. }
  8770. }
  8771. /*==========================================
  8772. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8773. *------------------------------------------*/
  8774. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8775. {
  8776. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8777. }
  8778. /*==========================================
  8779. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8780. *------------------------------------------*/
  8781. void clif_feel_hate_reset(struct map_session_data *sd)
  8782. {
  8783. clif_starskill(sd, "", 0, 0, 30);
  8784. }
  8785. /// Send out reply to configuration change
  8786. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8787. /// type: see enum e_config_type
  8788. /// value:
  8789. /// false = disabled
  8790. /// true = enabled
  8791. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8792. int fd;
  8793. nullpo_retv(sd);
  8794. fd = sd->fd;
  8795. WFIFOHEAD(fd, packet_len(0x2d9));
  8796. WFIFOW(fd, 0) = 0x2d9;
  8797. WFIFOL(fd, 2) = type;
  8798. WFIFOL(fd, 6) = enabled;
  8799. WFIFOSET(fd, packet_len(0x2d9));
  8800. }
  8801. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8802. /// 02da <open equip window>.B
  8803. /// open equip window:
  8804. /// 0 = disabled
  8805. /// 1 = enabled
  8806. void clif_equipcheckbox(struct map_session_data* sd)
  8807. {
  8808. int fd;
  8809. nullpo_retv(sd);
  8810. fd = sd->fd;
  8811. WFIFOHEAD(fd, packet_len(0x2da));
  8812. WFIFOW(fd, 0) = 0x2da;
  8813. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8814. WFIFOSET(fd, packet_len(0x2da));
  8815. }
  8816. /// Sends info about a player's equipped items.
  8817. /// 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)
  8818. /// 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)
  8819. /// 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)
  8820. /// 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)
  8821. /// 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)
  8822. /// 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)
  8823. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8824. nullpo_retv( sd );
  8825. nullpo_retv( tsd );
  8826. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8827. int equip = 0;
  8828. for( int i = 0; i < EQI_MAX; i++ ){
  8829. int k = tsd->equip_index[i];
  8830. if( k >= 0 ){
  8831. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8832. continue;
  8833. }
  8834. if( !tsd->inventory.u.items_inventory[k].equip ){
  8835. continue;
  8836. }
  8837. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8838. continue;
  8839. }
  8840. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8841. }
  8842. }
  8843. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8844. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8845. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8846. p->job = tsd->status.class_;
  8847. p->head = tsd->vd.hair_style;
  8848. p->accessory = tsd->vd.head_bottom;
  8849. p->accessory2 = tsd->vd.head_mid;
  8850. p->accessory3 = tsd->vd.head_top;
  8851. #if PACKETVER >= 20110111
  8852. p->robe = tsd->vd.robe;
  8853. #endif
  8854. p->headpalette = tsd->vd.hair_color;
  8855. p->bodypalette = tsd->vd.cloth_color;
  8856. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8857. p->body2 = tsd->vd.body_style;
  8858. #endif
  8859. p->sex = tsd->vd.sex;
  8860. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8861. }
  8862. /// Display msgstringtable.txt string (ZC_MSG).
  8863. /// 0291 <message>.W
  8864. void clif_msg(struct map_session_data* sd, unsigned short id)
  8865. {
  8866. int fd;
  8867. nullpo_retv(sd);
  8868. fd = sd->fd;
  8869. WFIFOHEAD(fd, packet_len(0x291));
  8870. WFIFOW(fd, 0) = 0x291;
  8871. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8872. WFIFOSET(fd, packet_len(0x291));
  8873. }
  8874. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8875. /// 0x7e2 <message>.W <value>.L
  8876. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8877. {
  8878. int fd = sd->fd;
  8879. WFIFOHEAD(fd, packet_len(0x7e2));
  8880. WFIFOW(fd,0) = 0x7e2;
  8881. WFIFOW(fd,2) = id;
  8882. WFIFOL(fd,4) = value;
  8883. WFIFOSET(fd, packet_len(0x7e2));
  8884. }
  8885. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8886. /// 07e6 <skill id>.W <msg id>.L
  8887. ///
  8888. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8889. /// "[SkillName] Message"
  8890. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8891. {
  8892. int fd = sd->fd;
  8893. WFIFOHEAD(fd, packet_len(0x7e6));
  8894. WFIFOW(fd,0) = 0x7e6;
  8895. WFIFOW(fd,2) = skill_id;
  8896. WFIFOL(fd,4) = msg_id;
  8897. WFIFOSET(fd, packet_len(0x7e6));
  8898. }
  8899. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8900. /// 09cd <msg id>.W <color>.L
  8901. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8902. nullpo_retv(sd);
  8903. int fd = sd->fd;
  8904. WFIFOHEAD(fd, packet_len(0x9cd));
  8905. WFIFOW(fd, 0) = 0x9cd;
  8906. WFIFOW(fd, 2) = msg_id;
  8907. WFIFOL(fd, 4) = color;
  8908. WFIFOSET(fd, packet_len(0x9cd));
  8909. }
  8910. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8911. /// Returns true if the packet was parsed successfully.
  8912. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8913. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8914. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8915. const char* seperator = " : ";
  8916. int fd;
  8917. struct s_packet_db* info;
  8918. uint16 packetLength, inputLength;
  8919. const char *input, *name, *message;
  8920. size_t nameLength, messageLength;
  8921. fd = sd->fd;
  8922. info = &packet_db[RFIFOW(fd,0)];
  8923. packetLength = RFIFOW(fd,info->pos[0]);
  8924. input = RFIFOCP(fd,info->pos[1]);
  8925. // basic structure check for the 4-byte header
  8926. if( packetLength < 4 ){
  8927. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8928. return false;
  8929. }else{
  8930. inputLength = packetLength - 4;
  8931. }
  8932. // process <name> part of the packet
  8933. if( whisperFormat ) {
  8934. // name has fixed width
  8935. if( inputLength < NAME_LENGTH + 1 ) {
  8936. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8937. return false;
  8938. }
  8939. name = input;
  8940. // validate name
  8941. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8942. // only restriction is that the name must be zero-terminated
  8943. if( name[nameLength] != '\0' ) {
  8944. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8945. return false;
  8946. }
  8947. message = input + NAME_LENGTH;
  8948. messageLength = inputLength - NAME_LENGTH;
  8949. }else{
  8950. // name and message are separated by ' : '
  8951. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8952. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8953. // check if there's enough data provided
  8954. if( inputLength < nameLength + seperatorLength + 1 ){
  8955. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8956. return false;
  8957. }
  8958. name = input;
  8959. // validate name
  8960. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8961. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8962. {
  8963. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8964. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8965. set_eof(sd->fd); // Just kick them out to correct it.
  8966. return false;
  8967. }
  8968. message = input + nameLength + seperatorLength;
  8969. messageLength = inputLength - nameLength - seperatorLength;
  8970. }
  8971. #if PACKETVER < 20151001
  8972. // the declared length must match real length
  8973. if( messageLength != strnlen(message, messageLength)+1 ) {
  8974. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8975. return false;
  8976. }
  8977. // verify <message> part of the packet
  8978. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8979. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8980. return false;
  8981. }
  8982. #else
  8983. // No zero termination anymore
  8984. messageLength += 1;
  8985. #endif
  8986. // messages mustn't be too long
  8987. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8988. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8989. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8990. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8991. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8992. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8993. return false;
  8994. }
  8995. // If it is not a whisper message, set the name to the fakename of the player
  8996. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8997. strcpy( out_name, sd->fakename );
  8998. }else{
  8999. safestrncpy( out_name, name, nameLength + 1 );
  9000. }
  9001. safestrncpy( out_message, message, messageLength );
  9002. if( whisperFormat ){
  9003. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  9004. out_full_message[nameLength] = '\0';
  9005. }else{
  9006. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  9007. }
  9008. if( is_atcommand( fd, sd, out_message, 1 ) )
  9009. return false;
  9010. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  9011. return false; //no "chatting" while muted.
  9012. if( battle_config.min_chat_delay ) { //[Skotlex]
  9013. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9014. return false;
  9015. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9016. }
  9017. if (battle_config.idletime_option&IDLE_CHAT)
  9018. sd->idletime = last_tick;
  9019. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  9020. sd->idletime_hom = last_tick;
  9021. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  9022. sd->idletime_mer = last_tick;
  9023. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  9024. return true;
  9025. }
  9026. /**
  9027. * Displays a message if the player enters a PK Zone (during pk_mode)
  9028. * @param sd: Player data
  9029. */
  9030. inline void clif_pk_mode_message(struct map_session_data * sd)
  9031. {
  9032. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9033. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9034. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9035. char output[CHAT_SIZE_MAX];
  9036. // 1504: You've entered a PK Zone (safe until level %d).
  9037. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9038. battle_config.pk_min_level);
  9039. clif_showscript(&sd->bl, output, SELF);
  9040. } else {
  9041. // 1503: You've entered a PK Zone.
  9042. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9043. }
  9044. }
  9045. return;
  9046. }
  9047. // ---------------------
  9048. // clif_parse_wanttoconnect
  9049. // ---------------------
  9050. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9051. // error codes:
  9052. // 0 - Success
  9053. // 1 - Unknown packet_ver
  9054. // 2 - Invalid account_id
  9055. // 3 - Invalid char_id
  9056. // 4 - Invalid login_id1 (reserved)
  9057. // 5 - Invalid client_tick (reserved)
  9058. // 6 - Invalid sex
  9059. // Only the first 'invalid' error that appears is used.
  9060. static int clif_parse_WantToConnection_sub(int fd)
  9061. {
  9062. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9063. unsigned short cmd;
  9064. //By default, start searching on the default one.
  9065. cmd = RFIFOW(fd, 0);
  9066. packet_len = RFIFOREST(fd);
  9067. // FIXME: If the packet is not received at once, this will FAIL.
  9068. // Figure out, when it happens, that only part of the packet is
  9069. // received, or fix the function to be able to deal with that
  9070. // case.
  9071. if( packet_len != packet_db[cmd].len )
  9072. return 1; /* wrong length */
  9073. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9074. return 2; /* invalid account_id */
  9075. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9076. return 3; /* invalid char_id */
  9077. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9078. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9079. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9080. return 6; /* invalid sex */
  9081. else
  9082. return 0;
  9083. }
  9084. /// Request to connect to map-server.
  9085. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9086. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9087. /// There are various variants of this packet, some of them have padding between fields.
  9088. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  9089. {
  9090. struct block_list* bl;
  9091. struct auth_node* node;
  9092. int cmd, account_id, char_id, login_id1, sex, err;
  9093. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9094. if (sd) {
  9095. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9096. return;
  9097. }
  9098. cmd = RFIFOW(fd, 0);
  9099. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9100. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9101. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9102. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9103. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9104. err = clif_parse_WantToConnection_sub(fd);
  9105. if( err ){ // connection rejected
  9106. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9107. err == 1 ? "." :
  9108. err == 2 ? ", possibly for having an invalid account_id." :
  9109. err == 3 ? ", possibly for having an invalid char_id." :
  9110. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9111. err == 4 ? ", possibly for having an invalid login_id1." :
  9112. err == 5 ? ", possibly for having an invalid client_tick." :
  9113. */
  9114. err == 6 ? ", possibly for having an invalid sex." :
  9115. ". ERROR invalid error code"));
  9116. WFIFOHEAD(fd,packet_len(0x6a));
  9117. WFIFOW(fd,0) = 0x6a;
  9118. WFIFOB(fd,2) = err;
  9119. WFIFOSET(fd,packet_len(0x6a));
  9120. #ifdef DUMP_INVALID_PACKET
  9121. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9122. #endif
  9123. RFIFOSKIP(fd, RFIFOREST(fd));
  9124. set_eof(fd);
  9125. return;
  9126. }
  9127. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  9128. clif_authfail_fd(fd,1);// server closed
  9129. return;
  9130. }
  9131. //Check for double login.
  9132. bl = map_id2bl(account_id);
  9133. if(bl && bl->type != BL_PC) {
  9134. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9135. WFIFOHEAD(fd,packet_len(0x6a));
  9136. WFIFOW(fd,0) = 0x6a;
  9137. WFIFOB(fd,2) = 3; // Rejected by server
  9138. WFIFOSET(fd,packet_len(0x6a));
  9139. set_eof(fd);
  9140. return;
  9141. }
  9142. if (bl ||
  9143. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9144. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9145. {
  9146. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9147. return;
  9148. }
  9149. CREATE(sd, TBL_PC, 1);
  9150. sd->fd = fd;
  9151. #ifdef PACKET_OBFUSCATION
  9152. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9153. #endif
  9154. session[fd]->session_data = sd;
  9155. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9156. #if PACKETVER < 20070521
  9157. WFIFOHEAD(fd,4);
  9158. WFIFOL(fd,0) = sd->bl.id;
  9159. WFIFOSET(fd,4);
  9160. #else
  9161. WFIFOHEAD(fd,packet_len(0x283));
  9162. WFIFOW(fd,0) = 0x283;
  9163. WFIFOL(fd,2) = sd->bl.id;
  9164. WFIFOSET(fd,packet_len(0x283));
  9165. #endif
  9166. chrif_authreq(sd,false);
  9167. }
  9168. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9169. /// 007d
  9170. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9171. {
  9172. bool guild_notice = false;
  9173. if(sd->bl.prev != NULL)
  9174. return;
  9175. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9176. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9177. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9178. sd->state.connect_new = 0;
  9179. return;
  9180. }
  9181. if (sd->state.rewarp) { //Rewarp player.
  9182. sd->state.rewarp = 0;
  9183. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9184. return;
  9185. }
  9186. sd->state.warping = 0;
  9187. // look
  9188. #if PACKETVER < 4
  9189. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9190. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9191. #else
  9192. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9193. #endif
  9194. pc_set_costume_view(sd);
  9195. if(sd->vd.cloth_color)
  9196. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9197. if(sd->vd.body_style)
  9198. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9199. // item
  9200. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9201. pc_checkitem(sd);
  9202. clif_equipswitch_list(sd);
  9203. // cart
  9204. if(pc_iscarton(sd)) {
  9205. clif_cartlist(sd);
  9206. clif_updatestatus(sd,SP_CARTINFO);
  9207. }
  9208. // weight
  9209. clif_updatestatus(sd,SP_WEIGHT);
  9210. clif_updatestatus(sd,SP_MAXWEIGHT);
  9211. // guild
  9212. // (needs to go before clif_spawn() to show guild emblems correctly)
  9213. if(sd->status.guild_id)
  9214. guild_send_memberinfoshort(sd,1);
  9215. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9216. if(battle_config.pc_invincible_time > 0) {
  9217. if(mapdata_flag_gvg(mapdata))
  9218. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9219. else
  9220. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9221. }
  9222. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9223. map_spawnmobs(sd->bl.m);
  9224. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9225. mapdata->users_pvp++;
  9226. }
  9227. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9228. // reset the callshop flag if the player changes map
  9229. sd->state.callshop = 0;
  9230. if(map_addblock(&sd->bl))
  9231. return;
  9232. clif_spawn(&sd->bl);
  9233. // Party
  9234. // (needs to go after clif_spawn() to show hp bars correctly)
  9235. if(sd->status.party_id) {
  9236. party_send_movemap(sd);
  9237. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  9238. }
  9239. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9240. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9241. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9242. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9243. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9244. sd->pvp_rank = 0;
  9245. sd->pvp_lastusers = 0;
  9246. sd->pvp_point = 5;
  9247. sd->pvp_won = 0;
  9248. sd->pvp_lost = 0;
  9249. }
  9250. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9251. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9252. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9253. else if (mapdata->flag[MF_GVG_DUNGEON])
  9254. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9255. else if( mapdata_flag_gvg(mapdata) )
  9256. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9257. else
  9258. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9259. // info about nearby objects
  9260. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9261. 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);
  9262. // pet
  9263. if( sd->pd ) {
  9264. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9265. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9266. pet_return_egg( sd, sd->pd );
  9267. } else {
  9268. if(map_addblock(&sd->pd->bl))
  9269. return;
  9270. clif_spawn(&sd->pd->bl);
  9271. clif_send_petdata(sd,sd->pd,0,0);
  9272. clif_send_petstatus(sd);
  9273. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9274. }
  9275. }
  9276. //homunculus [blackhole89]
  9277. if( hom_is_active(sd->hd) ) {
  9278. if(map_addblock(&sd->hd->bl))
  9279. return;
  9280. clif_spawn(&sd->hd->bl);
  9281. clif_send_homdata(sd,SP_ACK,0);
  9282. clif_hominfo(sd,sd->hd,1);
  9283. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9284. clif_homskillinfoblock(sd);
  9285. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9286. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9287. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9288. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9289. }
  9290. if( sd->md ) {
  9291. if(map_addblock(&sd->md->bl))
  9292. return;
  9293. clif_spawn(&sd->md->bl);
  9294. clif_mercenary_info(sd);
  9295. clif_mercenary_skillblock(sd);
  9296. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9297. }
  9298. if( sd->ed ) {
  9299. if (map_addblock(&sd->ed->bl))
  9300. return;
  9301. clif_spawn(&sd->ed->bl);
  9302. clif_elemental_info(sd);
  9303. clif_elemental_updatestatus(sd,SP_HP);
  9304. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9305. clif_elemental_updatestatus(sd,SP_SP);
  9306. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9307. }
  9308. if(sd->state.connect_new) {
  9309. int lv;
  9310. guild_notice = true;
  9311. clif_skillinfoblock(sd);
  9312. clif_hotkeys_send(sd,0);
  9313. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9314. clif_hotkeys_send(sd,1);
  9315. #endif
  9316. clif_updatestatus(sd,SP_BASEEXP);
  9317. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9318. clif_updatestatus(sd,SP_JOBEXP);
  9319. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9320. clif_updatestatus(sd,SP_SKILLPOINT);
  9321. clif_initialstatus(sd);
  9322. if (sd->sc.option&OPTION_FALCON)
  9323. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9324. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9325. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9326. else if (sd->sc.option&OPTION_WUGRIDER)
  9327. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9328. else if (sd->sc.data[SC_ALL_RIDING])
  9329. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9330. if(sd->status.manner < 0)
  9331. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9332. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9333. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9334. if(sd->bl.m == sd->feel_map[0].m
  9335. || sd->bl.m == sd->feel_map[1].m
  9336. || sd->bl.m == sd->feel_map[2].m)
  9337. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9338. }
  9339. if(sd->pd && sd->pd->pet.intimate > 900)
  9340. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9341. if(hom_is_active(sd->hd))
  9342. hom_init_timers(sd->hd);
  9343. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9344. sd->state.night = 1;
  9345. clif_status_load(&sd->bl, EFST_SKE, 1);
  9346. }
  9347. // Notify everyone that this char logged in [Skotlex].
  9348. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9349. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9350. //Login Event
  9351. npc_script_event(sd, NPCE_LOGIN);
  9352. }
  9353. // Set facing direction before check below to update client
  9354. if (battle_config.spawn_direction)
  9355. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9356. } else {
  9357. //For some reason the client "loses" these on warp/map-change.
  9358. clif_updatestatus(sd,SP_STR);
  9359. clif_updatestatus(sd,SP_AGI);
  9360. clif_updatestatus(sd,SP_VIT);
  9361. clif_updatestatus(sd,SP_INT);
  9362. clif_updatestatus(sd,SP_DEX);
  9363. clif_updatestatus(sd,SP_LUK);
  9364. #ifdef RENEWAL
  9365. clif_updatestatus(sd,SP_POW);
  9366. clif_updatestatus(sd,SP_STA);
  9367. clif_updatestatus(sd,SP_WIS);
  9368. clif_updatestatus(sd,SP_SPL);
  9369. clif_updatestatus(sd,SP_CON);
  9370. clif_updatestatus(sd,SP_CRT);
  9371. #endif
  9372. // abort currently running script
  9373. sd->state.using_fake_npc = 0;
  9374. sd->state.menu_or_input = 0;
  9375. sd->npc_menu = 0;
  9376. if(sd->npc_id)
  9377. npc_event_dequeue(sd);
  9378. }
  9379. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9380. #if PACKETVER >= 20070918
  9381. clif_partyinvitationstate(sd);
  9382. clif_equipcheckbox(sd);
  9383. #endif
  9384. clif_pet_autofeed_status(sd,false);
  9385. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9386. #if PACKETVER >= 20170920
  9387. if( battle_config.homunculus_autofeed_always ){
  9388. // Always send ON or OFF
  9389. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9390. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9391. }else{
  9392. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9393. }
  9394. }else{
  9395. // Only send when enabled
  9396. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9397. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9398. }
  9399. }
  9400. #endif
  9401. clif_reputation_list( *sd );
  9402. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9403. clif_guild_notice(sd); // Displays after VIP
  9404. guild_notice = false; // Do not display it twice
  9405. }
  9406. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9407. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9408. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9409. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9410. }
  9411. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9412. { //Display night.
  9413. if( !sd->state.night )
  9414. {
  9415. sd->state.night = 1;
  9416. clif_status_load(&sd->bl, EFST_SKE, 1);
  9417. }
  9418. }
  9419. else if( sd->state.night )
  9420. { //Clear night display.
  9421. sd->state.night = 0;
  9422. clif_status_load(&sd->bl, EFST_SKE, 0);
  9423. }
  9424. if( mapdata->flag[MF_BATTLEGROUND] )
  9425. {
  9426. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9427. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9428. clif_bg_updatescore_single(sd);
  9429. }
  9430. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9431. {
  9432. char output[128];
  9433. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9434. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9435. }
  9436. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9437. mapdata->hpmeter_visible++;
  9438. sd->state.hpmeter_visible = 1;
  9439. }
  9440. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9441. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9442. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9443. #ifdef VIP_ENABLE
  9444. if (!sd->state.connect_new &&
  9445. !sd->vip.disableshowrate &&
  9446. sd->state.pmap != sd->bl.m &&
  9447. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9448. )
  9449. {
  9450. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9451. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9452. }
  9453. #endif
  9454. // Instances do not need their own channels
  9455. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9456. channel_mjoin(sd); //join new map
  9457. clif_pk_mode_message(sd);
  9458. }
  9459. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9460. clif_guild_notice(sd); // Displays at end
  9461. }
  9462. mail_clear(sd);
  9463. /* Guild Aura Init */
  9464. if( sd->guild && sd->state.gmaster_flag ) {
  9465. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9466. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9467. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9468. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9469. }
  9470. if( sd->state.vending ) { /* show we have a vending */
  9471. clif_openvending(sd,sd->bl.id,sd->vending);
  9472. clif_showvendingboard(&sd->bl,sd->message,0);
  9473. }
  9474. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9475. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9476. npc_script_event(sd, NPCE_LOADMAP);
  9477. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9478. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9479. if (sd->sc.opt2) //Client loses these on warp.
  9480. clif_changeoption(&sd->bl);
  9481. 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)) {
  9482. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9483. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9484. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9485. }
  9486. clif_weather_check(sd);
  9487. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9488. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9489. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9490. else
  9491. sd->areanpc.clear();
  9492. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9493. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9494. pc_setdead(sd);
  9495. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9496. if(pc_isdead(sd))
  9497. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9498. else {
  9499. skill_usave_trigger(sd);
  9500. if (battle_config.spawn_direction)
  9501. clif_changed_dir(&sd->bl, SELF);
  9502. }
  9503. // Trigger skill effects if you appear standing on them
  9504. if(!battle_config.pc_invincible_time)
  9505. skill_unit_move(&sd->bl,gettick(),1);
  9506. pc_show_questinfo_reinit(sd);
  9507. pc_show_questinfo(sd);
  9508. #if PACKETVER >= 20150513
  9509. if( sd->mail.inbox.unread ){
  9510. clif_Mail_new(sd, 0, NULL, NULL);
  9511. }
  9512. #endif
  9513. sd->state.connect_new = 0;
  9514. sd->state.changemap = false;
  9515. }
  9516. /// Server's tick (ZC_NOTIFY_TIME).
  9517. /// 007f <time>.L
  9518. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9519. {
  9520. int fd = sd->fd;
  9521. WFIFOHEAD(fd,packet_len(0x7f));
  9522. WFIFOW(fd,0) = 0x7f;
  9523. WFIFOL(fd,2) = client_tick(time);
  9524. WFIFOSET(fd,packet_len(0x7f));
  9525. }
  9526. /// Request for server's tick.
  9527. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9528. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9529. /// There are various variants of this packet, some of them have padding between fields.
  9530. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9531. {
  9532. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9533. clif_notify_time(sd, gettick());
  9534. }
  9535. /// Sends hotkey bar.
  9536. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9537. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9538. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9539. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9540. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9541. #ifdef HOTKEY_SAVING
  9542. nullpo_retv( sd );
  9543. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9544. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9545. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9546. if( tab == 0 ){
  9547. p.rotate = sd->status.hotkey_rowshift;
  9548. }else{
  9549. p.rotate = sd->status.hotkey_rowshift2;
  9550. }
  9551. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9552. p.tab = tab;
  9553. #endif
  9554. #endif
  9555. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9556. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9557. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9558. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9559. }
  9560. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9561. #endif
  9562. }
  9563. /// Request to update a position on the hotkey row bar
  9564. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9565. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9566. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9567. if( p->tab == 0 ){
  9568. sd->status.hotkey_rowshift = p->rowshift;
  9569. }else{
  9570. sd->status.hotkey_rowshift2 = p->rowshift;
  9571. }
  9572. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9573. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9574. sd->status.hotkey_rowshift = p->rowshift;
  9575. #endif
  9576. }
  9577. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9578. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9579. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9580. #ifdef HOTKEY_SAVING
  9581. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9582. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9583. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9584. if( idx >= MAX_HOTKEYS_DB ){
  9585. return;
  9586. }
  9587. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9588. sd->status.hotkeys[idx].id = p->hotkey.id;
  9589. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9590. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9591. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9592. const unsigned short idx = p->index;
  9593. if( idx >= MAX_HOTKEYS_DB ){
  9594. return;
  9595. }
  9596. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9597. sd->status.hotkeys[idx].id = p->hotkey.id;
  9598. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9599. #endif
  9600. #endif
  9601. }
  9602. /// Displays cast-like progress bar (ZC_PROGRESS).
  9603. /// 02f0 <color>.L <time>.L
  9604. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9605. {
  9606. int fd = sd->fd;
  9607. WFIFOHEAD(fd,packet_len(0x2f0));
  9608. WFIFOW(fd,0) = 0x2f0;
  9609. WFIFOL(fd,2) = color;
  9610. WFIFOL(fd,6) = second;
  9611. WFIFOSET(fd,packet_len(0x2f0));
  9612. }
  9613. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9614. /// 02f2
  9615. void clif_progressbar_abort(struct map_session_data * sd)
  9616. {
  9617. int fd = sd->fd;
  9618. WFIFOHEAD(fd,packet_len(0x2f2));
  9619. WFIFOW(fd,0) = 0x2f2;
  9620. WFIFOSET(fd,packet_len(0x2f2));
  9621. }
  9622. /// Notification from the client, that the progress bar has reached 100%.
  9623. /// 02f1 (CZ_PROGRESS)
  9624. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9625. // No progressbar active, ignore it
  9626. if( !sd->progressbar.npc_id ){
  9627. return;
  9628. }
  9629. int npc_id = sd->progressbar.npc_id;
  9630. bool closing = false;
  9631. // Check if the progress was canceled
  9632. if( gettick() < sd->progressbar.timeout && sd->st ){
  9633. closing = true;
  9634. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9635. // If a message window was open, offer a close button to the user
  9636. if( sd->st->mes_active ){
  9637. clif_scriptclose( sd, npc_id );
  9638. }
  9639. }
  9640. sd->progressbar.npc_id = 0;
  9641. sd->progressbar.timeout = 0;
  9642. sd->state.workinprogress = WIP_DISABLE_NONE;
  9643. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9644. sd->idletime = last_tick;
  9645. }
  9646. npc_scriptcont(sd, npc_id, closing);
  9647. }
  9648. /// Displays cast-like progress bar on a NPC
  9649. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9650. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9651. #if PACKETVER >= 20130821
  9652. unsigned char buf[14];
  9653. if( nd->progressbar.timeout > 0 ){
  9654. WBUFW(buf,0) = 0x9d1;
  9655. WBUFL(buf,2) = nd->bl.id;
  9656. WBUFL(buf,6) = nd->progressbar.color;
  9657. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9658. if( sd ){
  9659. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9660. }else{
  9661. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9662. }
  9663. }
  9664. #endif
  9665. }
  9666. /// Request to walk to a certain position on the current map.
  9667. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9668. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9669. /// There are various variants of this packet, some of them have padding between fields.
  9670. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9671. {
  9672. short x, y;
  9673. if (pc_isdead(sd)) {
  9674. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9675. return;
  9676. }
  9677. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9678. ; //You CAN walk on this OPT1 value.
  9679. else if (sd->progressbar.npc_id) {
  9680. clif_progressbar_abort(sd);
  9681. return; // First walk attempt cancels the progress bar
  9682. } else if (pc_cant_act(sd))
  9683. return;
  9684. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9685. return;
  9686. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9687. //A move command one cell west is only valid if the target cell is free
  9688. if(battle_config.official_cell_stack_limit > 0
  9689. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9690. return;
  9691. // Cloaking wall check is actually updated when you click to process next movement
  9692. // not when you move each cell. This is official behaviour.
  9693. if (sd->sc.data[SC_CLOAKING])
  9694. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9695. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9696. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9697. pc_delinvincibletimer(sd);
  9698. //Set last idle time... [Skotlex]
  9699. if (battle_config.idletime_option&IDLE_WALK)
  9700. sd->idletime = last_tick;
  9701. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9702. sd->idletime_hom = last_tick;
  9703. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9704. sd->idletime_mer = last_tick;
  9705. unit_walktoxy(&sd->bl, x, y, 4);
  9706. }
  9707. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9708. /// 018b <result>.W
  9709. /// result:
  9710. /// 0 = disconnect (quit)
  9711. /// 1 = cannot disconnect (wait 10 seconds)
  9712. /// ? = ignored
  9713. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9714. {
  9715. int fd = sd->fd;
  9716. WFIFOHEAD(fd,packet_len(0x18b));
  9717. WFIFOW(fd,0) = 0x18b;
  9718. WFIFOW(fd,2) = result;
  9719. WFIFOSET(fd,packet_len(0x18b));
  9720. }
  9721. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9722. /// 018a <type>.W
  9723. /// type:
  9724. /// 0 = quit
  9725. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9726. {
  9727. /* Rovert's prevent logout option fixed [Valaris] */
  9728. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9729. 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] &&
  9730. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9731. {
  9732. pc_damage_log_clear(sd,0);
  9733. clif_disconnect_ack(sd, 0);
  9734. flush_fifo( fd );
  9735. if( battle_config.drop_connection_on_quit ){
  9736. set_eof( fd );
  9737. }
  9738. } else {
  9739. clif_disconnect_ack(sd, 1);
  9740. }
  9741. }
  9742. /// Requesting unit's name.
  9743. /// 0094 <id>.L (CZ_REQNAME)
  9744. /// 0368 <id>.L (CZ_REQNAME2)
  9745. /// There are various variants of this packet, some of them have padding between fields.
  9746. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9747. {
  9748. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9749. struct block_list* bl;
  9750. //struct status_change *sc;
  9751. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9752. id = sd->bl.id;
  9753. bl = map_id2bl(id);
  9754. if( bl == NULL )
  9755. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9756. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9757. return; // Block namerequests past view range
  9758. // 'see people in GM hide' cheat detection
  9759. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9760. sc = status_get_sc(bl);
  9761. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9762. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9763. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9764. ) {
  9765. char gm_msg[256];
  9766. 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);
  9767. ShowWarning(gm_msg);
  9768. // information is sent to all online GMs
  9769. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9770. return;
  9771. }
  9772. */
  9773. clif_name(&sd->bl,bl,SELF);
  9774. }
  9775. /// Validates and processes global messages
  9776. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9777. /// There are various variants of this packet.
  9778. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9779. {
  9780. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9781. size_t length;
  9782. // validate packet and retrieve name and message
  9783. if( !clif_process_message(sd, false, name, message, output ) )
  9784. return;
  9785. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9786. channel_send(sd->gcbind,sd,message);
  9787. return;
  9788. }
  9789. // send message to others (using the send buffer for temp. storage)
  9790. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9791. length = strlen(output) + 1;
  9792. // send back message to the speaker
  9793. WFIFOHEAD(fd,4+length);
  9794. WFIFOW(fd,0) = 0x8e;
  9795. WFIFOW(fd,2) = (uint16)(4+length);
  9796. safestrncpy(WFIFOCP(fd,4), output, length );
  9797. WFIFOSET(fd, WFIFOW(fd,2));
  9798. #ifdef PCRE_SUPPORT
  9799. // trigger listening npcs
  9800. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9801. #endif
  9802. // Chat logging type 'O' / Global Chat
  9803. 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);
  9804. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9805. }
  9806. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9807. /// Request to warp to a map on given coordinates.
  9808. /// 0140 <map name>.16B <x>.W <y>.W
  9809. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9810. {
  9811. char command[MAP_NAME_LENGTH_EXT+25];
  9812. char* map_name;
  9813. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9814. map_name = RFIFOCP(fd,info->pos[0]);
  9815. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9816. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9817. RFIFOW(fd,info->pos[1]), //x
  9818. RFIFOW(fd,info->pos[2])); //y
  9819. is_atcommand(fd, sd, command, 1);
  9820. }
  9821. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9822. /// 009c <id>.L <head dir>.W <dir>.B
  9823. /// head dir:
  9824. /// 0 = straight
  9825. /// 1 = turned CW
  9826. /// 2 = turned CCW
  9827. /// dir:
  9828. /// 0 = north
  9829. /// 1 = northwest
  9830. /// 2 = west
  9831. /// 3 = southwest
  9832. /// 4 = south
  9833. /// 5 = southeast
  9834. /// 6 = east
  9835. /// 7 = northeast
  9836. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9837. {
  9838. unsigned char buf[64];
  9839. WBUFW(buf,0) = 0x9c;
  9840. WBUFL(buf,2) = bl->id;
  9841. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9842. WBUFB(buf,8) = unit_getdir(bl);
  9843. clif_send(buf, packet_len(0x9c), bl, target);
  9844. if (disguised(bl)) {
  9845. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9846. WBUFW(buf,6) = 0;
  9847. clif_send(buf, packet_len(0x9c), bl, SELF);
  9848. }
  9849. }
  9850. /// Request to change own body and head direction.
  9851. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9852. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9853. /// There are various variants of this packet, some of them have padding between fields.
  9854. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9855. {
  9856. unsigned char headdir, dir;
  9857. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9858. headdir = RFIFOB(fd,info->pos[0]);
  9859. dir = RFIFOB(fd,info->pos[1]);
  9860. pc_setdir(sd, dir, headdir);
  9861. clif_changed_dir(&sd->bl, AREA_WOS);
  9862. }
  9863. /// Request to show an emotion (CZ_REQ_EMOTION).
  9864. /// 00bf <type>.B
  9865. /// type:
  9866. /// @see enum emotion_type
  9867. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9868. {
  9869. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9870. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9871. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9872. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9873. return;
  9874. }
  9875. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9876. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9877. sd->emotionlasttime = time(NULL);
  9878. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9879. return;
  9880. }
  9881. sd->emotionlasttime = time(NULL);
  9882. if (battle_config.idletime_option&IDLE_EMOTION)
  9883. sd->idletime = last_tick;
  9884. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9885. sd->idletime_hom = last_tick;
  9886. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9887. sd->idletime_mer = last_tick;
  9888. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9889. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9890. return;
  9891. }
  9892. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9893. emoticon = rnd()%6+ET_DICE1;
  9894. }
  9895. clif_emotion(&sd->bl, emoticon);
  9896. } else
  9897. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9898. }
  9899. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9900. /// 00c2 <count>.L
  9901. void clif_user_count(struct map_session_data* sd, int count)
  9902. {
  9903. int fd = sd->fd;
  9904. WFIFOHEAD(fd,packet_len(0xc2));
  9905. WFIFOW(fd,0) = 0xc2;
  9906. WFIFOL(fd,2) = count;
  9907. WFIFOSET(fd,packet_len(0xc2));
  9908. }
  9909. /// /w /who (CZ_REQ_USER_COUNT).
  9910. /// Request to display amount of currently connected players.
  9911. /// 00c1
  9912. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9913. {
  9914. clif_user_count(sd, map_getusers());
  9915. }
  9916. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9917. {
  9918. if (pc_isdead(sd)) {
  9919. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9920. return;
  9921. }
  9922. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9923. if (action_type != 0x00 && action_type != 0x07) {
  9924. if (sd->sc.cant.interact)
  9925. return;
  9926. pc_stop_walking(sd, 1);
  9927. }
  9928. pc_stop_attack(sd);
  9929. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9930. target_id = sd->bl.id;
  9931. switch(action_type)
  9932. {
  9933. case 0x00: // once attack
  9934. case 0x07: // continuous attack
  9935. if( pc_cant_act(sd) )
  9936. return;
  9937. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9938. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9939. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9940. return;
  9941. }
  9942. }
  9943. pc_delinvincibletimer(sd);
  9944. if (battle_config.idletime_option&IDLE_ATTACK)
  9945. sd->idletime = last_tick;
  9946. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9947. sd->idletime_hom = last_tick;
  9948. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9949. sd->idletime_mer = last_tick;
  9950. unit_attack(&sd->bl, target_id, action_type != 0);
  9951. break;
  9952. case 0x02: // sitdown
  9953. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9954. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9955. break;
  9956. }
  9957. if(pc_issit(sd)) {
  9958. //Bugged client? Just refresh them.
  9959. clif_sitting(&sd->bl);
  9960. return;
  9961. }
  9962. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9963. break;
  9964. if (sd->sc.count && (
  9965. sd->sc.data[SC_DANCING] ||
  9966. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9967. )) //No sitting during these states either.
  9968. break;
  9969. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9970. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9971. break;
  9972. }
  9973. if (battle_config.idletime_option&IDLE_SIT)
  9974. sd->idletime = last_tick;
  9975. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9976. sd->idletime_hom = last_tick;
  9977. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9978. sd->idletime_mer = last_tick;
  9979. pc_setsit(sd);
  9980. skill_sit(sd, true);
  9981. clif_sitting(&sd->bl);
  9982. break;
  9983. case 0x03: // standup
  9984. if (!pc_issit(sd)) {
  9985. //Bugged client? Just refresh them.
  9986. clif_standing(&sd->bl);
  9987. return;
  9988. }
  9989. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9990. break;
  9991. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9992. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9993. break;
  9994. }
  9995. if (pc_setstand(sd, false)) {
  9996. if (battle_config.idletime_option&IDLE_SIT)
  9997. sd->idletime = last_tick;
  9998. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9999. sd->idletime_hom = last_tick;
  10000. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  10001. sd->idletime_mer = last_tick;
  10002. skill_sit(sd, false);
  10003. clif_standing(&sd->bl);
  10004. }
  10005. break;
  10006. }
  10007. }
  10008. /// Request for an action.
  10009. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  10010. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  10011. /// action:
  10012. /// 0 = attack
  10013. /// 1 = pick up item
  10014. /// 2 = sit down
  10015. /// 3 = stand up
  10016. /// 7 = continous attack
  10017. /// 12 = (touch skill?)
  10018. /// There are various variants of this packet, some of them have padding between fields.
  10019. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  10020. {
  10021. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10022. clif_parse_ActionRequest_sub(sd,
  10023. RFIFOB(fd,info->pos[1]),
  10024. RFIFOL(fd,info->pos[0]),
  10025. gettick()
  10026. );
  10027. }
  10028. /// Response to the death/system menu (CZ_RESTART).
  10029. /// 00b2 <type>.B
  10030. /// type:
  10031. /// 0 = restart (respawn)
  10032. /// 1 = char-select (disconnect)
  10033. void clif_parse_Restart(int fd, struct map_session_data *sd)
  10034. {
  10035. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  10036. case 0x00:
  10037. pc_respawn(sd,CLR_OUTSIGHT);
  10038. break;
  10039. case 0x01:
  10040. /* Rovert's Prevent logout option - Fixed [Valaris] */
  10041. 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] &&
  10042. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  10043. { //Send to char-server for character selection.
  10044. pc_damage_log_clear(sd,0);
  10045. chrif_charselectreq(sd, session[fd]->client_addr);
  10046. } else {
  10047. clif_disconnect_ack(sd, 1);
  10048. }
  10049. break;
  10050. }
  10051. }
  10052. /// Validates and processes whispered messages (CZ_WHISPER).
  10053. /// 0096 <packet len>.W <nick>.24B <message>.?B
  10054. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  10055. {
  10056. struct map_session_data* dstsd;
  10057. int i;
  10058. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10059. // validate packet and retrieve name and message
  10060. if( !clif_process_message( sd, true, target, message, output ) )
  10061. return;
  10062. // Chat logging type 'W' / Whisper
  10063. 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);
  10064. //-------------------------------------------------------//
  10065. // Lordalfa - Paperboy - To whisper NPC commands //
  10066. //-------------------------------------------------------//
  10067. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  10068. {
  10069. char* str = target+4; //Skip the NPC: string part.
  10070. struct npc_data* npc;
  10071. if ((npc = npc_name2id(str))) {
  10072. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  10073. char *split;
  10074. char event[EVENT_NAME_LENGTH];
  10075. str = message;
  10076. // skip codepage indicator, if detected
  10077. if( str[0] == '|' && strlen(str) >= 4 )
  10078. str += 3;
  10079. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  10080. split = strchr(str,'#');
  10081. if( split == NULL ) { // use the remaining string
  10082. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10083. for( ++i; i < NUM_WHISPER_VAR; ++i )
  10084. split_data[i][0] = '\0';
  10085. break;
  10086. }
  10087. *split = '\0';
  10088. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10089. str = split+1;
  10090. }
  10091. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  10092. char variablename[CHAT_SIZE_MAX];
  10093. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  10094. set_var_str( sd, variablename, split_data[i] );
  10095. }
  10096. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10097. npc_event(sd,event,0); // Calls the NPC label
  10098. return;
  10099. }
  10100. } else if( target[0] == '#' ) {
  10101. struct Channel *channel = NULL;
  10102. char* chname = target;
  10103. channel = channel_name2channel(chname,sd,3);
  10104. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10105. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10106. channel_send(channel,sd,message);
  10107. }
  10108. else if( channel->pass[0] == '\0') { //no pass needed
  10109. if (channel_join(channel,sd)==0)
  10110. channel_send(channel,sd,message); //join success
  10111. }
  10112. else {
  10113. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10114. }
  10115. return;
  10116. }
  10117. }
  10118. // searching destination character
  10119. dstsd = map_nick2sd(target,false);
  10120. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10121. // player is not on this map-server
  10122. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10123. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10124. // and if we ask for 'Test', we must not contact 'test' player
  10125. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10126. intif_wis_message(sd, target, message, strlen(message) + 1);
  10127. return;
  10128. }
  10129. // if player ignores everyone
  10130. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10131. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10132. clif_wis_end(fd, 1); // 1: target character is not logged in
  10133. else
  10134. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10135. return;
  10136. }
  10137. // if player is autotrading
  10138. if (dstsd->state.autotrade == 1){
  10139. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10140. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10141. return;
  10142. }
  10143. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10144. // if player ignores the source character
  10145. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10146. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10147. clif_wis_end(fd, 2); // 2: ignored by target
  10148. return;
  10149. }
  10150. }
  10151. // notify sender of success
  10152. clif_wis_end(fd, 0); // 0: success to send wisper
  10153. // Normal message
  10154. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10155. }
  10156. /// /b /nb (CZ_BROADCAST).
  10157. /// Request to broadcast a message on whole server.
  10158. /// 0099 <packet len>.W <text>.?B 00
  10159. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  10160. char command[CHAT_SIZE_MAX+11];
  10161. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10162. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10163. char* msg = RFIFOCP(fd,info->pos[1]);
  10164. // as the length varies depending on the command used, just block unreasonably long strings
  10165. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10166. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10167. is_atcommand(fd, sd, command, 1);
  10168. }
  10169. /// Request to pick up an item.
  10170. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10171. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10172. /// There are various variants of this packet, some of them have padding between fields.
  10173. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  10174. {
  10175. struct flooritem_data *fitem;
  10176. int map_object_id;
  10177. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10178. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10179. do {
  10180. if (pc_isdead(sd)) {
  10181. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10182. break;
  10183. }
  10184. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10185. break;
  10186. if (pc_cant_act(sd))
  10187. break;
  10188. if (!pc_takeitem(sd, fitem))
  10189. break;
  10190. return;
  10191. } while (0);
  10192. // Client REQUIRES a fail packet or you can no longer pick items.
  10193. clif_additem(sd,0,0,6);
  10194. }
  10195. /// Request to drop an item.
  10196. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10197. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10198. /// There are various variants of this packet, some of them have padding between fields.
  10199. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  10200. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10201. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10202. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10203. for(;;) {
  10204. if (pc_isdead(sd))
  10205. break;
  10206. if (pc_cant_act2(sd) || sd->npc_id)
  10207. break;
  10208. if (sd->sc.cant.drop)
  10209. break;
  10210. if (!pc_dropitem(sd, item_index, item_amount))
  10211. break;
  10212. if (battle_config.idletime_option&IDLE_DROPITEM)
  10213. sd->idletime = last_tick;
  10214. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10215. sd->idletime_hom = last_tick;
  10216. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10217. sd->idletime_mer = last_tick;
  10218. return;
  10219. }
  10220. //Because the client does not like being ignored.
  10221. clif_dropitem(sd, item_index,0);
  10222. }
  10223. /// Request to use an item.
  10224. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10225. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10226. /// There are various variants of this packet, some of them have padding between fields.
  10227. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10228. {
  10229. int n;
  10230. if (pc_isdead(sd)) {
  10231. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10232. return;
  10233. }
  10234. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10235. clif_msg(sd, WORK_IN_PROGRESS);
  10236. return;
  10237. }
  10238. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10239. if (battle_config.idletime_option&IDLE_USEITEM)
  10240. sd->idletime = last_tick;
  10241. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10242. sd->idletime_hom = last_tick;
  10243. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10244. sd->idletime_mer = last_tick;
  10245. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10246. if(n <0 || n >= MAX_INVENTORY)
  10247. return;
  10248. if (!pc_useitem(sd,n))
  10249. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10250. }
  10251. /// Request to equip an item
  10252. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10253. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10254. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10255. {
  10256. int index;
  10257. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10258. if(pc_isdead(sd)) {
  10259. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10260. return;
  10261. }
  10262. index = RFIFOW(fd,info->pos[0])-2;
  10263. if (index < 0 || index >= MAX_INVENTORY)
  10264. return; //Out of bounds check.
  10265. if(sd->npc_id && !sd->npc_item_flag) {
  10266. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10267. return;
  10268. } else if (sd->state.storage_flag || sd->sc.opt1)
  10269. ; //You can equip/unequip stuff while storage is open/under status changes
  10270. else if (pc_cant_act2(sd))
  10271. return;
  10272. if(!sd->inventory.u.items_inventory[index].identify) {
  10273. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  10274. return;
  10275. }
  10276. if(!sd->inventory_data[index])
  10277. return;
  10278. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10279. pet_equipitem(sd,index);
  10280. return;
  10281. }
  10282. if (battle_config.idletime_option&IDLE_USEITEM)
  10283. sd->idletime = last_tick;
  10284. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10285. sd->idletime_hom = last_tick;
  10286. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10287. sd->idletime_mer = last_tick;
  10288. //Client doesn't send the position for ammo.
  10289. if(sd->inventory_data[index]->type == IT_AMMO)
  10290. pc_equipitem(sd,index,EQP_AMMO);
  10291. else {
  10292. int req_pos;
  10293. #if PACKETVER >= 20120925
  10294. req_pos = RFIFOL(fd,info->pos[1]);
  10295. #else
  10296. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10297. #endif
  10298. pc_equipitem(sd,index,req_pos);
  10299. }
  10300. }
  10301. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10302. /// 00ab <index>.W
  10303. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10304. {
  10305. int index;
  10306. if(pc_isdead(sd)) {
  10307. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10308. return;
  10309. }
  10310. if (sd->npc_id && !sd->npc_item_flag) {
  10311. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10312. return;
  10313. } else if (sd->state.storage_flag || sd->sc.opt1)
  10314. ; //You can equip/unequip stuff while storage is open/under status changes
  10315. else if (pc_cant_act2(sd))
  10316. return;
  10317. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10318. if (battle_config.idletime_option&IDLE_USEITEM)
  10319. sd->idletime = last_tick;
  10320. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10321. sd->idletime_hom = last_tick;
  10322. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10323. sd->idletime_mer = last_tick;
  10324. pc_unequipitem(sd,index,1);
  10325. }
  10326. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10327. /// 0090 <id>.L <type>.B
  10328. /// type:
  10329. /// 1 = click
  10330. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10331. {
  10332. struct block_list *bl;
  10333. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10334. if(pc_isdead(sd)) {
  10335. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10336. return;
  10337. }
  10338. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10339. #ifdef RENEWAL
  10340. clif_msg( sd, WORK_IN_PROGRESS );
  10341. #endif
  10342. return;
  10343. }
  10344. if( sd->state.mail_writing )
  10345. return;
  10346. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10347. //type = RFIFOB(fd,info->pos[1]);
  10348. if (!bl) return;
  10349. switch (bl->type) {
  10350. case BL_MOB:
  10351. case BL_PC:
  10352. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10353. break;
  10354. case BL_NPC:
  10355. #ifdef RENEWAL
  10356. 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
  10357. clif_msg(sd, WORK_IN_PROGRESS);
  10358. break;
  10359. }
  10360. #endif
  10361. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10362. struct npc_data* nd = (struct npc_data*)bl;
  10363. // Progressbar is running
  10364. if( nd->progressbar.timeout > 0 ){
  10365. return;
  10366. }
  10367. npc_click(sd,nd);
  10368. }
  10369. break;
  10370. }
  10371. }
  10372. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10373. /// 00c5 <id>.L <type>.B
  10374. /// type:
  10375. /// 0 = buy
  10376. /// 1 = sell
  10377. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10378. {
  10379. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10380. if (sd->state.trading)
  10381. return;
  10382. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10383. }
  10384. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10385. /// 00ca <result>.B
  10386. /// result:
  10387. /// 0 = "The deal has successfully completed."
  10388. /// 1 = "You do not have enough zeny."
  10389. /// 2 = "You are over your Weight Limit."
  10390. /// 3 = "Out of the maximum capacity, you have too many items."
  10391. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10392. /// 10 = "Props open-air store sales will be traded in RODEX"
  10393. /// 11 = "The exchange failed."
  10394. /// 12 = "The exchange was well done."
  10395. /// 13 = "The item is already sold and out of stock."
  10396. /// 14 = "There is not enough goods to exchange."
  10397. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10398. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10399. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10400. p.result = (uint8)result;
  10401. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10402. }
  10403. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10404. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10405. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10406. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10407. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10408. e_purchase_result result;
  10409. if( sd->state.trading || !sd->npc_shopid )
  10410. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10411. else{
  10412. std::vector<s_npc_buy_list> items = {};
  10413. items.reserve( n );
  10414. for( uint16 i = 0; i < n; i++ ){
  10415. s_npc_buy_list item = {};
  10416. item.nameid = p->items[i].itemId;
  10417. item.qty = p->items[i].amount;
  10418. items.push_back( item );
  10419. }
  10420. result = npc_buylist( sd, items );
  10421. }
  10422. sd->npc_shopid = 0; //Clear shop data.
  10423. clif_npc_buy_result(sd, result);
  10424. }
  10425. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10426. /// 00cb <result>.B
  10427. /// result:
  10428. /// 0 = "The deal has successfully completed."
  10429. /// 1 = "The deal has failed."
  10430. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10431. {
  10432. int fd = sd->fd;
  10433. WFIFOHEAD(fd,packet_len(0xcb));
  10434. WFIFOW(fd,0) = 0xcb;
  10435. WFIFOB(fd,2) = result;
  10436. WFIFOSET(fd,packet_len(0xcb));
  10437. }
  10438. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10439. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10440. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10441. {
  10442. int fail=0,n;
  10443. unsigned short *item_list;
  10444. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10445. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10446. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10447. if (sd->state.trading || !sd->npc_shopid)
  10448. fail = 1;
  10449. else
  10450. fail = npc_selllist(sd,n,item_list);
  10451. sd->npc_shopid = 0; //Clear shop data.
  10452. clif_npc_sell_result(sd, fail);
  10453. }
  10454. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10455. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10456. /// type:
  10457. /// 0 = private
  10458. /// 1 = public
  10459. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10460. {
  10461. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10462. int len = RFIFOW(fd,info->pos[0])-15;
  10463. int limit = RFIFOW(fd,info->pos[1]);
  10464. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10465. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10466. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10467. char s_password[CHATROOM_PASS_SIZE];
  10468. char s_title[CHATROOM_TITLE_SIZE];
  10469. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10470. return;
  10471. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10472. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10473. return;
  10474. }
  10475. if( npc_isnear(&sd->bl) ) {
  10476. // uncomment to send msg_txt.
  10477. //char output[150];
  10478. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10479. //clif_displaymessage(sd->fd, output);
  10480. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10481. return;
  10482. }
  10483. if( len <= 0 )
  10484. return; // invalid input
  10485. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10486. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10487. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10488. }
  10489. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10490. /// 00d9 <chat ID>.L <passwd>.8B
  10491. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10492. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10493. int chatid = RFIFOL(fd,info->pos[0]);
  10494. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10495. chat_joinchat(sd,chatid,password);
  10496. }
  10497. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10498. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10499. /// type:
  10500. /// 0 = private
  10501. /// 1 = public
  10502. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10503. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10504. int len = RFIFOW(fd,info->pos[0])-15;
  10505. int limit = RFIFOW(fd,info->pos[1]);
  10506. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10507. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10508. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10509. char s_password[CHATROOM_PASS_SIZE];
  10510. char s_title[CHATROOM_TITLE_SIZE];
  10511. if( len <= 0 )
  10512. return; // invalid input
  10513. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10514. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10515. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10516. }
  10517. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10518. /// 00e0 <role>.L <nick>.24B
  10519. /// role:
  10520. /// 0 = owner
  10521. /// 1 = normal
  10522. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10523. {
  10524. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10525. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10526. }
  10527. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10528. /// 00e2 <name>.24B
  10529. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10530. {
  10531. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10532. }
  10533. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10534. /// 00e3
  10535. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10536. {
  10537. chat_leavechat(sd,0);
  10538. }
  10539. //Handles notifying asker and rejecter of what has just ocurred.
  10540. //Type is used to determine the correct msg_txt to use:
  10541. //0:
  10542. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10543. {
  10544. const char* msg;
  10545. char output[256];
  10546. // Your request has been rejected by autoreject option.
  10547. msg = msg_txt(sd,392);
  10548. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10549. //Notice that a request was rejected.
  10550. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10551. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10552. }
  10553. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10554. /// 00e4 <account id>.L
  10555. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10556. {
  10557. struct map_session_data *t_sd;
  10558. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10559. if(!sd->chatID && pc_cant_act(sd))
  10560. return; //You can trade while in a chatroom.
  10561. if(t_sd){
  10562. // @noask [LuzZza]
  10563. if(t_sd->state.noask) {
  10564. clif_noask_sub(sd, t_sd, 0);
  10565. return;
  10566. }
  10567. if (t_sd->state.mail_writing) {
  10568. int old = sd->trade_partner;
  10569. // Fake trading
  10570. sd->trade_partner = t_sd->status.account_id;
  10571. clif_tradestart(sd, 5);
  10572. // Restore old state
  10573. sd->trade_partner = old;
  10574. return;
  10575. }
  10576. }
  10577. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10578. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10579. return;
  10580. }
  10581. trade_traderequest(sd,t_sd);
  10582. }
  10583. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10584. /// 00e6 <result>.B
  10585. /// result:
  10586. /// 3 = accepted
  10587. /// 4 = rejected
  10588. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10589. {
  10590. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10591. }
  10592. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10593. /// 00e8 <index>.W <amount>.L
  10594. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10595. {
  10596. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10597. short index = RFIFOW(fd,info->pos[0]);
  10598. int amount = RFIFOL(fd,info->pos[1]);
  10599. if( index == 0 )
  10600. trade_tradeaddzeny(sd, amount);
  10601. else
  10602. trade_tradeadditem(sd, index, (short)amount);
  10603. }
  10604. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10605. /// 00eb
  10606. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10607. {
  10608. trade_tradeok(sd);
  10609. }
  10610. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10611. /// 00ed
  10612. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10613. {
  10614. trade_tradecancel(sd);
  10615. }
  10616. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10617. /// 00ef
  10618. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10619. {
  10620. trade_tradecommit(sd);
  10621. }
  10622. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10623. /// 0118
  10624. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10625. {
  10626. pc_stop_attack(sd);
  10627. if (sd) sd->ud.state.attack_continue = 0;
  10628. }
  10629. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10630. /// 0126 <index>.W <amount>.L
  10631. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10632. {
  10633. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10634. if (pc_istrading(sd))
  10635. return;
  10636. if (!pc_iscarton(sd))
  10637. return;
  10638. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10639. return;
  10640. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10641. }
  10642. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10643. /// 0127 <index>.W <amount>.L
  10644. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10645. {
  10646. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10647. if (!pc_iscarton(sd))
  10648. return;
  10649. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10650. return;
  10651. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10652. }
  10653. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10654. /// 012a
  10655. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10656. {
  10657. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10658. #ifdef NEW_CARTS
  10659. && sd->sc.data[SC_PUSH_CART] )
  10660. pc_setcart(sd,0);
  10661. #else
  10662. )
  10663. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10664. #endif
  10665. else // priority to remove this option before we can clear cart
  10666. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10667. }
  10668. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10669. /// 097f <Length>.W <identity>.L <type>.B
  10670. void clif_SelectCart(struct map_session_data *sd) {
  10671. #if PACKETVER >= 20150826
  10672. int i = 0, carts = 3;
  10673. int fd = sd->fd;
  10674. WFIFOHEAD(fd,8 + carts);
  10675. WFIFOW(fd,0) = 0x97f;
  10676. WFIFOW(fd,2) = 8 + carts;
  10677. WFIFOL(fd,4) = sd->status.account_id;
  10678. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10679. for( i = 0; i < carts; i++ ) {
  10680. WFIFOB(fd,8 + i) = 10 + i;
  10681. }
  10682. WFIFOSET(fd,8 + carts);
  10683. #endif
  10684. }
  10685. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10686. /// 0980 <identity>.L <type>.B
  10687. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10688. #if PACKETVER >= 20150826
  10689. int type;
  10690. // Check identity
  10691. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10692. return;
  10693. type = (int)RFIFOB(fd,6);
  10694. // Check type
  10695. if( type < 10 || type > 12 )
  10696. return;
  10697. pc_setcart(sd, type);
  10698. #endif
  10699. }
  10700. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10701. /// 01af <num>.W
  10702. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10703. {// TODO: State tracking?
  10704. int type;
  10705. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10706. return;
  10707. #ifdef RENEWAL
  10708. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10709. clif_msg(sd, WORK_IN_PROGRESS);
  10710. return;
  10711. }
  10712. #endif
  10713. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10714. if(
  10715. #ifdef NEW_CARTS
  10716. #if PACKETVER >= 20191106
  10717. (type == 13 && sd->status.base_level > 100) ||
  10718. #endif
  10719. (type == 9 && sd->status.base_level > 130) ||
  10720. (type == 8 && sd->status.base_level > 120) ||
  10721. (type == 7 && sd->status.base_level > 110) ||
  10722. (type == 6 && sd->status.base_level > 100) ||
  10723. #endif
  10724. (type == 5 && sd->status.base_level > 90) ||
  10725. (type == 4 && sd->status.base_level > 80) ||
  10726. (type == 3 && sd->status.base_level > 65) ||
  10727. (type == 2 && sd->status.base_level > 40) ||
  10728. (type == 1))
  10729. pc_setcart(sd, type);
  10730. }
  10731. /// Request to increase status (CZ_STATUS_CHANGE).
  10732. /// 00bb <status id>.W <amount>.B
  10733. /// status id:
  10734. /// SP_STR ~ SP_LUK
  10735. /// amount:
  10736. /// Old clients always send 1 for this, even when using /str+ and the like.
  10737. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10738. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10739. {
  10740. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10741. if( increase_amount < 0 ) {
  10742. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10743. fd, increase_amount);
  10744. }
  10745. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10746. }
  10747. /// Request to increase trait status.
  10748. /// 0b24 <status id>.W <amount>.W
  10749. /// status id:
  10750. /// SP_POW ~ SP_CON
  10751. /// amount:
  10752. /// The amount to increase the trait status
  10753. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10754. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10755. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10756. if( p->amount < 0 ){
  10757. 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 );
  10758. return;
  10759. }
  10760. pc_traitstatusup( sd, p->type, p->amount );
  10761. #endif
  10762. }
  10763. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10764. /// 0112 <skill id>.W
  10765. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10766. {
  10767. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10768. }
  10769. 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)
  10770. {
  10771. int lv;
  10772. if( !hd )
  10773. return;
  10774. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10775. clif_emotion(&hd->bl, ET_THINK);
  10776. return;
  10777. }
  10778. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10779. target_id = hd->bl.id;
  10780. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10781. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10782. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10783. clif_emotion(&hd->bl, ET_THINK);
  10784. if (hd->master)
  10785. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10786. return;
  10787. }
  10788. lv = hom_checkskill(hd, skill_id);
  10789. if( skill_lv > lv )
  10790. skill_lv = lv;
  10791. if( skill_lv )
  10792. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10793. }
  10794. 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)
  10795. {
  10796. int lv;
  10797. if( !hd )
  10798. return;
  10799. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10800. clif_emotion(&hd->bl, ET_THINK);
  10801. return;
  10802. }
  10803. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10804. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10805. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10806. clif_emotion(&hd->bl, ET_THINK);
  10807. if (hd->master)
  10808. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10809. return;
  10810. }
  10811. #ifdef RENEWAL
  10812. if (hd->sc.data[SC_BASILICA_CELL])
  10813. #else
  10814. if (hd->sc.data[SC_BASILICA])
  10815. #endif
  10816. return;
  10817. lv = hom_checkskill(hd, skill_id);
  10818. if( skill_lv > lv )
  10819. skill_lv = lv;
  10820. if( skill_lv )
  10821. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10822. }
  10823. 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)
  10824. {
  10825. int lv;
  10826. if( !md )
  10827. return;
  10828. if( skill_isNotOk_mercenary(skill_id, md) )
  10829. return;
  10830. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10831. target_id = md->bl.id;
  10832. if( md->ud.skilltimer != INVALID_TIMER )
  10833. {
  10834. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10835. }
  10836. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10837. return;
  10838. lv = mercenary_checkskill(md, skill_id);
  10839. if( skill_lv > lv )
  10840. skill_lv = lv;
  10841. if( skill_lv )
  10842. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10843. }
  10844. 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)
  10845. {
  10846. int lv;
  10847. if( !md )
  10848. return;
  10849. if( skill_isNotOk_mercenary(skill_id, md) )
  10850. return;
  10851. if( md->ud.skilltimer != INVALID_TIMER )
  10852. return;
  10853. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10854. {
  10855. if (md->master)
  10856. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10857. return;
  10858. }
  10859. #ifdef RENEWAL
  10860. if (md->sc.data[SC_BASILICA_CELL])
  10861. #else
  10862. if (md->sc.data[SC_BASILICA])
  10863. #endif
  10864. return;
  10865. lv = mercenary_checkskill(md, skill_id);
  10866. if( skill_lv > lv )
  10867. skill_lv = lv;
  10868. if( skill_lv )
  10869. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10870. }
  10871. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10872. t_tick tick = gettick();
  10873. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10874. int inf = skill_get_inf(skill_id);
  10875. if (inf&INF_GROUND_SKILL || !inf)
  10876. return; //Using a ground/passive skill on a target? WRONG.
  10877. if (sd->state.block_action & PCBLOCK_SKILL) {
  10878. clif_msg(sd, WORK_IN_PROGRESS);
  10879. return;
  10880. }
  10881. if( SKILL_CHK_HOMUN(skill_id) ) {
  10882. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10883. return;
  10884. }
  10885. if( SKILL_CHK_MERC(skill_id) ) {
  10886. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10887. return;
  10888. }
  10889. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10890. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10891. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10892. sd->idletime = last_tick;
  10893. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10894. sd->idletime_hom = last_tick;
  10895. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10896. sd->idletime_mer = last_tick;
  10897. if( sd->npc_id ){
  10898. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10899. #ifdef RENEWAL
  10900. clif_msg( sd, WORK_IN_PROGRESS );
  10901. #endif
  10902. return;
  10903. }
  10904. }
  10905. if ((pc_cant_act2(sd) || sd->chatID) &&
  10906. skill_id != RK_REFRESH &&
  10907. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10908. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10909. return;
  10910. if( pc_issit(sd) )
  10911. return;
  10912. if( skill_isNotOk(skill_id, sd) )
  10913. return;
  10914. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10915. target_id = sd->bl.id; // never trust the client
  10916. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10917. target_id = sd->bl.id;
  10918. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10919. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10920. return;
  10921. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10922. if( sd->skillitem != skill_id ) {
  10923. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10924. return;
  10925. }
  10926. }
  10927. if( sd->sc.option&OPTION_COSTUME )
  10928. return;
  10929. #ifndef RENEWAL
  10930. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10931. return; // On basilica only caster can use Basilica again to stop it.
  10932. #endif
  10933. if( sd->menuskill_id ) {
  10934. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10935. clif_menuskill_clear(sd); //Cancel pet capture.
  10936. }else if( sd->menuskill_id == SG_FEEL ){
  10937. clif_menuskill_clear( sd ); // Cancel selection
  10938. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10939. return; //Can't use skills while a menu is open.
  10940. }
  10941. if( sd->skillitem == skill_id ) {
  10942. if( skill_lv != sd->skillitemlv )
  10943. skill_lv = sd->skillitemlv;
  10944. if( !(inf&INF_SELF_SKILL) )
  10945. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10946. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10947. return;
  10948. }
  10949. sd->skillitem = sd->skillitemlv = 0;
  10950. if( SKILL_CHK_GUILD(skill_id) ) {
  10951. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10952. skill_lv = guild_checkskill(sd->guild, skill_id);
  10953. else
  10954. skill_lv = 0;
  10955. } else {
  10956. if( skill_id != ALL_EQSWITCH ){
  10957. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10958. }
  10959. }
  10960. pc_delinvincibletimer(sd);
  10961. if( skill_lv )
  10962. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10963. }
  10964. /// Request to use a targeted skill.
  10965. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10966. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10967. /// There are various variants of this packet, some of them have padding between fields.
  10968. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10969. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10970. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10971. }
  10972. /*==========================================
  10973. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10974. *------------------------------------------*/
  10975. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10976. {
  10977. t_tick tick = gettick();
  10978. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10979. return; //Using a target skill on the ground? WRONG.
  10980. if (sd->state.block_action & PCBLOCK_SKILL) {
  10981. clif_msg(sd, WORK_IN_PROGRESS);
  10982. return;
  10983. }
  10984. if( SKILL_CHK_HOMUN(skill_id) ) {
  10985. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10986. return;
  10987. }
  10988. if( SKILL_CHK_MERC(skill_id) ) {
  10989. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10990. return;
  10991. }
  10992. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10993. #ifdef RENEWAL
  10994. clif_msg( sd, WORK_IN_PROGRESS );
  10995. #endif
  10996. return;
  10997. }
  10998. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10999. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  11000. sd->idletime = last_tick;
  11001. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  11002. sd->idletime_hom = last_tick;
  11003. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  11004. sd->idletime_mer = last_tick;
  11005. if( skill_isNotOk(skill_id, sd) )
  11006. return;
  11007. if( skillmoreinfo != -1 ) {
  11008. if( pc_issit(sd) ) {
  11009. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  11010. return;
  11011. }
  11012. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  11013. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  11014. }
  11015. if( sd->ud.skilltimer != INVALID_TIMER )
  11016. return;
  11017. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  11018. if( sd->skillitem != skill_id ) {
  11019. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  11020. return;
  11021. }
  11022. }
  11023. if( sd->sc.option&OPTION_COSTUME )
  11024. return;
  11025. #ifndef RENEWAL
  11026. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  11027. return; // On basilica only caster can use Basilica again to stop it.
  11028. #endif
  11029. if( sd->menuskill_id ) {
  11030. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  11031. clif_menuskill_clear(sd); //Cancel pet capture.
  11032. }else if( sd->menuskill_id == SG_FEEL ){
  11033. clif_menuskill_clear( sd ); // Cancel selection
  11034. } else if( sd->menuskill_id != SA_AUTOSPELL )
  11035. return; //Can't use skills while a menu is open.
  11036. }
  11037. pc_delinvincibletimer(sd);
  11038. if( sd->skillitem == skill_id ) {
  11039. if( skill_lv != sd->skillitemlv )
  11040. skill_lv = sd->skillitemlv;
  11041. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  11042. } else {
  11043. int lv;
  11044. sd->skillitem = sd->skillitemlv = 0;
  11045. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  11046. if( skill_lv > lv )
  11047. skill_lv = lv;
  11048. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  11049. }
  11050. }
  11051. }
  11052. /// Request to use a ground skill.
  11053. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11054. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11055. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11056. /// There are various variants of this packet, some of them have padding between fields.
  11057. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  11058. {
  11059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11060. if (pc_cant_act(sd))
  11061. return;
  11062. if (pc_issit(sd))
  11063. return;
  11064. clif_parse_UseSkillToPosSub(fd, sd,
  11065. RFIFOW(fd,info->pos[0]), //skill lv
  11066. RFIFOW(fd,info->pos[1]), //skill num
  11067. RFIFOW(fd,info->pos[2]), //pos x
  11068. RFIFOW(fd,info->pos[3]), //pos y
  11069. // TODO: find out what this is intended to do
  11070. //RFIFOB(fd, info->pos[4])
  11071. -1 //Skill more info.
  11072. );
  11073. }
  11074. /// Request to use a ground skill with text.
  11075. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11076. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11077. /// There are various variants of this packet, some of them have padding between fields.
  11078. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  11079. {
  11080. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11081. if (pc_cant_act(sd))
  11082. return;
  11083. if (pc_issit(sd))
  11084. return;
  11085. clif_parse_UseSkillToPosSub(fd, sd,
  11086. RFIFOW(fd,info->pos[0]), //Skill lv
  11087. RFIFOW(fd,info->pos[1]), //Skill num
  11088. RFIFOW(fd,info->pos[2]), //pos x
  11089. RFIFOW(fd,info->pos[3]), //pos y
  11090. info->pos[4] //skill more info
  11091. );
  11092. }
  11093. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11094. /// 011b <skill id>.W <map name>.16B
  11095. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  11096. {
  11097. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11098. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11099. char map_name[MAP_NAME_LENGTH];
  11100. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11101. sd->state.workinprogress = WIP_DISABLE_NONE;
  11102. if(skill_id != sd->menuskill_id)
  11103. return;
  11104. //It is possible to use teleport with the storage window open bugreport:8027
  11105. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11106. clif_menuskill_clear(sd);
  11107. return;
  11108. }
  11109. pc_delinvincibletimer(sd);
  11110. skill_castend_map(sd,skill_id,map_name);
  11111. }
  11112. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11113. /// 011d
  11114. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  11115. {
  11116. if (!pc_isdead(sd))
  11117. pc_memo(sd,-1);
  11118. }
  11119. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11120. /// 018e <name id>.W { <material id>.W }*3
  11121. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  11122. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11123. switch( sd->menuskill_id ) {
  11124. case -1:
  11125. case AM_PHARMACY:
  11126. case RK_RUNEMASTERY:
  11127. case GC_RESEARCHNEWPOISON:
  11128. break;
  11129. default:
  11130. return;
  11131. }
  11132. if (pc_istrading(sd)) {
  11133. //Make it fail to avoid shop exploits where you sell something different than you see.
  11134. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11135. clif_menuskill_clear(sd);
  11136. return;
  11137. }
  11138. int produce_idx;
  11139. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11140. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11141. clif_menuskill_clear(sd);
  11142. }
  11143. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11144. /// 025b <mk type>.W <name id>.W
  11145. /// mk type:
  11146. /// 1 = cooking
  11147. /// 2 = arrow
  11148. /// 3 = elemental
  11149. /// 4 = GN_MIX_COOKING
  11150. /// 5 = GN_MAKEBOMB
  11151. /// 6 = GN_S_PHARMACY
  11152. /// 7 = MT_M_MACHINE - Unconfirmed
  11153. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11154. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  11155. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11156. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11157. short food_idx = -1;
  11158. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11159. return;
  11160. if (pc_istrading(sd)) {
  11161. //Make it fail to avoid shop exploits where you sell something different than you see.
  11162. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11163. clif_menuskill_clear(sd);
  11164. return;
  11165. }
  11166. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11167. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11168. clif_menuskill_clear(sd);
  11169. }
  11170. /// Answer to repair weapon item selection dialog
  11171. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11172. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11173. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11174. // Hercules has wrong date -> use correct one here
  11175. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11176. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11177. #else
  11178. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11179. #endif
  11180. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11181. return;
  11182. if (pc_istrading(sd)) {
  11183. //Make it fail to avoid shop exploits where you sell something different than you see.
  11184. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11185. clif_menuskill_clear(sd);
  11186. return;
  11187. }
  11188. skill_repairweapon( sd, p->item.index );
  11189. clif_menuskill_clear(sd);
  11190. }
  11191. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11192. /// 0222 <index>.L
  11193. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11194. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11195. return;
  11196. if (pc_istrading(sd)) {
  11197. //Make it fail to avoid shop exploits where you sell something different than you see.
  11198. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11199. clif_menuskill_clear(sd);
  11200. return;
  11201. }
  11202. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11203. clif_menuskill_clear(sd);
  11204. }
  11205. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11206. /// 00b8 <npc id>.L <choice>.B
  11207. /// choice:
  11208. /// 1~254 = menu item
  11209. /// 255 = cancel
  11210. /// NOTE: If there were more than 254 items in the list, choice
  11211. /// overflows to choice%256.
  11212. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11213. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11214. int npc_id = RFIFOL(fd,info->pos[0]);
  11215. uint8 select = RFIFOB(fd,info->pos[1]);
  11216. #ifdef SECURE_NPCTIMEOUT
  11217. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11218. return;
  11219. #endif
  11220. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11221. TBL_NPC* nd = map_id2nd(npc_id);
  11222. 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);
  11223. clif_GM_kick(NULL,sd);
  11224. return;
  11225. }
  11226. sd->npc_menu = select;
  11227. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11228. sd->idletime = last_tick;
  11229. }
  11230. npc_scriptcont(sd,npc_id, false);
  11231. }
  11232. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11233. /// 00b9 <npc id>.L
  11234. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11235. {
  11236. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11237. sd->idletime = last_tick;
  11238. }
  11239. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11240. }
  11241. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11242. /// 0143 <npc id>.L <value>.L
  11243. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11244. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11245. int npcid = RFIFOL(fd,info->pos[0]);
  11246. int amount = (int)RFIFOL(fd,info->pos[1]);
  11247. sd->npc_amount = amount;
  11248. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11249. sd->idletime = last_tick;
  11250. }
  11251. npc_scriptcont(sd, npcid, false);
  11252. }
  11253. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11254. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11255. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11256. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11257. int message_len = RFIFOW(fd,info->pos[0])-8;
  11258. int npcid = RFIFOL(fd,info->pos[1]);
  11259. const char* message = RFIFOCP(fd,info->pos[2]);
  11260. if( message_len <= 0 )
  11261. return; // invalid input
  11262. #if PACKETVER >= 20151001
  11263. message_len++;
  11264. #endif
  11265. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11266. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11267. sd->idletime = last_tick;
  11268. }
  11269. npc_scriptcont(sd, npcid, false);
  11270. }
  11271. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11272. /// 0146 <npc id>.L
  11273. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11274. {
  11275. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11276. return;
  11277. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11278. sd->idletime = last_tick;
  11279. }
  11280. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11281. }
  11282. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11283. /// 0178 <index>.W
  11284. /// index:
  11285. /// -1 = cancel
  11286. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11287. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11288. if (sd->menuskill_id != MC_IDENTIFY)
  11289. return;
  11290. // Ignore the request
  11291. // - Invalid item index
  11292. // - Invalid item ID or item doesn't exist
  11293. // - Item is already identified
  11294. if (idx < 0 || idx >= MAX_INVENTORY ||
  11295. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11296. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11297. sd->state.workinprogress = WIP_DISABLE_NONE;
  11298. clif_menuskill_clear(sd);
  11299. return;
  11300. }
  11301. skill_identify(sd, idx);
  11302. clif_menuskill_clear(sd);
  11303. }
  11304. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11305. /// 01ae <name id>.W
  11306. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11307. if (pc_istrading(sd)) {
  11308. //Make it fail to avoid shop exploits where you sell something different than you see.
  11309. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11310. clif_menuskill_clear(sd);
  11311. return;
  11312. }
  11313. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11314. switch (sd->menuskill_id) {
  11315. case AC_MAKINGARROW:
  11316. skill_arrow_create(sd,p->itemId);
  11317. break;
  11318. case SA_CREATECON:
  11319. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11320. break;
  11321. case GC_POISONINGWEAPON:
  11322. skill_poisoningweapon(sd,p->itemId);
  11323. break;
  11324. case NC_MAGICDECOY:
  11325. skill_magicdecoy(sd,p->itemId);
  11326. break;
  11327. }
  11328. clif_menuskill_clear(sd);
  11329. }
  11330. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11331. /// 01ce <skill id>.L
  11332. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11333. {
  11334. if (sd->menuskill_id != SA_AUTOSPELL)
  11335. return;
  11336. sd->state.workinprogress = WIP_DISABLE_NONE;
  11337. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11338. clif_menuskill_clear(sd);
  11339. }
  11340. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11341. /// 017a <card index>.W
  11342. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11343. {
  11344. if (sd->state.trading != 0)
  11345. return;
  11346. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11347. }
  11348. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11349. /// 017c <card index>.W <equip index>.W
  11350. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11351. {
  11352. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11353. if (sd->state.trading != 0)
  11354. return;
  11355. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11356. }
  11357. /// Request of character's name by char ID.
  11358. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11359. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11360. /// There are various variants of this packet, some of them have padding between fields.
  11361. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11362. {
  11363. int charid;
  11364. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11365. map_reqnickdb(sd, charid);
  11366. }
  11367. /// /resetskill /resetstate (CZ_RESET).
  11368. /// Request to reset stats or skills.
  11369. /// 0197 <type>.W
  11370. /// type:
  11371. /// 0 = state
  11372. /// 1 = skill
  11373. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11374. char cmd[15];
  11375. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11376. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11377. else
  11378. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11379. is_atcommand(fd, sd, cmd, 1);
  11380. }
  11381. /// /lb /nlb (CZ_LOCALBROADCAST).
  11382. /// Request to broadcast a message on current map.
  11383. /// 019c <packet len>.W <text>.?B
  11384. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11385. {
  11386. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11387. char command[CHAT_SIZE_MAX+16];
  11388. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11389. char* msg = RFIFOCP(fd,info->pos[1]);
  11390. // as the length varies depending on the command used, just block unreasonably long strings
  11391. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11392. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11393. is_atcommand(fd, sd, command, 1);
  11394. }
  11395. /// Request to move an item from inventory to storage.
  11396. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11397. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11398. /// There are various variants of this packet, some of them have padding between fields.
  11399. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11400. {
  11401. int item_index, item_amount;
  11402. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11403. if (pc_istrading(sd))
  11404. return;
  11405. item_index = RFIFOW(fd,info->pos[0])-2;
  11406. item_amount = RFIFOL(fd,info->pos[1]);
  11407. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11408. return;
  11409. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11410. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11411. return;
  11412. }
  11413. if (sd->state.storage_flag == 1)
  11414. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11415. else
  11416. if (sd->state.storage_flag == 2)
  11417. storage_guild_storageadd(sd, item_index, item_amount);
  11418. else if (sd->state.storage_flag == 3)
  11419. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11420. }
  11421. /// Request to move an item from storage to inventory.
  11422. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11423. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11424. /// There are various variants of this packet, some of them have padding between fields.
  11425. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11426. {
  11427. int item_index, item_amount;
  11428. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11429. item_index = RFIFOW(fd,info->pos[0])-1;
  11430. item_amount = RFIFOL(fd,info->pos[1]);
  11431. if (sd->state.storage_flag == 1)
  11432. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11433. else if(sd->state.storage_flag == 2)
  11434. storage_guild_storageget(sd, item_index, item_amount);
  11435. else if(sd->state.storage_flag == 3)
  11436. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11437. }
  11438. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11439. /// 0129 <index>.W <amount>.L
  11440. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11441. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11442. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11443. int amount = RFIFOL(fd,info->pos[1]);
  11444. if( sd->state.vending )
  11445. return;
  11446. if (!pc_iscarton(sd))
  11447. return;
  11448. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11449. return;
  11450. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11451. return;
  11452. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11453. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11454. return;
  11455. }
  11456. if (sd->state.storage_flag == 1)
  11457. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11458. else if (sd->state.storage_flag == 2)
  11459. storage_guild_storageaddfromcart(sd, idx, amount);
  11460. else if (sd->state.storage_flag == 3)
  11461. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11462. }
  11463. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11464. /// 0128 <index>.W <amount>.L
  11465. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11466. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11467. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11468. int amount = RFIFOL(fd,info->pos[1]);
  11469. if( sd->state.vending )
  11470. return;
  11471. if (!pc_iscarton(sd))
  11472. return;
  11473. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11474. return;
  11475. if (sd->state.storage_flag == 1)
  11476. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11477. else
  11478. if (sd->state.storage_flag == 2)
  11479. storage_guild_storagegettocart(sd, idx, amount);
  11480. else if (sd->state.storage_flag == 3)
  11481. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11482. }
  11483. /// Request to close storage (CZ_CLOSE_STORE).
  11484. /// 00f7
  11485. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11486. {
  11487. if( sd->state.storage_flag == 1 )
  11488. storage_storageclose(sd);
  11489. else
  11490. if( sd->state.storage_flag == 2 )
  11491. storage_guild_storageclose(sd);
  11492. else if( sd->state.storage_flag == 3 )
  11493. storage_premiumStorage_close(sd);
  11494. }
  11495. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11496. /// 023a <info>.W
  11497. /// info:
  11498. /// 0 = password has not been set yet
  11499. /// 1 = storage is password-protected
  11500. /// 8 = too many wrong passwords
  11501. /// ? = ignored
  11502. /// NOTE: This packet is only available on certain non-kRO clients.
  11503. void clif_storagepassword(struct map_session_data* sd, short info)
  11504. {
  11505. int fd = sd->fd;
  11506. WFIFOHEAD(fd,packet_len(0x23a));
  11507. WFIFOW(fd,0) = 0x23a;
  11508. WFIFOW(fd,2) = info;
  11509. WFIFOSET(fd,packet_len(0x23a));
  11510. }
  11511. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11512. /// 023b <type>.W <password>.16B <new password>.16B
  11513. /// type:
  11514. /// 2 = change password
  11515. /// 3 = check password
  11516. /// NOTE: This packet is only available on certain non-kRO clients.
  11517. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11518. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11519. // int type = RFIFOW(fd,info->pos[0]);
  11520. // char* password = RFIFOP(fd,info->pos[1]);
  11521. // char* new_password = RFIFOP(fd,info->pos[2]);
  11522. // storage_changepass(sd,password,new_password);
  11523. }
  11524. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11525. /// 023c <result>.W <error count>.W
  11526. /// result:
  11527. /// 4 = password change success
  11528. /// 5 = password change failure
  11529. /// 6 = password check success
  11530. /// 7 = password check failure
  11531. /// 8 = too many wrong passwords
  11532. /// ? = ignored
  11533. /// NOTE: This packet is only available on certain non-kRO clients.
  11534. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11535. {
  11536. int fd = sd->fd;
  11537. WFIFOHEAD(fd,packet_len(0x23c));
  11538. WFIFOW(fd,0) = 0x23c;
  11539. WFIFOW(fd,2) = result;
  11540. WFIFOW(fd,4) = error_count;
  11541. WFIFOSET(fd,packet_len(0x23c));
  11542. }
  11543. /// Party creation request
  11544. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11545. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11546. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11547. name[NAME_LENGTH-1] = '\0';
  11548. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11549. clif_displaymessage(fd, msg_txt(sd,227));
  11550. return;
  11551. }
  11552. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11553. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11554. return;
  11555. }
  11556. party_create(sd,name,0,0);
  11557. }
  11558. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11559. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11560. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11561. char* name = RFIFOCP(fd,info->pos[0]);
  11562. int item1 = RFIFOB(fd,info->pos[1]);
  11563. int item2 = RFIFOB(fd,info->pos[2]);
  11564. name[NAME_LENGTH-1] = '\0';
  11565. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11566. clif_displaymessage(fd, msg_txt(sd,227));
  11567. return;
  11568. }
  11569. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11570. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11571. return;
  11572. }
  11573. party_create(sd,name,item1,item2);
  11574. }
  11575. /// Party invitation request
  11576. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11577. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11578. {
  11579. struct map_session_data *t_sd;
  11580. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11581. clif_displaymessage(fd, msg_txt(sd,227));
  11582. return;
  11583. }
  11584. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11585. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11586. clif_noask_sub(sd, t_sd, 1);
  11587. return;
  11588. }
  11589. party_invite(sd, t_sd);
  11590. }
  11591. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11592. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11593. struct map_session_data *t_sd;
  11594. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11595. name[NAME_LENGTH-1] = '\0';
  11596. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11597. clif_displaymessage(fd, msg_txt(sd,227));
  11598. return;
  11599. }
  11600. t_sd = map_nick2sd(name,false);
  11601. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11602. clif_noask_sub(sd, t_sd, 1);
  11603. return;
  11604. }
  11605. party_invite(sd, t_sd);
  11606. }
  11607. /// Party invitation reply
  11608. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11609. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11610. /// flag:
  11611. /// 0 = reject
  11612. /// 1 = accept
  11613. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11614. {
  11615. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11616. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11617. RFIFOL(fd,info->pos[1]));
  11618. }
  11619. //(CZ_PARTY_JOIN_REQ_ACK)
  11620. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11621. {
  11622. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11623. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11624. RFIFOB(fd,info->pos[1]));
  11625. }
  11626. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11627. /// 0100
  11628. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11629. {
  11630. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11631. clif_displaymessage(fd, msg_txt(sd,227));
  11632. return;
  11633. }
  11634. party_leave(sd);
  11635. }
  11636. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11637. /// 0103 <account id>.L <char name>.24B
  11638. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11639. {
  11640. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11641. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11642. clif_displaymessage(fd, msg_txt(sd,227));
  11643. return;
  11644. }
  11645. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11646. RFIFOCP(fd,info->pos[1]));
  11647. }
  11648. /// Request to change party options.
  11649. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11650. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11651. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11652. {
  11653. struct party_data *p;
  11654. int i,expflag;
  11655. int cmd = RFIFOW(fd,0);
  11656. struct s_packet_db* info = &packet_db[cmd];
  11657. if( !sd->status.party_id )
  11658. return;
  11659. p = party_search(sd->status.party_id);
  11660. if( p == NULL )
  11661. return;
  11662. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11663. if( i == MAX_PARTY )
  11664. return; //Shouldn't happen
  11665. if( !p->party.member[i].leader )
  11666. return;
  11667. expflag = RFIFOL(fd,info->pos[0]);
  11668. if(cmd == 0x0102){ //Client can't change the item-field
  11669. party_changeoption(sd, expflag, p->party.item);
  11670. }
  11671. else {
  11672. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11673. party_changeoption(sd, expflag, itemflag);
  11674. }
  11675. }
  11676. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11677. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11678. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11679. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11680. // validate packet and retrieve name and message
  11681. if( !clif_process_message( sd, false, name, message, output ) )
  11682. return;
  11683. party_send_message(sd, output, strlen(output) + 1 );
  11684. }
  11685. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11686. /// 07da <account id>.L
  11687. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11688. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11689. }
  11690. /// Party Booking in KRO [Spiria]
  11691. ///
  11692. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11693. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11694. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11695. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11696. short level = RFIFOW(fd,info->pos[0]);
  11697. short mapid = RFIFOW(fd,info->pos[1]);
  11698. int idxpbj = info->pos[2];
  11699. short job[MAX_PARTY_BOOKING_JOBS];
  11700. int i;
  11701. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11702. job[i] = RFIFOB(fd,idxpbj+i*2);
  11703. party_booking_register(sd, level, mapid, job);
  11704. }
  11705. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11706. /// 0803 <result>.W
  11707. /// result:
  11708. /// 0 = success
  11709. /// 1 = failure
  11710. /// 2 = already registered
  11711. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11712. {
  11713. int fd = sd->fd;
  11714. WFIFOHEAD(fd,packet_len(0x803));
  11715. WFIFOW(fd,0) = 0x803;
  11716. WFIFOW(fd,2) = flag;
  11717. WFIFOSET(fd,packet_len(0x803));
  11718. }
  11719. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11720. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11721. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11722. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11723. short level = RFIFOW(fd,info->pos[0]);
  11724. short mapid = RFIFOW(fd,info->pos[1]);
  11725. short job = RFIFOW(fd,info->pos[2]);
  11726. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11727. short resultcount = RFIFOW(fd,info->pos[4]);
  11728. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11729. }
  11730. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11731. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11732. /// more results:
  11733. /// 0 = no
  11734. /// 1 = yes
  11735. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11736. {
  11737. int i, j;
  11738. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11739. struct party_booking_ad_info *pb_ad;
  11740. WFIFOHEAD(fd,size*count + 5);
  11741. WFIFOW(fd,0) = 0x805;
  11742. WFIFOW(fd,2) = size*count + 5;
  11743. WFIFOB(fd,4) = more_result;
  11744. for(i=0; i<count; i++)
  11745. {
  11746. pb_ad = results[i];
  11747. WFIFOL(fd,i*size+5) = pb_ad->index;
  11748. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11749. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11750. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11751. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11752. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11753. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11754. }
  11755. WFIFOSET(fd,WFIFOW(fd,2));
  11756. }
  11757. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11758. /// 0806
  11759. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11760. {
  11761. if(party_booking_delete(sd))
  11762. clif_PartyBookingDeleteAck(sd, 0);
  11763. }
  11764. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11765. /// 0807 <result>.W
  11766. /// result:
  11767. /// 0 = success
  11768. /// 1 = success (auto-removed expired ad)
  11769. /// 2 = failure
  11770. /// 3 = nothing registered
  11771. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11772. {
  11773. int fd = sd->fd;
  11774. WFIFOHEAD(fd,packet_len(0x807));
  11775. WFIFOW(fd,0) = 0x807;
  11776. WFIFOW(fd,2) = flag;
  11777. WFIFOSET(fd,packet_len(0x807));
  11778. }
  11779. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11780. /// 0808 { <job>.W }*6
  11781. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11782. {
  11783. short job[MAX_PARTY_BOOKING_JOBS];
  11784. int i;
  11785. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11786. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11787. job[i] = RFIFOW(fd,idxpbu+i*2);
  11788. party_booking_update(sd, job);
  11789. }
  11790. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11791. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11792. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11793. {
  11794. int i;
  11795. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11796. if(pb_ad == NULL) return;
  11797. WBUFW(buf,0) = 0x809;
  11798. WBUFL(buf,2) = pb_ad->index;
  11799. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11800. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11801. WBUFW(buf,34) = pb_ad->p_detail.level;
  11802. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11803. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11804. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11805. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11806. }
  11807. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11808. /// 080a <index>.L { <job>.W }*6
  11809. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11810. {
  11811. int i;
  11812. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11813. if(pb_ad == NULL) return;
  11814. WBUFW(buf,0) = 0x80a;
  11815. WBUFL(buf,2) = pb_ad->index;
  11816. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11817. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11818. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11819. }
  11820. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11821. /// 080b <index>.L
  11822. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11823. {
  11824. uint8 buf[6];
  11825. WBUFW(buf,0) = 0x80b;
  11826. WBUFL(buf,2) = index;
  11827. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11828. }
  11829. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11830. /// 012e
  11831. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11832. {
  11833. vending_closevending(sd);
  11834. }
  11835. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11836. /// 0130 <account id>.L
  11837. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11838. {
  11839. if( sd->npc_id ) {// using an NPC
  11840. return;
  11841. }
  11842. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11843. }
  11844. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11845. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11846. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11847. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11848. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11849. int id = (int)RFIFOL(fd,info->pos[1]);
  11850. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11851. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11852. // whether it fails or not, the buy window is closed
  11853. sd->vended_id = 0;
  11854. }
  11855. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11856. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11857. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11858. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11859. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11860. int aid = (int)RFIFOL(fd,info->pos[1]);
  11861. int uid = (int)RFIFOL(fd,info->pos[2]);
  11862. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11863. vending_purchasereq(sd, aid, uid, data, len/4);
  11864. // whether it fails or not, the buy window is closed
  11865. sd->vended_id = 0;
  11866. }
  11867. /// Confirm or cancel the shop preparation window.
  11868. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11869. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11870. /// result:
  11871. /// 0 = canceled
  11872. /// 1 = open
  11873. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11874. int cmd = RFIFOW(fd,0);
  11875. struct s_packet_db* info = &packet_db[cmd];
  11876. short len = (short)RFIFOW(fd,info->pos[0]);
  11877. const char* message = RFIFOCP(fd,info->pos[1]);
  11878. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11879. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11880. len -= 84;
  11881. }
  11882. else { //(CZ_REQ_OPENSTORE2)
  11883. bool flag;
  11884. len -= 85;
  11885. flag = RFIFOB(fd,info->pos[2]) != 0;
  11886. if (!flag) {
  11887. sd->state.prevend = 0;
  11888. sd->state.workinprogress = WIP_DISABLE_NONE;
  11889. }
  11890. }
  11891. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11892. return;
  11893. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11894. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11895. return;
  11896. }
  11897. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11898. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11899. return;
  11900. }
  11901. if( message[0] == '\0' ) // invalid input
  11902. return;
  11903. vending_openvending(sd, message, data, len/8, NULL);
  11904. }
  11905. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11906. /// 0165 <char id>.L <guild name>.24B
  11907. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11908. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11909. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11910. name[NAME_LENGTH-1] = '\0';
  11911. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11912. clif_displaymessage(fd, msg_txt(sd,228));
  11913. return;
  11914. }
  11915. if(sd->clan){
  11916. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11917. return;
  11918. }
  11919. guild_create(sd, name);
  11920. }
  11921. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11922. /// 014d
  11923. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11924. {
  11925. clif_guild_masterormember(sd);
  11926. }
  11927. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11928. /// 014f <type>.L
  11929. /// type:
  11930. /// 0 = basic info
  11931. /// 1 = member manager
  11932. /// 2 = positions
  11933. /// 3 = skills
  11934. /// 4 = expulsion list
  11935. /// 5 = unknown (GM_ALLGUILDLIST)
  11936. /// 6 = notice
  11937. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11938. {
  11939. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11940. if( !sd->status.guild_id && !sd->bg_id )
  11941. return;
  11942. switch( type )
  11943. {
  11944. case 0: // Basic Information Guild, hostile alliance information
  11945. clif_guild_basicinfo(sd);
  11946. clif_guild_allianceinfo(sd);
  11947. break;
  11948. case 1: // Members list, list job title
  11949. clif_guild_positionnamelist(sd);
  11950. clif_guild_memberlist(sd);
  11951. break;
  11952. case 2: // List job title, title information list
  11953. clif_guild_positionnamelist(sd);
  11954. clif_guild_positioninfolist(sd);
  11955. break;
  11956. case 3: // Skill list
  11957. clif_guild_skillinfo(sd);
  11958. break;
  11959. case 4: // Expulsion list
  11960. clif_guild_expulsionlist(sd);
  11961. break;
  11962. default:
  11963. ShowError("clif: guild request info: unknown type %d\n", type);
  11964. break;
  11965. }
  11966. }
  11967. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11968. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11969. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11970. {
  11971. int i;
  11972. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11973. int len = RFIFOW(fd,info->pos[0]);
  11974. int idxgpos = info->pos[1];
  11975. if(!sd->state.gmaster_flag)
  11976. return;
  11977. for(i = idxgpos; i < len; i += 40 ){
  11978. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11979. }
  11980. }
  11981. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11982. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11983. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11984. {
  11985. int i;
  11986. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11987. int len = RFIFOW(fd,info->pos[0]);
  11988. int idxgpos = info->pos[1];
  11989. if(!sd->state.gmaster_flag)
  11990. return;
  11991. // Guild leadership change
  11992. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11993. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11994. clif_msg(sd, GUILD_MASTER_WOE);
  11995. return;
  11996. }
  11997. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11998. clif_msg(sd, GUILD_MASTER_DELAY);
  11999. return;
  12000. }
  12001. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  12002. return;
  12003. }
  12004. for(i=idxgpos;i<len;i+=12){
  12005. int position = RFIFOL(fd,i+8);
  12006. if( position > 0 ){
  12007. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  12008. }
  12009. }
  12010. }
  12011. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  12012. /// 0151 <guild id>.L
  12013. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  12014. {
  12015. struct guild* g;
  12016. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12017. if( (g = guild_search(guild_id)) != NULL )
  12018. clif_guild_emblem(sd,g);
  12019. }
  12020. /// Validates data of a guild emblem (compressed bitmap)
  12021. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  12022. EMBVALIDATE_SUCCESS = 0,
  12023. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  12024. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  12025. };
  12026. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12027. {
  12028. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12029. unsigned long buf_len = sizeof(buf);
  12030. int offset = 0;
  12031. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12032. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12033. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12034. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12035. ))
  12036. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12037. if(inter_config.emblem_transparency_limit != 100) {
  12038. int i, transcount = 1, tmp[3];
  12039. for(i = offset; i < buf_len-1; i++) {
  12040. int j = i%3;
  12041. tmp[j] = RBUFL(buf,i);
  12042. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12043. transcount++;
  12044. }
  12045. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  12046. return EMBVALIDATE_ERR_TRANSPARENCY;
  12047. }
  12048. return EMBVALIDATE_SUCCESS;
  12049. }
  12050. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12051. /// 0153 <packet len>.W <emblem data>.?B
  12052. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  12053. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12054. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12055. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12056. int emb_val=0;
  12057. if( !emblem_len || !sd->state.gmaster_flag )
  12058. return;
  12059. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  12060. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12061. return;
  12062. }
  12063. emb_val = clif_validate_emblem(emblem, emblem_len);
  12064. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12065. 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);
  12066. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12067. return;
  12068. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12069. char output[128];
  12070. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  12071. 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"
  12072. return;
  12073. }
  12074. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  12075. }
  12076. /// Request to update the guild emblem id (version, according to Gravity)
  12077. /// 0b46 <guild id>.L <version>.L
  12078. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  12079. nullpo_retv(sd);
  12080. #if PACKETVER >= 20190724
  12081. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12082. guild* g = sd->guild;
  12083. if (g == nullptr || g->guild_id != p->guild_id)
  12084. return;
  12085. if (!sd->state.gmaster_flag)
  12086. return;
  12087. if (!inter_config.emblem_woe_change && is_agit_start()) {
  12088. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12089. return;
  12090. }
  12091. guild_change_emblem_version(sd, p->version);
  12092. #endif
  12093. }
  12094. /// Guild notice update request (CZ_GUILD_NOTICE).
  12095. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12096. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  12097. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12098. int guild_id = RFIFOL(fd,info->pos[0]);
  12099. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12100. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12101. if(!sd->state.gmaster_flag)
  12102. return;
  12103. // compensate for some client defects when using multilanguage mode
  12104. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12105. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12106. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12107. guild_change_notice(sd, guild_id, msg1, msg2);
  12108. }
  12109. // Helper function for guild invite functions
  12110. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  12111. {
  12112. if (t_sd == NULL) // not online or does not exist
  12113. return 1;
  12114. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12115. clif_displaymessage(fd, msg_txt(sd,228));
  12116. return 1;
  12117. }
  12118. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12119. clif_noask_sub(sd, t_sd, 2);
  12120. return 1;
  12121. }
  12122. // Players in a clan can not join a guild
  12123. if(t_sd && t_sd->clan){
  12124. return 1;
  12125. }
  12126. guild_invite(sd, t_sd);
  12127. return 0;
  12128. }
  12129. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12130. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12131. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  12132. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12133. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12134. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12135. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12136. if (clif_sub_guild_invite(fd, sd, t_sd))
  12137. return;
  12138. }
  12139. /// Guild invite request (/guildinvite)
  12140. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12141. void
  12142. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  12143. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12144. if (clif_sub_guild_invite(fd, sd, t_sd))
  12145. return;
  12146. }
  12147. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12148. /// 016b <guild id>.L <answer>.L
  12149. /// answer:
  12150. /// 0 = refuse
  12151. /// 1 = accept
  12152. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  12153. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12154. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12155. RFIFOL(fd,info->pos[1]));
  12156. }
  12157. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12158. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12159. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  12160. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12161. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12162. clif_displaymessage(fd, msg_txt(sd,228));
  12163. return;
  12164. }
  12165. if( sd->bg_id ) {
  12166. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12167. return;
  12168. }
  12169. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12170. RFIFOL(fd,info->pos[1]),
  12171. RFIFOL(fd,info->pos[2]),
  12172. RFIFOCP(fd,info->pos[3]));
  12173. }
  12174. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12175. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12176. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  12177. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12178. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12179. { // Guild locked.
  12180. clif_displaymessage(fd, msg_txt(sd,228));
  12181. return;
  12182. }
  12183. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12184. RFIFOL(fd,info->pos[1]),
  12185. RFIFOL(fd,info->pos[2]),
  12186. RFIFOCP(fd,info->pos[3]));
  12187. }
  12188. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12189. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12190. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12191. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12192. // validate packet and retrieve name and message
  12193. if( !clif_process_message( sd, false, name, message, output ) )
  12194. return;
  12195. if( sd->bg_id )
  12196. bg_send_message(sd, output, strlen(output) );
  12197. else
  12198. guild_send_message(sd, output, strlen(output) );
  12199. }
  12200. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12201. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12202. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12203. {
  12204. struct map_session_data *t_sd;
  12205. if(!sd->state.gmaster_flag)
  12206. return;
  12207. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12208. clif_displaymessage(fd, msg_txt(sd,228));
  12209. return;
  12210. }
  12211. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12212. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12213. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12214. // @noask [LuzZza]
  12215. if(t_sd && t_sd->state.noask) {
  12216. clif_noask_sub(sd, t_sd, 3);
  12217. return;
  12218. }
  12219. guild_reqalliance(sd,t_sd);
  12220. }
  12221. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12222. /// 0172 <inviter account id>.L <answer>.L
  12223. /// answer:
  12224. /// 0 = refuse
  12225. /// 1 = accept
  12226. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12227. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12228. guild_reply_reqalliance(sd,
  12229. RFIFOL(fd,info->pos[0]),
  12230. RFIFOL(fd,info->pos[1]));
  12231. }
  12232. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12233. /// 0183 <opponent guild id>.L <relation>.L
  12234. /// relation:
  12235. /// 0 = Ally
  12236. /// 1 = Enemy
  12237. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12238. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  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. guild_delalliance(sd,
  12246. RFIFOL(fd,info->pos[0]),
  12247. RFIFOL(fd,info->pos[1]));
  12248. }
  12249. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12250. /// 0180 <account id>.L
  12251. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12252. {
  12253. struct map_session_data *t_sd;
  12254. if(!sd->state.gmaster_flag)
  12255. return;
  12256. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12257. clif_displaymessage(fd, msg_txt(sd,228));
  12258. return;
  12259. }
  12260. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12261. // @noask [LuzZza]
  12262. if(t_sd && t_sd->state.noask) {
  12263. clif_noask_sub(sd, t_sd, 4);
  12264. return;
  12265. }
  12266. guild_opposition(sd,t_sd);
  12267. }
  12268. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12269. /// 015d <key>.40B
  12270. /// key:
  12271. /// now guild name; might have been (intended) email, since the
  12272. /// field name and size is same as the one in CH_DELETE_CHAR.
  12273. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12274. {
  12275. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12276. clif_displaymessage(fd, msg_txt(sd,228));
  12277. return;
  12278. }
  12279. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12280. }
  12281. /// Pet
  12282. ///
  12283. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12284. /// 01a1 <type>.B
  12285. /// type:
  12286. /// 0 = pet information
  12287. /// 1 = feed
  12288. /// 2 = performance
  12289. /// 3 = return to egg
  12290. /// 4 = unequip accessory
  12291. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12292. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12293. }
  12294. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12295. /// 019f <id>.L
  12296. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12297. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12298. }
  12299. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12300. /// 01a7 <index>.W
  12301. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12302. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12303. return;
  12304. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12305. clif_menuskill_clear(sd);
  12306. }
  12307. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12308. /// 01a9 <data>.L
  12309. /// data:
  12310. /// is either emotion (@see enum emotion_type) or a compound value
  12311. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12312. /// entry (given in parentheses) in data\pettalktable.xml
  12313. /// act id:
  12314. /// 0 = feeding
  12315. /// 1 = hunting
  12316. /// 2 = danger
  12317. /// 3 = dead
  12318. /// 4 = normal (stand)
  12319. /// 5 = special performance (perfor_s)
  12320. /// 6 = level up (levelup)
  12321. /// 7 = performance 1 (perfor_1)
  12322. /// 8 = performance 2 (perfor_2)
  12323. /// 9 = performance 3 (perfor_3)
  12324. /// 10 = log-in greeting (connect)
  12325. /// hungry value:
  12326. /// 0 = very hungry (hungry)
  12327. /// 1 = hungry (bit_hungry)
  12328. /// 2 = satisfied (noting)
  12329. /// 3 = stuffed (full)
  12330. /// 4 = full (so_full)
  12331. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12332. {
  12333. if(sd->pd)
  12334. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12335. }
  12336. /// Request to change pet's name (CZ_RENAME_PET).
  12337. /// 01a5 <name>.24B
  12338. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12339. {
  12340. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12341. }
  12342. /// /kill (CZ_DISCONNECT_CHARACTER).
  12343. /// Request to disconnect a character.
  12344. /// 00cc <account id>.L
  12345. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12346. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12347. {
  12348. struct block_list *target;
  12349. int tid;
  12350. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12351. target = map_id2bl(tid);
  12352. if (!target) {
  12353. clif_GM_kickack(sd, 0);
  12354. return;
  12355. }
  12356. switch (target->type) {
  12357. case BL_PC:
  12358. {
  12359. char command[NAME_LENGTH+6];
  12360. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12361. is_atcommand(fd, sd, command, 1);
  12362. }
  12363. break;
  12364. /**
  12365. * This one does not invoke any atcommand, so we need to check for permissions.
  12366. */
  12367. case BL_MOB:
  12368. {
  12369. char command[100];
  12370. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12371. clif_GM_kickack(sd, 0);
  12372. return;
  12373. }
  12374. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12375. log_atcommand(sd, command);
  12376. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12377. }
  12378. break;
  12379. case BL_NPC:
  12380. {
  12381. struct npc_data* nd = (struct npc_data *)target;
  12382. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12383. npc_unload_duplicates(nd);
  12384. npc_unload(nd,true);
  12385. npc_read_event_script();
  12386. }
  12387. }
  12388. break;
  12389. default:
  12390. clif_GM_kickack(sd, 0);
  12391. }
  12392. }
  12393. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12394. /// Request to disconnect all characters.
  12395. /// 00ce
  12396. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12397. char cmd[15];
  12398. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12399. is_atcommand(fd, sd, cmd, 1);
  12400. }
  12401. /// /remove (CZ_REMOVE_AID).
  12402. /// Request to warp to a character with given login ID.
  12403. /// 01ba <account name>.24B
  12404. /// /shift (CZ_SHIFT).
  12405. /// Request to warp to a character with given name.
  12406. /// 01bb <char name>.24B
  12407. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12408. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12409. char *player_name;
  12410. char command[NAME_LENGTH+8];
  12411. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12412. player_name[NAME_LENGTH-1] = '\0';
  12413. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12414. is_atcommand(fd, sd, command, 1);
  12415. }
  12416. /// /remove (CZ_REMOVE_AID_SSO).
  12417. /// Request to warp to a character with given account ID.
  12418. /// 0843 <account id>.L
  12419. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12420. {
  12421. uint32 account_id;
  12422. struct map_session_data* pl_sd;
  12423. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12424. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12425. char command[NAME_LENGTH+8];
  12426. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12427. is_atcommand(fd, sd, command, 1);
  12428. }
  12429. }
  12430. /// /recall (CZ_RECALL).
  12431. /// Request to summon a player with given login ID to own position.
  12432. /// 01bc <account name>.24B
  12433. /// /summon (CZ_RECALL_GID).
  12434. /// Request to summon a player with given name to own position.
  12435. /// 01bd <char name>.24B
  12436. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12437. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12438. char *player_name;
  12439. char command [NAME_LENGTH+8];
  12440. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12441. player_name[NAME_LENGTH-1] = '\0';
  12442. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12443. is_atcommand(fd, sd, command, 1);
  12444. }
  12445. /// /recall (CZ_RECALL_SSO).
  12446. /// Request to summon a player with given account ID to own position.
  12447. /// 0842 <account id>.L
  12448. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12449. {
  12450. uint32 account_id;
  12451. struct map_session_data* pl_sd;
  12452. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12453. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12454. char command[NAME_LENGTH+8];
  12455. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12456. is_atcommand(fd, sd, command, 1);
  12457. }
  12458. }
  12459. /// /item /monster (CZ_ITEM_CREATE).
  12460. /// Request to execute GM commands.
  12461. /// Usage:
  12462. /// /item n - summon n monster or acquire n item/s
  12463. /// /item money - grants 2147483647 zenies
  12464. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12465. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12466. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12467. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12468. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12469. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12470. /// 013f <item/mob name>.24B
  12471. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12472. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12473. {
  12474. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12475. int mob_id = 0;
  12476. StringBuf command;
  12477. char *str;
  12478. //#if PACKETVER >= 20131218
  12479. // char str[100];
  12480. //#else
  12481. // char str[24];
  12482. //#endif
  12483. str = RFIFOCP(fd,info->pos[0]);
  12484. if (!str || str[0] == '\0')
  12485. return;
  12486. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12487. return;
  12488. trim(str);
  12489. // Zeny
  12490. if( strcmpi(str, "money") == 0 ) {
  12491. StringBuf_Init(&command);
  12492. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12493. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12494. StringBuf_Destroy(&command);
  12495. return;
  12496. }
  12497. std::shared_ptr<item_data> id = item_db.searchname( str );
  12498. // Item
  12499. if( id ){
  12500. StringBuf_Init(&command);
  12501. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12502. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12503. }else{
  12504. if (id->flag.guid)
  12505. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12506. else
  12507. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12508. }
  12509. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12510. StringBuf_Destroy(&command);
  12511. return;
  12512. }
  12513. // Monster
  12514. if ((mob_id = mobdb_searchname(str)) == 0)
  12515. mob_id = mobdb_checkid(atoi(str));
  12516. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12517. if( mob != nullptr ) {
  12518. StringBuf_Init(&command);
  12519. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12520. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12521. StringBuf_Destroy(&command);
  12522. return;
  12523. }
  12524. }
  12525. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12526. /// 019d <effect state>.L
  12527. /// effect state:
  12528. /// TODO: Any OPTION_* ?
  12529. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12530. char cmd[6];
  12531. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12532. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12533. is_atcommand(fd, sd, cmd, 1);
  12534. }
  12535. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12536. /// 0149 <account id>.L <type>.B <value>.W
  12537. /// type:
  12538. /// 0 = positive points
  12539. /// 1 = negative points
  12540. /// 2 = self mute (+10 minutes)
  12541. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12542. {
  12543. int id, type, value;
  12544. struct map_session_data *dstsd;
  12545. char command[NAME_LENGTH+15];
  12546. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12547. id = RFIFOL(fd,info->pos[0]);
  12548. type = RFIFOB(fd,info->pos[1]);
  12549. value = RFIFOW(fd,info->pos[2]);
  12550. if( type == 0 )
  12551. value = -value;
  12552. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12553. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12554. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12555. return;
  12556. dstsd = map_id2sd(id);
  12557. if( dstsd == NULL )
  12558. return;
  12559. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12560. is_atcommand(fd, sd, command, 1);
  12561. }
  12562. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12563. /// GM adjustment of a player's manner value by -60.
  12564. /// 0212 <char name>.24B
  12565. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12566. {
  12567. char command[NAME_LENGTH+15];
  12568. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12569. name[NAME_LENGTH-1] = '\0';
  12570. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12571. is_atcommand(fd, sd, command, 1);
  12572. }
  12573. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12574. /// 01e0 <account id>.L <account name>.24B
  12575. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12576. {
  12577. WFIFOHEAD(fd,packet_len(0x1e0));
  12578. WFIFOW(fd,0) = 0x1e0;
  12579. WFIFOL(fd,2) = account_id;
  12580. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12581. WFIFOSET(fd,packet_len(0x1e0));
  12582. }
  12583. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12584. /// 01df <account id>.L
  12585. //! TODO: Figure out how does this actually work
  12586. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12587. {
  12588. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12589. /*
  12590. char query[30];
  12591. safesnprintf(query,sizeof(query),"%d", account_id);
  12592. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12593. */
  12594. clif_account_name(fd, account_id, "");
  12595. }
  12596. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12597. /// GM single cell type change request.
  12598. /// 0198 <x>.W <y>.W <type>.W
  12599. /// type:
  12600. /// 0 = not walkable
  12601. /// 1 = walkable
  12602. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12603. {
  12604. int x,y,type;
  12605. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12606. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12607. return;
  12608. x = RFIFOW(fd,info->pos[0]);
  12609. y = RFIFOW(fd,info->pos[1]);
  12610. type = RFIFOW(fd,info->pos[2]);
  12611. map_setgatcell(sd->bl.m,x,y,type);
  12612. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12613. //FIXME: once players leave the map, the client 'forgets' this information.
  12614. }
  12615. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12616. /// Request to allow/deny whispers from a nick.
  12617. /// 00cf <nick>.24B <type>.B
  12618. /// type:
  12619. /// 0 = (/ex nick) deny speech from nick
  12620. /// 1 = (/in nick) allow speech from nick
  12621. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12622. {
  12623. char* nick;
  12624. uint8 type;
  12625. int i;
  12626. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12627. nick = RFIFOCP(fd,info->pos[0]);
  12628. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12629. type = RFIFOB(fd,info->pos[1]);
  12630. if( type == 0 ) { // Add name to ignore list (block)
  12631. if (strcmp(wisp_server_name, nick) == 0) {
  12632. clif_wisexin(sd, type, 1); // fail
  12633. return;
  12634. }
  12635. // try to find a free spot, while checking for duplicates at the same time
  12636. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12637. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12638. clif_wisexin(sd, type, 2); // too many blocks
  12639. return;
  12640. }
  12641. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12642. clif_wisexin(sd, type, 0); // Aegis reports success.
  12643. return;
  12644. }
  12645. //Insert in position i
  12646. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12647. } else { // Remove name from ignore list (unblock)
  12648. // find entry
  12649. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12650. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12651. clif_wisexin(sd, type, 1); // fail
  12652. return;
  12653. }
  12654. // move everything one place down to overwrite removed entry
  12655. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12656. // wipe last entry
  12657. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12658. }
  12659. clif_wisexin(sd, type, 0); // success
  12660. }
  12661. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12662. /// Request to allow/deny all whispers.
  12663. /// 00d0 <type>.B
  12664. /// type:
  12665. /// 0 = (/exall) deny all speech
  12666. /// 1 = (/inall) allow all speech
  12667. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12668. {
  12669. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12670. if( type == 0 ) {// Deny all
  12671. if( sd->state.ignoreAll ) {
  12672. flag = 1; // fail
  12673. } else {
  12674. sd->state.ignoreAll = 1;
  12675. flag = 0; // success
  12676. }
  12677. } else {//Unblock everyone
  12678. if( sd->state.ignoreAll ) {
  12679. sd->state.ignoreAll = 0;
  12680. flag = 0; // success
  12681. } else {
  12682. if (sd->ignore[0].name[0] != '\0')
  12683. { //Wipe the ignore list.
  12684. memset(sd->ignore, 0, sizeof(sd->ignore));
  12685. flag = 0; // success
  12686. } else {
  12687. flag = 1; // fail
  12688. }
  12689. }
  12690. }
  12691. clif_wisall(sd, type, flag);
  12692. }
  12693. /// Whisper ignore list (ZC_WHISPER_LIST).
  12694. /// 00d4 <packet len>.W { <char name>.24B }*
  12695. void clif_PMIgnoreList(struct map_session_data* sd)
  12696. {
  12697. int i, fd = sd->fd;
  12698. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12699. WFIFOW(fd,0) = 0xd4;
  12700. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12701. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12702. }
  12703. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12704. WFIFOSET(fd,WFIFOW(fd,2));
  12705. }
  12706. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12707. /// 00d3
  12708. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12709. {
  12710. clif_PMIgnoreList(sd);
  12711. }
  12712. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12713. /// 01e7
  12714. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12715. {
  12716. if (sd->state.doridori) return;
  12717. switch (sd->class_&MAPID_UPPERMASK) {
  12718. case MAPID_SOUL_LINKER:
  12719. case MAPID_STAR_GLADIATOR:
  12720. case MAPID_TAEKWON:
  12721. if (!sd->state.rest)
  12722. break;
  12723. case MAPID_SUPER_NOVICE:
  12724. case MAPID_SUPER_BABY:
  12725. case MAPID_SUPER_NOVICE_E:
  12726. case MAPID_SUPER_BABY_E:
  12727. sd->state.doridori=1;
  12728. break;
  12729. }
  12730. }
  12731. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12732. /// 01ed
  12733. /// Note: This packet is caused by 7 lines of any text, followed by
  12734. /// the prayer and an another line of any text. The prayer is
  12735. /// defined by lines 790~793 in data\msgstringtable.txt
  12736. /// "Dear angel, can you hear my voice?"
  12737. /// "I am" (space separated player name) "Super Novice~"
  12738. /// "Help me out~ Please~ T_T"
  12739. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12740. {
  12741. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12742. t_exp next = pc_nextbaseexp(sd);
  12743. if( next ) {
  12744. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12745. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12746. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12747. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12748. }
  12749. }
  12750. }
  12751. }
  12752. /// Friends List
  12753. ///
  12754. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12755. /// 0206 <account id>.L <char id>.L <state>.B
  12756. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12757. /// state:
  12758. /// 0 = online
  12759. /// 1 = offline
  12760. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12761. {
  12762. int i, fd = sd->fd;
  12763. //Seek friend.
  12764. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12765. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12766. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12767. return; //Not found
  12768. WFIFOHEAD(fd,packet_len(0x206));
  12769. WFIFOW(fd, 0) = 0x206;
  12770. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12771. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12772. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12773. #if PACKETVER >= 20180221
  12774. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12775. #endif
  12776. WFIFOSET(fd, packet_len(0x206));
  12777. }
  12778. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12779. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12780. {
  12781. uint32 account_id, char_id, online;
  12782. account_id = va_arg(ap, int);
  12783. char_id = va_arg(ap, int);
  12784. online = va_arg(ap, int);
  12785. clif_friendslist_toggle(sd, account_id, char_id, online);
  12786. return 0;
  12787. }
  12788. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12789. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12790. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12791. void clif_friendslist_send(struct map_session_data *sd)
  12792. {
  12793. int i = 0, n, fd = sd->fd;
  12794. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12795. const int size = 8 + NAME_LENGTH;
  12796. #else
  12797. const int size = 8;
  12798. #endif
  12799. // Send friends list
  12800. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12801. WFIFOW(fd, 0) = 0x201;
  12802. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12803. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12804. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12805. #if PACKETVER < 20180221 || PACKETVER_RE_NUM >= 20200902
  12806. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12807. #endif
  12808. }
  12809. if (i) {
  12810. WFIFOW(fd,2) = 4 + size * i;
  12811. WFIFOSET(fd, WFIFOW(fd,2));
  12812. }
  12813. for (n = 0; n < i; n++) { //Sending the online players
  12814. if (map_charid2sd(sd->status.friends[n].char_id))
  12815. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12816. }
  12817. }
  12818. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12819. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12820. /// result:
  12821. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12822. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12823. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12824. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12825. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12826. {
  12827. int fd;
  12828. nullpo_retv(sd);
  12829. fd = sd->fd;
  12830. WFIFOHEAD(fd,packet_len(0x209));
  12831. WFIFOW(fd,0) = 0x209;
  12832. WFIFOW(fd,2) = type;
  12833. if (f_sd) {
  12834. WFIFOL(fd,4) = f_sd->status.account_id;
  12835. WFIFOL(fd,8) = f_sd->status.char_id;
  12836. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12837. }
  12838. WFIFOSET(fd, packet_len(0x209));
  12839. }
  12840. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12841. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12842. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12843. {
  12844. int fd = sd->fd;
  12845. WFIFOHEAD(fd,packet_len(0x207));
  12846. WFIFOW(fd,0) = 0x207;
  12847. WFIFOL(fd,2) = account_id;
  12848. WFIFOL(fd,6) = char_id;
  12849. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12850. WFIFOSET(fd,packet_len(0x207));
  12851. }
  12852. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12853. /// 0202 <name>.24B
  12854. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12855. {
  12856. struct map_session_data *f_sd;
  12857. int i;
  12858. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12859. // Friend doesn't exist (no player with this name)
  12860. if (f_sd == NULL) {
  12861. clif_displaymessage(fd, msg_txt(sd,3));
  12862. return;
  12863. }
  12864. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12865. return;
  12866. }
  12867. // ensure that the request player's friend list is not full
  12868. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12869. if( i == MAX_FRIENDS ){
  12870. clif_friendslist_reqack(sd, f_sd, 2);
  12871. return;
  12872. }
  12873. // @noask [LuzZza]
  12874. if(f_sd->state.noask) {
  12875. clif_noask_sub(sd, f_sd, 5);
  12876. return;
  12877. }
  12878. // Friend already exists
  12879. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12880. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12881. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12882. return;
  12883. }
  12884. }
  12885. f_sd->friend_req = sd->status.char_id;
  12886. sd->friend_req = f_sd->status.char_id;
  12887. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12888. }
  12889. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12890. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12891. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12892. /// reply:
  12893. /// 0 = rejected
  12894. /// 1 = accepted
  12895. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12896. {
  12897. struct map_session_data *f_sd;
  12898. uint32 account_id;
  12899. char reply;
  12900. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12901. account_id = RFIFOL(fd,info->pos[0]);
  12902. //char_id = RFIFOL(fd,info->pos[1]);
  12903. #if PACKETVER < 6
  12904. reply = RFIFOB(fd,info->pos[2]);
  12905. #else
  12906. reply = RFIFOL(fd,info->pos[2]);
  12907. #endif
  12908. if( sd->bl.id == account_id ) {// adding oneself as friend
  12909. return;
  12910. }
  12911. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12912. if (f_sd == NULL)
  12913. return;
  12914. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12915. clif_friendslist_reqack(f_sd, sd, 1);
  12916. else {
  12917. int i;
  12918. // Find an empty slot
  12919. for (i = 0; i < MAX_FRIENDS; i++)
  12920. if (f_sd->status.friends[i].char_id == 0)
  12921. break;
  12922. if (i == MAX_FRIENDS) {
  12923. clif_friendslist_reqack(f_sd, sd, 2);
  12924. return;
  12925. }
  12926. f_sd->status.friends[i].account_id = sd->status.account_id;
  12927. f_sd->status.friends[i].char_id = sd->status.char_id;
  12928. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12929. clif_friendslist_reqack(f_sd, sd, 0);
  12930. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12931. if (battle_config.friend_auto_add) {
  12932. // Also add f_sd to sd's friendlist.
  12933. for (i = 0; i < MAX_FRIENDS; i++) {
  12934. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12935. return; //No need to add anything.
  12936. if (sd->status.friends[i].char_id == 0)
  12937. break;
  12938. }
  12939. if (i == MAX_FRIENDS) {
  12940. clif_friendslist_reqack(sd, f_sd, 2);
  12941. return;
  12942. }
  12943. sd->status.friends[i].account_id = f_sd->status.account_id;
  12944. sd->status.friends[i].char_id = f_sd->status.char_id;
  12945. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12946. clif_friendslist_reqack(sd, f_sd, 0);
  12947. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12948. }
  12949. }
  12950. }
  12951. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12952. /// 0203 <account id>.L <char id>.L
  12953. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12954. {
  12955. struct map_session_data *f_sd = NULL;
  12956. uint32 account_id, char_id;
  12957. int i, j;
  12958. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12959. account_id = RFIFOL(fd,info->pos[0]);
  12960. char_id = RFIFOL(fd,info->pos[1]);
  12961. // Search friend
  12962. for (i = 0; i < MAX_FRIENDS &&
  12963. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12964. if (i == MAX_FRIENDS) {
  12965. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12966. return;
  12967. }
  12968. //remove from friend's list first
  12969. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12970. for (i = 0; i < MAX_FRIENDS &&
  12971. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12972. if (i != MAX_FRIENDS) {
  12973. // move all chars up
  12974. for(j = i + 1; j < MAX_FRIENDS; j++)
  12975. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12976. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12977. //should the guy be notified of some message? we should add it here if so
  12978. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12979. WFIFOW(f_sd->fd,0) = 0x20a;
  12980. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12981. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12982. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12983. }
  12984. } else { //friend not online -- ask char server to delete from his friendlist
  12985. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12986. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12987. return;
  12988. }
  12989. }
  12990. // We can now delete from original requester
  12991. for (i = 0; i < MAX_FRIENDS &&
  12992. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12993. // move all chars up
  12994. for(j = i + 1; j < MAX_FRIENDS; j++)
  12995. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12996. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12997. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12998. WFIFOHEAD(fd,packet_len(0x20a));
  12999. WFIFOW(fd,0) = 0x20a;
  13000. WFIFOL(fd,2) = account_id;
  13001. WFIFOL(fd,6) = char_id;
  13002. WFIFOSET(fd, packet_len(0x20a));
  13003. }
  13004. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  13005. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  13006. void clif_PVPInfo(struct map_session_data* sd)
  13007. {
  13008. int fd = sd->fd;
  13009. WFIFOHEAD(fd,packet_len(0x210));
  13010. WFIFOW(fd,0) = 0x210;
  13011. WFIFOL(fd,2) = sd->status.char_id;
  13012. WFIFOL(fd,6) = sd->status.account_id;
  13013. WFIFOL(fd,10) = sd->pvp_won; // times won
  13014. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  13015. WFIFOL(fd,18) = sd->pvp_point;
  13016. WFIFOSET(fd, packet_len(0x210));
  13017. }
  13018. /// /pvpinfo (CZ_REQ_PVPPOINT).
  13019. /// 020f <char id>.L <account id>.L
  13020. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  13021. {
  13022. // TODO: Is there a way to use this on an another player (char/acc id)?
  13023. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13024. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13025. clif_PVPInfo(sd);
  13026. }
  13027. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  13028. /// 0254 <which>.B
  13029. /// which: (unused atm for security purpose)
  13030. /// 0 = sun
  13031. /// 1 = moon
  13032. /// 2 = star
  13033. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  13034. {
  13035. int i;
  13036. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13037. if (sd->menuskill_id != SG_FEEL)
  13038. return;
  13039. i = sd->menuskill_val-1;
  13040. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13041. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13042. sd->feel_map[i].m = sd->bl.m;
  13043. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13044. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13045. // clif_misceffect2(&sd->bl, 0x1b0);
  13046. // clif_misceffect2(&sd->bl, 0x21f);
  13047. clif_feel_info(sd, i, 0);
  13048. clif_menuskill_clear(sd);
  13049. }
  13050. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13051. /// 0253 <which>.B
  13052. /// which:
  13053. /// 0 = sun
  13054. /// 1 = moon
  13055. /// 2 = star
  13056. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  13057. {
  13058. WFIFOHEAD(fd,packet_len(0x253));
  13059. WFIFOW(fd,0)=0x253;
  13060. WFIFOB(fd,2)=TOB(skill_lv-1);
  13061. WFIFOSET(fd, packet_len(0x253));
  13062. sd->menuskill_id = SG_FEEL;
  13063. sd->menuskill_val = skill_lv;
  13064. }
  13065. /// Request to change homunculus' name (CZ_RENAME_MER).
  13066. /// 0231 <name>.24B
  13067. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  13068. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13069. }
  13070. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13071. /// 0234 <id>.L
  13072. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  13073. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13074. struct block_list *bl = NULL;
  13075. struct unit_data *ud = NULL;
  13076. if( sd->md && sd->md->bl.id == id )
  13077. bl = &sd->md->bl;
  13078. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13079. bl = &sd->hd->bl; // Moving Homunculus
  13080. else
  13081. return;
  13082. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13083. ud = unit_bl2ud(bl);
  13084. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13085. }
  13086. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13087. /// 0232 <id>.L <position data>.3B
  13088. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  13089. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13090. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13091. struct block_list *bl = NULL;
  13092. short x, y;
  13093. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13094. if( sd->md && sd->md->bl.id == id )
  13095. bl = &sd->md->bl; // Moving Mercenary
  13096. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13097. bl = &sd->hd->bl; // Moving Homunculus
  13098. else
  13099. return;
  13100. unit_walktoxy(bl, x, y, 4);
  13101. }
  13102. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13103. /// 0233 <id>.L <target id>.L <action>.B
  13104. /// action:
  13105. /// always 0
  13106. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  13107. {
  13108. struct block_list *bl = NULL;
  13109. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13110. int id = RFIFOL(fd,info->pos[0]);
  13111. int target_id = RFIFOL(fd,info->pos[1]);
  13112. int action_type = RFIFOB(fd,info->pos[2]);
  13113. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13114. bl = &sd->hd->bl;
  13115. else if( sd->md && sd->md->bl.id == id )
  13116. bl = &sd->md->bl;
  13117. else return;
  13118. unit_stop_attack(bl);
  13119. unit_attack(bl, target_id, action_type != 0);
  13120. }
  13121. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13122. /// 022d <type>.W <command>.B
  13123. /// type:
  13124. /// always 0
  13125. /// command:
  13126. /// 0 = homunculus information
  13127. /// 1 = feed
  13128. /// 2 = delete
  13129. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  13130. { //[orn]
  13131. int cmd = RFIFOW(fd,0);
  13132. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13133. if(!hom_is_active(sd->hd))
  13134. return;
  13135. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13136. }
  13137. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13138. /// 0292
  13139. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  13140. {
  13141. pc_revive_item(sd);
  13142. }
  13143. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13144. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13145. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13146. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13147. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13148. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13149. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13150. void clif_check(int fd, struct map_session_data* pl_sd)
  13151. {
  13152. WFIFOHEAD(fd,packet_len(0x214));
  13153. WFIFOW(fd, 0) = 0x214;
  13154. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13155. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13156. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13157. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13158. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13159. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13160. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13161. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13162. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13163. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13164. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13165. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13166. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13167. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13168. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13169. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13170. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13171. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13172. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13173. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13174. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13175. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13176. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13177. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13178. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13179. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13180. WFIFOSET(fd,packet_len(0x214));
  13181. }
  13182. /// /check (CZ_REQ_STATUS_GM).
  13183. /// Request character's status values.
  13184. /// 0213 <char name>.24B
  13185. void clif_parse_Check(int fd, struct map_session_data *sd)
  13186. {
  13187. char charname[NAME_LENGTH];
  13188. struct map_session_data* pl_sd;
  13189. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13190. return;
  13191. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13192. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13193. {
  13194. return;
  13195. }
  13196. clif_check(fd, pl_sd);
  13197. }
  13198. /// MAIL SYSTEM
  13199. /// By Zephyrus
  13200. ///
  13201. /// Notification about the result of adding an item to mail
  13202. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13203. /// result:
  13204. /// 0 = success
  13205. /// 1 = failure
  13206. /// 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)
  13207. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13208. /// result:
  13209. /// 0 = success
  13210. /// 1 = over weight
  13211. /// 2 = fatal error
  13212. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13213. int fd = sd->fd;
  13214. #if PACKETVER < 20150513
  13215. WFIFOHEAD(fd,packet_len(0x255));
  13216. WFIFOW(fd,0) = 0x255;
  13217. WFIFOW(fd,2) = index;
  13218. WFIFOB(fd,4) = flag;
  13219. WFIFOSET(fd,packet_len(0x255));
  13220. #else
  13221. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13222. if( flag ){
  13223. memset( &p, 0, sizeof( p ) );
  13224. }else{
  13225. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13226. p.index = index;
  13227. p.count = amount;
  13228. p.itemId = client_nameid( item->nameid );
  13229. p.type = itemtype( item->nameid );
  13230. p.IsIdentified = item->identify ? 1 : 0;
  13231. p.IsDamaged = item->attribute ? 1 : 0;
  13232. p.refiningLevel = item->refine;
  13233. clif_addcards( &p.slot, item );
  13234. clif_add_random_options( p.optionData, item );
  13235. p.weight = 0;
  13236. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13237. if( sd->mail.item[i].nameid == 0 ){
  13238. continue;
  13239. }
  13240. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13241. }
  13242. p.favorite = item->favorite;
  13243. p.location = pc_equippoint( sd, server_index( index ) );
  13244. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13245. p.enchantgrade = item->enchantgrade;
  13246. #endif
  13247. }
  13248. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13249. p.result = flag;
  13250. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13251. #endif
  13252. }
  13253. /// Notification about the result of retrieving a mail attachment
  13254. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13255. /// result:
  13256. /// 0 = success
  13257. /// 1 = failure
  13258. /// 2 = too many items
  13259. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13260. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13261. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13262. #if PACKETVER < 20150513
  13263. int fd = sd->fd;
  13264. WFIFOHEAD(fd,packet_len(0x245));
  13265. WFIFOW(fd,0) = 0x245;
  13266. WFIFOB(fd,2) = result;
  13267. WFIFOSET(fd,packet_len(0x245));
  13268. #else
  13269. switch( type ){
  13270. case MAIL_ATT_ITEM:
  13271. case MAIL_ATT_ZENY:
  13272. break;
  13273. default:
  13274. return;
  13275. }
  13276. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13277. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13278. p.MailID = msg->id;
  13279. p.opentype = msg->type;
  13280. p.result = result;
  13281. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13282. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13283. #endif
  13284. }
  13285. /// Notification about the result of sending a mail
  13286. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13287. /// result:
  13288. /// 0 = success
  13289. /// 1 = recipinent does not exist
  13290. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13291. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13292. #if PACKETVER < 20150513
  13293. int fd = sd->fd;
  13294. WFIFOHEAD(fd,packet_len(0x249));
  13295. WFIFOW(fd,0) = 0x249;
  13296. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13297. WFIFOSET(fd,packet_len(0x249));
  13298. #else
  13299. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13300. p.PacketType = rodexwriteresult;
  13301. p.result = result;
  13302. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13303. #endif
  13304. }
  13305. /// Notification about the result of deleting a mail.
  13306. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13307. /// result:
  13308. /// 0 = success
  13309. /// 1 = failure
  13310. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13311. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13312. #if PACKETVER < 20150513
  13313. int fd = sd->fd;
  13314. WFIFOHEAD(fd, packet_len(0x257));
  13315. WFIFOW(fd,0) = 0x257;
  13316. WFIFOL(fd,2) = msg->id;
  13317. WFIFOW(fd,6) = !success;
  13318. WFIFOSET(fd, packet_len(0x257));
  13319. #else
  13320. // This is only a success notification
  13321. if( success ){
  13322. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13323. p.PacketType = rodexdelete;
  13324. p.opentype = msg->type;
  13325. p.MailID = msg->id;
  13326. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13327. }
  13328. #endif
  13329. }
  13330. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13331. /// 0274 <mail id>.L <result>.W
  13332. /// result:
  13333. /// 0 = success
  13334. /// 1 = failure
  13335. void clif_Mail_return(int fd, int mail_id, short fail)
  13336. {
  13337. WFIFOHEAD(fd,packet_len(0x274));
  13338. WFIFOW(fd,0) = 0x274;
  13339. WFIFOL(fd,2) = mail_id;
  13340. WFIFOW(fd,6) = fail;
  13341. WFIFOSET(fd,packet_len(0x274));
  13342. }
  13343. /// Notification about new mail.
  13344. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13345. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13346. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13347. #if PACKETVER < 20150513
  13348. int fd = sd->fd;
  13349. WFIFOHEAD(fd,packet_len(0x24a));
  13350. WFIFOW(fd,0) = 0x24a;
  13351. WFIFOL(fd,2) = mail_id;
  13352. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13353. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13354. WFIFOSET(fd,packet_len(0x24a));
  13355. #else
  13356. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13357. p.PacketType = rodexicon;
  13358. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13359. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13360. #endif
  13361. }
  13362. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13363. /// 0260 <type>.L
  13364. /// type:
  13365. /// 0 = open
  13366. /// 1 = close
  13367. void clif_Mail_window(int fd, int flag)
  13368. {
  13369. WFIFOHEAD(fd,packet_len(0x260));
  13370. WFIFOW(fd,0) = 0x260;
  13371. WFIFOL(fd,2) = flag;
  13372. WFIFOSET(fd,packet_len(0x260));
  13373. }
  13374. /// Lists mails stored in inbox.
  13375. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13376. /// read:
  13377. /// 0 = unread
  13378. /// 1 = read
  13379. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13380. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13381. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13382. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13383. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13384. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13385. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13386. #if PACKETVER < 20150513
  13387. int fd = sd->fd;
  13388. struct mail_data *md = &sd->mail.inbox;
  13389. struct mail_message *msg;
  13390. int len, i, j;
  13391. len = 8 + (73 * md->amount);
  13392. WFIFOHEAD(fd,len);
  13393. WFIFOW(fd,0) = 0x240;
  13394. WFIFOW(fd,2) = len;
  13395. WFIFOL(fd,4) = md->amount;
  13396. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13397. {
  13398. msg = &md->msg[i];
  13399. if (msg->id < 1)
  13400. continue;
  13401. WFIFOL(fd,8+73*j) = msg->id;
  13402. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13403. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13404. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13405. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13406. j++;
  13407. }
  13408. WFIFOSET(fd,len);
  13409. if( md->full ) {// TODO: is this official?
  13410. char output[100];
  13411. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13412. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13413. }
  13414. #else
  13415. int fd = sd->fd;
  13416. struct mail_data *md = &sd->mail.inbox;
  13417. struct mail_message *msg;
  13418. int i, j, k, offset, titleLength;
  13419. uint8 mailType, amount, remaining;
  13420. uint32 now = (uint32)time(NULL);
  13421. #if PACKETVER >= 20170419
  13422. int cmd = 0xac2;
  13423. #elif PACKETVER >= 20160601
  13424. int cmd = 0xa7d;
  13425. #else
  13426. int cmd = 0x9f0;
  13427. #endif
  13428. if( battle_config.mail_daily_count ){
  13429. mail_refresh_remaining_amount(sd);
  13430. }
  13431. #if PACKETVER >= 20170419
  13432. // Always send all
  13433. i = md->amount;
  13434. #else
  13435. // If a starting mail id was sent
  13436. if( mailID != 0 ){
  13437. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13438. // Unknown mail
  13439. if( i == md->amount ){
  13440. // Ignore the request for now
  13441. return; // TODO: Should we just show the first page instead?
  13442. }
  13443. // It was actually the oldest/first mail, there is no further page
  13444. if( i == 0 ){
  13445. return;
  13446. }
  13447. // We actually want the next/older mail
  13448. i -= 1;
  13449. }else{
  13450. i = md->amount;
  13451. }
  13452. #endif
  13453. // Count the remaining mails from the starting mail or the beginning
  13454. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13455. for( j = i, remaining = 0; j >= 0; j-- ){
  13456. msg = &md->msg[j];
  13457. if (msg->id < 1)
  13458. continue;
  13459. #if PACKETVER < 20170419
  13460. if (msg->type != type)
  13461. continue;
  13462. #endif
  13463. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13464. continue;
  13465. remaining++;
  13466. }
  13467. #if PACKETVER >= 20170419
  13468. // Always send all
  13469. amount = remaining;
  13470. #else
  13471. if( remaining > MAIL_PAGE_SIZE ){
  13472. amount = MAIL_PAGE_SIZE;
  13473. }else{
  13474. amount = remaining;
  13475. }
  13476. #endif
  13477. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13478. WFIFOW(fd, 0) = cmd;
  13479. #if PACKETVER >= 20170419
  13480. WFIFOB(fd, 4) = 1; // Unknown
  13481. offset = 5;
  13482. #else
  13483. WFIFOB(fd, 4) = type;
  13484. WFIFOB(fd, 5) = amount;
  13485. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13486. offset = 7;
  13487. #endif
  13488. for( amount = 0; i >= 0; i-- ){
  13489. msg = &md->msg[i];
  13490. if (msg->id < 1)
  13491. continue;
  13492. #if PACKETVER < 20170419
  13493. if (msg->type != type)
  13494. continue;
  13495. #endif
  13496. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13497. continue;
  13498. #if PACKETVER >= 20170419
  13499. WFIFOB(fd, offset) = msg->type;
  13500. offset += 1;
  13501. #endif
  13502. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13503. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13504. mailType = MAIL_TYPE_TEXT; // Normal letter
  13505. if( msg->zeny > 0 ){
  13506. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13507. }
  13508. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13509. if( msg->item[k].nameid > 0 ){
  13510. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13511. break;
  13512. }
  13513. }
  13514. #if PACKETVER >= 20170419
  13515. // If it came from an npc?
  13516. if( !msg->send_id ){
  13517. mailType |= MAIL_TYPE_NPC;
  13518. }
  13519. #endif
  13520. WFIFOB(fd, offset + 9) = mailType;
  13521. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13522. #if PACKETVER < 20170419
  13523. // How much time has passed since you received the mail
  13524. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13525. offset += 4;
  13526. #endif
  13527. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13528. if( msg->scheduled_deletion > 0 ){
  13529. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13530. }else{
  13531. // Fake the scheduled deletion to one year in the future
  13532. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13533. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13534. }
  13535. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13536. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13537. offset += 40 + titleLength;
  13538. }
  13539. WFIFOW(fd, 2) = (int16)offset;
  13540. WFIFOSET(fd, offset);
  13541. #endif
  13542. }
  13543. /// Mail inbox list request.
  13544. /// 023f (CZ_MAIL_GET_LIST)
  13545. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13546. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13547. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13548. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13549. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13550. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13551. if( mail_invalid_operation( sd ) ){
  13552. return;
  13553. }
  13554. #if PACKETVER < 20150513
  13555. struct mail_data* md = &sd->mail.inbox;
  13556. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13557. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13558. else
  13559. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13560. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13561. mail_removezeny(sd, false);
  13562. #else
  13563. int cmd = RFIFOW(fd, 0);
  13564. #if PACKETVER < 20170419
  13565. uint8 openType = RFIFOB(fd, 2);
  13566. uint64 mailId = RFIFOQ(fd, 3);
  13567. #else
  13568. uint8 openType;
  13569. uint64 mailId = RFIFOQ(fd, 2);
  13570. int i;
  13571. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13572. if( i == MAIL_MAX_INBOX ){
  13573. openType = MAIL_INBOX_NORMAL;
  13574. mailId = 0;
  13575. }else{
  13576. openType = sd->mail.inbox.msg[i].type;
  13577. mailId = 0;
  13578. }
  13579. #endif
  13580. switch( openType ){
  13581. case MAIL_INBOX_NORMAL:
  13582. case MAIL_INBOX_ACCOUNT:
  13583. case MAIL_INBOX_RETURNED:
  13584. break;
  13585. default:
  13586. // Unknown type: ignore request
  13587. return;
  13588. }
  13589. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13590. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13591. return;
  13592. }
  13593. // If it is not a next page request
  13594. if( cmd != 0x9ee ){
  13595. mailId = 0;
  13596. }
  13597. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13598. #endif
  13599. }
  13600. /// Opens a mail
  13601. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13602. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13603. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13604. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13605. /// { }*n
  13606. // TODO: Packet description => for repeated block
  13607. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13608. int i, fd = sd->fd;
  13609. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13610. if( i == MAIL_MAX_INBOX ) {
  13611. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13612. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13613. return;
  13614. } else {
  13615. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13616. struct item *item;
  13617. int msg_len = strlen(msg->body);
  13618. if( msg_len == 0 ) {
  13619. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13620. msg_len = strlen(msg->body);
  13621. }
  13622. #if PACKETVER < 20150513
  13623. item = &msg->item[0];
  13624. int len = 101 + msg_len;
  13625. WFIFOHEAD(fd,len);
  13626. WFIFOW(fd,0) = 0x242;
  13627. WFIFOW(fd,2) = len;
  13628. WFIFOL(fd,4) = msg->id;
  13629. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13630. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13631. WFIFOL(fd,72) = 0;
  13632. WFIFOL(fd,76) = msg->zeny;
  13633. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13634. if( item->nameid && data != nullptr ) {
  13635. WFIFOL(fd,80) = item->amount;
  13636. WFIFOW(fd,84) = client_nameid( item->nameid );
  13637. WFIFOW(fd,86) = itemtype( item->nameid );
  13638. WFIFOB(fd,88) = item->identify;
  13639. WFIFOB(fd,89) = item->attribute;
  13640. WFIFOB(fd,90) = item->refine;
  13641. WFIFOW(fd,91) = item->card[0];
  13642. WFIFOW(fd,93) = item->card[1];
  13643. WFIFOW(fd,95) = item->card[2];
  13644. WFIFOW(fd,97) = item->card[3];
  13645. } else // no item, set all to zero
  13646. memset(WFIFOP(fd,80), 0x00, 19);
  13647. WFIFOB(fd,99) = (unsigned char)msg_len;
  13648. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13649. WFIFOSET(fd,len);
  13650. #else
  13651. msg_len += 1; // Zero Termination
  13652. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13653. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13654. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13655. p->opentype = msg->type;
  13656. p->MailID = msg->id;
  13657. p->TextcontentsLength = msg_len;
  13658. p->zeny = msg->zeny;
  13659. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13660. p->PacketLength += p->TextcontentsLength;
  13661. p->ItemCnt = 0;
  13662. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13663. item = &msg->item[j];
  13664. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13665. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13666. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13667. mailitem->ITID = client_nameid( item->nameid );
  13668. mailitem->count = item->amount;
  13669. mailitem->type = itemtype( item->nameid );
  13670. mailitem->IsIdentified = item->identify ? 1 : 0;
  13671. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13672. mailitem->refiningLevel = item->refine;
  13673. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13674. mailitem->viewSprite = data->look;
  13675. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13676. clif_addcards( &mailitem->slot, item );
  13677. clif_add_random_options( mailitem->option_data, item );
  13678. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13679. mailitem->enchantgrade = item->enchantgrade;
  13680. #endif
  13681. p->PacketLength += sizeof( *mailitem );
  13682. p->ItemCnt++;
  13683. }
  13684. }
  13685. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13686. #endif
  13687. if (msg->status == MAIL_UNREAD) {
  13688. msg->status = MAIL_READ;
  13689. intif_Mail_read(mail_id);
  13690. clif_parse_Mail_refreshinbox(fd, sd);
  13691. sd->mail.inbox.unread--;
  13692. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13693. }
  13694. }
  13695. }
  13696. /// Request to open a mail.
  13697. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13698. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13699. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13700. #if PACKETVER < 20150513
  13701. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13702. #else
  13703. //uint8 openType = RFIFOB(fd, 2);
  13704. int mail_id = (int)RFIFOQ(fd, 3);
  13705. #endif
  13706. if( mail_id <= 0 )
  13707. return;
  13708. if( mail_invalid_operation(sd) )
  13709. return;
  13710. clif_Mail_read(sd, mail_id);
  13711. }
  13712. /// Allow a player to begin writing a mail
  13713. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13714. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13715. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13716. p.PacketType = rodexopenwrite;
  13717. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13718. p.result = success;
  13719. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13720. }
  13721. /// Request to start writing a mail
  13722. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13723. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13724. char name[NAME_LENGTH];
  13725. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13726. if( mail_invalid_operation( sd ) ){
  13727. return;
  13728. }
  13729. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13730. clif_send_Mail_beginwrite_ack(sd, name, false);
  13731. return;
  13732. }
  13733. mail_clear(sd);
  13734. sd->state.mail_writing = true;
  13735. clif_send_Mail_beginwrite_ack(sd, name,true);
  13736. }
  13737. /// Notification that the client cancelled writing a mail
  13738. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13739. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13740. sd->state.mail_writing = false;
  13741. }
  13742. /// Give the client information about the recipient, if available
  13743. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13744. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13745. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13746. #if PACKETVER >= 20141119
  13747. PACKET_ZC_CHECKNAME p = { 0 };
  13748. p.PacketType = HEADER_ZC_CHECKNAME;
  13749. p.CharId = char_id;
  13750. p.Class = class_;
  13751. p.BaseLevel = level;
  13752. #if PACKETVER >= 20160302
  13753. strncpy(p.Name, name, NAME_LENGTH);
  13754. #endif
  13755. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13756. #endif
  13757. }
  13758. /// Request information about the recipient
  13759. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13760. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13761. #if PACKETVER >= 20140423
  13762. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13763. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13764. #else
  13765. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13766. #endif
  13767. static char name[NAME_LENGTH];
  13768. if( mail_invalid_operation( sd ) ){
  13769. return;
  13770. }
  13771. safestrncpy(name, p->Name, NAME_LENGTH);
  13772. intif_mail_checkreceiver(sd, name);
  13773. #endif
  13774. }
  13775. /// Request to receive mail's attachment.
  13776. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13777. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13778. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13779. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13780. int i;
  13781. struct mail_message* msg;
  13782. #if PACKETVER < 20150513
  13783. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13784. int attachment = MAIL_ATT_ALL;
  13785. #else
  13786. uint16 packet_id = RFIFOW(fd, 0);
  13787. int mail_id = (int)RFIFOQ(fd, 2);
  13788. //int openType = RFIFOB(fd, 10);
  13789. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13790. #endif
  13791. if( !chrif_isconnected() )
  13792. return;
  13793. if( mail_id <= 0 )
  13794. return;
  13795. if( mail_invalid_operation(sd) )
  13796. return;
  13797. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13798. if( i == MAIL_MAX_INBOX )
  13799. return;
  13800. msg = &sd->mail.inbox.msg[i];
  13801. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13802. attachment &= ~MAIL_ATT_ZENY;
  13803. }
  13804. if( attachment&MAIL_ATT_ITEM ){
  13805. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13806. // No items were found
  13807. if( i == MAIL_MAX_ITEM ){
  13808. attachment &= ~MAIL_ATT_ITEM;
  13809. }
  13810. }
  13811. // Either no attachment requested at all or there are no zeny or items in the mail
  13812. if( attachment == MAIL_ATT_NONE ){
  13813. return;
  13814. }
  13815. if( attachment&MAIL_ATT_ZENY ){
  13816. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13817. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13818. return;
  13819. }else{
  13820. // Store the pending zeny (required for the "retrieve all" feature)
  13821. sd->mail.pending_zeny += msg->zeny;
  13822. // To make sure another request fails
  13823. msg->zeny = 0;
  13824. }
  13825. }
  13826. if( attachment&MAIL_ATT_ITEM ){
  13827. int slots = 0, totalweight = 0;
  13828. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13829. struct item* item = &msg->item[i];
  13830. if( item->nameid > 0 && item->amount > 0 ){
  13831. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13832. if(data == nullptr)
  13833. continue;
  13834. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13835. case CHKADDITEM_NEW:
  13836. slots += data->inventorySlotNeeded( item->amount );
  13837. break;
  13838. case CHKADDITEM_OVERAMOUNT:
  13839. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13840. return;
  13841. }
  13842. totalweight += data->weight * item->amount;
  13843. }
  13844. }
  13845. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13846. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13847. return;
  13848. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13849. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13850. return;
  13851. }
  13852. // To make sure another request fails
  13853. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13854. // Store the pending weight (required for the "retrieve all" feature)
  13855. sd->mail.pending_weight += totalweight;
  13856. // Store the pending slots (required for the "retrieve all" feature)
  13857. sd->mail.pending_slots += slots;
  13858. }
  13859. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13860. }
  13861. /// Request to delete a mail.
  13862. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13863. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13864. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13865. #if PACKETVER < 20150513
  13866. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13867. #else
  13868. //int openType = RFIFOB(fd, 2);
  13869. int mail_id = (int)RFIFOQ(fd, 3);
  13870. #endif
  13871. int i, j;
  13872. if( !chrif_isconnected() )
  13873. return;
  13874. if( mail_id <= 0 )
  13875. return;
  13876. if( mail_invalid_operation(sd) )
  13877. return;
  13878. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13879. if (i < MAIL_MAX_INBOX) {
  13880. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13881. // can't delete mail without removing zeny first
  13882. if( msg->zeny > 0 ){
  13883. clif_mail_delete(sd, msg, false);
  13884. return;
  13885. }
  13886. // can't delete mail without removing attachment(s) first
  13887. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13888. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13889. clif_mail_delete(sd, msg, false);
  13890. return;
  13891. }
  13892. }
  13893. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13894. sd->mail.inbox.unread--;
  13895. clif_Mail_new(sd,0,NULL,NULL);
  13896. }
  13897. }
  13898. }
  13899. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13900. /// 0273 <mail id>.L <receive name>.24B
  13901. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13902. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13903. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13904. //ShowDump( p, sizeof( p ) );
  13905. int mail_id = p->msgId;
  13906. // not supported for now
  13907. return;
  13908. #else
  13909. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13910. #endif
  13911. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13912. int i;
  13913. if( mail_id <= 0 )
  13914. return;
  13915. if( mail_invalid_operation(sd) )
  13916. return;
  13917. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13918. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13919. intif_Mail_return(sd->status.char_id, mail_id);
  13920. else
  13921. clif_Mail_return(sd->fd, mail_id, 1);
  13922. }
  13923. /// Request to add an item or Zeny to mail.
  13924. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13925. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13926. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13927. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13928. uint16 idx = RFIFOW(fd,info->pos[0]);
  13929. #if PACKETVER < 20150513
  13930. int amount = RFIFOL(fd,info->pos[1]);
  13931. #else
  13932. int amount = RFIFOW(fd,info->pos[1]);
  13933. #endif
  13934. unsigned char flag;
  13935. if( !chrif_isconnected() )
  13936. return;
  13937. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13938. return;
  13939. if (sd->inventory_data[server_index(idx)] == nullptr)
  13940. return;
  13941. if( mail_invalid_operation( sd ) ){
  13942. return;
  13943. }
  13944. flag = mail_setitem(sd, idx, amount);
  13945. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13946. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13947. }else{
  13948. clif_Mail_setattachment(sd,idx,amount,flag);
  13949. }
  13950. }
  13951. /// Remove an item from a mail
  13952. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13953. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13954. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13955. p.PacketType = rodexremoveitem;
  13956. p.result = success;
  13957. p.index = index;
  13958. p.cnt = amount;
  13959. int total = 0;
  13960. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13961. if( sd->mail.item[i].nameid == 0 ){
  13962. break;
  13963. }
  13964. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13965. }
  13966. p.weight = total;
  13967. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13968. }
  13969. /// Request to reset mail item and/or Zeny
  13970. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13971. /// type:
  13972. /// 0 = reset all
  13973. /// 1 = remove item
  13974. /// 2 = remove zeny
  13975. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13976. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13977. {
  13978. #if PACKETVER < 20150513
  13979. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13980. if (type == 0 || type == 1)
  13981. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13982. if (type == 0 || type == 2)
  13983. mail_removezeny(sd, false);
  13984. #else
  13985. uint16 index = RFIFOW(fd, 2);
  13986. uint16 count = RFIFOW(fd, 4);
  13987. mail_removeitem(sd,0,index,count);
  13988. #endif
  13989. }
  13990. /// Request to send mail
  13991. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13992. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13993. /// 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)
  13994. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13995. #if PACKETVER < 20150513
  13996. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13997. if( !chrif_isconnected() )
  13998. return;
  13999. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  14000. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  14001. return;
  14002. }
  14003. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  14004. #else
  14005. uint16 length = RFIFOW(fd, 2);
  14006. if( length < 0x3e ){
  14007. ShowWarning("Too short...\n");
  14008. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  14009. return;
  14010. }
  14011. if( mail_invalid_operation( sd ) ){
  14012. return;
  14013. }
  14014. // Forged request without a begin writing packet?
  14015. if( !sd->state.mail_writing ){
  14016. return; // Ignore it
  14017. }
  14018. char receiver[NAME_LENGTH];
  14019. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  14020. // char sender[NAME_LENGTH];
  14021. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  14022. uint64 zeny = RFIFOQ(fd, 52);
  14023. uint16 titleLength = RFIFOW(fd, 60);
  14024. uint16 textLength = RFIFOW(fd, 62);
  14025. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  14026. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  14027. char title[MAIL_TITLE_LENGTH];
  14028. char text[MAIL_BODY_LENGTH];
  14029. #if PACKETVER <= 20160330
  14030. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  14031. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  14032. #else
  14033. // 64 = <char id>.L
  14034. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  14035. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  14036. #endif
  14037. if( zeny > 0 ){
  14038. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  14039. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  14040. return;
  14041. }
  14042. }
  14043. mail_send(sd, receiver, title, text, realTextLength);
  14044. #endif
  14045. }
  14046. /// AUCTION SYSTEM
  14047. /// By Zephyrus
  14048. ///
  14049. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  14050. /// 025f <type>.L
  14051. /// type:
  14052. /// 0 = open
  14053. /// 1 = close
  14054. void clif_Auction_openwindow(struct map_session_data *sd)
  14055. {
  14056. int fd = sd->fd;
  14057. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  14058. return;
  14059. if( !battle_config.feature_auction )
  14060. return;
  14061. WFIFOHEAD(fd,packet_len(0x25f));
  14062. WFIFOW(fd,0) = 0x25f;
  14063. WFIFOL(fd,2) = 0;
  14064. WFIFOSET(fd,packet_len(0x25f));
  14065. }
  14066. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  14067. /// 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 }*
  14068. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  14069. {
  14070. int i, fd = sd->fd, len = sizeof(struct auction_data);
  14071. struct auction_data auction;
  14072. WFIFOHEAD(fd,12 + (count * 83));
  14073. WFIFOW(fd,0) = 0x252;
  14074. WFIFOW(fd,2) = 12 + (count * 83);
  14075. WFIFOL(fd,4) = pages;
  14076. WFIFOL(fd,8) = count;
  14077. for( i = 0; i < count; i++ ) {
  14078. int k = 12 + (i * 83);
  14079. memcpy(&auction, RBUFP(buf,i * len), len);
  14080. WFIFOL(fd,k) = auction.auction_id;
  14081. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  14082. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  14083. WFIFOL(fd,30+k) = auction.type;
  14084. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  14085. WFIFOB(fd,36+k) = auction.item.identify;
  14086. WFIFOB(fd,37+k) = auction.item.attribute;
  14087. WFIFOB(fd,38+k) = auction.item.refine;
  14088. WFIFOW(fd,39+k) = auction.item.card[0];
  14089. WFIFOW(fd,41+k) = auction.item.card[1];
  14090. WFIFOW(fd,43+k) = auction.item.card[2];
  14091. WFIFOW(fd,45+k) = auction.item.card[3];
  14092. WFIFOL(fd,47+k) = auction.price;
  14093. WFIFOL(fd,51+k) = auction.buynow;
  14094. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  14095. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  14096. }
  14097. WFIFOSET(fd,WFIFOW(fd,2));
  14098. }
  14099. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  14100. /// 0256 <index>.W <result>.B
  14101. /// result:
  14102. /// 0 = success
  14103. /// 1 = failure
  14104. static void clif_Auction_setitem(int fd, int index, bool fail)
  14105. {
  14106. WFIFOHEAD(fd,packet_len(0x256));
  14107. WFIFOW(fd,0) = 0x256;
  14108. WFIFOW(fd,2) = index;
  14109. WFIFOB(fd,4) = fail;
  14110. WFIFOSET(fd,packet_len(0x256));
  14111. }
  14112. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14113. /// 024b <type>.W
  14114. /// type:
  14115. /// 0 = create (any other action in auction window)
  14116. /// 1 = cancel (cancel pressed on register tab)
  14117. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14118. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  14119. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14120. if( sd->auction.amount > 0 )
  14121. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14122. sd->auction.amount = 0;
  14123. }
  14124. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14125. /// 024c <index>.W <count>.L
  14126. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  14127. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14128. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14129. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14130. if( !battle_config.feature_auction )
  14131. return;
  14132. if( sd->auction.amount > 0 )
  14133. sd->auction.amount = 0;
  14134. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14135. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14136. return;
  14137. }
  14138. 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.
  14139. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14140. return;
  14141. }
  14142. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  14143. if( id != nullptr && !(id->type == IT_ARMOR || id->type == IT_PETARMOR || id->type == IT_WEAPON || id->type == IT_CARD || id->type == IT_ETC || id->type == IT_SHADOWGEAR) )
  14144. { // Consumable or pets are not allowed
  14145. clif_Auction_setitem(sd->fd, idx, true);
  14146. return;
  14147. }
  14148. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14149. !sd->inventory.u.items_inventory[idx].identify ||
  14150. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14151. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14152. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14153. clif_Auction_setitem(sd->fd, idx, true);
  14154. return;
  14155. }
  14156. sd->auction.index = idx;
  14157. sd->auction.amount = amount;
  14158. clif_Auction_setitem(fd, idx + 2, false);
  14159. }
  14160. /// Result from an auction action (ZC_AUCTION_RESULT).
  14161. /// 0250 <result>.B
  14162. /// result:
  14163. /// 0 = You have failed to bid into the auction
  14164. /// 1 = You have successfully bid in the auction
  14165. /// 2 = The auction has been canceled
  14166. /// 3 = An auction with at least one bidder cannot be canceled
  14167. /// 4 = You cannot register more than 5 items in an auction at a time
  14168. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14169. /// 6 = You have won the auction
  14170. /// 7 = You have failed to win the auction
  14171. /// 8 = You do not have enough Zeny
  14172. /// 9 = You cannot place more than 5 bids at a time
  14173. void clif_Auction_message(int fd, unsigned char flag)
  14174. {
  14175. WFIFOHEAD(fd,packet_len(0x250));
  14176. WFIFOW(fd,0) = 0x250;
  14177. WFIFOB(fd,2) = flag;
  14178. WFIFOSET(fd,packet_len(0x250));
  14179. }
  14180. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14181. /// 025e <result>.W
  14182. /// result:
  14183. /// 0 = You have ended the auction
  14184. /// 1 = You cannot end the auction
  14185. /// 2 = Auction ID is incorrect
  14186. void clif_Auction_close(int fd, unsigned char flag)
  14187. {
  14188. WFIFOHEAD(fd,packet_len(0x25e));
  14189. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14190. WFIFOW(fd,2) = flag;
  14191. WFIFOSET(fd,packet_len(0x25e));
  14192. }
  14193. /// Request to add an auction (CZ_AUCTION_ADD).
  14194. /// 024d <now money>.L <max money>.L <delete hour>.W
  14195. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  14196. {
  14197. struct auction_data auction;
  14198. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14199. if( !battle_config.feature_auction )
  14200. return;
  14201. auction.price = RFIFOL(fd,info->pos[0]);
  14202. auction.buynow = RFIFOL(fd,info->pos[1]);
  14203. auction.hours = RFIFOW(fd,info->pos[2]);
  14204. // Invalid Situations...
  14205. if( sd->auction.amount < 1 ) {
  14206. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14207. return;
  14208. }
  14209. if( auction.price >= auction.buynow ) {
  14210. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14211. return;
  14212. }
  14213. if( auction.hours < 1 || auction.hours > 48 ) {
  14214. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14215. return;
  14216. }
  14217. // Auction checks...
  14218. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14219. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14220. clif_Auction_message(fd, 2); // The auction has been canceled
  14221. return;
  14222. }
  14223. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14224. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14225. return;
  14226. }
  14227. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14228. auction.buynow = battle_config.auction_maximumprice;
  14229. if( auction.price >= auction.buynow )
  14230. auction.price = auction.buynow - 1;
  14231. }
  14232. auction.auction_id = 0;
  14233. auction.seller_id = sd->status.char_id;
  14234. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14235. auction.buyer_id = 0;
  14236. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14237. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14238. {
  14239. clif_Auction_message(fd, 2); // The auction has been canceled
  14240. return;
  14241. }
  14242. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14243. if( id == nullptr )
  14244. { // Just in case
  14245. clif_Auction_message(fd, 2); // The auction has been canceled
  14246. return;
  14247. }
  14248. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14249. auction.type = id->type;
  14250. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14251. auction.item.amount = 1;
  14252. auction.timestamp = 0;
  14253. if( !intif_Auction_register(&auction) )
  14254. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14255. else
  14256. {
  14257. int zeny = auction.hours*battle_config.auction_feeperhour;
  14258. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14259. sd->auction.amount = 0;
  14260. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14261. }
  14262. }
  14263. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14264. /// 024e <auction id>.L
  14265. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  14266. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14267. intif_Auction_cancel(sd->status.char_id, auction_id);
  14268. }
  14269. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14270. /// 025d <auction id>.L
  14271. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  14272. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14273. intif_Auction_close(sd->status.char_id, auction_id);
  14274. }
  14275. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14276. /// 024f <auction id>.L <money>.L
  14277. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  14278. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14279. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14280. int bid = RFIFOL(fd,info->pos[1]);
  14281. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14282. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14283. return;
  14284. }
  14285. if( bid <= 0 )
  14286. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14287. else if( bid > sd->status.zeny )
  14288. clif_Auction_message(fd, 8); // You do not have enough zeny
  14289. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14290. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14291. else {
  14292. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14293. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14294. }
  14295. }
  14296. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14297. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14298. /// search type:
  14299. /// 0 = armor
  14300. /// 1 = weapon
  14301. /// 2 = card
  14302. /// 3 = misc
  14303. /// 4 = name search
  14304. /// 5 = auction id search
  14305. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14306. char search_text[NAME_LENGTH];
  14307. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14308. short type = RFIFOW(fd,info->pos[0]);
  14309. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14310. int page = RFIFOW(fd,info->pos[3]);
  14311. if( !battle_config.feature_auction )
  14312. return;
  14313. clif_parse_Auction_cancelreg(fd, sd);
  14314. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14315. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14316. }
  14317. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14318. /// 025c <type>.W
  14319. /// type:
  14320. /// 0 = sell (own auctions)
  14321. /// 1 = buy (own bids)
  14322. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14323. {
  14324. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14325. if( !battle_config.feature_auction )
  14326. return;
  14327. clif_parse_Auction_cancelreg(fd, sd);
  14328. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14329. }
  14330. /// CASH/POINT SHOP
  14331. ///
  14332. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14333. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14334. nullpo_retv( sd );
  14335. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14336. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14337. p.cashPoints = sd->cashPoints;
  14338. p.kafraPoints = sd->kafraPoints;
  14339. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14340. p.tab = tab;
  14341. #endif
  14342. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14343. #endif
  14344. }
  14345. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14346. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14347. nullpo_retv( sd );
  14348. int tab = 0;
  14349. #if PACKETVER >= 20191224
  14350. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14351. tab = p->tab;
  14352. #endif
  14353. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14354. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14355. return;
  14356. }
  14357. sd->state.cashshop_open = true;
  14358. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14359. clif_cashshop_open( sd, tab );
  14360. #endif
  14361. }
  14362. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14363. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14364. sd->state.cashshop_open = false;
  14365. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14366. // No need to do anything here
  14367. #endif
  14368. }
  14369. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14370. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14371. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14372. // [4144] packet exists only in 2011 and was dropped after
  14373. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14374. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14375. int j;
  14376. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14377. return;
  14378. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14379. WFIFOW(fd, 0) = 0x8c0;
  14380. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14381. WFIFOL(fd, 4) = tab;
  14382. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14383. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14384. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14385. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14386. }
  14387. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14388. #endif
  14389. }
  14390. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14391. void clif_cashshop_list( struct map_session_data* sd ){
  14392. nullpo_retv( sd );
  14393. int fd = sd->fd;
  14394. if( !session_isActive( fd ) ){
  14395. return;
  14396. }
  14397. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14398. // Skip empty tabs, the client only expects filled ones
  14399. if( cash_shop_items[tab].count == 0 ){
  14400. continue;
  14401. }
  14402. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14403. WFIFOHEAD( fd, len );
  14404. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14405. p->packetType = 0x8ca;
  14406. p->packetLength = len;
  14407. p->count = cash_shop_items[tab].count;
  14408. p->tabNum = tab;
  14409. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14410. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14411. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14412. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14413. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14414. if( id == nullptr ){
  14415. p->items[i].location = 0;
  14416. p->items[i].viewSprite = 0;
  14417. }else{
  14418. p->items[i].location = pc_equippoint_sub( sd, id );
  14419. p->items[i].viewSprite = id->look;
  14420. }
  14421. #endif
  14422. }
  14423. WFIFOSET( fd, len );
  14424. }
  14425. }
  14426. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14427. if( !sd->status.cashshop_sent ) {
  14428. clif_cashshop_list( sd );
  14429. #if PACKETVER_SUPPORTS_SALES
  14430. sale_notify_login(sd);
  14431. #endif
  14432. sd->status.cashshop_sent = true;
  14433. }
  14434. }
  14435. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14436. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14437. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14438. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14439. nullpo_retv( sd );
  14440. nullpo_retv( nd );
  14441. int fd = sd->fd;
  14442. if( !session_isActive( fd ) ){
  14443. return;
  14444. }
  14445. sd->npc_shopid = nd->bl.id;
  14446. int cost[2] = { 0, 0 };
  14447. npc_shop_currency_type( sd, nd, cost, true );
  14448. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14449. WFIFOHEAD( fd, len );
  14450. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14451. p->packetType = 0x287;
  14452. p->packetLength = len;
  14453. p->cashPoints = cost[0];
  14454. #if PACKETVER >= 20070711
  14455. p->kafraPoints = cost[1];
  14456. #endif
  14457. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14458. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14459. p->items[i].price = nd->u.shop.shop_item[i].value;
  14460. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14461. p->items[i].itemType = itemtype( id->nameid );
  14462. p->items[i].itemId = client_nameid( id->nameid );
  14463. }
  14464. WFIFOSET( fd, len );
  14465. }
  14466. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14467. /// 0289 <cash point>.L <error>.W
  14468. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14469. /// error:
  14470. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14471. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14472. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14473. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14474. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14475. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14476. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14477. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14478. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14479. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14480. {
  14481. int fd, cost[2] = { 0, 0 };
  14482. struct npc_data *nd;
  14483. nullpo_retv(sd);
  14484. fd = sd->fd;
  14485. nd = map_id2nd(sd->npc_shopid);
  14486. npc_shop_currency_type(sd, nd, cost, false);
  14487. WFIFOHEAD(fd, packet_len(0x289));
  14488. WFIFOW(fd,0) = 0x289;
  14489. WFIFOL(fd,2) = cost[0];
  14490. #if PACKETVER < 20070711
  14491. WFIFOW(fd,6) = TOW(error);
  14492. #else
  14493. WFIFOL(fd,6) = cost[1];
  14494. WFIFOW(fd,10) = TOW(error);
  14495. #endif
  14496. WFIFOSET(fd, packet_len(0x289));
  14497. }
  14498. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14499. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14500. nullpo_retv( sd );
  14501. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14502. packet.packetType = 0x849;
  14503. if( item_id != 0 ){
  14504. packet.itemId = client_nameid( item_id );
  14505. }else{
  14506. packet.itemId = 0;
  14507. }
  14508. packet.result = result;
  14509. packet.cashPoints = sd->cashPoints;
  14510. packet.kafraPoints = sd->kafraPoints;
  14511. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14512. #endif
  14513. }
  14514. /// Request to buy item(s) from cash shop.
  14515. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14516. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14517. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14518. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14519. nullpo_retv( sd );
  14520. if( sd->state.trading || !sd->npc_shopid ){
  14521. clif_cashshop_ack( sd, 1 );
  14522. return;
  14523. }
  14524. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14525. #if PACKETVER < 20070711
  14526. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14527. #elif PACKETVER < 20101116
  14528. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14529. #else
  14530. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14531. 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 ){
  14532. 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 );
  14533. return;
  14534. }
  14535. std::vector<s_npc_buy_list> item_list = {};
  14536. item_list.reserve( p->count );
  14537. for( int i = 0; i < p->count; i++ ){
  14538. s_npc_buy_list item = {};
  14539. item.nameid = p->items[i].itemId;
  14540. item.qty = p->items[i].amount;
  14541. item_list.push_back( item );
  14542. }
  14543. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14544. #endif
  14545. }
  14546. /// Request to buy item(s) from cash shop.
  14547. /// 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)
  14548. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14549. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14550. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14551. 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 ){
  14552. 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 );
  14553. return;
  14554. }
  14555. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14556. }
  14557. /// Adoption System
  14558. ///
  14559. /// Adoption message (ZC_BABYMSG).
  14560. /// 0216 <msg>.L
  14561. /// msg:
  14562. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14563. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14564. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14565. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14566. {
  14567. int fd = sd->fd;
  14568. WFIFOHEAD(fd,6);
  14569. WFIFOW(fd,0) = 0x216;
  14570. WFIFOL(fd,2) = type;
  14571. WFIFOSET(fd,6);
  14572. }
  14573. /// Adoption confirmation (ZC_REQ_BABY).
  14574. /// 01f6 <account id>.L <char id>.L <name>.B
  14575. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14576. {
  14577. int fd = sd->fd;
  14578. WFIFOHEAD(fd,34);
  14579. WFIFOW(fd,0) = 0x1f6;
  14580. WFIFOL(fd,2) = src->status.account_id;
  14581. WFIFOL(fd,6) = p_id;
  14582. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14583. WFIFOSET(fd,34);
  14584. }
  14585. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14586. /// 01f9 <account id>.L
  14587. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14588. {
  14589. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14590. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14591. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14592. {
  14593. tsd->adopt_invite = sd->status.account_id;
  14594. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14595. }
  14596. }
  14597. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14598. /// 01f7 <account id>.L <char id>.L <answer>.L
  14599. /// answer:
  14600. /// 0 = rejected
  14601. /// 1 = accepted
  14602. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14603. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14604. int p1_id = RFIFOL(fd,info->pos[0]);
  14605. int p2_id = RFIFOL(fd,info->pos[1]);
  14606. int result = RFIFOL(fd,info->pos[2]);
  14607. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14608. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14609. int pid = sd->adopt_invite;
  14610. sd->adopt_invite = 0;
  14611. if( p1_sd == NULL || p2_sd == NULL )
  14612. return; // Both players need to be online
  14613. if( pid != p1_sd->status.account_id )
  14614. return; // Incorrect values
  14615. if( result == 0 )
  14616. return; // Rejected
  14617. pc_adoption(p1_sd, p2_sd, sd);
  14618. }
  14619. /// Convex Mirror (ZC_BOSS_INFO).
  14620. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14621. /// infoType:
  14622. /// BOSS_INFO_NOT = No boss on this map.
  14623. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14624. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14625. /// BOSS_INFO_DEAD = Boss is dead.
  14626. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14627. {
  14628. int fd = sd->fd;
  14629. WFIFOHEAD(fd,70);
  14630. memset(WFIFOP(fd,0),0,70);
  14631. WFIFOW(fd,0) = 0x293;
  14632. switch (flag) {
  14633. case BOSS_INFO_NOT:
  14634. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14635. // No data required
  14636. break;
  14637. case BOSS_INFO_ALIVE:
  14638. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14639. // Update X/Y
  14640. WFIFOL(fd,3) = md->bl.x;
  14641. WFIFOL(fd,7) = md->bl.y;
  14642. break;
  14643. case BOSS_INFO_ALIVE_WITHMSG:
  14644. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14645. // Current X/Y
  14646. WFIFOL(fd,3) = md->bl.x;
  14647. WFIFOL(fd,7) = md->bl.y;
  14648. break;
  14649. case BOSS_INFO_DEAD:
  14650. {
  14651. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14652. unsigned int seconds;
  14653. int hours, minutes;
  14654. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14655. hours = seconds / (60 * 60);
  14656. seconds = seconds - (60 * 60 * hours);
  14657. minutes = seconds / 60;
  14658. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14659. // Add respawn info
  14660. WFIFOW(fd,11) = hours; // Hours
  14661. WFIFOW(fd,13) = minutes; // Minutes
  14662. }
  14663. break;
  14664. }
  14665. if (md != NULL)
  14666. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14667. WFIFOSET(fd,70);
  14668. }
  14669. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14670. /// 02d6 <account id>.L
  14671. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14672. {
  14673. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14674. struct map_session_data* tsd = map_id2sd(aid);
  14675. if (!tsd)
  14676. return;
  14677. if (sd->bl.m != tsd->bl.m)
  14678. return;
  14679. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14680. clif_viewequip_ack(sd, tsd);
  14681. else
  14682. clif_msg(sd, VIEW_EQUIP_FAIL);
  14683. }
  14684. /// Request to a configuration.
  14685. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14686. /// type: see enum e_config_type
  14687. /// flag:
  14688. /// false = disabled
  14689. /// true = enabled
  14690. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14691. int cmd = RFIFOW(fd,0);
  14692. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14693. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14694. switch( type ){
  14695. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14696. sd->status.show_equip = flag;
  14697. break;
  14698. case CONFIG_CALL:
  14699. sd->status.disable_call = flag;
  14700. break;
  14701. case CONFIG_PET_AUTOFEED:
  14702. // Player can not click this if he does not have a pet
  14703. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14704. return;
  14705. }
  14706. sd->pd->pet.autofeed = flag;
  14707. break;
  14708. case CONFIG_HOMUNCULUS_AUTOFEED:
  14709. // Player can not click this if he does not have a homunculus or it is vaporized
  14710. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14711. return;
  14712. }
  14713. sd->hd->homunculus.autofeed = flag;
  14714. break;
  14715. default:
  14716. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14717. return;
  14718. }
  14719. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14720. }
  14721. /// Request to change party invitation tick.
  14722. /// value:
  14723. /// 0 = disabled
  14724. /// 1 = enabled
  14725. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14726. {
  14727. bool flag = RFIFOB(fd,6) ? true : false;
  14728. sd->status.allow_party = flag;
  14729. clif_partytickack(sd, flag);
  14730. }
  14731. /// Questlog System [Kevin] [Inkfish]
  14732. ///
  14733. /**
  14734. * Safe check to init packet len & quest num for player.
  14735. * @param def_len
  14736. * @param info_len Length of each quest info.
  14737. * @param avail_quests Avail quests that player has.
  14738. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14739. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14740. **/
  14741. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14742. (*limit_out) = (0xFFFF - def_len) / info_len;
  14743. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14744. (*len_out) = ((*limit_out) * info_len) + def_len;
  14745. }
  14746. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14747. std::string race_name;
  14748. switch( objective->race ){
  14749. case RC_FORMLESS: race_name = "Formless"; break;
  14750. case RC_UNDEAD: race_name = "Undead"; break;
  14751. case RC_BRUTE: race_name = "Brute"; break;
  14752. case RC_PLANT: race_name = "Plant"; break;
  14753. case RC_INSECT: race_name = "Insect"; break;
  14754. case RC_FISH: race_name = "Fish"; break;
  14755. case RC_DEMON: race_name = "Demon"; break;
  14756. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14757. case RC_ANGEL: race_name = "Angel"; break;
  14758. case RC_DRAGON: race_name = "Dragon"; break;
  14759. default:
  14760. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14761. // Fallthrough
  14762. case RC_ALL: race_name = ""; break;
  14763. }
  14764. std::string size_name;
  14765. switch( objective->size ){
  14766. case SZ_SMALL: size_name = "Small"; break;
  14767. case SZ_MEDIUM: size_name = "Medium"; break;
  14768. case SZ_BIG: size_name = "Large"; break;
  14769. default:
  14770. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14771. // Fallthrough
  14772. case SZ_ALL: size_name = ""; break;
  14773. }
  14774. std::string ele_name;
  14775. switch( objective->element ){
  14776. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14777. case ELE_WATER: ele_name = "Water Element"; break;
  14778. case ELE_EARTH: ele_name = "Earth Element"; break;
  14779. case ELE_FIRE: ele_name = "Fire Element"; break;
  14780. case ELE_WIND: ele_name = "Wind Element"; break;
  14781. case ELE_POISON: ele_name = "Poison Element"; break;
  14782. case ELE_HOLY: ele_name = "Holy Element"; break;
  14783. case ELE_DARK: ele_name = "Shadow Element"; break;
  14784. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14785. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14786. default:
  14787. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14788. // Fallthrough
  14789. case ELE_ALL: ele_name = ""; break;
  14790. }
  14791. std::string str;
  14792. if( !objective->map_name.empty() ){
  14793. str += objective->map_name;
  14794. }
  14795. if( !race_name.empty() ){
  14796. if( !str.empty() ){
  14797. str += ", ";
  14798. }
  14799. str += race_name;
  14800. }
  14801. if( !size_name.empty() ){
  14802. if( !str.empty() ){
  14803. str += ", ";
  14804. }
  14805. str += size_name;
  14806. }
  14807. if( !ele_name.empty() ){
  14808. if( !str.empty() ){
  14809. str += ", ";
  14810. }
  14811. str += ele_name;
  14812. }
  14813. return str;
  14814. }
  14815. /// Sends list of all quest states
  14816. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14817. /// 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)
  14818. /// 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)
  14819. void clif_quest_send_list(struct map_session_data *sd)
  14820. {
  14821. nullpo_retv(sd);
  14822. int fd = sd->fd;
  14823. int i;
  14824. int offset = 8;
  14825. int limit = 0;
  14826. #if PACKETVER >= 20141022
  14827. #if PACKETVER >= 20150513
  14828. int size = 22 + NAME_LENGTH;
  14829. #else
  14830. int size = 10 + NAME_LENGTH;
  14831. #endif
  14832. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14833. WFIFOHEAD(fd,i);
  14834. #if PACKETVER >= 20150513
  14835. WFIFOW(fd, 0) = 0x9f8;
  14836. #else
  14837. WFIFOW(fd, 0) = 0x97a;
  14838. #endif
  14839. WFIFOL(fd, 4) = limit;
  14840. for (i = 0; i < limit; i++) {
  14841. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14842. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14843. offset += 4;
  14844. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14845. offset++;
  14846. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14847. offset += 4;
  14848. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14849. offset += 4;
  14850. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14851. offset += 2;
  14852. if (!qi->objectives.empty()) {
  14853. std::shared_ptr<s_mob_db> mob;
  14854. for (int j = 0; j < qi->objectives.size(); j++) {
  14855. mob = mob_db.find(qi->objectives[j]->mob_id);
  14856. e_race race = qi->objectives[j]->race;
  14857. e_size size = qi->objectives[j]->size;
  14858. e_element element = qi->objectives[j]->element;
  14859. #if PACKETVER >= 20150513
  14860. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14861. offset += 4;
  14862. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14863. offset += 4;
  14864. #endif
  14865. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14866. offset += 4;
  14867. #if PACKETVER >= 20150513
  14868. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14869. offset += 2;
  14870. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14871. offset += 2;
  14872. #endif
  14873. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14874. offset += 2;
  14875. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14876. offset += 2;
  14877. if (mob && qi->objectives[j]->mob_id > 0)
  14878. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14879. else
  14880. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14881. offset += NAME_LENGTH;
  14882. }
  14883. }
  14884. }
  14885. WFIFOW(fd, 2) = offset;
  14886. WFIFOSET(fd, offset);
  14887. #else
  14888. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14889. WFIFOHEAD(fd,i);
  14890. WFIFOW(fd, 0) = 0x2b1;
  14891. WFIFOL(fd, 4) = limit;
  14892. for (i = 0; i < limit; i++) {
  14893. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14894. offset += 4;
  14895. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14896. offset += 1;
  14897. }
  14898. WFIFOW(fd, 2) = offset;
  14899. WFIFOSET(fd, offset);
  14900. #endif
  14901. }
  14902. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14903. /// 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
  14904. void clif_quest_send_mission(struct map_session_data *sd)
  14905. {
  14906. nullpo_retv(sd);
  14907. int fd = sd->fd;
  14908. int limit = 0;
  14909. int len = sd->avail_quests*104+8;
  14910. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14911. WFIFOHEAD(fd, len);
  14912. WFIFOW(fd, 0) = 0x2b2;
  14913. WFIFOW(fd, 2) = len;
  14914. WFIFOL(fd, 4) = limit;
  14915. for (int i = 0; i < limit; i++) {
  14916. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14917. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14918. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14919. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14920. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14921. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14922. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14923. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14924. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14925. if (mob && qi->objectives[j]->mob_id > 0)
  14926. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14927. else
  14928. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14929. }
  14930. }
  14931. WFIFOSET(fd, len);
  14932. }
  14933. /// Notification about a new quest
  14934. /// 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)
  14935. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14936. /// 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)
  14937. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14938. {
  14939. nullpo_retv(sd);
  14940. nullpo_retv(qd);
  14941. int fd = sd->fd;
  14942. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14943. if (!qi)
  14944. return;
  14945. #if PACKETVER >= 20150513
  14946. int cmd = 0x9f9;
  14947. #else
  14948. int cmd = 0x2b3;
  14949. #endif
  14950. WFIFOHEAD(fd, packet_len(cmd));
  14951. WFIFOW(fd, 0) = cmd;
  14952. WFIFOL(fd, 2) = qd->quest_id;
  14953. WFIFOB(fd, 6) = qd->state;
  14954. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14955. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14956. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14957. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14958. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14959. e_race race = qi->objectives[i]->race;
  14960. e_size size = qi->objectives[i]->size;
  14961. e_element element = qi->objectives[i]->element;
  14962. #if PACKETVER >= 20150513
  14963. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14964. offset += 4;
  14965. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14966. offset += 4;
  14967. #endif
  14968. 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
  14969. offset += 4;
  14970. #if PACKETVER >= 20150513
  14971. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14972. offset += 2;
  14973. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14974. offset += 2;
  14975. #endif
  14976. WFIFOW(fd, offset) = qd->count[i];
  14977. offset += 2;
  14978. if (mob && qi->objectives[i]->mob_id > 0)
  14979. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14980. else
  14981. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14982. offset += NAME_LENGTH;
  14983. }
  14984. WFIFOSET(fd, packet_len(cmd));
  14985. #if PACKETVER >= 20150513
  14986. int len = 4 + qi->objectives.size() * 12;
  14987. WFIFOHEAD(fd, len);
  14988. WFIFOW(fd, 0) = 0x8fe;
  14989. WFIFOW(fd, 2) = len;
  14990. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14991. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14992. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14993. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14994. WFIFOW(fd, offset + 10) = qd->count[i];
  14995. }
  14996. WFIFOSET(fd, len);
  14997. #endif
  14998. }
  14999. /// Notification about a quest being removed (ZC_DEL_QUEST).
  15000. /// 02b4 <quest id>.L
  15001. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  15002. {
  15003. int fd = sd->fd;
  15004. WFIFOHEAD(fd, packet_len(0x2b4));
  15005. WFIFOW(fd, 0) = 0x2b4;
  15006. WFIFOL(fd, 2) = quest_id;
  15007. WFIFOSET(fd, packet_len(0x2b4));
  15008. }
  15009. /// Notification of an update to the hunting mission counter
  15010. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  15011. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  15012. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  15013. {
  15014. int fd = sd->fd;
  15015. int offset = 6;
  15016. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  15017. int len = qi->objectives.size() * 12 + 6;
  15018. #if PACKETVER >= 20150513
  15019. int cmd = 0x9fa;
  15020. #else
  15021. int cmd = 0x2b5;
  15022. #endif
  15023. WFIFOHEAD(fd, len);
  15024. WFIFOW(fd, 0) = cmd;
  15025. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  15026. for (int i = 0; i < qi->objectives.size(); i++) {
  15027. WFIFOL(fd, offset) = qd->quest_id;
  15028. offset += 4;
  15029. #if PACKETVER >= 20150513
  15030. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15031. offset += 4;
  15032. #else
  15033. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  15034. offset += 4;
  15035. #endif
  15036. WFIFOW(fd, offset) = qi->objectives[i]->count;
  15037. offset += 2;
  15038. WFIFOW(fd, offset) = qd->count[i];
  15039. offset += 2;
  15040. }
  15041. WFIFOW(fd, 2) = offset;
  15042. WFIFOSET(fd, offset);
  15043. }
  15044. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  15045. /// 02b6 <quest id>.L <active>.B
  15046. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  15047. {
  15048. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15049. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  15050. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  15051. }
  15052. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  15053. /// 02b7 <quest id>.L <active>.B
  15054. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  15055. {
  15056. int fd = sd->fd;
  15057. WFIFOHEAD(fd, packet_len(0x2b7));
  15058. WFIFOW(fd, 0) = 0x2b7;
  15059. WFIFOL(fd, 2) = quest_id;
  15060. WFIFOB(fd, 6) = active;
  15061. WFIFOSET(fd, packet_len(0x2b7));
  15062. }
  15063. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  15064. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  15065. /// effect:
  15066. /// 0 = none
  15067. /// 1 = exclamation mark icon
  15068. /// 2 = question mark icon
  15069. /// color:
  15070. /// 0 = yellow
  15071. /// 1 = orange
  15072. /// 2 = green
  15073. /// 3 = purple
  15074. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  15075. {
  15076. #if PACKETVER >= 20090218
  15077. nullpo_retv(sd);
  15078. nullpo_retv(bl);
  15079. int fd = sd->fd;
  15080. WFIFOHEAD(fd, packet_len(0x446));
  15081. WFIFOW(fd, 0) = 0x446;
  15082. WFIFOL(fd, 2) = bl->id;
  15083. WFIFOW(fd, 6) = bl->x;
  15084. WFIFOW(fd, 8) = bl->y;
  15085. WFIFOW(fd, 10) = effect;
  15086. WFIFOW(fd, 12) = color;
  15087. WFIFOSET(fd, packet_len(0x446));
  15088. #endif
  15089. }
  15090. /// Mercenary System
  15091. ///
  15092. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  15093. /// 02a2 <var id>.W <value>.L
  15094. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  15095. {
  15096. s_mercenary_data *md;
  15097. struct status_data *status;
  15098. int fd;
  15099. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15100. return;
  15101. fd = sd->fd;
  15102. status = &md->battle_status;
  15103. WFIFOHEAD(fd,packet_len(0x2a2));
  15104. WFIFOW(fd,0) = 0x2a2;
  15105. WFIFOW(fd,2) = type;
  15106. switch( type ) {
  15107. case SP_ATK1:
  15108. {
  15109. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15110. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15111. }
  15112. break;
  15113. case SP_MATK1:
  15114. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15115. break;
  15116. case SP_HIT:
  15117. WFIFOL(fd,4) = status->hit;
  15118. break;
  15119. case SP_CRITICAL:
  15120. WFIFOL(fd,4) = status->cri/10;
  15121. break;
  15122. case SP_DEF1:
  15123. WFIFOL(fd,4) = status->def;
  15124. break;
  15125. case SP_MDEF1:
  15126. WFIFOL(fd,4) = status->mdef;
  15127. break;
  15128. case SP_MERCFLEE:
  15129. WFIFOL(fd,4) = status->flee;
  15130. break;
  15131. case SP_ASPD:
  15132. WFIFOL(fd,4) = status->amotion;
  15133. break;
  15134. case SP_HP:
  15135. WFIFOL(fd,4) = status->hp;
  15136. break;
  15137. case SP_MAXHP:
  15138. WFIFOL(fd,4) = status->max_hp;
  15139. break;
  15140. case SP_SP:
  15141. WFIFOL(fd,4) = status->sp;
  15142. break;
  15143. case SP_MAXSP:
  15144. WFIFOL(fd,4) = status->max_sp;
  15145. break;
  15146. case SP_MERCKILLS:
  15147. WFIFOL(fd,4) = md->mercenary.kill_count;
  15148. break;
  15149. case SP_MERCFAITH:
  15150. WFIFOL(fd,4) = mercenary_get_faith(md);
  15151. break;
  15152. }
  15153. WFIFOSET(fd,packet_len(0x2a2));
  15154. }
  15155. /// Mercenary base status data (ZC_MER_INIT).
  15156. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15157. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15158. /// <calls>.L <kills>.L <atk range>.W
  15159. void clif_mercenary_info(struct map_session_data *sd)
  15160. {
  15161. int fd;
  15162. s_mercenary_data *md;
  15163. struct status_data *status;
  15164. int atk;
  15165. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15166. return;
  15167. fd = sd->fd;
  15168. status = &md->battle_status;
  15169. WFIFOHEAD(fd,packet_len(0x29b));
  15170. WFIFOW(fd,0) = 0x29b;
  15171. WFIFOL(fd,2) = md->bl.id;
  15172. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15173. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15174. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15175. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15176. WFIFOW(fd,10) = status->hit;
  15177. WFIFOW(fd,12) = status->cri/10;
  15178. WFIFOW(fd,14) = status->def;
  15179. WFIFOW(fd,16) = status->mdef;
  15180. WFIFOW(fd,18) = status->flee;
  15181. WFIFOW(fd,20) = status->amotion;
  15182. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15183. WFIFOW(fd,46) = md->db->lv;
  15184. WFIFOL(fd,48) = status->hp;
  15185. WFIFOL(fd,52) = status->max_hp;
  15186. WFIFOL(fd,56) = status->sp;
  15187. WFIFOL(fd,60) = status->max_sp;
  15188. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15189. WFIFOW(fd,68) = mercenary_get_faith(md);
  15190. WFIFOL(fd,70) = mercenary_get_calls(md);
  15191. WFIFOL(fd,74) = md->mercenary.kill_count;
  15192. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15193. WFIFOSET(fd,packet_len(0x29b));
  15194. }
  15195. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15196. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15197. void clif_mercenary_skillblock(struct map_session_data *sd)
  15198. {
  15199. s_mercenary_data *md;
  15200. int fd, len = 4;
  15201. if( sd == NULL || (md = sd->md) == NULL )
  15202. return;
  15203. fd = sd->fd;
  15204. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15205. WFIFOW(fd,0) = 0x29d;
  15206. for (const auto &it : md->db->skill) {
  15207. uint16 id = it.first;
  15208. if (!SKILL_CHK_MERC(id))
  15209. continue;
  15210. uint16 lv = it.second;
  15211. WFIFOW(fd,len) = id;
  15212. WFIFOL(fd,len+2) = skill_get_inf(id);
  15213. WFIFOW(fd,len+6) = lv;
  15214. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15215. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15216. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15217. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15218. len += 37;
  15219. }
  15220. WFIFOW(fd,2) = len;
  15221. WFIFOSET(fd,len);
  15222. }
  15223. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15224. /// 029f <command>.B
  15225. /// 1 = mercenary information
  15226. /// 2 = delete
  15227. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  15228. {
  15229. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15230. if( sd->md == NULL )
  15231. return;
  15232. if( option == 2 ) mercenary_delete(sd->md, 2);
  15233. }
  15234. /// Mercenary Message
  15235. /// message:
  15236. /// 0 = Mercenary soldier's duty hour is over.
  15237. /// 1 = Your mercenary soldier has been killed.
  15238. /// 2 = Your mercenary soldier has been fired.
  15239. /// 3 = Your mercenary soldier has ran away.
  15240. void clif_mercenary_message(struct map_session_data* sd, int message){
  15241. clif_msg(sd, MERC_MSG_BASE + message);
  15242. }
  15243. /// Notification about the remaining time of a rental item.
  15244. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15245. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  15246. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15247. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15248. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15249. p.itemId = client_nameid( nameid );
  15250. p.seconds = seconds;
  15251. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15252. }
  15253. /// Deletes a rental item from client's inventory.
  15254. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15255. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  15256. // '<ItemName>' item has been deleted from the Inventory
  15257. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15258. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15259. p.index = client_index( index );
  15260. p.itemId = client_nameid( nameid );
  15261. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15262. }
  15263. /// Book Reading (ZC_READ_BOOK).
  15264. /// 0294 <book id>.L <page>.L
  15265. void clif_readbook(int fd, int book_id, int page)
  15266. {
  15267. WFIFOHEAD(fd,packet_len(0x294));
  15268. WFIFOW(fd,0) = 0x294;
  15269. WFIFOL(fd,2) = book_id;
  15270. WFIFOL(fd,6) = page;
  15271. WFIFOSET(fd,packet_len(0x294));
  15272. }
  15273. /// Battlegrounds
  15274. ///
  15275. /// Updates HP bar of a camp member.
  15276. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15277. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15278. void clif_bg_hp(struct map_session_data *sd) {
  15279. #if PACKETVER < 20140613
  15280. unsigned char buf[34];
  15281. const int cmd = 0x2e0;
  15282. #else
  15283. unsigned char buf[14];
  15284. const int cmd = 0xa0e;
  15285. #endif
  15286. nullpo_retv(sd);
  15287. WBUFW(buf,0) = cmd;
  15288. WBUFL(buf,2) = sd->status.account_id;
  15289. #if PACKETVER < 20140613
  15290. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15291. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15292. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15293. WBUFW(buf,32) = 100;
  15294. } else {
  15295. WBUFW(buf,30) = sd->battle_status.hp;
  15296. WBUFW(buf,32) = sd->battle_status.max_hp;
  15297. }
  15298. #else
  15299. if( sd->battle_status.max_hp > INT32_MAX ) {
  15300. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15301. WBUFL(buf,10) = 100;
  15302. } else {
  15303. WBUFL(buf,6) = sd->battle_status.hp;
  15304. WBUFL(buf,10) = sd->battle_status.max_hp;
  15305. }
  15306. #endif
  15307. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15308. }
  15309. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15310. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15311. void clif_bg_xy(struct map_session_data *sd)
  15312. {
  15313. unsigned char buf[36];
  15314. nullpo_retv(sd);
  15315. WBUFW(buf,0)=0x2df;
  15316. WBUFL(buf,2)=sd->status.account_id;
  15317. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15318. WBUFW(buf,30)=sd->status.class_;
  15319. WBUFW(buf,32)=sd->bl.x;
  15320. WBUFW(buf,34)=sd->bl.y;
  15321. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15322. }
  15323. void clif_bg_xy_remove(struct map_session_data *sd)
  15324. {
  15325. unsigned char buf[36];
  15326. nullpo_retv(sd);
  15327. WBUFW(buf,0)=0x2df;
  15328. WBUFL(buf,2)=sd->status.account_id;
  15329. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15330. WBUFW(buf,30)=0;
  15331. WBUFW(buf,32)=-1;
  15332. WBUFW(buf,34)=-1;
  15333. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15334. }
  15335. /// Notifies clients of a battleground message.
  15336. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15337. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15338. struct map_session_data *sd = bg_getavailablesd( bg );
  15339. if( sd == nullptr ){
  15340. return;
  15341. }
  15342. // limit length
  15343. len = min( len + 1, CHAT_SIZE_MAX );
  15344. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15345. WBUFW(buf,0) = 0x2dc;
  15346. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15347. WBUFL(buf,4) = src_id;
  15348. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15349. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15350. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15351. }
  15352. /// Validates and processes battlechat messages.
  15353. /// All messages that are sent after enabling battleground chat with /battlechat.
  15354. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15355. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15356. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15357. if( !clif_process_message( sd, false, name, message, output ) )
  15358. return;
  15359. bg_send_message(sd, output, strlen(output) );
  15360. }
  15361. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15362. /// 02de <camp A points>.W <camp B points>.W
  15363. void clif_bg_updatescore(int16 m)
  15364. {
  15365. struct block_list bl;
  15366. unsigned char buf[6];
  15367. struct map_data *mapdata = map_getmapdata(m);
  15368. bl.id = 0;
  15369. bl.type = BL_NUL;
  15370. bl.m = m;
  15371. WBUFW(buf,0) = 0x2de;
  15372. WBUFW(buf,2) = mapdata->bgscore_lion;
  15373. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15374. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15375. }
  15376. void clif_bg_updatescore_single(struct map_session_data *sd)
  15377. {
  15378. int fd;
  15379. nullpo_retv(sd);
  15380. fd = sd->fd;
  15381. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15382. WFIFOHEAD(fd,packet_len(0x2de));
  15383. WFIFOW(fd,0) = 0x2de;
  15384. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15385. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15386. WFIFOSET(fd,packet_len(0x2de));
  15387. }
  15388. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15389. /// 02dd <account id>.L <name>.24B <camp>.W
  15390. void clif_sendbgemblem_area(struct map_session_data *sd)
  15391. {
  15392. unsigned char buf[33];
  15393. nullpo_retv(sd);
  15394. WBUFW(buf, 0) = 0x2dd;
  15395. WBUFL(buf,2) = sd->bl.id;
  15396. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15397. WBUFW(buf,30) = sd->bg_id;
  15398. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15399. }
  15400. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15401. {
  15402. nullpo_retv(sd);
  15403. WFIFOHEAD(fd,32);
  15404. WFIFOW(fd,0) = 0x2dd;
  15405. WFIFOL(fd,2) = sd->bl.id;
  15406. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15407. WFIFOW(fd,30) = sd->bg_id;
  15408. WFIFOSET(fd,packet_len(0x2dd));
  15409. }
  15410. /// Battlegrounds queue incoming apply request from client.
  15411. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15412. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15413. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15414. {
  15415. if (!battle_config.feature_bgqueue)
  15416. return;
  15417. nullpo_retv(sd);
  15418. short type = RFIFOW(fd,2);
  15419. char name[NAME_LENGTH];
  15420. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15421. if (sd->bg_queue_id > 0) {
  15422. //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);
  15423. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15424. return;
  15425. } else if (type == 1) // Solo
  15426. bg_queue_join_solo(name, sd);
  15427. else if (type == 2) // Party
  15428. bg_queue_join_party(name, sd);
  15429. else if (type == 4) // Guild
  15430. bg_queue_join_guild(name, sd);
  15431. else {
  15432. 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);
  15433. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15434. return;
  15435. }
  15436. }
  15437. /// Outgoing battlegrounds queue apply result.
  15438. /// Result types: @see e_bg_queue_apply_ack
  15439. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15440. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15441. {
  15442. nullpo_retv(sd);
  15443. int fd = sd->fd;
  15444. WFIFOHEAD(fd, packet_len(0x8d8));
  15445. WFIFOW(fd,0) = 0x8d8;
  15446. WFIFOB(fd,2) = result;
  15447. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15448. WFIFOSET(fd, packet_len(0x8d8));
  15449. }
  15450. /// Outgoing battlegrounds queue apply notification.
  15451. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15452. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15453. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15454. {
  15455. nullpo_retv(sd);
  15456. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15457. if (queue == nullptr) {
  15458. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15459. return;
  15460. }
  15461. int fd = sd->fd;
  15462. WFIFOHEAD(fd, packet_len(0x8d9));
  15463. WFIFOW(fd,0) = 0x8d9;
  15464. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15465. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15466. WFIFOSET(fd, packet_len(0x8d9));
  15467. }
  15468. /// Battlegrounds queue outgoing cancel result.
  15469. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15470. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15471. {
  15472. nullpo_retv(sd);
  15473. int fd = sd->fd;
  15474. WFIFOHEAD(fd, packet_len(0x8d8));
  15475. WFIFOW(fd,0) = 0x8db;
  15476. WFIFOB(fd,2) = success;
  15477. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15478. WFIFOSET(fd, packet_len(0x8d8));
  15479. }
  15480. /// Battlegrounds queue incoming cancel request from client.
  15481. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15482. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15483. {
  15484. if (!battle_config.feature_bgqueue)
  15485. return;
  15486. nullpo_retv(sd);
  15487. bool success;
  15488. if (sd->bg_queue_id > 0) {
  15489. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15490. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15491. 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.
  15492. else
  15493. success = bg_queue_leave(sd);
  15494. } else {
  15495. 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);
  15496. success = false;
  15497. }
  15498. char name[NAME_LENGTH];
  15499. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15500. clif_bg_queue_cancel_result(success, name, sd);
  15501. }
  15502. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15503. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15504. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15505. {
  15506. nullpo_retv(sd);
  15507. int fd = sd->fd;
  15508. WFIFOHEAD(fd, packet_len(0x8df));
  15509. WFIFOW(fd,0) = 0x8df;
  15510. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15511. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15512. WFIFOSET(fd, packet_len(0x8df));
  15513. }
  15514. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15515. /// Result types: 1(Accept), 2(Decline).
  15516. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15517. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15518. {
  15519. nullpo_retv(sd);
  15520. if(sd->bg_queue_id > 0) {
  15521. uint8 result = RFIFOB(fd, 2);
  15522. if(result == 1) { // Accept
  15523. bg_queue_on_accept_invite(sd);
  15524. } else if(result == 2) { // Decline
  15525. bg_queue_leave(sd);
  15526. clif_bg_queue_entry_init(sd);
  15527. }
  15528. }
  15529. }
  15530. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15531. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15532. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15533. {
  15534. nullpo_retv(sd);
  15535. int fd = sd->fd;
  15536. WFIFOHEAD(fd, packet_len(0x8e1));
  15537. WFIFOW(fd,0) = 0x8e1;
  15538. WFIFOB(fd,2) = result;
  15539. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15540. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15541. WFIFOSET(fd, packet_len(0x8e1));
  15542. }
  15543. /// Battlegrounds queue incoming queue number request from client.
  15544. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15545. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15546. {
  15547. nullpo_retv(sd);
  15548. char name[NAME_LENGTH];
  15549. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15550. clif_bg_queue_apply_notify(name, sd);
  15551. }
  15552. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15553. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15554. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15555. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15556. {
  15557. nullpo_retv(sd);
  15558. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15559. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15560. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15561. }
  15562. /// Custom Fonts (ZC_NOTIFY_FONT).
  15563. /// 02ef <account_id>.L <font id>.W
  15564. void clif_font(struct map_session_data *sd)
  15565. {
  15566. #if PACKETVER >= 20080102
  15567. unsigned char buf[8];
  15568. nullpo_retv(sd);
  15569. WBUFW(buf,0) = 0x2ef;
  15570. WBUFL(buf,2) = sd->bl.id;
  15571. WBUFW(buf,6) = sd->status.font;
  15572. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15573. #endif
  15574. }
  15575. /// Required to start the instancing information window on Client
  15576. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15577. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15578. void clif_instance_create(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[65];
  15584. instance_getsd(instance_id, sd, &target);
  15585. if (!sd)
  15586. return;
  15587. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15588. if (!db)
  15589. return;
  15590. WBUFW(buf,0) = 0x2cb;
  15591. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15592. WBUFW(buf,63) = num;
  15593. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15594. #endif
  15595. return;
  15596. }
  15597. /// To announce Instancing queue creation if no maps available
  15598. /// S 0x2cc <Standby Position>.W
  15599. void clif_instance_changewait(int instance_id, int num)
  15600. {
  15601. #if PACKETVER >= 20071128
  15602. struct map_session_data *sd = NULL;
  15603. enum send_target target = PARTY;
  15604. unsigned char buf[4];
  15605. instance_getsd(instance_id, sd, &target);
  15606. if (!sd)
  15607. return;
  15608. WBUFW(buf,0) = 0x2cc;
  15609. WBUFW(buf,2) = num;
  15610. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15611. #endif
  15612. return;
  15613. }
  15614. /// Notify the current status to members
  15615. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15616. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15617. {
  15618. #if PACKETVER >= 20071128
  15619. struct map_session_data *sd = NULL;
  15620. enum send_target target = PARTY;
  15621. unsigned char buf[71];
  15622. instance_getsd(instance_id, sd, &target);
  15623. if (!sd)
  15624. return;
  15625. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15626. if (!db)
  15627. return;
  15628. WBUFW(buf,0) = 0x2cd;
  15629. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15630. WBUFL(buf,63) = limit1;
  15631. WBUFL(buf,67) = limit2;
  15632. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15633. #endif
  15634. return;
  15635. }
  15636. /// Notify a status change to members
  15637. /// S 0x2ce <Message ID>.L
  15638. /// 0 = Notification (EnterLimitDate update?)
  15639. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15640. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15641. /// 3 = The Memorial Dungeon has been removed.
  15642. /// 4 = Create failure (removes the instance window)
  15643. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15644. {
  15645. #if PACKETVER >= 20071128
  15646. struct map_session_data *sd = NULL;
  15647. enum send_target target = PARTY;
  15648. unsigned char buf[10];
  15649. instance_getsd(instance_id, sd, &target);
  15650. if (!sd)
  15651. return;
  15652. WBUFW(buf,0) = 0x2ce;
  15653. WBUFL(buf,2) = type;
  15654. WBUFL(buf,6) = limit;
  15655. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15656. #endif
  15657. return;
  15658. }
  15659. /// Destroy an instance from the status window
  15660. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15661. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15662. {
  15663. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15664. return;
  15665. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15666. switch (p->command) {
  15667. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15668. instance_destroy_command(sd);
  15669. break;
  15670. }
  15671. }
  15672. /// Notifies clients about item picked up by a party member.
  15673. /// 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)
  15674. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15675. #if PACKETVER >= 20071002
  15676. nullpo_retv( sd );
  15677. nullpo_retv( item_data );
  15678. struct item_data* id = itemdb_search( item_data->nameid );
  15679. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15680. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15681. p.AID = sd->status.account_id;
  15682. p.itemId = client_nameid( item_data->nameid );
  15683. p.identified = item_data->identify;
  15684. p.damaged = item_data->attribute;
  15685. p.refine = item_data->refine;
  15686. clif_addcards( &p.slot, item_data );
  15687. p.location = id->equip; // equip location
  15688. p.itemType = itemtype( id->nameid ); // item type
  15689. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15690. p.enchantgrade = item_data->enchantgrade;
  15691. #endif
  15692. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15693. #endif
  15694. }
  15695. /** Display gained exp.
  15696. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15697. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15698. * amount: INT32_MIN ~ INT32_MAX
  15699. * var id:
  15700. * SP_BASEEXP, SP_JOBEXP
  15701. * exp type:
  15702. * 0 = normal exp gained/lost
  15703. * 1 = quest exp gained/lost
  15704. * @param sd Player
  15705. * @param exp EXP value gained/loss
  15706. * @param type SP_BASEEXP, SP_JOBEXP
  15707. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15708. * @param lost True:if losing EXP
  15709. */
  15710. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15711. {
  15712. int fd;
  15713. int offset;
  15714. #if PACKETVER >= 20170830
  15715. int cmd = 0xacc;
  15716. #else
  15717. int cmd = 0x7f6;
  15718. #endif
  15719. nullpo_retv(sd);
  15720. fd = sd->fd;
  15721. WFIFOHEAD(fd, packet_len(cmd));
  15722. WFIFOW(fd,0) = cmd;
  15723. WFIFOL(fd,2) = sd->bl.id;
  15724. #if PACKETVER >= 20170830
  15725. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15726. offset = 4;
  15727. #else
  15728. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15729. offset = 0;
  15730. #endif
  15731. WFIFOW(fd,10+offset) = type;
  15732. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15733. WFIFOSET(fd,packet_len(cmd));
  15734. }
  15735. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15736. /// type:
  15737. /// 0 = Displays 'value' for 5 seconds.
  15738. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15739. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15740. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15741. /// value:
  15742. /// 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).
  15743. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15744. {
  15745. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15746. WFIFOW(sd->fd,0) = 0x1b1;
  15747. WFIFOB(sd->fd,2) = type;
  15748. WFIFOL(sd->fd,3) = value;
  15749. WFIFOSET(sd->fd, packet_len(0x1b1));
  15750. }
  15751. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15752. /// 021d <state>.L
  15753. /// state:
  15754. /// 0 = Full effects
  15755. /// 1 = Reduced effects
  15756. ///
  15757. /// NOTE: The state is used on Aegis for sending skill unit packet
  15758. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15759. /// whenever possible. Due to the way the decision check is
  15760. /// constructed, this state tracking was rendered useless,
  15761. /// as the only skill unit, that is sent with 0x1c9 is
  15762. /// Graffiti.
  15763. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15764. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15765. sd->state.lesseffect = ( isLess != 0 );
  15766. }
  15767. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15768. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15769. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15770. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15771. int type = RFIFOL(fd,info->pos[1]);
  15772. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15773. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15774. if( sd->state.trading || sd->npc_shopid )
  15775. return;
  15776. if( flag == 0 || n == 0) {
  15777. clif_menuskill_clear(sd);
  15778. return; // Canceled by player.
  15779. }
  15780. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15781. clif_menuskill_clear(sd);
  15782. return; // Prevent hacking.
  15783. }
  15784. switch( type ) {
  15785. case 0: // Change Material
  15786. skill_changematerial(sd,n,item_list);
  15787. break;
  15788. case 1: // Level 1: Pure to Rough
  15789. case 2: // Level 2: Rough to Pure
  15790. skill_elementalanalysis(sd,n,type,item_list);
  15791. break;
  15792. }
  15793. clif_menuskill_clear(sd);
  15794. return;
  15795. }
  15796. /*==========================================
  15797. * Elemental System
  15798. *==========================================*/
  15799. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15800. s_elemental_data *ed;
  15801. struct status_data *status;
  15802. int fd;
  15803. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15804. return;
  15805. fd = sd->fd;
  15806. status = &ed->battle_status;
  15807. WFIFOHEAD(fd,8);
  15808. WFIFOW(fd,0) = 0x81e;
  15809. WFIFOW(fd,2) = type;
  15810. switch( type ) {
  15811. case SP_HP:
  15812. WFIFOL(fd,4) = status->hp;
  15813. break;
  15814. case SP_MAXHP:
  15815. WFIFOL(fd,4) = status->max_hp;
  15816. break;
  15817. case SP_SP:
  15818. WFIFOL(fd,4) = status->sp;
  15819. break;
  15820. case SP_MAXSP:
  15821. WFIFOL(fd,4) = status->max_sp;
  15822. break;
  15823. }
  15824. WFIFOSET(fd,8);
  15825. }
  15826. void clif_elemental_info(struct map_session_data *sd) {
  15827. int fd;
  15828. s_elemental_data *ed;
  15829. struct status_data *status;
  15830. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15831. return;
  15832. fd = sd->fd;
  15833. status = &ed->battle_status;
  15834. WFIFOHEAD(fd,22);
  15835. WFIFOW(fd, 0) = 0x81d;
  15836. WFIFOL(fd, 2) = ed->bl.id;
  15837. WFIFOL(fd, 6) = status->hp;
  15838. WFIFOL(fd,10) = status->max_hp;
  15839. WFIFOL(fd,14) = status->sp;
  15840. WFIFOL(fd,18) = status->max_sp;
  15841. WFIFOSET(fd,22);
  15842. }
  15843. /// Buying Store System
  15844. ///
  15845. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15846. /// 0810 <slots>.B
  15847. void clif_buyingstore_open(struct map_session_data* sd)
  15848. {
  15849. int fd = sd->fd;
  15850. WFIFOHEAD(fd,packet_len(0x810));
  15851. WFIFOW(fd,0) = 0x810;
  15852. WFIFOB(fd,2) = sd->buyingstore.slots;
  15853. WFIFOSET(fd,packet_len(0x810));
  15854. }
  15855. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15856. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15857. /// result:
  15858. /// 0 = cancel
  15859. /// 1 = open
  15860. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15861. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15862. // TODO: Make this check global for all variable length packets.
  15863. // minimum packet length
  15864. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15865. 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 );
  15866. return;
  15867. }
  15868. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15869. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15870. return;
  15871. }
  15872. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15873. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15874. return;
  15875. }
  15876. char storename[MESSAGE_SIZE];
  15877. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15878. // so that buyingstore_create knows, how many elements it has access to
  15879. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15880. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15881. 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 ) );
  15882. return;
  15883. }
  15884. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15885. }
  15886. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15887. /// 0812 <result>.W <total weight>.L
  15888. /// result:
  15889. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15890. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15891. /// 8 = "No sale (purchase) information available." (0x705)
  15892. /// ? = nothing
  15893. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15894. {
  15895. int fd = sd->fd;
  15896. WFIFOHEAD(fd,packet_len(0x812));
  15897. WFIFOW(fd,0) = 0x812;
  15898. WFIFOW(fd,2) = result;
  15899. WFIFOL(fd,4) = weight;
  15900. WFIFOSET(fd,packet_len(0x812));
  15901. }
  15902. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15903. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15904. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15905. nullpo_retv( sd );
  15906. int fd = sd->fd;
  15907. if( !session_isActive( fd ) ){
  15908. return;
  15909. }
  15910. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15911. WFIFOHEAD( fd, length );
  15912. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15913. p->packetType = 0x813;
  15914. p->packetLength = length;
  15915. p->AID = sd->bl.id;
  15916. p->zenyLimit = sd->buyingstore.zenylimit;
  15917. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15918. p->items[i].price = sd->buyingstore.items[i].price;
  15919. p->items[i].amount = sd->buyingstore.items[i].amount;
  15920. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15921. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15922. }
  15923. WFIFOSET( fd, p->packetLength );
  15924. }
  15925. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15926. /// 0814 <account id>.L <store name>.80B
  15927. void clif_buyingstore_entry(struct map_session_data* sd)
  15928. {
  15929. uint8 buf[MESSAGE_SIZE+6];
  15930. WBUFW(buf,0) = 0x814;
  15931. WBUFL(buf,2) = sd->bl.id;
  15932. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15933. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15934. }
  15935. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15936. {
  15937. int fd = sd->fd;
  15938. WFIFOHEAD(fd,packet_len(0x814));
  15939. WFIFOW(fd,0) = 0x814;
  15940. WFIFOL(fd,2) = pl_sd->bl.id;
  15941. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15942. WFIFOSET(fd,packet_len(0x814));
  15943. }
  15944. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15945. /// 0815
  15946. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15947. {
  15948. buyingstore_close(sd);
  15949. }
  15950. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15951. /// 0816 <account id>.L
  15952. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15953. {
  15954. uint8 buf[6];
  15955. WBUFW(buf,0) = 0x816;
  15956. WBUFL(buf,2) = sd->bl.id;
  15957. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15958. }
  15959. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15960. {
  15961. int fd = sd->fd;
  15962. WFIFOHEAD(fd,packet_len(0x816));
  15963. WFIFOW(fd,0) = 0x816;
  15964. WFIFOL(fd,2) = pl_sd->bl.id;
  15965. WFIFOSET(fd,packet_len(0x816));
  15966. }
  15967. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15968. /// 0817 <account id>.L
  15969. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15970. {
  15971. uint32 account_id;
  15972. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15973. buyingstore_open(sd, account_id);
  15974. }
  15975. /// Sends buying store item list.
  15976. /// 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)
  15977. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15978. nullpo_retv( sd );
  15979. nullpo_retv( pl_sd );
  15980. int fd = sd->fd;
  15981. if( !session_isActive( fd ) ){
  15982. return;
  15983. }
  15984. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15985. WFIFOHEAD( fd, length );
  15986. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15987. p->packetType = 0x818;
  15988. p->packetLength = length;
  15989. p->AID = pl_sd->bl.id;
  15990. p->storeId = pl_sd->buyer_id;
  15991. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15992. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15993. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15994. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15995. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15996. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15997. }
  15998. WFIFOSET( fd, p->packetLength );
  15999. }
  16000. /// Request to sell items to a buying store.
  16001. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  16002. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  16003. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  16004. // minimum packet length
  16005. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  16006. 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 );
  16007. return;
  16008. }
  16009. // so that buyingstore_trade knows, how many elements it has access to
  16010. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  16011. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  16012. 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 ) );
  16013. return;
  16014. }
  16015. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  16016. }
  16017. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  16018. /// 081a <result>.W
  16019. /// result:
  16020. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  16021. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  16022. /// ? = nothing
  16023. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  16024. {
  16025. int fd = sd->fd;
  16026. WFIFOHEAD(fd,packet_len(0x81a));
  16027. WFIFOW(fd,0) = 0x81a;
  16028. WFIFOW(fd,2) = result;
  16029. WFIFOSET(fd,packet_len(0x81a));
  16030. }
  16031. /// Updates the zeny limit and an item in the buying store item list.
  16032. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16033. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16034. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16035. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16036. p.packetType = buyingStoreUpdateItemType;
  16037. p.itemId = client_nameid( nameid );
  16038. p.amount = amount;
  16039. p.zenyLimit = sd->buyingstore.zenylimit;
  16040. #if PACKETVER >= 20141016
  16041. p.zeny = zeny;
  16042. p.charId = char_id; // GID
  16043. p.updateTime = (int)time(NULL);
  16044. #endif
  16045. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16046. }
  16047. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16048. /// 081c <index>.W <amount>.W <price>.L
  16049. /// message:
  16050. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16051. ///
  16052. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16053. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  16054. {
  16055. int fd = sd->fd;
  16056. WFIFOHEAD(fd,packet_len(0x81c));
  16057. WFIFOW(fd,0) = 0x81c;
  16058. WFIFOW(fd,2) = client_index( index );
  16059. WFIFOW(fd,4) = amount;
  16060. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16061. WFIFOSET(fd,packet_len(0x81c));
  16062. }
  16063. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16064. /// 0824 <result>.W <name id>.W
  16065. /// result:
  16066. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16067. /// 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)
  16068. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16069. /// ? = nothing
  16070. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  16071. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16072. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16073. p.result = result;
  16074. p.itemId = client_nameid( nameid );
  16075. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16076. }
  16077. /// Search Store Info System
  16078. ///
  16079. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16080. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16081. /// type:
  16082. /// 0 = Vending
  16083. /// 1 = Buying Store
  16084. ///
  16085. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16086. /// amount of card slots. If the client does not know about the item it
  16087. /// cannot be searched.
  16088. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  16089. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16090. // minimum packet length
  16091. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16092. 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 );
  16093. return;
  16094. }
  16095. // check, if there is enough data for the claimed count of items
  16096. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16097. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16098. 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 ) );
  16099. return;
  16100. }
  16101. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16102. if( count < p->itemsCount + p->cardsCount ){
  16103. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16104. return;
  16105. }
  16106. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16107. }
  16108. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16109. /// 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 }*
  16110. /// is first page:
  16111. /// 0 = appends to existing results
  16112. /// 1 = clears previous results before displaying this result set
  16113. /// is next page:
  16114. /// 0 = no "next" label
  16115. /// 1 = "next" label to retrieve more results
  16116. void clif_search_store_info_ack( struct map_session_data* sd ){
  16117. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16118. nullpo_retv( sd );
  16119. int fd = sd->fd;
  16120. if( !session_isActive( fd ) ){
  16121. return;
  16122. }
  16123. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16124. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16125. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16126. WFIFOHEAD( fd, len );
  16127. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16128. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16129. p->packetLength = len;
  16130. p->firstPage = !sd->searchstore.pages;
  16131. p->nextPage = searchstore_querynext( sd );
  16132. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16133. for( int i = 0; i < end - start; i++ ) {
  16134. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16135. p->items[i].storeId = ssitem->store_id;
  16136. p->items[i].AID = ssitem->account_id;
  16137. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16138. p->items[i].itemId = client_nameid( ssitem->nameid );
  16139. p->items[i].itemType = itemtype( ssitem->nameid );
  16140. p->items[i].price = ssitem->price;
  16141. p->items[i].amount = ssitem->amount;
  16142. p->items[i].refine = ssitem->refine;
  16143. // make-up an item for clif_addcards
  16144. struct item it = {};
  16145. for( int j = 0; j < MAX_SLOTS; j++ ){
  16146. it.card[j] = ssitem->card[j];
  16147. }
  16148. it.nameid = ssitem->nameid;
  16149. it.amount = ssitem->amount;
  16150. clif_addcards( &p->items[i].slot, &it );
  16151. #if PACKETVER >= 20150226
  16152. clif_add_random_options( p->items[i].option_data, &it );
  16153. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16154. p->items[i].enchantgrade = ssitem->enchantgrade;
  16155. #endif
  16156. #endif
  16157. }
  16158. WFIFOSET( fd, len );
  16159. #endif
  16160. }
  16161. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16162. /// 0837 <reason>.B
  16163. /// reason:
  16164. /// 0 = "No matching stores were found." (0x70b)
  16165. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16166. /// 2 = "You cannot search anymore." (0x706)
  16167. /// 3 = "You cannot search yet." (0x708)
  16168. /// 4 = "No sale (purchase) information available." (0x705)
  16169. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16170. {
  16171. int fd = sd->fd;
  16172. WFIFOHEAD(fd,packet_len(0x837));
  16173. WFIFOW(fd,0) = 0x837;
  16174. WFIFOB(fd,2) = reason;
  16175. WFIFOSET(fd,packet_len(0x837));
  16176. }
  16177. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16178. /// 0838
  16179. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16180. {
  16181. searchstore_next(sd);
  16182. }
  16183. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16184. /// 083a <type>.W <remaining uses>.B
  16185. /// type:
  16186. /// 0 = Search Stores
  16187. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16188. void clif_open_search_store_info(struct map_session_data* sd)
  16189. {
  16190. int fd = sd->fd;
  16191. WFIFOHEAD(fd,packet_len(0x83a));
  16192. WFIFOW(fd,0) = 0x83a;
  16193. WFIFOW(fd,2) = sd->searchstore.effect;
  16194. #if PACKETVER > 20100701
  16195. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16196. #endif
  16197. WFIFOSET(fd,packet_len(0x83a));
  16198. }
  16199. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16200. /// 083b
  16201. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16202. {
  16203. searchstore_close(sd);
  16204. }
  16205. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16206. /// 083c <account id>.L <store id>.L <nameid>.W
  16207. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16208. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16209. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16210. }
  16211. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16212. /// 083d <xPos>.W <yPos>.W
  16213. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16214. {
  16215. int fd = sd->fd;
  16216. WFIFOHEAD(fd,packet_len(0x83d));
  16217. WFIFOW(fd,0) = 0x83d;
  16218. WFIFOW(fd,2) = x;
  16219. WFIFOW(fd,4) = y;
  16220. WFIFOSET(fd,packet_len(0x83d));
  16221. }
  16222. /// Parse function for packet debugging.
  16223. void clif_parse_debug(int fd,struct map_session_data *sd)
  16224. {
  16225. int cmd, packet_len;
  16226. // clif_parse ensures, that there is at least 2 bytes of data
  16227. cmd = RFIFOW(fd,0);
  16228. if( sd ) {
  16229. packet_len = packet_db[cmd].len;
  16230. if( packet_len == 0 )
  16231. {// unknown
  16232. packet_len = RFIFOREST(fd);
  16233. }
  16234. else if( packet_len == -1 )
  16235. {// variable length
  16236. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16237. }
  16238. 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);
  16239. }
  16240. else
  16241. {
  16242. packet_len = RFIFOREST(fd);
  16243. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16244. }
  16245. ShowDump(RFIFOP(fd,0), packet_len);
  16246. }
  16247. /*==========================================
  16248. * Server tells client to display a window similar to Magnifier (item) one
  16249. * Server populates the window with avilable elemental converter options according to player's inventory
  16250. *------------------------------------------*/
  16251. void clif_elementalconverter_list( struct map_session_data *sd ){
  16252. nullpo_retv( sd );
  16253. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16254. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16255. int count = 0;
  16256. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16257. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16258. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16259. count++;
  16260. }
  16261. }
  16262. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16263. clif_send( p, p->packetLength, &sd->bl, SELF );
  16264. if( count > 0 ){
  16265. sd->menuskill_id = SA_CREATECON;
  16266. sd->menuskill_val = count;
  16267. }
  16268. }
  16269. /**
  16270. * Rune Knight
  16271. **/
  16272. void clif_millenniumshield(struct block_list *bl, short shields) {
  16273. #if PACKETVER >= 20081217
  16274. unsigned char buf[10];
  16275. WBUFW(buf,0) = 0x440;
  16276. WBUFL(buf,2) = bl->id;
  16277. WBUFW(buf,6) = shields;
  16278. WBUFW(buf,8) = 0;
  16279. clif_send(buf,packet_len(0x440),bl,AREA);
  16280. #endif
  16281. }
  16282. /**
  16283. * Mechanic
  16284. **/
  16285. /*==========================================
  16286. * Magic Decoy Material List
  16287. *------------------------------------------*/
  16288. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16289. nullpo_retv( sd );
  16290. int fd = sd->fd;
  16291. if( !session_isActive( fd ) ){
  16292. return;
  16293. }
  16294. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16295. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16296. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16297. int count = 0;
  16298. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16299. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16300. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16301. count++;
  16302. }
  16303. }
  16304. if( count > 0 ) {
  16305. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16306. WFIFOSET( fd, p->packetLength );
  16307. sd->menuskill_id = NC_MAGICDECOY;
  16308. sd->menuskill_val = skill_lv;
  16309. sd->sc.comet_x = x;
  16310. sd->sc.comet_y = y;
  16311. }else{
  16312. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16313. }
  16314. }
  16315. /*==========================================
  16316. * Guillotine Cross Poisons List
  16317. *------------------------------------------*/
  16318. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16319. nullpo_retv( sd );
  16320. int fd = sd->fd;
  16321. if( !session_isActive( fd ) ){
  16322. return;
  16323. }
  16324. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16325. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16326. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16327. int count = 0;
  16328. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16329. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16330. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16331. count++;
  16332. }
  16333. }
  16334. if( count > 0 ){
  16335. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16336. WFIFOSET( fd, p->packetLength );
  16337. sd->menuskill_id = GC_POISONINGWEAPON;
  16338. sd->menuskill_val = skill_lv;
  16339. }else{
  16340. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16341. }
  16342. }
  16343. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16344. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16345. int fd, i, c;
  16346. nullpo_ret(sd);
  16347. fd = sd->fd;
  16348. if( !session_isActive(fd) )
  16349. return 0;
  16350. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16351. return 0;
  16352. WFIFOHEAD(fd, 2 * 6 + 4);
  16353. WFIFOW(fd,0) = 0x442;
  16354. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16355. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16356. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16357. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16358. {
  16359. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16360. c++;
  16361. }
  16362. if( c > 0 ) {
  16363. WFIFOW(fd,2) = 8 + c * 2;
  16364. WFIFOL(fd,4) = c;
  16365. WFIFOSET(fd,WFIFOW(fd,2));
  16366. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16367. sd->menuskill_val = c;
  16368. } else {
  16369. status_change_end(&sd->bl,SC_STOP);
  16370. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16371. }
  16372. return 1;
  16373. }
  16374. /*===========================================
  16375. * Skill list for Four Elemental Analysis
  16376. * and Change Material skills.
  16377. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16378. *------------------------------------------*/
  16379. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16380. #if PACKETVER >= 20090922
  16381. int fd = sd->fd;
  16382. nullpo_ret(sd);
  16383. sd->menuskill_id = skill_id; // To prevent hacking.
  16384. sd->menuskill_val = skill_lv;
  16385. if( skill_id == GN_CHANGEMATERIAL )
  16386. skill_lv = 0; // Changematerial
  16387. WFIFOHEAD(fd, packet_len(0x7e3));
  16388. WFIFOW(fd,0) = 0x7e3;
  16389. WFIFOL(fd,2) = skill_lv;
  16390. WFIFOL(fd,4) = 0;
  16391. WFIFOSET(fd, packet_len(0x7e3));
  16392. #endif
  16393. return 1;
  16394. }
  16395. /*==========================================
  16396. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16397. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16398. * RFIFOL(fd,2) - type (currently not used)
  16399. *------------------------------------------*/
  16400. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16401. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16402. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16403. if (sd->menuskill_id == SA_AUTOSPELL) {
  16404. sd->state.workinprogress = WIP_DISABLE_NONE;
  16405. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16406. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16407. if (pc_istrading(sd)) {
  16408. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16409. clif_menuskill_clear(sd);
  16410. return;
  16411. }
  16412. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16413. } else
  16414. return;
  16415. clif_menuskill_clear(sd);
  16416. }
  16417. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16418. /// 08cf <id>.L <type>.W <num>.W
  16419. void clif_spiritcharm(struct map_session_data *sd) {
  16420. unsigned char buf[10];
  16421. nullpo_retv(sd);
  16422. WBUFW(buf,0) = 0x08cf;
  16423. WBUFL(buf,2) = sd->bl.id;
  16424. WBUFW(buf,6) = sd->spiritcharm_type;
  16425. WBUFW(buf,8) = sd->spiritcharm;
  16426. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16427. }
  16428. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16429. /// 0907 <index>.W
  16430. ///
  16431. /// R 0908 <index>.w <type>.b
  16432. /// type:
  16433. /// 0 = move item to personal tab
  16434. /// 1 = move item to normal tab
  16435. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16436. #if PACKETVER >= 20111122
  16437. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16438. int index = RFIFOW(fd,info->pos[0]) - 2;
  16439. int type = RFIFOB(fd, info->pos[1]);
  16440. /* can't move while dead. */
  16441. if(pc_isdead(sd)) {
  16442. return;
  16443. }
  16444. if (index < 0 || index >= MAX_INVENTORY)
  16445. return;
  16446. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16447. sd->inventory.u.items_inventory[index].favorite = 0;
  16448. else if( type == 0 )
  16449. sd->inventory.u.items_inventory[index].favorite = 1;
  16450. else
  16451. return;/* nothing to do. */
  16452. clif_favorite_item(sd, index);
  16453. #endif
  16454. }
  16455. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16456. /// 0900 <index>.W <favorite>.B
  16457. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16458. int fd = sd->fd;
  16459. WFIFOHEAD(fd,packet_len(0x908));
  16460. WFIFOW(fd,0) = 0x908;
  16461. WFIFOW(fd,2) = index+2;
  16462. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16463. WFIFOSET(fd,packet_len(0x908));
  16464. }
  16465. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16466. void clif_snap( struct block_list *bl, short x, short y ) {
  16467. unsigned char buf[10];
  16468. WBUFW(buf,0) = 0x8d2;
  16469. WBUFL(buf,2) = bl->id;
  16470. WBUFW(buf,6) = x;
  16471. WBUFW(buf,8) = y;
  16472. if( disguised(bl) )
  16473. {
  16474. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16475. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16476. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16477. } else
  16478. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16479. }
  16480. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16481. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16482. #if PACKETVER >= 20120404
  16483. WFIFOHEAD(fd,packet_len(0x977));
  16484. WFIFOW(fd,0) = 0x977;
  16485. WFIFOL(fd,2) = md->bl.id;
  16486. WFIFOL(fd,6) = md->status.hp;
  16487. WFIFOL(fd,10) = md->status.max_hp;
  16488. WFIFOSET(fd,packet_len(0x977));
  16489. #endif
  16490. }
  16491. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16492. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16493. return;
  16494. }
  16495. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16496. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16497. WFIFOW(sd->fd,0) = 0x2c9;
  16498. WFIFOB(sd->fd,2) = flag;
  16499. WFIFOSET(sd->fd, packet_len(0x2c9));
  16500. }
  16501. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16502. /// 0979 <world name>.24B <char name>.24B
  16503. void clif_ackworldinfo(struct map_session_data* sd) {
  16504. int fd;
  16505. nullpo_retv(sd);
  16506. fd = sd->fd;
  16507. WFIFOHEAD(fd,packet_len(0x979));
  16508. WFIFOW(fd,0)=0x979;
  16509. //AID -> world name ?
  16510. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16511. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16512. WFIFOSET(fd,packet_len(0x979));
  16513. }
  16514. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16515. /// 0978 <AID>.L
  16516. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16517. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16518. if(sd)
  16519. clif_ackworldinfo(sd);
  16520. }
  16521. static void clif_loadConfirm( struct map_session_data *sd ){
  16522. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16523. nullpo_retv( sd );
  16524. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16525. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16526. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16527. if (sd->instance_id > 0)
  16528. instance_reqinfo(sd, sd->instance_id);
  16529. if (sd->status.party_id > 0)
  16530. party_member_joined(sd);
  16531. if (sd->status.guild_id > 0)
  16532. guild_member_joined(sd);
  16533. if (sd->status.clan_id > 0)
  16534. clan_member_joined(sd);
  16535. #endif
  16536. }
  16537. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16538. /// 0447
  16539. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16540. clif_loadConfirm( sd );
  16541. }
  16542. /// req world info (CZ_CLIENT_VERSION)
  16543. /// 044A <version>.L
  16544. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16545. //if(sd)
  16546. ;
  16547. }
  16548. /// Ranking list
  16549. /// ranking pointlist { <name>.24B <point>.L }*10
  16550. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16551. struct fame_list* list;
  16552. int i, size = MAX_FAME_LIST;
  16553. switch(rankingtype) {
  16554. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16555. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16556. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16557. // PK currently unsupported
  16558. case RANK_KILLER: list = NULL; size = 0; break;
  16559. default:
  16560. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16561. return;
  16562. }
  16563. //Packet size limits this list to 10 elements. [Skotlex]
  16564. for (i = 0; i < min(10,size); i++) {
  16565. if (list[i].id > 0) {
  16566. const char* name;
  16567. if (strcmp(list[i].name, "-") == 0 &&
  16568. (name = map_charid2nick(list[i].id)) != NULL)
  16569. {
  16570. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16571. } else {
  16572. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16573. }
  16574. } else {
  16575. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16576. }
  16577. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16578. }
  16579. for(;i < 10; i++) { //In case the MAX is less than 10.
  16580. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16581. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16582. }
  16583. }
  16584. /// Request for the blacksmith ranklist.
  16585. /// /blacksmith command sends this packet to the server.
  16586. /// 0217 (CZ_BLACKSMITH_RANK)
  16587. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16588. clif_ranklist(sd,RANK_BLACKSMITH);
  16589. }
  16590. /// Request for the alchemist ranklist.
  16591. /// /alchemist command sends this packet to the server.
  16592. /// 0218 (CZ_ALCHEMIST_RANK)
  16593. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16594. clif_ranklist(sd,RANK_ALCHEMIST);
  16595. }
  16596. /// Request for the taekwon ranklist.
  16597. /// /taekwon command sends this packet to the server.
  16598. /// 0225 (CZ_TAEKWON_RANK)
  16599. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16600. clif_ranklist(sd,RANK_TAEKWON);
  16601. }
  16602. /// Request for the killer ranklist.
  16603. /// /pk command sends this packet to the server.
  16604. /// 0237 (CZ_KILLER_RANK)
  16605. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16606. clif_ranklist(sd,RANK_KILLER);
  16607. }
  16608. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16609. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16610. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16611. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16612. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16613. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16614. enum e_rank rank;
  16615. #if PACKETVER < 20130710
  16616. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16617. short cmd;
  16618. switch( rankingType ){
  16619. case RANK_BLACKSMITH: cmd = 0x219; break;
  16620. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16621. case RANK_TAEKWON: cmd = 0x226; break;
  16622. case RANK_KILLER: cmd = 0x238; break;
  16623. default:
  16624. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16625. return;
  16626. }
  16627. // Can be safely casted here, since we validated it before
  16628. rank = (enum e_rank)rankingType;
  16629. WBUFW(buf,0) = cmd;
  16630. clif_sub_ranklist(buf,2,sd,rank);
  16631. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16632. #else
  16633. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16634. int mypoint = 0;
  16635. switch( rankingType ){
  16636. case RANK_BLACKSMITH:
  16637. case RANK_ALCHEMIST:
  16638. case RANK_TAEKWON:
  16639. case RANK_KILLER:
  16640. break;
  16641. default:
  16642. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16643. return;
  16644. }
  16645. // Can be safely casted here, since we validated it before
  16646. rank = (enum e_rank)rankingType;
  16647. WBUFW(buf,0) = 0x97d;
  16648. WBUFW(buf,2) = rank;
  16649. clif_sub_ranklist(buf,4,sd,rank);
  16650. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16651. case MAPID_BLACKSMITH:
  16652. case MAPID_ALCHEMIST:
  16653. case MAPID_TAEKWON:
  16654. mypoint = sd->status.fame;
  16655. }
  16656. WBUFL(buf,284) = mypoint; //mypoint
  16657. clif_send(buf, 288, &sd->bl, SELF);
  16658. #endif
  16659. }
  16660. /*
  16661. * 097c <type> (CZ_REQ_RANKING)
  16662. * type
  16663. * 0: /blacksmith
  16664. * 1: /alchemist
  16665. * 2: /taekwon
  16666. * 3: /pk
  16667. * */
  16668. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16669. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16670. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16671. clif_ranklist(sd,rankingtype);
  16672. }
  16673. /// Updates the fame rank points for the given ranking.
  16674. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16675. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16676. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16677. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16678. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16679. int fd = sd.fd;
  16680. #if PACKETVER < 20130710
  16681. short cmd;
  16682. switch(rankingtype){
  16683. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16684. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16685. case RANK_TAEKWON: cmd = 0x224; break;
  16686. default:
  16687. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16688. return;
  16689. }
  16690. WFIFOHEAD(fd,packet_len(cmd));
  16691. WFIFOW(fd,0) = cmd;
  16692. WFIFOL(fd,2) = point;
  16693. WFIFOL(fd,6) = sd.status.fame;
  16694. WFIFOSET(fd, packet_len(cmd));
  16695. #else
  16696. WFIFOHEAD(fd,packet_len(0x97e));
  16697. WFIFOW(fd,0) = 0x97e;
  16698. WFIFOW(fd,2) = rankingtype;
  16699. WFIFOL(fd,4) = point;
  16700. WFIFOL(fd,8) = sd.status.fame;
  16701. WFIFOSET(fd,packet_len(0x97e));
  16702. #endif
  16703. }
  16704. /**
  16705. * Transmit personal information to player. (rates)
  16706. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16707. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16708. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16709. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16710. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16711. * FIXME!
  16712. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16713. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16714. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16715. */
  16716. #ifdef VIP_ENABLE
  16717. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16718. if (sd) {
  16719. struct s_packet_db* info;
  16720. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16721. int cmd = 0, fd, i = 0;
  16722. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16723. int details_bexp[PINFO_MAX];
  16724. int details_drop[PINFO_MAX];
  16725. int details_penalty[PINFO_MAX];
  16726. /**
  16727. * Set for EXP
  16728. */
  16729. //0:PCRoom
  16730. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16731. if (details_bexp[0] == 100 || !details_bexp[0])
  16732. details_bexp[0] = 0;
  16733. else {
  16734. if (details_bexp[0] < 100) {
  16735. details_bexp[0] = 100 - details_bexp[0];
  16736. details_bexp[0] = 0 - details_bexp[0];
  16737. }
  16738. else
  16739. details_bexp[0] = details_bexp[0] - 100;
  16740. }
  16741. //1:Premium
  16742. if (pc_isvip(sd)) {
  16743. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16744. if (details_bexp[1] < 0)
  16745. details_bexp[1] = 0 - details_bexp[1];
  16746. }
  16747. else
  16748. details_bexp[1] = 0;
  16749. //2:Server
  16750. details_bexp[2] = battle_config.base_exp_rate;
  16751. if (details_bexp[2] == 100)
  16752. details_bexp[2] = 0;
  16753. else {
  16754. if (details_bexp[2] < 100) {
  16755. details_bexp[2] = 100 - details_bexp[2];
  16756. details_bexp[2] = 0 - details_bexp[2];
  16757. }
  16758. else
  16759. details_bexp[2] = details_bexp[2] - 100;
  16760. }
  16761. //3:TPLUS
  16762. details_bexp[3] = 0;
  16763. /* End - EXP set*/
  16764. /**
  16765. * Set for Drop rate
  16766. */
  16767. //0:PCRoom
  16768. details_drop[0] = 0;
  16769. //1:Premium
  16770. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16771. if (pc_isvip(sd)) {
  16772. if (details_drop[1] < 0)
  16773. details_drop[1] = 0 - details_drop[1];
  16774. }
  16775. else
  16776. details_drop[1] = 0;
  16777. //2:Server
  16778. details_drop[2] = battle_config.item_rate_common;
  16779. if (details_drop[2] == 100)
  16780. details_drop[2] = 0;
  16781. else {
  16782. if (details_drop[2] < 100) {
  16783. details_drop[2] = 100 - details_drop[2];
  16784. details_drop[2] = 0 - details_drop[2];
  16785. }
  16786. else
  16787. details_drop[2] = details_drop[2] - 100;
  16788. }
  16789. //3:TPLUS
  16790. details_drop[3] = 0;
  16791. /* End - Drop set*/
  16792. /**
  16793. * Set for Penalty rate
  16794. */
  16795. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16796. //0:PCRoom
  16797. details_penalty[0] = 0;
  16798. //1:Premium
  16799. if (pc_isvip(sd)) {
  16800. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16801. if (details_penalty[1] == 100)
  16802. details_penalty[1] = 0;
  16803. else {
  16804. if (details_penalty[1] < 100) {
  16805. details_penalty[1] = 100 - details_penalty[1];
  16806. details_penalty[1] = 0 - details_penalty[1];
  16807. }
  16808. else
  16809. details_penalty[1] = details_penalty[1] - 100;
  16810. }
  16811. }
  16812. else
  16813. details_penalty[1] = 0;
  16814. //2:Server
  16815. details_penalty[2] = battle_config.death_penalty_base;
  16816. if (details_penalty[2] == 100)
  16817. details_penalty[2] = 0;
  16818. else {
  16819. if (details_penalty[2] < 100) {
  16820. details_penalty[2] = 100 - details_penalty[2];
  16821. details_penalty[2] = 0 - details_penalty[2];
  16822. }
  16823. else
  16824. details_penalty[2] = details_penalty[2] - 100;
  16825. }
  16826. //3:TPLUS
  16827. details_penalty[3] = 0;
  16828. /* End - Penalty set*/
  16829. cmd = packet_db_ack[cmdtype];
  16830. info = &packet_db[cmd];
  16831. len = info->len; //this is the base len without details
  16832. if(!len) return; //version as packet disable
  16833. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16834. szdetails = 7;
  16835. factor = 1;
  16836. }
  16837. else if (cmd == 0x097b) {
  16838. tot_baseexp *= factor;
  16839. tot_drop *= factor;
  16840. tot_penalty *= factor;
  16841. }
  16842. fd = sd->fd;
  16843. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16844. WFIFOW(fd,0) = cmd;
  16845. for (i = 0; i < maxinfotype; i++) {
  16846. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16847. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16848. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16849. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16850. tot_baseexp += details_bexp[i]*factor;
  16851. tot_drop += details_penalty[i]*factor;
  16852. tot_penalty += details_drop[i]*factor;
  16853. len += szdetails;
  16854. }
  16855. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16856. if (cmd == 0x08cb) { //0x08cb version
  16857. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16858. WFIFOW(fd,info->pos[2]) = tot_drop;
  16859. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16860. }
  16861. else { //2013-08-07aRagexe uses 0x097b
  16862. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16863. WFIFOL(fd,info->pos[2]) = tot_drop;
  16864. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16865. }
  16866. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16867. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16868. WFIFOSET(fd,len);
  16869. }
  16870. }
  16871. #endif
  16872. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16873. char cmd[30];
  16874. int t_aid = RFIFOL(fd,2);
  16875. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16876. is_atcommand(fd, sd, cmd, 1);
  16877. }
  16878. /**
  16879. * Marks Crimson Marker target on mini-map to the caster
  16880. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16881. * @param fd
  16882. * @param bl Crimson Marker target
  16883. **/
  16884. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16885. struct s_packet_db* info;
  16886. int cmd = 0;
  16887. int16 len;
  16888. unsigned char buf[11];
  16889. nullpo_retv(sd);
  16890. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16891. if (!cmd)
  16892. cmd = 0x09C1; //default
  16893. info = &packet_db[cmd];
  16894. if (!(len = info->len))
  16895. return;
  16896. WBUFW(buf, 0) = cmd;
  16897. WBUFL(buf, info->pos[0]) = bl->id;
  16898. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16899. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16900. clif_send(buf, len, &sd->bl, SELF);
  16901. }
  16902. /**
  16903. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16904. **/
  16905. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16906. struct s_packet_db *info = NULL;
  16907. int cmd = 0;
  16908. nullpo_retv(sd);
  16909. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16910. info = &packet_db[cmd];
  16911. if (!cmd || !info->len)
  16912. return;
  16913. WFIFOHEAD(sd->fd, info->len);
  16914. WFIFOW(sd->fd, 0) = cmd;
  16915. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16916. WFIFOSET(sd->fd, info->len);
  16917. }
  16918. /**
  16919. * [Ind/Hercules]
  16920. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16921. **/
  16922. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16923. char buf[256];
  16924. size_t len;
  16925. nullpo_retv(bl);
  16926. if(!message)
  16927. return;
  16928. len = strlen(message)+1;
  16929. if( len > sizeof(buf)-8 ) {
  16930. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16931. len = sizeof(buf)-8;
  16932. }
  16933. WBUFW(buf,0) = 0x8b3;
  16934. WBUFW(buf,2) = (uint16)(len+8);
  16935. WBUFL(buf,4) = bl->id;
  16936. safestrncpy(WBUFCP(buf,8), message, len);
  16937. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16938. }
  16939. /**
  16940. * [Ind/Hercules]
  16941. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16942. **/
  16943. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16944. unsigned char buf[10];
  16945. nullpo_retv(sd);
  16946. WBUFW(buf,0) = 0x7fc;
  16947. WBUFL(buf,2) = prev_leader_aid;
  16948. WBUFL(buf,6) = new_leader_aid;
  16949. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16950. }
  16951. /**
  16952. * Sends a clan message to a player
  16953. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16954. **/
  16955. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16956. #if PACKETVER >= 20131223
  16957. struct map_session_data *sd;
  16958. uint8 buf[256];
  16959. if( len == 0 ){
  16960. return;
  16961. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16962. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16963. len = sizeof(buf)-5-NAME_LENGTH;
  16964. }
  16965. WBUFW(buf, 0) = 0x98e;
  16966. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16967. // 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
  16968. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16969. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16970. if((sd = clan_getavailablesd(clan)) != NULL)
  16971. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16972. #endif
  16973. }
  16974. /**
  16975. * Parses a clan message from a player.
  16976. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16977. **/
  16978. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16979. #if PACKETVER >= 20131223
  16980. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16981. // validate packet and retrieve name and message
  16982. if( !clif_process_message(sd, false, name, message, output ) )
  16983. return;
  16984. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16985. #endif
  16986. }
  16987. /**
  16988. * Sends the basic clan informations to the client.
  16989. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16990. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16991. **/
  16992. void clif_clan_basicinfo( struct map_session_data *sd ){
  16993. #if PACKETVER >= 20131223
  16994. int fd, offset, length, i, flag;
  16995. struct clan* clan;
  16996. char mapname[MAP_NAME_LENGTH_EXT];
  16997. nullpo_retv( sd );
  16998. nullpo_retv( clan = sd->clan );
  16999. // Check if the player has a valid session and is not autotrading
  17000. if( !clif_session_isValid( sd ) ){
  17001. return;
  17002. }
  17003. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  17004. fd = sd->fd;
  17005. WFIFOHEAD(fd,length);
  17006. memset( WFIFOP(fd, 0), 0, length );
  17007. WFIFOW( fd, 0 ) = 0x98a;
  17008. WFIFOL( fd, 4 ) = clan->id;
  17009. offset = 8;
  17010. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  17011. offset += NAME_LENGTH;
  17012. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  17013. offset += NAME_LENGTH;
  17014. mapindex_getmapname_ext( clan->map, mapname );
  17015. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  17016. offset += MAP_NAME_LENGTH_EXT;
  17017. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  17018. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  17019. for( flag = 0; flag < 2; flag++ ){
  17020. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  17021. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  17022. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  17023. offset += NAME_LENGTH;
  17024. }
  17025. }
  17026. }
  17027. WFIFOW( fd, 2 ) = offset;
  17028. WFIFOSET(fd,offset);
  17029. #endif
  17030. }
  17031. /**
  17032. * Updates the online and maximum player count of a clan.
  17033. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  17034. **/
  17035. void clif_clan_onlinecount( struct clan* clan ){
  17036. #if PACKETVER >= 20131223
  17037. uint8 buf[6];
  17038. struct map_session_data *sd;
  17039. WBUFW(buf,0) = 0x988;
  17040. WBUFW(buf,2) = clan->connect_member;
  17041. WBUFW(buf,4) = clan->max_member;
  17042. if((sd = clan_getavailablesd(clan)) != NULL)
  17043. clif_send(buf, 6, &sd->bl, CLAN);
  17044. #endif
  17045. }
  17046. /**
  17047. * Notifies the client that the player has left his clan.
  17048. * 0989 (ZC_ACK_CLAN_LEAVE)
  17049. **/
  17050. void clif_clan_leave( struct map_session_data* sd ){
  17051. #if PACKETVER >= 20131223
  17052. int fd;
  17053. nullpo_retv( sd );
  17054. if( !clif_session_isValid( sd ) ){
  17055. return;
  17056. }
  17057. fd = sd->fd;
  17058. WFIFOHEAD(fd,2);
  17059. WFIFOW(fd,0) = 0x989;
  17060. WFIFOSET(fd,2);
  17061. #endif
  17062. }
  17063. /**
  17064. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17065. * 0A2F <result>.B <title_id>.L
  17066. */
  17067. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  17068. {
  17069. #if PACKETVER >= 20150513
  17070. int fd;
  17071. nullpo_retv(sd);
  17072. if (!clif_session_isValid(sd))
  17073. return;
  17074. fd = sd->fd;
  17075. WFIFOHEAD(fd, packet_len(0xa2f));
  17076. WFIFOW(fd, 0) = 0xa2f;
  17077. WFIFOB(fd, 2) = result;
  17078. WFIFOL(fd, 3) = title_id;
  17079. WFIFOSET(fd, packet_len(0xa2f));
  17080. #endif
  17081. }
  17082. /**
  17083. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17084. * 0A2E <title_id>.L
  17085. */
  17086. void clif_parse_change_title(int fd, struct map_session_data *sd)
  17087. {
  17088. int title_id;
  17089. nullpo_retv(sd);
  17090. title_id = RFIFOL(fd, 2);
  17091. if( title_id == sd->status.title_id ){
  17092. // It is exactly the same as the old one
  17093. return;
  17094. }else if( title_id <= 0 ){
  17095. sd->status.title_id = 0;
  17096. }else{
  17097. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17098. clif_change_title_ack(sd, 1, title_id);
  17099. return;
  17100. }
  17101. sd->status.title_id = title_id;
  17102. }
  17103. clif_name_area(&sd->bl);
  17104. clif_change_title_ack(sd, 0, title_id);
  17105. }
  17106. #ifdef DUMP_UNKNOWN_PACKET
  17107. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17108. {
  17109. const char* packet_txt = "save/packet.txt";
  17110. FILE* fp;
  17111. time_t time_server;
  17112. struct tm *datetime;
  17113. char datestr[512];
  17114. time(&time_server); // get time in seconds since 1/1/1970
  17115. datetime = localtime(&time_server); // convert seconds in structure
  17116. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17117. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17118. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17119. if( sd ) {
  17120. 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);
  17121. } else {
  17122. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17123. }
  17124. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17125. fprintf(fp, "\n");
  17126. fclose(fp);
  17127. } else {
  17128. ShowError("Failed to write '%s'.\n", packet_txt);
  17129. // Dump on console instead
  17130. if( sd ) {
  17131. 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);
  17132. } else {
  17133. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17134. }
  17135. ShowDump(RFIFOP(fd,0), packet_len);
  17136. }
  17137. }
  17138. #endif
  17139. /// Roulette System
  17140. /// Author: Yommy
  17141. /// Opens the roulette window
  17142. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17143. void clif_roulette_open( struct map_session_data* sd ){
  17144. nullpo_retv( sd );
  17145. struct packet_roulette_open_ack p;
  17146. p.PacketType = 0xa1a;
  17147. p.Result = 0; // result
  17148. p.Serial = 0; // serial
  17149. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17150. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17151. p.AdditionItemID = -1; //! TODO: Display bonus item
  17152. p.GoldPoint = sd->roulette_point.gold;
  17153. p.SilverPoint = sd->roulette_point.silver;
  17154. p.BronzePoint = sd->roulette_point.bronze;
  17155. sd->state.roulette_open = true;
  17156. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17157. }
  17158. /// Request to open the roulette window
  17159. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17160. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  17161. nullpo_retv(sd);
  17162. if (!battle_config.feature_roulette) {
  17163. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17164. return;
  17165. }
  17166. clif_roulette_open(sd);
  17167. }
  17168. /// Sends the info about the available roulette rewards to the client
  17169. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17170. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17171. void clif_roulette_info( struct map_session_data* sd ){
  17172. nullpo_retv(sd);
  17173. struct packet_roulette_info_ack p;
  17174. p.PacketType = rouletteinfoackType;
  17175. p.PacketLength = sizeof(p);
  17176. p.RouletteSerial = 1;
  17177. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17178. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17179. p.ItemInfo[count].Row = i;
  17180. p.ItemInfo[count].Position = j;
  17181. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17182. p.ItemInfo[count].Count = rd.qty[i][j];
  17183. #if PACKETVER >= 20180511
  17184. p.ItemInfo[count].unused = 0;
  17185. #endif
  17186. count++;
  17187. }
  17188. }
  17189. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17190. }
  17191. /// Request the roulette reward data
  17192. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17193. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  17194. nullpo_retv(sd);
  17195. if (!battle_config.feature_roulette) {
  17196. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17197. return;
  17198. }
  17199. clif_roulette_info(sd);
  17200. }
  17201. /// Notification of the client that the roulette window was closed
  17202. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17203. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  17204. nullpo_retv(sd);
  17205. if (!battle_config.feature_roulette) {
  17206. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17207. return;
  17208. }
  17209. sd->state.roulette_open = false;
  17210. }
  17211. /// Response to a item reward request
  17212. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17213. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17214. #if PACKETVER >= 20141016
  17215. nullpo_retv(sd);
  17216. struct packet_roulette_itemrecv_ack p;
  17217. p.PacketType = roulettercvitemackType;
  17218. p.Result = type;
  17219. p.AdditionItemID = 0; //! TODO: Additional item
  17220. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17221. #endif
  17222. }
  17223. /**
  17224. * Claim roulette reward
  17225. * @param sd Player
  17226. * @return 0:Success
  17227. **/
  17228. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17229. struct item it;
  17230. uint8 res = 1;
  17231. nullpo_retr(1, sd);
  17232. if (sd->roulette.prizeIdx < 0)
  17233. return RECV_ITEM_FAILED;
  17234. memset(&it, 0, sizeof(it));
  17235. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17236. it.identify = 1;
  17237. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17238. ; // onSuccess
  17239. }
  17240. sd->roulette.claimPrize = false;
  17241. sd->roulette.prizeStage = 0;
  17242. sd->roulette.prizeIdx = -1;
  17243. sd->roulette.stage = 0;
  17244. return res;
  17245. }
  17246. /// Update Roulette window with current stats
  17247. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17248. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17249. nullpo_retv( sd );
  17250. struct packet_roulette_generate_ack p;
  17251. p.PacketType = roulettgenerateackType;
  17252. p.Result = result;
  17253. p.Step = stage;
  17254. p.Idx = prizeIdx;
  17255. p.AdditionItemID = bonusItemID;
  17256. p.RemainGold = sd->roulette_point.gold;
  17257. p.RemainSilver = sd->roulette_point.silver;
  17258. p.RemainBronze = sd->roulette_point.bronze;
  17259. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17260. }
  17261. /// Request to start the roulette
  17262. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17263. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17264. enum GENERATE_ROULETTE_ACK result;
  17265. nullpo_retv(sd);
  17266. if (!battle_config.feature_roulette) {
  17267. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17268. return;
  17269. }
  17270. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17271. return;
  17272. }
  17273. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17274. sd->roulette.stage = 0;
  17275. sd->roulette.claimPrize = false;
  17276. sd->roulette.prizeStage = 0;
  17277. sd->roulette.prizeIdx = -1;
  17278. }
  17279. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17280. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17281. }else{
  17282. if (!sd->roulette.stage) {
  17283. if (sd->roulette_point.bronze > 0) {
  17284. sd->roulette_point.bronze -= 1;
  17285. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17286. } else if (sd->roulette_point.silver > 9) {
  17287. sd->roulette_point.silver -= 10;
  17288. sd->roulette.stage = 2;
  17289. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17290. } else if (sd->roulette_point.gold > 9) {
  17291. sd->roulette_point.gold -= 10;
  17292. sd->roulette.stage = 4;
  17293. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17294. }
  17295. }
  17296. sd->roulette.prizeStage = sd->roulette.stage;
  17297. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17298. sd->roulette.claimPrize = true;
  17299. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17300. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17301. result = GENERATE_ROULETTE_LOSING;
  17302. sd->roulette.stage = 0;
  17303. }else{
  17304. result = GENERATE_ROULETTE_SUCCESS;
  17305. sd->roulette.stage++;
  17306. }
  17307. }
  17308. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17309. }
  17310. /// Request to claim a prize
  17311. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17312. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17313. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17314. nullpo_retv(sd);
  17315. if (!battle_config.feature_roulette) {
  17316. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17317. return;
  17318. }
  17319. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17320. return;
  17321. }
  17322. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17323. switch (clif_roulette_getitem(sd)) {
  17324. case ADDITEM_SUCCESS:
  17325. type = RECV_ITEM_SUCCESS;
  17326. break;
  17327. case ADDITEM_INVALID:
  17328. case ADDITEM_OVERITEM:
  17329. case ADDITEM_OVERAMOUNT:
  17330. type = RECV_ITEM_OVERCOUNT;
  17331. break;
  17332. case ADDITEM_OVERWEIGHT:
  17333. type = RECV_ITEM_OVERWEIGHT;
  17334. break;
  17335. case ADDITEM_STACKLIMIT:
  17336. default:
  17337. type = RECV_ITEM_FAILED;
  17338. break;
  17339. }
  17340. }
  17341. clif_roulette_recvitem_ack(sd,type);
  17342. }
  17343. /// MERGE ITEM
  17344. /**
  17345. * Acknowledge the client about item merger result
  17346. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17347. * @param fd
  17348. * @param sd
  17349. **/
  17350. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  17351. unsigned char buf[9];
  17352. struct s_packet_db *info = NULL;
  17353. short cmd = 0;
  17354. nullpo_retv(sd);
  17355. if (!clif_session_isValid(sd))
  17356. return;
  17357. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  17358. return;
  17359. if (!(info = &packet_db[cmd]) || info->len == 0)
  17360. return;
  17361. WBUFW(buf, 0) = cmd;
  17362. WBUFW(buf, info->pos[0]) = index;
  17363. WBUFW(buf, info->pos[1]) = count;
  17364. WBUFB(buf, info->pos[2]) = type;
  17365. clif_send(buf, info->len, &sd->bl, SELF);
  17366. }
  17367. /**
  17368. * Check if item has the pair to be merged
  17369. * @param sd
  17370. * @param it Item
  17371. * @return True if has pair, False if not
  17372. **/
  17373. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17374. struct item *it_;
  17375. unsigned short i;
  17376. nullpo_retr(false, sd);
  17377. 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);
  17378. if (i < MAX_INVENTORY)
  17379. return true;
  17380. return false;
  17381. }
  17382. /**
  17383. * Check if item can be merged
  17384. * @param id Item Data
  17385. * @param it Item
  17386. * @return True if can be merged, False if not
  17387. **/
  17388. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17389. if (!id || !it)
  17390. return false;
  17391. if (id->type == IT_CASH)
  17392. return false;
  17393. if (!itemdb_isstackable2(id))
  17394. return false;
  17395. if (itemdb_isspecial(it->card[0]))
  17396. return false;
  17397. if (!it->unique_id)
  17398. return false;
  17399. return true;
  17400. }
  17401. /**
  17402. * Open available item to be merged.
  17403. * Only show 1 item in 1 process.
  17404. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17405. * @param sd
  17406. **/
  17407. void clif_merge_item_open(struct map_session_data *sd) {
  17408. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  17409. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  17410. int len = 0;
  17411. struct s_packet_db *info = NULL;
  17412. struct item *it;
  17413. nullpo_retv(sd);
  17414. if (!clif_session_isValid(sd))
  17415. return;
  17416. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  17417. return;
  17418. if (!(info = &packet_db[cmd]) || info->len == 0)
  17419. return;
  17420. // Get entries
  17421. for (i = 0; i < MAX_INVENTORY; i++) {
  17422. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  17423. continue;
  17424. if (clif_merge_item_has_pair(sd, it))
  17425. indexes[n++] = i;
  17426. }
  17427. if (n < 2) { // No item need to be merged
  17428. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17429. return;
  17430. }
  17431. WBUFW(buf, 0) = cmd;
  17432. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  17433. for (i = 0; i < n; i++) {
  17434. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  17435. }
  17436. clif_send(buf, len, &sd->bl, SELF);
  17437. }
  17438. /**
  17439. * Process item merger
  17440. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17441. * @param fd
  17442. * @param sd
  17443. **/
  17444. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17445. struct s_packet_db *info = NULL;
  17446. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17447. unsigned int count = 0;
  17448. struct item_data *id = NULL;
  17449. nullpo_retv(sd);
  17450. if (!clif_session_isValid(sd))
  17451. return;
  17452. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17453. return;
  17454. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17455. if (n < 2) { // No item need to be merged
  17456. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17457. return;
  17458. }
  17459. for (i = 0, j = 0; i < n; i++) {
  17460. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17461. if( idx >= MAX_INVENTORY ){
  17462. return;
  17463. }
  17464. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17465. continue;
  17466. indexes[j] = idx;
  17467. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17468. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17469. return;
  17470. }
  17471. count += sd->inventory.u.items_inventory[idx].amount;
  17472. j++;
  17473. }
  17474. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17475. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17476. return;
  17477. }
  17478. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17479. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17480. return;
  17481. }
  17482. // Merrrrge!!!!
  17483. for (i = 1; i < n; i++) {
  17484. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17485. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17486. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17487. sd->inventory_data[idx] = NULL;
  17488. clif_delitem(sd, idx, amt, 0);
  17489. }
  17490. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17491. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17492. }
  17493. /**
  17494. * Cancel item merge
  17495. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17496. * @param fd
  17497. * @param sd
  17498. **/
  17499. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17500. return; // Nothing todo yet
  17501. }
  17502. /**
  17503. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17504. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17505. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17506. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17507. **/
  17508. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17509. char name[NAME_LENGTH];
  17510. if( battle_config.broadcast_hide_name ){
  17511. std::string dispname = std::string( char_name );
  17512. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17513. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17514. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17515. }else{
  17516. safestrncpy( name, char_name, sizeof( name ) );
  17517. }
  17518. switch( type ){
  17519. case ITEMOBTAIN_TYPE_BOXITEM:
  17520. {
  17521. struct packet_package_item_announce p;
  17522. p.PacketType = package_item_announceType;
  17523. p.type = type;
  17524. p.ItemID = client_nameid( nameid );
  17525. p.len = NAME_LENGTH;
  17526. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17527. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17528. p.BoxItemID = client_nameid( container );
  17529. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17530. p.PacketLength = 15 + p.len;
  17531. #else
  17532. p.PacketLength = 11 + p.len;
  17533. #endif
  17534. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17535. }
  17536. break;
  17537. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17538. case ITEMOBTAIN_TYPE_NPC:
  17539. {
  17540. struct packet_item_drop_announce p;
  17541. p.PacketType = item_drop_announceType;
  17542. p.type = type;
  17543. p.ItemID = client_nameid( nameid );
  17544. p.len = NAME_LENGTH;
  17545. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17546. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17547. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17548. p.monsterNameLen = NAME_LENGTH;
  17549. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17550. }else{
  17551. p.monsterNameLen = 0;
  17552. p.monsterName[0] = '\0';
  17553. }
  17554. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17555. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17556. #else
  17557. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17558. #endif
  17559. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17560. }
  17561. break;
  17562. }
  17563. }
  17564. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17565. /// 0A02 <view>.W
  17566. /// Value <flag> has the following effects:
  17567. /// 1: Open a Dress Room window.
  17568. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17569. #if PACKETVER >= 20150513
  17570. int fd = sd->fd;
  17571. nullpo_retv(sd);
  17572. WFIFOHEAD(fd, packet_len(0xa02));
  17573. WFIFOW(fd,0) = 0xa02;
  17574. WFIFOW(fd,2) = flag;
  17575. WFIFOSET(fd, packet_len(0xa02));
  17576. #endif
  17577. }
  17578. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17579. /// 0A35 <result>.W
  17580. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17581. #if PACKETVER >= 20150513
  17582. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17583. // Ignore the request
  17584. // - Invalid item index
  17585. // - Invalid item ID or item doesn't exist
  17586. // - Item is already identified
  17587. if (idx < 0 || idx >= MAX_INVENTORY ||
  17588. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17589. sd->inventory.u.items_inventory[idx].identify)
  17590. return;
  17591. // Ignore the request - No magnifiers in inventory
  17592. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17593. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17594. return;
  17595. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17596. return;
  17597. skill_identify(sd, idx);
  17598. #endif
  17599. }
  17600. /// Starts navigation to the given target on client side
  17601. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17602. #if PACKETVER >= 20111010
  17603. int fd = sd->fd;
  17604. WFIFOHEAD(fd,27);
  17605. WFIFOW(fd,0) = 0x08e2;
  17606. // How detailed will our navigation be?
  17607. if( mob_id > 0 ){
  17608. x = 0;
  17609. y = 0;
  17610. WFIFOB(fd,2) = 3; // monster with destination field
  17611. }else if( x > 0 && y > 0 ){
  17612. WFIFOB(fd,2) = 0; // with coordinates
  17613. }else{
  17614. x = 0;
  17615. y = 0;
  17616. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17617. }
  17618. // Which services can be used for transportation?
  17619. WFIFOB(fd,3) = flag;
  17620. // If this flag is set, the navigation window will not be opened up
  17621. WFIFOB(fd,4) = hideWindow;
  17622. // Target map
  17623. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17624. // Target x
  17625. WFIFOW(fd,21) = x;
  17626. // Target y
  17627. WFIFOW(fd,23) = y;
  17628. // Target monster ID
  17629. WFIFOW(fd,25) = mob_id;
  17630. WFIFOSET(fd,27);
  17631. #endif
  17632. }
  17633. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17634. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17635. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17636. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17637. struct map_session_data *tsd;
  17638. struct block_list* tbl;
  17639. if( target == SELF ){
  17640. tsd = BL_CAST(BL_PC,bl);
  17641. tbl = &sd->bl;
  17642. }else{
  17643. tsd = sd;
  17644. tbl = bl;
  17645. }
  17646. nullpo_retv( tsd );
  17647. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17648. return;
  17649. }
  17650. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17651. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17652. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17653. p->aid = tsd->bl.id;
  17654. p->status = 1;
  17655. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17656. p->effects[i] = tsd->hatEffects[i];
  17657. }
  17658. clif_send( p, p->packetLength, tbl, target );
  17659. #endif
  17660. }
  17661. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17662. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17663. nullpo_retv( sd );
  17664. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17665. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17666. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17667. p->aid = sd->bl.id;
  17668. p->status = enable;
  17669. p->effects[0] = effectId;
  17670. clif_send( p, p->packetLength, &sd->bl, AREA );
  17671. #endif
  17672. }
  17673. /// Notify the client that a sale has started
  17674. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17675. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17676. #if PACKETVER_SUPPORTS_SALES
  17677. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17678. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17679. p.itemId = client_nameid( sale_item->nameid );
  17680. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17681. clif_send( &p, sizeof( p ), bl, target );
  17682. #endif
  17683. }
  17684. /// Notify the client that a sale has ended
  17685. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17686. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17687. #if PACKETVER_SUPPORTS_SALES
  17688. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17689. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17690. p.itemId = client_nameid( sale_item->nameid );
  17691. clif_send( &p, sizeof( p ), bl, target );
  17692. #endif
  17693. }
  17694. /// Update the remaining amount of a sale item.
  17695. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17696. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17697. #if PACKETVER_SUPPORTS_SALES
  17698. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17699. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17700. p.itemId = client_nameid( sale_item->nameid );
  17701. p.amount = sale_item->amount;
  17702. clif_send( &p, sizeof( p ), bl, target );
  17703. #endif
  17704. }
  17705. /// The client requested a refresh of the current remaining count of a sale item
  17706. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17707. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17708. #if PACKETVER_SUPPORTS_SALES
  17709. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17710. struct sale_item_data* sale;
  17711. if( p->AID != sd->status.account_id ){
  17712. return;
  17713. }
  17714. sale = sale_find_item( p->itemId, true );
  17715. if( sale == NULL ){
  17716. return;
  17717. }
  17718. clif_sale_amount(sale, &sd->bl, SELF);
  17719. #endif
  17720. }
  17721. /// Opens the sale administration window on the client
  17722. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17723. void clif_sale_open( struct map_session_data* sd ){
  17724. #if PACKETVER_SUPPORTS_SALES
  17725. nullpo_retv(sd);
  17726. if( sd->state.sale_open ){
  17727. return;
  17728. }
  17729. sd->state.sale_open = true;
  17730. int fd = sd->fd;
  17731. WFIFOHEAD(fd, 2);
  17732. WFIFOW(fd, 0) = 0x9b5;
  17733. WFIFOSET(fd, 2);
  17734. #endif
  17735. }
  17736. /// Client request to open the sale administration window.
  17737. /// This is sent by /limitedsale
  17738. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17739. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17740. #if PACKETVER_SUPPORTS_SALES
  17741. nullpo_retv(sd);
  17742. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17743. return;
  17744. }
  17745. char command[CHAT_SIZE_MAX];
  17746. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17747. is_atcommand(fd, sd, command, 1);
  17748. #endif
  17749. }
  17750. /// Closes the sale administration window on the client.
  17751. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17752. void clif_sale_close(struct map_session_data* sd) {
  17753. #if PACKETVER_SUPPORTS_SALES
  17754. nullpo_retv(sd);
  17755. if( !sd->state.sale_open ){
  17756. return;
  17757. }
  17758. sd->state.sale_open = false;
  17759. int fd = sd->fd;
  17760. WFIFOHEAD(fd, 2);
  17761. WFIFOW(fd, 0) = 0x9bd;
  17762. WFIFOSET(fd, 2);
  17763. #endif
  17764. }
  17765. /// Client request to close the sale administration window.
  17766. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17767. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17768. #if PACKETVER_SUPPORTS_SALES
  17769. nullpo_retv(sd);
  17770. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17771. return;
  17772. }
  17773. clif_sale_close(sd);
  17774. #endif
  17775. }
  17776. /// Reply to a item search request for item sale administration.
  17777. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17778. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17779. #if PACKETVER_SUPPORTS_SALES
  17780. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17781. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17782. if( item != NULL ){
  17783. p.result = 0;
  17784. p.itemId = client_nameid( item->nameid );
  17785. p.price = item->price;
  17786. }else{
  17787. p.result = 1;
  17788. p.itemId = 0;
  17789. p.price = 0;
  17790. }
  17791. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17792. #endif
  17793. }
  17794. /// Search request for an item sale administration.
  17795. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17796. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17797. #if PACKETVER_SUPPORTS_SALES
  17798. char item_name[ITEM_NAME_LENGTH];
  17799. nullpo_retv(sd);
  17800. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17801. return;
  17802. }
  17803. if( !sd->state.sale_open ){
  17804. return;
  17805. }
  17806. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17807. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17808. if( id ){
  17809. int i;
  17810. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17811. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17812. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17813. return;
  17814. }
  17815. }
  17816. }
  17817. // not found
  17818. clif_sale_search_reply( sd, NULL );
  17819. #endif
  17820. }
  17821. /// Reply if an item was successfully put on sale or not.
  17822. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17823. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17824. #if PACKETVER_SUPPORTS_SALES
  17825. int fd = sd->fd;
  17826. WFIFOHEAD(fd, 4);
  17827. WFIFOW(fd, 0) = 0x9af;
  17828. WFIFOW(fd, 2) = (uint16)result;
  17829. WFIFOSET(fd, 4);
  17830. #endif
  17831. }
  17832. /// A client request to put an item on sale.
  17833. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17834. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17835. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17836. #if PACKETVER_SUPPORTS_SALES
  17837. nullpo_retv( sd );
  17838. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17839. if( p->AID != sd->status.account_id ){
  17840. return;
  17841. }
  17842. if( !sd->state.sale_open ){
  17843. return;
  17844. }
  17845. time_t endTime = p->startTime + p->hours * 60 * 60;
  17846. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17847. #endif
  17848. }
  17849. /// Reply to an item removal from sale.
  17850. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17851. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17852. #if PACKETVER_SUPPORTS_SALES
  17853. int fd = sd->fd;
  17854. WFIFOHEAD(fd, 4);
  17855. WFIFOW(fd, 0) = 0x9b1;
  17856. WFIFOW(fd, 2) = failed;
  17857. WFIFOSET(fd, 4);
  17858. #endif
  17859. }
  17860. /// Request to remove an item from sale.
  17861. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17862. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17863. #if PACKETVER_SUPPORTS_SALES
  17864. nullpo_retv( sd );
  17865. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17866. if( p->AID != sd->status.account_id ){
  17867. return;
  17868. }
  17869. if( !sd->state.sale_open ){
  17870. return;
  17871. }
  17872. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17873. #endif
  17874. }
  17875. /// Achievement System
  17876. /// Author: Luxuri, Aleos
  17877. /**
  17878. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17879. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17880. */
  17881. void clif_achievement_list_all(struct map_session_data *sd)
  17882. {
  17883. nullpo_retv(sd);
  17884. if (!battle_config.feature_achievement) {
  17885. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17886. return;
  17887. }
  17888. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17889. if (count == 0)
  17890. return;
  17891. int len = (50 * count) + 22;
  17892. int fd = sd->fd;
  17893. int *info = achievement_level(sd, true);
  17894. WFIFOHEAD(fd,len);
  17895. WFIFOW(fd, 0) = 0xa23;
  17896. WFIFOW(fd, 2) = len;
  17897. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17898. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17899. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17900. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17901. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17902. for (int i = 0; i < count; i++) {
  17903. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17904. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17905. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17906. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17907. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17908. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17909. }
  17910. WFIFOSET(fd, len);
  17911. }
  17912. /**
  17913. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17914. * 0a24 <ACHPoint>.L
  17915. */
  17916. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17917. {
  17918. nullpo_retv(sd);
  17919. if (!battle_config.feature_achievement) {
  17920. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17921. return;
  17922. }
  17923. int fd = sd->fd;
  17924. int *info = achievement_level(sd, true);
  17925. WFIFOHEAD(fd, packet_len(0xa24));
  17926. WFIFOW(fd, 0) = 0xa24;
  17927. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17928. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17929. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17930. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17931. if (ach) {
  17932. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17933. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17934. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17935. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17936. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17937. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17938. } else
  17939. memset(WFIFOP(fd, 16), 0, 40);
  17940. WFIFOSET(fd, packet_len(0xa24));
  17941. }
  17942. /**
  17943. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17944. * 0a25 <achievementID>.L
  17945. */
  17946. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17947. {
  17948. nullpo_retv(sd);
  17949. if( sd->achievement_data.save )
  17950. intif_achievement_save(sd);
  17951. achievement_check_reward(sd, RFIFOL(fd,2));
  17952. }
  17953. /**
  17954. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17955. * 0a26 <result>.W <achievementID>.L
  17956. */
  17957. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17958. {
  17959. WFIFOHEAD(fd, packet_len(0xa26));
  17960. WFIFOW(fd, 0) = 0xa26;
  17961. WFIFOB(fd, 2) = result;
  17962. WFIFOL(fd, 3) = achievement_id;
  17963. WFIFOSET(fd, packet_len(0xa26));
  17964. }
  17965. /// Process the pet evolution request
  17966. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17967. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17968. #if PACKETVER >= 20141008
  17969. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17970. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17971. if (!pet) {
  17972. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17973. return;
  17974. }
  17975. pet_evolution(sd, pet->class_);
  17976. #endif
  17977. }
  17978. /// Sends the result of the evolution to the client.
  17979. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17980. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17981. #if PACKETVER >= 20141008
  17982. int fd = sd->fd;
  17983. WFIFOHEAD(fd, packet_len(0x9fc));
  17984. WFIFOW(fd, 0) = 0x9fc;
  17985. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17986. WFIFOSET(fd, packet_len(0x9fc));
  17987. #endif
  17988. }
  17989. /*
  17990. * This packet is sent by /changedress or /nocosplay
  17991. *
  17992. * 0ae8
  17993. */
  17994. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17995. #if PACKETVER >= 20180103
  17996. char command[CHAT_SIZE_MAX];
  17997. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17998. is_atcommand( fd, sd, command, 1 );
  17999. #endif
  18000. }
  18001. /// Opens an UI window of the given type and initializes it with the given data
  18002. /// 0AE2 <type>.B <data>.L
  18003. void clif_ui_open( struct map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  18004. #if PACKETVER >= 20151202
  18005. // If the UI requires state tracking
  18006. switch( ui_type ){
  18007. case OUT_UI_STYLIST:
  18008. sd.state.stylist_open = true;
  18009. break;
  18010. case OUT_UI_ENCHANTGRADE:
  18011. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  18012. sd.state.enchantgrade_open = true;
  18013. break;
  18014. #else
  18015. return;
  18016. #endif
  18017. }
  18018. struct PACKET_ZC_UI_OPEN p = {};
  18019. p.PacketType = HEADER_ZC_UI_OPEN;
  18020. p.UIType = ui_type;
  18021. #if PACKETVER >= 20171122
  18022. p.data = data;
  18023. #endif
  18024. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  18025. #endif
  18026. }
  18027. /// Request to open an UI window of the given type
  18028. /// 0A68 <type>.B
  18029. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  18030. switch( RFIFOB(fd,2) ){
  18031. case IN_UI_ATTENDANCE:
  18032. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  18033. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  18034. }else if( pc_attendance_enabled() ){
  18035. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  18036. }else{
  18037. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  18038. }
  18039. break;
  18040. }
  18041. }
  18042. /// Response for attedance request
  18043. /// 0AF0 <unknown>.L <data>.L
  18044. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  18045. nullpo_retv(sd);
  18046. int fd = sd->fd;
  18047. WFIFOHEAD(fd,packet_len(0xAF0));
  18048. WFIFOW(fd,0) = 0xAF0;
  18049. WFIFOL(fd,2) = 0;
  18050. WFIFOL(fd,6) = data;
  18051. WFIFOSET(fd,packet_len(0xAF0));
  18052. }
  18053. /// Request from the client to retrieve today's attendance reward
  18054. /// 0AEF
  18055. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  18056. pc_attendance_claim_reward(sd);
  18057. }
  18058. /// Send out the percentage of weight that causes it to be displayed in red.
  18059. /// 0ADE <percentage>.L
  18060. void clif_weight_limit( struct map_session_data* sd ){
  18061. #if PACKETVER >= 20171025
  18062. nullpo_retv(sd);
  18063. int fd = sd->fd;
  18064. WFIFOHEAD(fd, packet_len(0xADE));
  18065. WFIFOW(fd, 0) = 0xADE;
  18066. #ifdef RENEWAL
  18067. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18068. #else
  18069. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18070. #endif
  18071. WFIFOSET(fd, packet_len(0xADE));
  18072. #endif
  18073. }
  18074. enum e_private_airship_response : uint32{
  18075. PRIVATEAIRSHIP_OK,
  18076. PRIVATEAIRSHIP_RETRY,
  18077. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18078. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18079. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18080. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18081. };
  18082. /// Send out the response to a private airship request
  18083. /// 0A4A <response>.L
  18084. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  18085. #if PACKETVER >= 20180321
  18086. nullpo_retv( sd );
  18087. int fd = sd->fd;
  18088. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18089. WFIFOW( fd, 0 ) = 0xA4A;
  18090. WFIFOL( fd, 2 ) = response;
  18091. WFIFOSET( fd, packet_len( 0xA4A ) );
  18092. #endif
  18093. }
  18094. /// Parses a request for a private airship
  18095. /// 0A49 <mapname>.16B <itemid>.W
  18096. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  18097. #if PACKETVER >= 20180321
  18098. // Check if the feature is enabled
  18099. if( !battle_config.feature_privateairship ){
  18100. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18101. return;
  18102. }
  18103. // Check if the player is allowed to warp from the source map
  18104. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18105. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18106. return;
  18107. }
  18108. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18109. char mapname[MAP_NAME_LENGTH_EXT];
  18110. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18111. int16 mapindex = mapindex_name2id( mapname );
  18112. // Check if we know the mapname
  18113. if( mapindex < 0 ){
  18114. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18115. return;
  18116. }
  18117. int16 mapid = map_mapindex2mapid( mapindex );
  18118. // Check if the map is available on this server
  18119. if( mapid < 0 ){
  18120. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18121. return;
  18122. }
  18123. // Check if the player tried to warp to the map he is on
  18124. if( sd->bl.m == mapid ){
  18125. // This is blocked by the client, but just to be sure
  18126. return;
  18127. }
  18128. // This can only be a hack, so we prevent it
  18129. if( map_getmapdata( mapid )->instance_id ){
  18130. // Ignore requests to warp directly into a running instance
  18131. return;
  18132. }
  18133. // Check if the player is allowed to warp to the target map
  18134. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18135. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18136. return;
  18137. }
  18138. t_itemid item_id = p->ItemID;
  18139. // Check if the item sent by the client is known to us
  18140. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18141. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18142. return;
  18143. }
  18144. int idx = pc_search_inventory( sd, item_id );
  18145. // Check if the player has the item at all
  18146. if( idx < 0 ){
  18147. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18148. return;
  18149. }
  18150. // Delete the chosen item
  18151. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18152. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18153. return;
  18154. }
  18155. // Warp the player to a random spot on the destination map
  18156. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18157. #endif
  18158. }
  18159. /// Sends out the usage history of the guild storage
  18160. /// 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
  18161. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18162. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18163. #if PACKETVER >= 20140205
  18164. nullpo_retv( sd );
  18165. int fd = sd->fd;
  18166. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18167. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18168. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18169. }else{
  18170. log.clear();
  18171. }
  18172. WFIFOHEAD( fd, size );
  18173. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18174. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18175. p->PacketLength = size;
  18176. p->result = result;
  18177. p->amount = (uint16)log.size();
  18178. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18179. for( int i = 0; i < log.size(); i++ ){
  18180. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18181. struct guild_log_entry& entry = log[i];
  18182. item->id = entry.id;
  18183. item->itemId = client_nameid( entry.item.nameid );
  18184. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18185. item->action = entry.amount > 0; // action = true(put), false(get)
  18186. item->refine = entry.item.refine;
  18187. item->uniqueId = entry.item.unique_id;
  18188. item->IsIdentified = entry.item.identify;
  18189. item->itemType = itemtype( entry.item.nameid );
  18190. clif_addcards( &item->slot, &entry.item );
  18191. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18192. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18193. item->attribute = entry.item.attribute;
  18194. }
  18195. }
  18196. WFIFOSET( fd, p->PacketLength );
  18197. #endif
  18198. }
  18199. /// Activates the client camera info or updates the client camera with the given values.
  18200. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18201. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18202. #if PACKETVER >= 20160525
  18203. int fd = sd->fd;
  18204. WFIFOHEAD(fd, packet_len(0xa78));
  18205. WFIFOW(fd, 0) = 0xa78;
  18206. WFIFOB(fd, 2) = show;
  18207. WFIFOF(fd, 3) = range;
  18208. WFIFOF(fd, 7) = rotation;
  18209. WFIFOF(fd, 11) = latitude;
  18210. WFIFOSET(fd, packet_len(0xa78));
  18211. #endif
  18212. }
  18213. /// Activates or deactives the client camera info or updates the camera settings.
  18214. /// This packet is triggered by /viewpointvalue or /setcamera
  18215. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18216. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18217. char command[CHAT_SIZE_MAX];
  18218. // /viewpointvalue
  18219. if( RFIFOB( fd, 2 ) == 1 ){
  18220. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18221. // /setcamera
  18222. }else{
  18223. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18224. }
  18225. is_atcommand( fd, sd, command, 1 );
  18226. }
  18227. /// Send the full list of items in the equip switch window
  18228. /// 0a9b <length>.W { <index>.W <position>.L }*
  18229. void clif_equipswitch_list( struct map_session_data* sd ){
  18230. #if PACKETVER >= 20170208
  18231. int fd = sd->fd;
  18232. int offset, i, position;
  18233. WFIFOW(fd, 0) = 0xa9b;
  18234. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18235. short index = sd->equip_switch_index[i];
  18236. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18237. WFIFOW(fd, offset) = index + 2;
  18238. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18239. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18240. offset += 6;
  18241. }
  18242. }
  18243. WFIFOW(fd, 2) = offset;
  18244. WFIFOSET(fd, offset);
  18245. #endif
  18246. }
  18247. /// Acknowledgement for removing an equip to the equip switch window
  18248. /// 0a9a <index>.W <position.>.L <failure>.W
  18249. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18250. #if PACKETVER >= 20170208
  18251. int fd = sd->fd;
  18252. WFIFOHEAD(fd, packet_len(0xa9a));
  18253. WFIFOW(fd, 0) = 0xa9a;
  18254. WFIFOW(fd, 2) = index + 2;
  18255. WFIFOL(fd, 4) = pos;
  18256. WFIFOW(fd, 8) = failed;
  18257. WFIFOSET(fd, packet_len(0xa9a));
  18258. #endif
  18259. }
  18260. /// Request to remove an equip from the equip switch window
  18261. /// 0a99 <index>.W <position>.L <= 20170502
  18262. /// 0a99 <index>.W
  18263. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18264. #if PACKETVER >= 20170208
  18265. uint16 index = RFIFOW(fd, 2) - 2;
  18266. bool removed = false;
  18267. if( !battle_config.feature_equipswitch ){
  18268. return;
  18269. }
  18270. // Check if the index is valid
  18271. if( index >= MAX_INVENTORY ){
  18272. return;
  18273. }
  18274. pc_equipswitch_remove( sd, index );
  18275. #endif
  18276. }
  18277. /// Acknowledgement for adding an equip to the equip switch window
  18278. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18279. /// 0a98 <index>.W <position.>.L <flag>.W
  18280. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18281. #if PACKETVER >= 20170208
  18282. int fd = sd->fd;
  18283. WFIFOHEAD(fd, packet_len(0xa98));
  18284. WFIFOW(fd, 0) = 0xa98;
  18285. WFIFOW(fd, 2) = index + 2;
  18286. WFIFOL(fd, 4) = pos;
  18287. #if PACKETVER <= 20170502
  18288. WFIFOL(fd, 8) = flag;
  18289. #else
  18290. WFIFOW(fd, 8) = flag;
  18291. #endif
  18292. WFIFOSET(fd,packet_len(0xa98));
  18293. #endif
  18294. }
  18295. /// Request to add an equip to the equip switch window
  18296. /// 0a97 <index>.W <position>.L
  18297. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18298. #if PACKETVER >= 20170208
  18299. uint16 index = RFIFOW(fd, 2) - 2;
  18300. uint32 position = RFIFOL(fd, 4);
  18301. if( !battle_config.feature_equipswitch ){
  18302. return;
  18303. }
  18304. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18305. return;
  18306. }
  18307. if( sd->state.trading || sd->npc_shopid ){
  18308. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18309. return;
  18310. }
  18311. if( sd->inventory_data[index]->type == IT_AMMO ){
  18312. position = EQP_AMMO;
  18313. }
  18314. pc_equipitem( sd, index, position, true );
  18315. #endif
  18316. }
  18317. /// Acknowledgement packet for the full equip switch
  18318. /// 0a9d <failed>.W
  18319. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18320. #if PACKETVER >= 20170208
  18321. int fd = sd->fd;
  18322. WFIFOHEAD(fd, packet_len(0xa9d));
  18323. WFIFOW(fd, 0) = 0xa9d;
  18324. WFIFOW(fd, 2) = failed;
  18325. WFIFOSET(fd, packet_len(0xa9d));
  18326. #endif
  18327. }
  18328. /// Request to do a full equip switch
  18329. /// 0a9c
  18330. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18331. #if PACKETVER >= 20170208
  18332. int i;
  18333. t_tick tick = gettick();
  18334. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18335. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18336. // Client will not let you send a request
  18337. return;
  18338. }
  18339. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18340. if( !battle_config.feature_equipswitch ){
  18341. return;
  18342. }
  18343. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18344. if( i == EQI_MAX ){
  18345. // client will show: "There is no item to replace." and should not even come here
  18346. clif_equipswitch_reply( sd, false );
  18347. return;
  18348. }
  18349. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18350. return;
  18351. }
  18352. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18353. #endif
  18354. }
  18355. /// Request to do a single equip switch
  18356. /// 0ace <index>.W
  18357. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18358. #if PACKETVER >= 20170502
  18359. uint16 index = RFIFOW(fd, 2) - 2;
  18360. if( !battle_config.feature_equipswitch ){
  18361. return;
  18362. }
  18363. // Check if the index is valid
  18364. if( index >= MAX_INVENTORY ){
  18365. return;
  18366. }
  18367. // Check if the item exists
  18368. if (sd->inventory_data[index] == nullptr)
  18369. return;
  18370. // Check if the item was already added to equip switch
  18371. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18372. if( sd->npc_id ){
  18373. #ifdef RENEWAL
  18374. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18375. clif_msg( sd, WORK_IN_PROGRESS );
  18376. return;
  18377. }
  18378. #endif
  18379. if( !sd->npc_item_flag ){
  18380. return;
  18381. }
  18382. }
  18383. pc_equipswitch( sd, index );
  18384. return;
  18385. }
  18386. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18387. #endif
  18388. }
  18389. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18390. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18391. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18392. // Only rolling cutter is supported for now
  18393. if( p->skillId != GC_ROLLINGCUTTER ){
  18394. return;
  18395. }
  18396. // Already running - cant happen on officials, since only one skill is supported
  18397. if( sd->skill_keep_using.skill_id != 0 ){
  18398. return;
  18399. }
  18400. sd->skill_keep_using.tid = INVALID_TIMER;
  18401. sd->skill_keep_using.skill_id = p->skillId;
  18402. sd->skill_keep_using.level = p->skillLv;
  18403. sd->skill_keep_using.target = p->targetId;
  18404. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18405. #endif
  18406. }
  18407. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18408. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18409. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18410. // Not running
  18411. if( sd->skill_keep_using.skill_id == 0 ){
  18412. return;
  18413. }
  18414. #if 0
  18415. // Hack
  18416. if( p->skillId != sd->skill_keep_using.skill_id ){
  18417. return;
  18418. }
  18419. #endif
  18420. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18421. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18422. sd->skill_keep_using.tid = INVALID_TIMER;
  18423. }
  18424. sd->skill_keep_using.skill_id = 0;
  18425. sd->skill_keep_using.level = 0;
  18426. sd->skill_keep_using.target = 0;
  18427. #endif
  18428. }
  18429. void clif_ping( struct map_session_data* sd ){
  18430. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18431. nullpo_retv( sd );
  18432. int fd = sd->fd;
  18433. if( !session_isActive( fd ) ){
  18434. return;
  18435. }
  18436. struct PACKET_ZC_PING_LIVE p = {};
  18437. p.packetType = HEADER_ZC_PING_LIVE;
  18438. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18439. #endif
  18440. }
  18441. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18442. nullpo_ret( sd );
  18443. int fd = sd->fd;
  18444. if( !session_isActive( fd ) ){
  18445. return 0;
  18446. }
  18447. t_tick tick = va_arg( ap, t_tick );
  18448. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18449. clif_ping( sd );
  18450. }
  18451. return 0;
  18452. }
  18453. TIMER_FUNC( clif_ping_timer ){
  18454. map_foreachpc( clif_ping_timer_sub, gettick() );
  18455. return 0;
  18456. }
  18457. /**
  18458. * Opens the refine UI on the designated client.
  18459. * 0aa0
  18460. */
  18461. void clif_refineui_open( struct map_session_data* sd ){
  18462. #if PACKETVER >= 20161012
  18463. nullpo_retv( sd );
  18464. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18465. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18466. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18467. sd->state.refineui_open = true;
  18468. #endif
  18469. }
  18470. /**
  18471. * Parses cancel/close of the refine UI on client side.
  18472. * 0aa4
  18473. */
  18474. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18475. #if PACKETVER >= 20161012
  18476. sd->state.refineui_open = false;
  18477. #endif
  18478. }
  18479. /**
  18480. * Adds the selected item into the refine UI and sends the possible materials
  18481. * to the client.
  18482. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18483. */
  18484. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18485. #if PACKETVER >= 20161012
  18486. int fd = sd->fd;
  18487. // Get the item db reference
  18488. struct item_data* id = sd->inventory_data[index];
  18489. // No item data was found
  18490. if( id == NULL ){
  18491. return;
  18492. }
  18493. // Check the inventory
  18494. struct item* item = &sd->inventory.u.items_inventory[index];
  18495. // No item was found at the given index
  18496. if( item == NULL ){
  18497. return;
  18498. }
  18499. // Check if the item is identified
  18500. if( !item->identify ){
  18501. return;
  18502. }
  18503. // Check if the item is broken
  18504. if( item->attribute ){
  18505. return;
  18506. }
  18507. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18508. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18509. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18510. p->itemIndex = client_index( index );
  18511. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18512. // No possibilities were found
  18513. if( info == nullptr ){
  18514. p->blacksmithBlessing = 0;
  18515. }else{
  18516. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18517. uint16 count = 0;
  18518. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18519. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18520. if( cost != nullptr ){
  18521. p->req[count].itemId = client_nameid( cost->nameid );
  18522. p->req[count].chance = (uint8)( cost->chance / 100 );
  18523. p->req[count].zeny = cost->zeny;
  18524. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18525. count++;
  18526. }
  18527. }
  18528. }
  18529. clif_send( p, p->packetLength, &sd->bl, SELF );
  18530. #endif
  18531. }
  18532. /**
  18533. * Client request to add an item to the refine UI.
  18534. * 0aa1 <index>.W
  18535. */
  18536. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18537. #if PACKETVER >= 20161012
  18538. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18539. uint16 index = server_index( p->index );
  18540. // Check if the refine UI is open
  18541. if( !sd->state.refineui_open ){
  18542. return;
  18543. }
  18544. // Check if the index is valid
  18545. if( index >= MAX_INVENTORY ){
  18546. return;
  18547. }
  18548. // Send out the requirements for the refine process
  18549. clif_refineui_info( sd, index );
  18550. #endif
  18551. }
  18552. /**
  18553. * Client requests to try to refine an item.
  18554. * 0aa3 <index>.W <material>.W <catalyst>.B
  18555. */
  18556. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18557. #if PACKETVER >= 20161012
  18558. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18559. uint16 index = server_index( p->index );
  18560. t_itemid material = p->itemId;
  18561. int16 j;
  18562. // Check if the refine UI is open
  18563. if( !sd->state.refineui_open ){
  18564. return;
  18565. }
  18566. // Check if the index is valid
  18567. if( index >= MAX_INVENTORY ){
  18568. return;
  18569. }
  18570. // Get the item db reference
  18571. struct item_data* id = sd->inventory_data[index];
  18572. // No item data was found
  18573. if( id == NULL ){
  18574. return;
  18575. }
  18576. // Check the inventory
  18577. struct item* item = &sd->inventory.u.items_inventory[index];
  18578. // No item was found at the given index
  18579. if( item == NULL ){
  18580. return;
  18581. }
  18582. // Check if the item is identified
  18583. if( !item->identify ){
  18584. return;
  18585. }
  18586. // Check if the item is broken
  18587. if( item->attribute ){
  18588. return;
  18589. }
  18590. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18591. // No refine possible
  18592. if( info == nullptr ){
  18593. return;
  18594. }
  18595. // No possibilities were found
  18596. if( info->costs.empty() ){
  18597. return;
  18598. }
  18599. // Check if the player has the selected material
  18600. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18601. return;
  18602. }
  18603. int16 blacksmith_index = -1;
  18604. uint16 blacksmith_amount = 0;
  18605. // Check if the player has enough blacksmith blessings
  18606. if( p->blacksmithBlessing != 0 ){
  18607. blacksmith_amount = info->blessing_amount;
  18608. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18609. if( blacksmith_amount == 0 ){
  18610. return;
  18611. }
  18612. // Check if the player has blacksmith blessings
  18613. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18614. return;
  18615. }
  18616. // Check if the player has enough blacksmith blessings
  18617. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18618. return;
  18619. }
  18620. }
  18621. std::shared_ptr<s_refine_cost> cost = nullptr;
  18622. for( const auto& pair : info->costs ){
  18623. if( pair.second->nameid == material ){
  18624. cost = pair.second;
  18625. break;
  18626. }
  18627. }
  18628. // The material was not in the list of possible materials
  18629. if( cost == nullptr ){
  18630. return;
  18631. }
  18632. // Try to pay for the refine
  18633. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18634. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18635. return;
  18636. }
  18637. // Delete the required material
  18638. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18639. return;
  18640. }
  18641. // Delete the required blacksmith blessings
  18642. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18643. return;
  18644. }
  18645. // Try to refine the item
  18646. if( cost->chance >= ( rnd() % 10000 ) ){
  18647. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18648. // Success
  18649. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18650. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18651. clif_misceffect( &sd->bl, 3 );
  18652. clif_refine( fd, 0, index, item->refine );
  18653. if( id->type == IT_WEAPON ){
  18654. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18655. }
  18656. clif_refineui_info( sd, index );
  18657. }else{
  18658. // Failure
  18659. // Blacksmith blessings were used to prevent breaking and downgrading
  18660. if( blacksmith_amount > 0 ){
  18661. clif_refine( fd, 3, index, item->refine );
  18662. clif_refineui_info( sd, index );
  18663. // Delete the item if it is breakable
  18664. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18665. clif_refine( fd, 1, index, item->refine );
  18666. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18667. // Downgrade the item if necessary
  18668. }else if( cost->downgrade_amount > 0 ){
  18669. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18670. clif_refine( fd, 2, index, item->refine );
  18671. clif_refineui_info(sd, index);
  18672. // Only show failure, but dont do anything
  18673. }else{
  18674. clif_refine( fd, 3, index, item->refine );
  18675. clif_refineui_info( sd, index );
  18676. }
  18677. clif_misceffect( &sd->bl, 2 );
  18678. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18679. }
  18680. #endif
  18681. }
  18682. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18683. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18684. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18685. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18686. p.result = failed;
  18687. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18688. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18689. }
  18690. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18691. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18692. if( pc_cant_act( sd ) ){
  18693. clif_unequipall_reply( sd, true );
  18694. return;
  18695. }
  18696. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18697. if( sd->equip_index[i] >= 0 ){
  18698. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18699. }
  18700. }
  18701. clif_unequipall_reply( sd, false );
  18702. #endif
  18703. }
  18704. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18705. #if PACKETVER >= 20151104
  18706. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18707. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18708. p.flag = failed;
  18709. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18710. if( !failed ){
  18711. sd->state.stylist_open = false;
  18712. }
  18713. #endif
  18714. }
  18715. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18716. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18717. if( list == nullptr ){
  18718. return false;
  18719. }
  18720. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18721. if( entry == nullptr ){
  18722. return false;
  18723. }
  18724. std::shared_ptr<s_stylist_costs> costs;
  18725. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18726. costs = entry->doram;
  18727. }else{
  18728. costs = entry->human;
  18729. }
  18730. if( costs == nullptr ){
  18731. return false;
  18732. }
  18733. if( sd->status.zeny < costs->price ){
  18734. return false;
  18735. }
  18736. int16 inventoryIndex = -1;
  18737. if( costs->requiredItem != 0 ){
  18738. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18739. if( inventoryIndex < 0 ){
  18740. // No other option
  18741. if( costs->requiredItemBox == 0 ){
  18742. return false;
  18743. }
  18744. // Check if the box that contains the item is in the inventory
  18745. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18746. // The box containing the item also does not exist
  18747. if( inventoryIndex < 0 ){
  18748. return false;
  18749. }
  18750. }
  18751. }else if( costs->requiredItemBox != 0 ){
  18752. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18753. if( inventoryIndex < 0 ){
  18754. return false;
  18755. }
  18756. }
  18757. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18758. return false;
  18759. }
  18760. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18761. return false;
  18762. }
  18763. switch( look ){
  18764. case LOOK_HAIR:
  18765. case LOOK_HAIR_COLOR:
  18766. case LOOK_CLOTHES_COLOR:
  18767. case LOOK_BODY2:
  18768. pc_changelook( sd, look, entry->value );
  18769. break;
  18770. case LOOK_HEAD_BOTTOM:
  18771. case LOOK_HEAD_MID:
  18772. case LOOK_HEAD_TOP: {
  18773. struct mail_message msg = {};
  18774. msg.dest_id = sd->status.char_id;
  18775. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18776. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18777. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18778. msg.item[0].nameid = entry->value;
  18779. msg.item[0].identify = 1;
  18780. msg.item[0].amount = 1;
  18781. msg.status = MAIL_NEW;
  18782. msg.type = MAIL_INBOX_NORMAL;
  18783. msg.timestamp = time( nullptr );
  18784. intif_Mail_send( 0, &msg );
  18785. } break;
  18786. }
  18787. return true;
  18788. }
  18789. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18790. #if PACKETVER >= 20151104
  18791. #if PACKETVER >= 20180516
  18792. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18793. #else
  18794. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18795. #endif
  18796. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18797. clif_stylist_response( sd, true );
  18798. return;
  18799. }
  18800. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18801. clif_stylist_response( sd, true );
  18802. return;
  18803. }
  18804. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18805. clif_stylist_response( sd, true );
  18806. return;
  18807. }
  18808. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18809. clif_stylist_response( sd, true );
  18810. return;
  18811. }
  18812. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18813. clif_stylist_response( sd, true );
  18814. return;
  18815. }
  18816. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18817. clif_stylist_response( sd, true );
  18818. return;
  18819. }
  18820. #if PACKETVER >= 20180516
  18821. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18822. clif_stylist_response( sd, true );
  18823. return;
  18824. }
  18825. #endif
  18826. clif_stylist_response( sd, false );
  18827. #endif
  18828. }
  18829. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18830. #if PACKETVER >= 20151104
  18831. sd->state.stylist_open = false;
  18832. #endif
  18833. }
  18834. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18835. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18836. nullpo_retv( sd );
  18837. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18838. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18839. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18840. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18841. #endif
  18842. }
  18843. enum class e_inventory_expansion_response : uint8{
  18844. ASK_CONFIRMATION = 0,
  18845. FAILED,
  18846. BUSY,
  18847. MISSING_ITEM,
  18848. MAXIMUM_REACHED
  18849. };
  18850. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18851. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18852. nullpo_retv( sd );
  18853. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18854. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18855. p.result = (uint8)response;
  18856. p.itemId = sd->state.inventory_expansion_confirmation;
  18857. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18858. #endif
  18859. }
  18860. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18861. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18862. // Check if player is dead or busy with other stuff
  18863. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18864. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18865. return;
  18866. }
  18867. // Check if the player already reached the maximum
  18868. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18869. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18870. return;
  18871. }
  18872. static std::map<t_itemid, uint16> items = {
  18873. // The order of entries in this list defines which will be used first
  18874. // This order and the usable items are hardcoded into the client
  18875. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18876. { ITEMID_INVENTORY_EX_EVT, 10 },
  18877. { ITEMID_INVENTORY_EX_DIS, 10 },
  18878. { ITEMID_INVENTORY_EX, 10 },
  18879. };
  18880. int16 index = -1;
  18881. bool found_over_limit = false;
  18882. for( const auto& entry : items ){
  18883. // Check if the player has the required item
  18884. index = pc_search_inventory( sd, entry.first );
  18885. // Found an item
  18886. if( index >= 0 ){
  18887. // Check if the player would exceed the maximum
  18888. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18889. found_over_limit = true;
  18890. }else{
  18891. found_over_limit = false;
  18892. sd->state.inventory_expansion_confirmation = entry.first;
  18893. sd->state.inventory_expansion_amount = entry.second;
  18894. break;
  18895. }
  18896. }
  18897. }
  18898. // Check if an item was found
  18899. if( sd->state.inventory_expansion_confirmation == 0 ){
  18900. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18901. return;
  18902. }
  18903. // Check if an item would have been found, but the player would exceed the maximum
  18904. if( found_over_limit ){
  18905. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18906. return;
  18907. }
  18908. // The player met all requirements => ask him for confirmation
  18909. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18910. #endif
  18911. }
  18912. enum class e_inventory_expansion_result : uint8{
  18913. SUCCESS = 0,
  18914. FAILED,
  18915. BUSY,
  18916. MISSING_ITEM,
  18917. MAXIMUM_REACHED
  18918. };
  18919. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18920. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18921. nullpo_retv( sd );
  18922. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18923. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18924. p.result = (uint8)result;
  18925. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18926. // Reset the state tracking
  18927. sd->state.inventory_expansion_confirmation = 0;
  18928. sd->state.inventory_expansion_amount = 0;
  18929. #endif
  18930. }
  18931. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18932. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18933. if( sd->state.inventory_expansion_confirmation == 0 ){
  18934. return;
  18935. }
  18936. // Check if player is dead
  18937. if( pc_isdead( sd ) ){
  18938. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18939. return;
  18940. }
  18941. // Check if the player already reached the maximum
  18942. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18943. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18944. return;
  18945. }
  18946. // Check if the player has the required item
  18947. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18948. // The player did not have the item anymore
  18949. if( index < 0 ){
  18950. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18951. return;
  18952. }
  18953. // Check if the player would exceed the maximum
  18954. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18955. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18956. return;
  18957. }
  18958. // Delete the required item
  18959. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18960. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18961. return;
  18962. }
  18963. // Increase the slots
  18964. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18965. // Save player data (slots) and inventory data (removed item)
  18966. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18967. // Inform the player of success
  18968. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18969. clif_inventory_expansion_info( sd );
  18970. #endif
  18971. }
  18972. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18973. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18974. sd->state.inventory_expansion_confirmation = 0;
  18975. sd->state.inventory_expansion_amount = 0;
  18976. #endif
  18977. }
  18978. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  18979. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18980. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18981. return;
  18982. }
  18983. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18984. if( barter == nullptr ){
  18985. return;
  18986. }
  18987. sd.state.barter_open = true;
  18988. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18989. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18990. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  18991. int16 count = 0;
  18992. for( const auto& itemPair : barter->items ){
  18993. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  18994. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18995. item->nameid = client_nameid( id->nameid );
  18996. item->type = itemtype( id->nameid );
  18997. if( itemPair.second->stockLimited ){
  18998. item->amount = itemPair.second->stock;
  18999. }else{
  19000. item->amount = -1;
  19001. }
  19002. item->weight = id->weight;
  19003. item->index = itemPair.second->index;
  19004. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19005. item->viewSprite = id->look;
  19006. item->location = pc_equippoint_sub( &sd, id.get() );
  19007. #endif
  19008. // Use a loop if someone did not start with index 0
  19009. for( const auto& requirementPair : itemPair.second->requirements ){
  19010. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19011. item->currencyNameid = client_nameid( requirement->nameid );
  19012. item->currencyAmount = requirement->amount;
  19013. // It is a normal barter, cancel after first entry
  19014. break;
  19015. }
  19016. p->packetLength += (int16)( sizeof( *item ) );
  19017. count++;
  19018. }
  19019. clif_send( p, p->packetLength, &sd.bl, SELF );
  19020. #endif
  19021. }
  19022. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  19023. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19024. if( sd->state.barter_open ){
  19025. sd->npc_shopid = 0;
  19026. sd->state.barter_open = false;
  19027. }
  19028. #endif
  19029. }
  19030. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  19031. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19032. // No shop open
  19033. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19034. return;
  19035. }
  19036. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19037. // Unknown shop
  19038. if( nd == nullptr ){
  19039. return;
  19040. }
  19041. // Not a barter
  19042. if( nd->subtype != NPCTYPE_BARTER ){
  19043. return;
  19044. }
  19045. // It is an extended barter
  19046. if( nd->u.barter.extended ){
  19047. return;
  19048. }
  19049. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19050. if( barter == nullptr ){
  19051. return;
  19052. }
  19053. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19054. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  19055. // Empty purchase list
  19056. if( entries == 0 ){
  19057. return;
  19058. }
  19059. std::vector<s_barter_purchase> purchases;
  19060. purchases.reserve( entries );
  19061. // Make sure each shop index and target item id is only used once
  19062. for( int i = 0; i < entries; i++ ){
  19063. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19064. // Invalid shop index
  19065. if( item == nullptr ){
  19066. return;
  19067. }
  19068. for( int j = i + 1; j < entries; j++ ){
  19069. // Same shop index
  19070. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19071. return;
  19072. }
  19073. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19074. // Invalid shop index
  19075. if( item2 == nullptr ){
  19076. return;
  19077. }
  19078. // Same target item id
  19079. if( item->nameid == item2->nameid ){
  19080. return;
  19081. }
  19082. }
  19083. s_barter_purchase purchase = {};
  19084. purchase.item = item;
  19085. purchase.amount = p->list[i].amount;
  19086. purchases.push_back( purchase );
  19087. }
  19088. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19089. #endif
  19090. }
  19091. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  19092. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19093. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19094. return;
  19095. }
  19096. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19097. if( barter == nullptr ){
  19098. return;
  19099. }
  19100. sd.state.barter_extended_open = true;
  19101. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19102. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19103. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19104. p->items_count = 0;
  19105. for( const auto& itemPair : barter->items ){
  19106. // Needs dynamic calculation, because of variable currencies
  19107. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19108. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19109. item->nameid = client_nameid( id->nameid );
  19110. item->type = itemtype( id->nameid );
  19111. if( itemPair.second->stockLimited ){
  19112. item->amount = itemPair.second->stock;
  19113. }else{
  19114. item->amount = -1;
  19115. }
  19116. item->weight = id->weight;
  19117. item->index = itemPair.second->index;
  19118. item->zeny = itemPair.second->price;
  19119. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19120. item->viewSprite = id->look;
  19121. item->location = pc_equippoint_sub( &sd, id.get() );
  19122. #endif
  19123. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19124. p->items_count++;
  19125. item->currency_count = 0;
  19126. for( const auto& requirementPair : itemPair.second->requirements ){
  19127. // Needs dynamic calculation, because of variable currencies
  19128. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19129. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19130. req->nameid = requirement->nameid;
  19131. if( requirement->refine >= 0 ){
  19132. req->refine_level = requirement->refine;
  19133. }else{
  19134. req->refine_level = 0;
  19135. }
  19136. req->amount = requirement->amount;
  19137. req->type = itemtype( requirement->nameid );
  19138. p->packetLength += (int16)( sizeof( *req ) );
  19139. item->currency_count++;
  19140. }
  19141. }
  19142. clif_send( p, p->packetLength, &sd.bl, SELF );
  19143. #endif
  19144. }
  19145. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  19146. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19147. if( sd->state.barter_extended_open ){
  19148. sd->npc_shopid = 0;
  19149. sd->state.barter_extended_open = false;
  19150. }
  19151. #endif
  19152. }
  19153. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  19154. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19155. // No shop open
  19156. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19157. return;
  19158. }
  19159. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19160. // Unknown shop
  19161. if( nd == nullptr ){
  19162. return;
  19163. }
  19164. // Not a barter
  19165. if( nd->subtype != NPCTYPE_BARTER ){
  19166. return;
  19167. }
  19168. // Not an extended barter
  19169. if( !nd->u.barter.extended ){
  19170. return;
  19171. }
  19172. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19173. if( barter == nullptr ){
  19174. return;
  19175. }
  19176. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19177. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19178. // Empty purchase list
  19179. if( entries == 0 ){
  19180. return;
  19181. }
  19182. std::vector<s_barter_purchase> purchases;
  19183. purchases.reserve( entries );
  19184. // Make sure each shop index and target item id is only used once
  19185. for( int i = 0; i < entries; i++ ){
  19186. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19187. // Invalid shop index
  19188. if( item == nullptr ){
  19189. return;
  19190. }
  19191. for( int j = i + 1; j < entries; j++ ){
  19192. // Same shop index
  19193. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19194. return;
  19195. }
  19196. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19197. // Invalid shop index
  19198. if( item2 == nullptr ){
  19199. return;
  19200. }
  19201. // Same target item id
  19202. if( item->nameid == item2->nameid ){
  19203. return;
  19204. }
  19205. }
  19206. s_barter_purchase purchase = {};
  19207. purchase.item = item;
  19208. purchase.amount = p->list[i].amount;
  19209. purchases.push_back( purchase );
  19210. }
  19211. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19212. #endif
  19213. }
  19214. void clif_summon_init(struct mob_data& md) {
  19215. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19216. struct block_list* master_bl = battle_get_master(&md.bl);
  19217. if( master_bl == nullptr ){
  19218. return;
  19219. }
  19220. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19221. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19222. p.summonAID = md.bl.id;
  19223. p.CurrentHP = md.status.hp;
  19224. p.MaxHP = md.status.max_hp;
  19225. clif_send( &p, sizeof( p ), master_bl, SELF );
  19226. #endif
  19227. }
  19228. void clif_summon_hp_bar(struct mob_data& md) {
  19229. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19230. struct block_list* master_bl = battle_get_master(&md.bl);
  19231. if( master_bl == nullptr ){
  19232. return;
  19233. }
  19234. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19235. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19236. p.summonAID = md.bl.id;
  19237. p.VarId = SP_HP; // HP parameter
  19238. p.Value = md.status.hp;
  19239. clif_send( &p, sizeof( p ), master_bl, SELF );
  19240. #endif
  19241. }
  19242. void clif_laphine_synthesis_open( struct map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19243. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19244. nullpo_retv( sd );
  19245. sd->state.laphine_synthesis = synthesis->item_id;
  19246. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19247. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19248. p.itemId = client_nameid( synthesis->item_id );
  19249. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19250. #endif
  19251. }
  19252. void clif_parse_laphine_synthesis_close( int fd, struct map_session_data* sd ){
  19253. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19254. sd->state.laphine_synthesis = 0;
  19255. #endif
  19256. }
  19257. enum e_laphine_synthesis_result : int16{
  19258. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19259. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19260. LAPHINE_SYNTHESIS_ITEM = 7
  19261. };
  19262. void clif_laphine_synthesis_result( struct map_session_data* sd, enum e_laphine_synthesis_result result ){
  19263. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19264. nullpo_retv( sd );
  19265. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19266. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19267. p.result = result;
  19268. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19269. #endif
  19270. }
  19271. void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){
  19272. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19273. if( sd->state.laphine_synthesis == 0 ){
  19274. return;
  19275. }
  19276. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19277. if( sd->state.laphine_synthesis != p->itemId ){
  19278. return;
  19279. }
  19280. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19281. if( synthesis == nullptr ){
  19282. return;
  19283. }
  19284. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19285. // Player sent more or less than actually required
  19286. if( count != synthesis->requiredRequirements ){
  19287. return;
  19288. }
  19289. // Check for duplicates
  19290. for( size_t i = 0; i < count; i++ ){
  19291. for( size_t j = i + 1; j < count; j++ ){
  19292. if( p->items[i].index == p->items[j].index ){
  19293. return;
  19294. }
  19295. }
  19296. }
  19297. for( size_t i = 0; i < count; i++ ){
  19298. int16 index = server_index( p->items[i].index );
  19299. if( index >= MAX_INVENTORY ){
  19300. return;
  19301. }
  19302. if( sd->inventory_data[i] == nullptr ){
  19303. return;
  19304. }
  19305. struct item* item = &sd->inventory.u.items_inventory[index];
  19306. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19307. if( requirement == nullptr ){
  19308. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19309. return;
  19310. }
  19311. if( p->items[i].count != requirement->amount ){
  19312. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19313. return;
  19314. }
  19315. if( item->amount < requirement->amount ){
  19316. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19317. return;
  19318. }
  19319. if( item->refine < synthesis->minimumRefine ){
  19320. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19321. return;
  19322. }
  19323. if( item->refine > synthesis->maximumRefine ){
  19324. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19325. return;
  19326. }
  19327. if( item->equip != 0 ){
  19328. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19329. return;
  19330. }
  19331. if( item->equipSwitch != 0 ){
  19332. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19333. return;
  19334. }
  19335. }
  19336. // If triggered from item
  19337. if( sd->itemid == sd->state.laphine_synthesis ){
  19338. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19339. if( index < 0 ){
  19340. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19341. return;
  19342. }
  19343. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19344. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19345. return;
  19346. }
  19347. }
  19348. }
  19349. for( size_t i = 0; i < count; i++ ){
  19350. int16 index = server_index( p->items[i].index );
  19351. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19352. return;
  19353. }
  19354. }
  19355. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19356. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19357. #endif
  19358. }
  19359. void clif_laphine_upgrade_open( struct map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19360. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19361. nullpo_retv( sd );
  19362. sd->state.laphine_upgrade = upgrade->item_id;
  19363. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19364. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19365. p.itemId = client_nameid( upgrade->item_id );
  19366. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19367. #endif
  19368. }
  19369. void clif_parse_laphine_upgrade_close( int fd, struct map_session_data* sd ){
  19370. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19371. sd->state.laphine_upgrade = 0;
  19372. #endif
  19373. }
  19374. void clif_laphine_upgrade_result( struct map_session_data *sd, bool failed ){
  19375. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19376. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19377. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19378. p.result = failed;
  19379. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19380. #endif
  19381. }
  19382. static void clif_item_preview( struct map_session_data *sd, int16 index ){
  19383. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19384. nullpo_retv( sd );
  19385. struct item* item = &sd->inventory.u.items_inventory[index];
  19386. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19387. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19388. p.index = client_index( index );
  19389. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19390. p.isDamaged = item->attribute != 0;
  19391. #endif
  19392. p.refiningLevel = item->refine;
  19393. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19394. p.enchantgrade = item->enchantgrade;
  19395. #endif
  19396. clif_addcards( &p.slot, item );
  19397. clif_add_random_options( p.option_data, item );
  19398. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19399. #endif
  19400. }
  19401. void clif_parse_laphine_upgrade( int fd, struct map_session_data* sd ){
  19402. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19403. if( sd->state.laphine_upgrade == 0 ){
  19404. return;
  19405. }
  19406. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19407. if( sd->state.laphine_upgrade != p->itemId ){
  19408. return;
  19409. }
  19410. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19411. if( upgrade == nullptr ){
  19412. return;
  19413. }
  19414. uint16 index = server_index( p->index );
  19415. if( index >= MAX_INVENTORY ){
  19416. return;
  19417. }
  19418. if( sd->inventory_data[index] == nullptr ){
  19419. return;
  19420. }
  19421. struct item* item = &sd->inventory.u.items_inventory[index];
  19422. // Not a valid target item
  19423. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19424. clif_laphine_upgrade_result( sd, true );
  19425. return;
  19426. }
  19427. // If target item is not identified
  19428. if( item->identify == 0 ){
  19429. clif_laphine_upgrade_result( sd, true );
  19430. return;
  19431. }
  19432. // If target item is equipped
  19433. if( item->equip != 0 ){
  19434. clif_laphine_upgrade_result( sd, true );
  19435. return;
  19436. }
  19437. // If target item is in equipswitch
  19438. if( item->equipSwitch != 0 ){
  19439. clif_laphine_upgrade_result( sd, true );
  19440. return;
  19441. }
  19442. // Check minimum refine requirement
  19443. if( item->refine < upgrade->minimumRefine ){
  19444. clif_laphine_upgrade_result( sd, true );
  19445. return;
  19446. }
  19447. // Check maximum refine requirement
  19448. if( item->refine > upgrade->maximumRefine ){
  19449. clif_laphine_upgrade_result( sd, true );
  19450. return;
  19451. }
  19452. // If no cards are allowed
  19453. if( !upgrade->cardsAllowed ){
  19454. for( int i = 0; i < MAX_SLOTS; i++ ){
  19455. if( item->card[i] != 0 ){
  19456. clif_laphine_upgrade_result( sd, true );
  19457. return;
  19458. }
  19459. }
  19460. }
  19461. // If random options are required
  19462. if( upgrade->requiredRandomOptions > 0 ){
  19463. int i;
  19464. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19465. if( item->option[i].id != 0 ){
  19466. break;
  19467. }
  19468. }
  19469. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19470. clif_laphine_upgrade_result( sd, true );
  19471. return;
  19472. }
  19473. }
  19474. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19475. if( index2 < 0 ){
  19476. clif_laphine_upgrade_result( sd, true );
  19477. return;
  19478. }
  19479. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19480. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19481. return;
  19482. }
  19483. }
  19484. // Log removal of item
  19485. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19486. // Visually remove it from the client
  19487. clif_delitem( sd, index, 1, 0 );
  19488. // Apply the random options
  19489. if( upgrade->randomOptionGroup != nullptr ){
  19490. upgrade->randomOptionGroup->apply( *item );
  19491. }
  19492. // Change the refine rate if needed
  19493. if( upgrade->resultRefine > 0 ){
  19494. // Absolute refine level change
  19495. item->refine = max( item->refine, upgrade->resultRefine );
  19496. }else if( upgrade->resultRefineMaximum > 0 ){
  19497. // If a minimum is specified it can also downgrade
  19498. if( upgrade->resultRefineMinimum ){
  19499. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19500. }else{
  19501. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19502. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19503. }
  19504. }else if( upgrade->resultRefineMinimum > 0 ){
  19505. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19506. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19507. }
  19508. // Log retrieving the item again -> with the new options
  19509. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19510. // Make it visible for the client again
  19511. clif_additem( sd, index, 1, 0 );
  19512. // Open a preview of the item
  19513. clif_item_preview( sd, index );
  19514. // Tell the client we are done
  19515. clif_laphine_upgrade_result( sd, false );
  19516. #endif
  19517. }
  19518. void clif_enchantgrade_add( struct map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19519. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19520. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19521. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19522. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19523. if( index < UINT16_MAX ){
  19524. p->index = client_index( index );
  19525. if( sd.inventory.u.items_inventory[index].refine >= gradeLevel->refine ){
  19526. p->success_chance = gradeLevel->chance / 100;
  19527. }else{
  19528. p->success_chance = 0;
  19529. }
  19530. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19531. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19532. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19533. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19534. // Not displayed by client
  19535. p->protect_itemid = 0;
  19536. p->protect_amount = 0;
  19537. int i = 0;
  19538. for( const auto& pair : gradeLevel->options ){
  19539. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19540. p->material_info[i].nameid = client_nameid( option->item );
  19541. p->material_info[i].amount = option->amount;
  19542. p->material_info[i].price = option->zeny;
  19543. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19544. p->material_info[i].breakable = option->breaking_rate > 0;
  19545. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19546. i++;
  19547. }
  19548. }else{
  19549. p->index = -1;
  19550. p->success_chance = 0;
  19551. p->blessing_info.id = 0;
  19552. p->blessing_info.amount = 0;
  19553. p->blessing_info.max_blessing = 0;
  19554. p->blessing_info.bonus = 0;
  19555. p->protect_itemid = 0;
  19556. p->protect_amount = 0;
  19557. }
  19558. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19559. #endif
  19560. }
  19561. void clif_parse_enchantgrade_add( int fd, struct map_session_data* sd ){
  19562. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19563. nullpo_retv( sd );
  19564. if( !sd->state.enchantgrade_open ){
  19565. return;
  19566. }
  19567. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19568. uint16 index = server_index( p->index );
  19569. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19570. return;
  19571. }
  19572. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19573. // Unsupported item type - no answer, because client should have actually prevented this request
  19574. if( enchantgrade == nullptr ){
  19575. return;
  19576. }
  19577. // Item can't be enhanced
  19578. if( !sd->inventory_data[index]->flag.gradable ){
  19579. return;
  19580. }
  19581. uint16 level = 0;
  19582. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19583. level = sd->inventory_data[index]->weapon_level;
  19584. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19585. level = sd->inventory_data[index]->armor_level;
  19586. }
  19587. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19588. // Cannot upgrade this weapon or armor level
  19589. if( enchantgradelevels == enchantgrade->levels.end() ){
  19590. clif_enchantgrade_add( *sd );
  19591. return;
  19592. }
  19593. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19594. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19595. if( enchantgradelevel == nullptr ){
  19596. return;
  19597. }
  19598. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19599. #endif
  19600. }
  19601. /// <summary>
  19602. /// Sends the result for trying to enchant an item
  19603. /// </summary>
  19604. /// <param name="sd">The player session</param>
  19605. /// <param name="index">The target item</param>
  19606. /// <param name="result">
  19607. /// 0= The grade has been successfully upgraded.
  19608. /// 1= Refinement failed.
  19609. /// 2= The refine level has decreased.
  19610. /// 3= Equipment destroyed.
  19611. /// 4= The equipment is protected.
  19612. /// </param>
  19613. void clif_enchantgrade_result( struct map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19614. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19615. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19616. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19617. p.index = client_index( index );
  19618. p.enchantgrade = sd.inventory.u.items_inventory[index].enchantgrade;
  19619. p.result = result;
  19620. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19621. #endif
  19622. }
  19623. void clif_enchantgrade_announce( struct map_session_data& sd, struct item& item, bool success ){
  19624. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19625. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19626. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19627. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19628. p.itemId = client_nameid( item.nameid );
  19629. p.enchantgrade = item.enchantgrade;
  19630. p.status = success;
  19631. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19632. #endif
  19633. }
  19634. void clif_parse_enchantgrade_start( int fd, struct map_session_data* sd ){
  19635. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19636. nullpo_retv( sd );
  19637. if( !sd->state.enchantgrade_open ){
  19638. return;
  19639. }
  19640. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19641. uint16 index = server_index( p->index );
  19642. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19643. return;
  19644. }
  19645. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19646. // Unsupported item type - no answer
  19647. if( enchantgrade == nullptr ){
  19648. return;
  19649. }
  19650. uint16 level = 0;
  19651. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19652. level = sd->inventory_data[index]->weapon_level;
  19653. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19654. level = sd->inventory_data[index]->armor_level;
  19655. }
  19656. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19657. // Cannot upgrade this weapon or armor level - no answer
  19658. if( enchantgradelevels == enchantgrade->levels.end() ){
  19659. return;
  19660. }
  19661. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19662. // Cannot increase enchantgrade any further - no answer
  19663. if( enchantgradelevel == nullptr ){
  19664. return;
  19665. }
  19666. // Not refined enough
  19667. if( sd->inventory.u.items_inventory[index].refine < enchantgradelevel->refine ){
  19668. return;
  19669. }
  19670. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19671. // Unknown option id - no answer
  19672. if( option == nullptr ){
  19673. return;
  19674. }
  19675. // Not enough zeny
  19676. if( sd->status.zeny < option->zeny ){
  19677. return;
  19678. }
  19679. uint16 totalChance = enchantgradelevel->chance;
  19680. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19681. std::unordered_map<uint16, uint16> requiredItems;
  19682. if( p->blessing_flag ){
  19683. // If the catalysator item is the same as the option item build the sum of amounts
  19684. if( enchantgradelevel->catalyst.item == option->item ){
  19685. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19686. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19687. if( index < 0 ){
  19688. return;
  19689. }
  19690. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19691. return;
  19692. }
  19693. requiredItems[index] = amount;
  19694. }else{
  19695. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19696. // Check catalysator item
  19697. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19698. if( index < 0 ){
  19699. return;
  19700. }
  19701. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19702. return;
  19703. }
  19704. requiredItems[index] = amount;
  19705. // Check option item
  19706. index = pc_search_inventory( sd, option->item );
  19707. if( index < 0 ){
  19708. return;
  19709. }
  19710. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19711. return;
  19712. }
  19713. requiredItems[index] = option->amount;
  19714. }
  19715. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19716. }else{
  19717. // Check option item
  19718. int16 index = pc_search_inventory( sd, option->item );
  19719. if( index < 0 ){
  19720. return;
  19721. }
  19722. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19723. return;
  19724. }
  19725. requiredItems[index] = option->amount;
  19726. }
  19727. // All items should be there, start deleting
  19728. for( const auto& pair : requiredItems ){
  19729. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19730. return;
  19731. }
  19732. }
  19733. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE, nullptr ) > 0 ){
  19734. return;
  19735. }
  19736. if( rnd()%10000 < totalChance ){
  19737. // Log removal of item
  19738. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19739. // Increase enchantgrade
  19740. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19741. // On successful enchantgrade increase the refine is reset
  19742. sd->inventory.u.items_inventory[index].refine = 0;
  19743. // Log retrieving the item again -> with the new refine and enchantgrade
  19744. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19745. // Show success
  19746. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19747. // Check if it has to be announced
  19748. if( enchantgradelevel->announce ){
  19749. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19750. }
  19751. }else{
  19752. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19753. if( enchantgradelevel->announce ){
  19754. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19755. }
  19756. // Delete the item if it is breakable
  19757. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19758. // Delete the item
  19759. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19760. // Show failure
  19761. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19762. // Downgrade the item if necessary
  19763. }else if( option->downgrade_amount > 0 ){
  19764. // Log removal of item
  19765. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19766. // Decrease refine level
  19767. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19768. // Log retrieving the item again -> with the new refine
  19769. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19770. // Show downgrade
  19771. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19772. // Only show failure, but dont do anything
  19773. }else{
  19774. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19775. }
  19776. }
  19777. #endif
  19778. }
  19779. void clif_parse_enchantgrade_close( int fd, struct map_session_data* sd ){
  19780. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19781. nullpo_retv( sd );
  19782. sd->state.enchantgrade_open = false;
  19783. #endif
  19784. }
  19785. void clif_reputation_type( struct map_session_data& sd, int64 type, int64 points ){
  19786. #if PACKETVER_RE_NUM >= 20211103
  19787. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19788. p->packetType = HEADER_ZC_REPUTE_INFO;
  19789. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19790. p->success = true;
  19791. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19792. entry->type = type;
  19793. entry->points = points;
  19794. clif_send( p, p->packetLength, &sd.bl, SELF );
  19795. #endif
  19796. }
  19797. void clif_reputation_list( struct map_session_data& sd ){
  19798. #if PACKETVER_RE_NUM >= 20211103
  19799. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19800. p->packetType = HEADER_ZC_REPUTE_INFO;
  19801. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19802. p->success = true;
  19803. size_t index = 0;
  19804. for( const auto& entry : reputation_db ){
  19805. std::shared_ptr<s_reputation> reputation = entry.second;
  19806. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19807. list_entry->type = reputation->id;
  19808. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19809. p->packetLength += sizeof( *list_entry );
  19810. index++;
  19811. }
  19812. clif_send( p, p->packetLength, &sd.bl, SELF );
  19813. #endif
  19814. }
  19815. void clif_item_reform_open( struct map_session_data& sd, t_itemid item ){
  19816. #if PACKETVER_RE_NUM >= 20211103
  19817. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19818. p.packetType = HEADER_ZC_OPEN_REFORM_UI;
  19819. p.itemId = item;
  19820. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19821. sd.state.item_reform = item;
  19822. #endif
  19823. }
  19824. void clif_parse_item_reform_close( int fd, struct map_session_data* sd ){
  19825. #if PACKETVER_RE_NUM >= 20211103
  19826. sd->state.item_reform = 0;
  19827. #endif
  19828. }
  19829. void clif_item_reform_result( struct map_session_data& sd, uint16 index, uint8 result ){
  19830. #if PACKETVER_RE_NUM >= 20211103
  19831. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19832. p.packetType = HEADER_ZC_ITEM_REFORM_ACK;
  19833. p.index = client_index( index );
  19834. p.result = result;
  19835. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19836. if( result == 0 ){
  19837. // Client closes the window on success
  19838. sd.state.item_reform = 0;
  19839. }
  19840. #endif
  19841. }
  19842. void clif_parse_item_reform_start( int fd, struct map_session_data* sd ){
  19843. #if PACKETVER_RE_NUM >= 20211103
  19844. // Not opened
  19845. if( sd->state.item_reform == 0 ){
  19846. return;
  19847. }
  19848. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19849. // Item mismatch
  19850. if( p->itemId != sd->state.item_reform ){
  19851. return;
  19852. }
  19853. uint16 index = server_index( p->index );
  19854. if( index >= MAX_INVENTORY ){
  19855. return;
  19856. }
  19857. if( sd->inventory_data[index] == nullptr ){
  19858. return;
  19859. }
  19860. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19861. if( reform == nullptr ){
  19862. return;
  19863. }
  19864. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19865. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19866. if( base == nullptr ){
  19867. return;
  19868. }
  19869. // If target item is not identified
  19870. if( selected_item.identify == 0 ){
  19871. return;
  19872. }
  19873. // If target item is equipped
  19874. if( selected_item.equip != 0 ){
  19875. return;
  19876. }
  19877. // Check minimum refine requirement
  19878. if( selected_item.refine < base->minimumRefine ){
  19879. return;
  19880. }
  19881. // Check maximum refine requirement
  19882. if( selected_item.refine > base->maximumRefine ){
  19883. return;
  19884. }
  19885. // If no cards are allowed
  19886. if( !base->cardsAllowed ){
  19887. for( int i = 0; i < MAX_SLOTS; i++ ){
  19888. if( selected_item.card[i] != 0 ){
  19889. return;
  19890. }
  19891. }
  19892. }
  19893. // If random options are required
  19894. if( base->requiredRandomOptions > 0 ){
  19895. int i;
  19896. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19897. if( selected_item.option[i].id != 0 ){
  19898. break;
  19899. }
  19900. }
  19901. if( ( i + 1 ) < base->requiredRandomOptions ){
  19902. return;
  19903. }
  19904. }
  19905. std::unordered_map<uint16, uint16> materials;
  19906. // Check if all materials exist
  19907. for( const auto& material : base->materials ){
  19908. int16 material_index = pc_search_inventory( sd, material.first );
  19909. if( material_index < 0 ){
  19910. return;
  19911. }
  19912. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19913. return;
  19914. }
  19915. materials[material_index] = material.second;
  19916. }
  19917. // Remove the material
  19918. for( const auto& material : materials ){
  19919. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19920. return;
  19921. }
  19922. }
  19923. // If triggered from item
  19924. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19925. return;
  19926. }
  19927. // Log removal of item
  19928. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19929. // Visually remove it from the client
  19930. clif_delitem( sd, index, 1, 0 );
  19931. // Apply the random options
  19932. if( base->randomOptionGroup != nullptr ){
  19933. base->randomOptionGroup->apply( selected_item );
  19934. }
  19935. // Change the refine rate if needed
  19936. if( base->refineChange != 0 ){
  19937. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19938. }
  19939. // Remove all cards and socket enchants
  19940. if( base->clearSlots ){
  19941. for( int i = 0; i < MAX_SLOTS; i++ ){
  19942. selected_item.card[i] = 0;
  19943. }
  19944. }
  19945. // Remove the current enchantgrade
  19946. if( base->removeEnchantgrade ){
  19947. selected_item.enchantgrade = 0;
  19948. }
  19949. // Finally change the item id
  19950. selected_item.nameid = base->resultItemId;
  19951. // Link inventory data cache to the new item
  19952. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19953. // Log retrieving the item again -> with the new options
  19954. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19955. // Make it visible for the client again
  19956. clif_additem( sd, index, 1, 0 );
  19957. clif_item_reform_result( *sd, index, 0 );
  19958. #endif
  19959. }
  19960. /*==========================================
  19961. * Main client packet processing function
  19962. *------------------------------------------*/
  19963. static int clif_parse(int fd)
  19964. {
  19965. int cmd, packet_len;
  19966. TBL_PC* sd;
  19967. int pnum;
  19968. #ifdef PACKET_OBFUSCATION
  19969. int cmd2;
  19970. #endif
  19971. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  19972. // Note: "click masters" can do 80+ clicks in 10 seconds
  19973. 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]
  19974. { // begin main client packet processing loop
  19975. sd = (TBL_PC *)session[fd]->session_data;
  19976. if (session[fd]->flag.eof) {
  19977. if (sd) {
  19978. if (sd->state.autotrade) {
  19979. //Disassociate character from the socket connection.
  19980. session[fd]->session_data = NULL;
  19981. sd->fd = 0;
  19982. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  19983. } else
  19984. if (sd->state.active) {
  19985. // Player logout display [Valaris]
  19986. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  19987. clif_quitsave(fd, sd);
  19988. } else {
  19989. //Unusual logout (during log on/off/map-changer procedure)
  19990. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  19991. map_quit(sd);
  19992. }
  19993. } else {
  19994. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  19995. }
  19996. do_close(fd);
  19997. return 0;
  19998. }
  19999. if (RFIFOREST(fd) < 2)
  20000. return 0;
  20001. cmd = RFIFOW(fd, 0);
  20002. #ifdef PACKET_OBFUSCATION
  20003. // Check if it is a player that tries to connect to the map server.
  20004. if( sd ){
  20005. // Decrypt the current packet ID with the last key stored in the session.
  20006. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20007. }else{
  20008. // Store the original value for checking
  20009. cmd2 = cmd;
  20010. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20011. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20012. }
  20013. #endif
  20014. // filter out invalid / unsupported packets
  20015. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20016. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20017. #ifdef DUMP_INVALID_PACKET
  20018. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20019. #endif
  20020. #ifdef PACKET_OBFUSCATION_WARN
  20021. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20022. if( !sd ){
  20023. #ifdef PACKET_OBFUSCATION
  20024. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20025. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20026. }
  20027. #else
  20028. // Try to use the initial keys for the decryption of the packet ID.
  20029. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20030. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20031. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20032. }
  20033. #endif
  20034. }
  20035. #endif
  20036. set_eof(fd);
  20037. return 0;
  20038. }
  20039. // determine real packet length
  20040. packet_len = packet_db[cmd].len;
  20041. if (packet_len == -1) { // variable-length packet
  20042. if (RFIFOREST(fd) < 4)
  20043. return 0;
  20044. packet_len = RFIFOW(fd,2);
  20045. if (packet_len < 4 || packet_len > 32768) {
  20046. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20047. #ifdef DUMP_INVALID_PACKET
  20048. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20049. #endif
  20050. set_eof(fd);
  20051. return 0;
  20052. }
  20053. }
  20054. if ((int)RFIFOREST(fd) < packet_len){
  20055. 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 );
  20056. #ifdef DUMP_INVALID_PACKET
  20057. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20058. #endif
  20059. set_eof( fd );
  20060. return 0; // not enough data received to form the packet
  20061. }
  20062. #ifdef PACKET_OBFUSCATION
  20063. RFIFOW(fd, 0) = cmd;
  20064. if (sd)
  20065. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20066. #endif
  20067. if( packet_db[cmd].func == clif_parse_debug )
  20068. packet_db[cmd].func(fd, sd);
  20069. else if( packet_db[cmd].func != NULL ) {
  20070. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20071. ; //Only valid packet when there is no session
  20072. else
  20073. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20074. ; //Only valid packet when player is not on a map
  20075. else
  20076. packet_db[cmd].func(fd, sd);
  20077. }
  20078. #ifdef DUMP_UNKNOWN_PACKET
  20079. else DumpUnknown(fd,sd,cmd,packet_len);
  20080. #endif
  20081. RFIFOSKIP(fd, packet_len);
  20082. }; // main loop end
  20083. return 0;
  20084. }
  20085. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  20086. va_list argp;
  20087. int i;
  20088. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20089. return;
  20090. packet_db[cmd].len = length;
  20091. packet_db[cmd].func = func;
  20092. va_start(argp, func);
  20093. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20094. int offset = va_arg(argp, int);
  20095. if( offset == 0 ){
  20096. break;
  20097. }
  20098. packet_db[cmd].pos[i] = offset;
  20099. }
  20100. if( i == MAX_PACKET_POS ){
  20101. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20102. }
  20103. va_end(argp);
  20104. }
  20105. /*==========================================
  20106. * Reads packets and setups its array reference
  20107. *------------------------------------------*/
  20108. void packetdb_readdb(){
  20109. memset(packet_db,0,sizeof(packet_db));
  20110. memset(packet_db_ack,0,sizeof(packet_db_ack));
  20111. #include "clif_packetdb.hpp"
  20112. #include "clif_shuffle.hpp"
  20113. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20114. #ifdef PACKET_OBFUSCATION
  20115. 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]);
  20116. #else
  20117. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20118. #endif
  20119. }
  20120. /*==========================================
  20121. *
  20122. *------------------------------------------*/
  20123. void do_init_clif(void) {
  20124. const char* colors[COLOR_MAX] = {
  20125. "0x00FF00",
  20126. "0xFF0000",
  20127. "0xFFFFFF",
  20128. "0xFFFF00",
  20129. "0x00FFFF",
  20130. "0xB5FFB5",
  20131. };
  20132. int i;
  20133. /**
  20134. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20135. **/
  20136. for(i = 0; i < COLOR_MAX; i++) {
  20137. color_table[i] = strtoul(colors[i],NULL,0);
  20138. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  20139. }
  20140. packetdb_readdb();
  20141. set_defaultparse(clif_parse);
  20142. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20143. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20144. exit(EXIT_FAILURE);
  20145. }
  20146. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20147. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20148. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20149. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20150. if( battle_config.ping_timer_interval > 0 ){
  20151. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20152. }
  20153. #endif
  20154. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20155. }
  20156. void do_final_clif(void) {
  20157. ers_destroy(delay_clearunit_ers);
  20158. }