clif.cpp 721 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006
  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. // Reuseable global packet buffer to prevent too many allocations
  74. // Take socket.cpp::socket_max_client_packet into consideration
  75. static int8 packet_buffer[UINT16_MAX];
  76. unsigned long color_table[COLOR_MAX];
  77. #include "clif_obfuscation.hpp"
  78. static bool clif_session_isValid(struct map_session_data *sd);
  79. static void clif_loadConfirm( struct map_session_data *sd );
  80. #if PACKETVER >= 20150513
  81. enum mail_type {
  82. MAIL_TYPE_TEXT = 0x0,
  83. MAIL_TYPE_ZENY = 0x2,
  84. MAIL_TYPE_ITEM = 0x4,
  85. MAIL_TYPE_NPC = 0x8
  86. };
  87. #endif
  88. enum e_inventory_type{
  89. INVTYPE_INVENTORY = 0,
  90. INVTYPE_CART = 1,
  91. INVTYPE_STORAGE = 2,
  92. INVTYPE_GUILD_STORAGE = 3,
  93. };
  94. /** Converts item type to display it on client if necessary.
  95. * @param nameid: Item ID
  96. * @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
  97. */
  98. static inline int itemtype(t_itemid nameid) {
  99. 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
  100. int type = id->type;
  101. if( type == IT_SHADOWGEAR ) {
  102. if( id->equip&EQP_SHADOW_WEAPON )
  103. return IT_WEAPON;
  104. else
  105. return IT_ARMOR;
  106. }
  107. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  108. }
  109. // TODO: doc
  110. static inline uint16 client_index( uint16 server_index ){
  111. return server_index + 2;
  112. }
  113. static inline uint16 server_index( uint16 client_index ){
  114. return client_index - 2;
  115. }
  116. static inline uint16 client_storage_index( uint16 server_index ){
  117. return server_index + 1;
  118. }
  119. static inline uint16 server_storage_index( uint16 client_index ){
  120. return client_index - 1;
  121. }
  122. static inline uint32 disguised_bl_id( uint32 bl_id ){
  123. // Casting to prevent a compiler warning
  124. return -((int32)bl_id);
  125. }
  126. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  127. static inline uint32 client_nameid( t_itemid server_nameid ){
  128. t_itemid view = itemdb_viewid( server_nameid );
  129. if( view > 0 ){
  130. return view;
  131. }else{
  132. return server_nameid;
  133. }
  134. }
  135. #else
  136. static inline uint16 client_nameid( t_itemid server_nameid ){
  137. t_itemid view = itemdb_viewid( server_nameid );
  138. if( view > 0 ){
  139. if( view > UINT16_MAX ){
  140. return (uint16)UNKNOWN_ITEM_ID;
  141. }
  142. return (uint16)view;
  143. }else{
  144. if( server_nameid > UINT16_MAX ){
  145. return (uint16)UNKNOWN_ITEM_ID;
  146. }
  147. return (uint16)server_nameid;
  148. }
  149. }
  150. #endif
  151. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  152. p += pos;
  153. p[0] = (uint8)(x>>2);
  154. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  155. p[2] = (uint8)((y<<4) | (dir&0xf));
  156. }
  157. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  158. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  159. p += pos;
  160. p[0] = (uint8)(x0>>2);
  161. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  162. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  163. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  164. p[4] = (uint8)y1;
  165. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  166. }
  167. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  168. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  169. }
  170. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  171. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  172. }
  173. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  174. p += pos;
  175. if( x ) {
  176. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  177. }
  178. if( y ) {
  179. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  180. }
  181. if( dir ) {
  182. dir[0] = ( p[2] & 0x0f );
  183. }
  184. }
  185. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  186. p += pos;
  187. if( x0 ) {
  188. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  189. }
  190. if( y0 ) {
  191. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  192. }
  193. if( x1 ) {
  194. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  195. }
  196. if( y1 ) {
  197. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  198. }
  199. if( sx0 ) {
  200. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  201. }
  202. if( sy0 ) {
  203. sy0[0] = ( p[5] & 0x0f ) >> 0;
  204. }
  205. }
  206. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  207. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  208. }
  209. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  210. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  211. }
  212. //To idenfity disguised characters.
  213. static inline bool disguised(struct block_list* bl) {
  214. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  215. }
  216. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  217. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  218. if( len > max )
  219. len = max;
  220. mes[len-1] = '\0';
  221. return len;
  222. }
  223. static char map_ip_str[128];
  224. static uint32 map_ip;
  225. static uint32 bind_ip = INADDR_ANY;
  226. static uint16 map_port = 5121;
  227. static bool clif_ally_only = false;
  228. int map_fd;
  229. static int clif_parse (int fd);
  230. /*==========================================
  231. * Ip setting of map-server
  232. *------------------------------------------*/
  233. int clif_setip(const char* ip) {
  234. char ip_str[16];
  235. map_ip = host2ip(ip);
  236. if (!map_ip) {
  237. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  238. return 0;
  239. }
  240. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  241. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  242. return 1;
  243. }
  244. void clif_setbindip(const char* ip)
  245. {
  246. bind_ip = host2ip(ip);
  247. if (bind_ip) {
  248. char ip_str[16];
  249. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  250. } else {
  251. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  252. }
  253. }
  254. /*==========================================
  255. * Sets map port to 'port'
  256. * is run from map.cpp upon loading map server configuration
  257. *------------------------------------------*/
  258. void clif_setport(uint16 port)
  259. {
  260. map_port = port;
  261. }
  262. /*==========================================
  263. * Returns map server IP
  264. *------------------------------------------*/
  265. uint32 clif_getip(void)
  266. {
  267. return map_ip;
  268. }
  269. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  270. uint32 clif_refresh_ip(void)
  271. {
  272. uint32 new_ip;
  273. new_ip = host2ip(map_ip_str);
  274. if (new_ip && new_ip != map_ip) {
  275. map_ip = new_ip;
  276. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  277. return map_ip;
  278. }
  279. return 0;
  280. }
  281. /*==========================================
  282. * Returns map port which is set by clif_setport()
  283. *------------------------------------------*/
  284. uint16 clif_getport(void)
  285. {
  286. return map_port;
  287. }
  288. #if PACKETVER >= 20071106
  289. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  290. switch (bl->type) {
  291. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  292. case BL_ITEM: return 0x2; //ITEM_TYPE
  293. case BL_SKILL: return 0x3; //SKILL_TYPE
  294. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  295. case BL_MOB:
  296. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  297. return 0x0; //PC_TYPE
  298. }else{
  299. switch( ( (mob_data*)bl )->special_state.ai ){
  300. case AI_ABR:
  301. return 0xd; //NPC_ABR_TYPE
  302. case AI_BIONIC:
  303. return 0xe; //NPC_BIONIC_TYPE
  304. default:
  305. return 0x5; //NPC_MOB_TYPE
  306. }
  307. }
  308. case BL_NPC:
  309. // From 2017-07-26 on NPC type units can also use player sprites.
  310. // There is one exception and this is if they are walking.
  311. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  312. #if PACKETVER >= 20170726
  313. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0xC; // New walking NPC type
  314. #else
  315. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  316. #endif
  317. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  318. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  319. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  320. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  321. default: return 0x1; //NPC_TYPE
  322. }
  323. }
  324. #endif
  325. static bool clif_session_isValid(struct map_session_data *sd) {
  326. return ( sd != nullptr && session_isActive(sd->fd) );
  327. }
  328. /*==========================================
  329. * sub process of clif_send
  330. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  331. * In order to send area-wise packets, such as:
  332. * - AREA : everyone nearby your area
  333. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  334. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  335. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  336. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  337. *------------------------------------------*/
  338. static int clif_send_sub(struct block_list *bl, va_list ap)
  339. {
  340. struct block_list *src_bl;
  341. struct map_session_data *sd;
  342. unsigned char *buf;
  343. int len, type, fd;
  344. nullpo_ret(bl);
  345. nullpo_ret(sd = (struct map_session_data *)bl);
  346. // Don't send to disconnected clients.
  347. if( !session_isActive( fd = sd->fd ) ){
  348. return 0;
  349. }
  350. buf = va_arg(ap,unsigned char*);
  351. len = va_arg(ap,int);
  352. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  353. type = va_arg(ap,int);
  354. switch(type) {
  355. case AREA_WOS:
  356. if (bl == src_bl)
  357. return 0;
  358. break;
  359. case AREA_WOC:
  360. if (sd->chatID || bl == src_bl)
  361. return 0;
  362. break;
  363. case AREA_WOSC:
  364. {
  365. if(src_bl->type == BL_PC) {
  366. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  367. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  368. return 0;
  369. }
  370. else if(src_bl->type == BL_NPC) {
  371. struct npc_data *nd = (struct npc_data *)src_bl;
  372. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  373. return 0;
  374. }
  375. }
  376. break;
  377. }
  378. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  379. // Do not send anything
  380. return 0;
  381. }
  382. /* unless visible, hold it here */
  383. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  384. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  385. return 0;
  386. WFIFOHEAD(fd, len);
  387. if (WFIFOP(fd,0) == buf) {
  388. ShowError("WARNING: Invalid use of clif_send function\n");
  389. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  390. ShowError(" Please correct your code.\n");
  391. // don't send to not move the pointer of the packet for next sessions in the loop
  392. //WFIFOSET(fd,0);//## TODO is this ok?
  393. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  394. return 0;
  395. }
  396. memcpy(WFIFOP(fd,0), buf, len);
  397. WFIFOSET(fd,len);
  398. return 0;
  399. }
  400. /*==========================================
  401. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  402. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  403. *------------------------------------------*/
  404. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  405. {
  406. int i;
  407. struct map_session_data *sd, *tsd;
  408. struct party_data *p = NULL;
  409. struct guild *g = NULL;
  410. std::shared_ptr<s_battleground_data> bg;
  411. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  412. struct s_mapiterator* iter;
  413. if( type != ALL_CLIENT )
  414. nullpo_ret(bl);
  415. sd = BL_CAST(BL_PC, bl);
  416. switch(type) {
  417. case ALL_CLIENT: //All player clients.
  418. iter = mapit_getallusers();
  419. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  420. if( session_isActive( fd = tsd->fd ) ){
  421. WFIFOHEAD( fd, len );
  422. memcpy( WFIFOP( fd, 0 ), buf, len );
  423. WFIFOSET( fd, len );
  424. }
  425. }
  426. mapit_free(iter);
  427. break;
  428. case ALL_SAMEMAP: //All players on the same map
  429. iter = mapit_getallusers();
  430. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  431. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  432. WFIFOHEAD( fd, len );
  433. memcpy( WFIFOP( fd, 0 ), buf, len );
  434. WFIFOSET( fd, len );
  435. }
  436. }
  437. mapit_free(iter);
  438. break;
  439. case AREA:
  440. case AREA_WOSC:
  441. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  442. clif_send (buf, len, bl, SELF);
  443. case AREA_WOC:
  444. case AREA_WOS:
  445. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  446. BL_PC, buf, len, bl, type);
  447. break;
  448. case AREA_CHAT_WOC:
  449. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  450. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  451. break;
  452. case CHAT:
  453. case CHAT_WOS:
  454. {
  455. struct chat_data *cd;
  456. if (sd) {
  457. cd = (struct chat_data*)map_id2bl(sd->chatID);
  458. } else if (bl->type == BL_CHAT) {
  459. cd = (struct chat_data*)bl;
  460. } else break;
  461. if (cd == NULL)
  462. break;
  463. for(i = 0; i < cd->users; i++) {
  464. if (type == CHAT_WOS && cd->usersd[i] == sd)
  465. continue;
  466. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  467. WFIFOHEAD(fd,len);
  468. memcpy(WFIFOP(fd,0), buf, len);
  469. WFIFOSET(fd,len);
  470. }
  471. }
  472. }
  473. break;
  474. case PARTY_AREA:
  475. case PARTY_AREA_WOS:
  476. x0 = bl->x - AREA_SIZE;
  477. y0 = bl->y - AREA_SIZE;
  478. x1 = bl->x + AREA_SIZE;
  479. y1 = bl->y + AREA_SIZE;
  480. case PARTY:
  481. case PARTY_WOS:
  482. case PARTY_SAMEMAP:
  483. case PARTY_SAMEMAP_WOS:
  484. if (sd && sd->status.party_id)
  485. p = party_search(sd->status.party_id);
  486. if (p) {
  487. for(i=0;i<MAX_PARTY;i++){
  488. if( (sd = p->data[i].sd) == NULL )
  489. continue;
  490. if( !session_isActive( fd = sd->fd ) )
  491. continue;
  492. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  493. continue;
  494. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  495. continue;
  496. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  497. continue;
  498. WFIFOHEAD(fd, len);
  499. memcpy(WFIFOP(fd, 0), buf, len);
  500. WFIFOSET(fd, len);
  501. }
  502. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  503. break;
  504. iter = mapit_getallusers();
  505. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  506. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  507. WFIFOHEAD( fd, len );
  508. memcpy( WFIFOP( fd, 0 ), buf, len );
  509. WFIFOSET( tsd->fd, len );
  510. }
  511. }
  512. mapit_free(iter);
  513. }
  514. break;
  515. case DUEL:
  516. case DUEL_WOS:
  517. if (!sd || !sd->duel_group) break; //Invalid usage.
  518. iter = mapit_getallusers();
  519. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  520. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  521. continue;
  522. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  523. WFIFOHEAD( fd, len );
  524. memcpy( WFIFOP( fd, 0 ), buf, len );
  525. WFIFOSET( fd, len );
  526. }
  527. }
  528. mapit_free(iter);
  529. break;
  530. case SELF:
  531. if( clif_session_isValid(sd) ){
  532. fd = sd->fd;
  533. WFIFOHEAD(fd,len);
  534. memcpy(WFIFOP(fd,0), buf, len);
  535. WFIFOSET(fd,len);
  536. }
  537. break;
  538. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  539. case GUILD_AREA:
  540. case GUILD_AREA_WOS:
  541. x0 = bl->x - AREA_SIZE;
  542. y0 = bl->y - AREA_SIZE;
  543. x1 = bl->x + AREA_SIZE;
  544. y1 = bl->y + AREA_SIZE;
  545. case GUILD_SAMEMAP:
  546. case GUILD_SAMEMAP_WOS:
  547. case GUILD:
  548. case GUILD_WOS:
  549. case GUILD_NOBG:
  550. if (sd && sd->status.guild_id)
  551. g = sd->guild;
  552. if (g) {
  553. for(i = 0; i < g->max_member; i++) {
  554. if( (sd = g->member[i].sd) != nullptr ){
  555. if( !session_isActive( fd = sd->fd ) )
  556. continue;
  557. if( type == GUILD_NOBG && sd->bg_id )
  558. continue;
  559. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  560. continue;
  561. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  562. continue;
  563. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  564. continue;
  565. WFIFOHEAD(fd,len);
  566. memcpy(WFIFOP(fd,0), buf, len);
  567. WFIFOSET(fd,len);
  568. }
  569. }
  570. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  571. break;
  572. iter = mapit_getallusers();
  573. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  574. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  575. WFIFOHEAD( fd, len );
  576. memcpy( WFIFOP( fd, 0 ), buf, len );
  577. WFIFOSET( fd, len );
  578. }
  579. }
  580. mapit_free(iter);
  581. }
  582. break;
  583. case BG_AREA:
  584. case BG_AREA_WOS:
  585. x0 = bl->x - AREA_SIZE;
  586. y0 = bl->y - AREA_SIZE;
  587. x1 = bl->x + AREA_SIZE;
  588. y1 = bl->y + AREA_SIZE;
  589. case BG_SAMEMAP:
  590. case BG_SAMEMAP_WOS:
  591. case BG:
  592. case BG_WOS:
  593. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  594. {
  595. for (const auto &member : bg->members) {
  596. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  597. continue;
  598. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  599. continue;
  600. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  601. continue;
  602. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  603. continue;
  604. WFIFOHEAD(fd,len);
  605. memcpy(WFIFOP(fd,0), buf, len);
  606. WFIFOSET(fd,len);
  607. }
  608. }
  609. break;
  610. case CLAN:
  611. if( sd && sd->clan ){
  612. struct clan* clan = sd->clan;
  613. for( i = 0; i < clan->max_member; i++ ){
  614. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  615. continue;
  616. }
  617. WFIFOHEAD(fd,len);
  618. memcpy(WFIFOP(fd,0), buf, len);
  619. WFIFOSET(fd,len);
  620. }
  621. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  622. break;
  623. iter = mapit_getallusers();
  624. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  625. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  626. WFIFOHEAD(fd, len);
  627. memcpy(WFIFOP(fd, 0), buf, len);
  628. WFIFOSET(fd, len);
  629. }
  630. }
  631. mapit_free(iter);
  632. }
  633. break;
  634. default:
  635. ShowError("clif_send: Unrecognized type %d\n",type);
  636. return -1;
  637. }
  638. return 0;
  639. }
  640. /// Notifies the client, that it's connection attempt was accepted.
  641. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  642. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  643. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  644. void clif_authok(struct map_session_data *sd)
  645. {
  646. #if PACKETVER < 20080102
  647. const int cmd = 0x73;
  648. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  649. const int cmd = 0x2eb;
  650. #else
  651. const int cmd = 0xa18;
  652. #endif
  653. int fd = sd->fd;
  654. WFIFOHEAD(fd,packet_len(cmd));
  655. WFIFOW(fd, 0) = cmd;
  656. WFIFOL(fd, 2) = client_tick(gettick());
  657. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  658. WFIFOB(fd, 9) = 5; // ignored
  659. WFIFOB(fd,10) = 5; // ignored
  660. #if PACKETVER >= 20080102
  661. WFIFOW(fd,11) = sd->status.font;
  662. #endif
  663. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  664. WFIFOB(fd,13) = sd->status.sex;
  665. #endif
  666. WFIFOSET(fd,packet_len(cmd));
  667. }
  668. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  669. /// 0074 <error code>.B
  670. /// error code:
  671. /// 0 = client type mismatch
  672. /// 1 = ID mismatch
  673. /// 2 = mobile - out of available time
  674. /// 3 = mobile - already logged in
  675. /// 4 = mobile - waiting state
  676. void clif_authrefuse(int fd, uint8 error_code)
  677. {
  678. WFIFOHEAD(fd,packet_len(0x74));
  679. WFIFOW(fd,0) = 0x74;
  680. WFIFOB(fd,2) = error_code;
  681. WFIFOSET(fd,packet_len(0x74));
  682. }
  683. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  684. /// 0081 <error code>.B
  685. /// error code:
  686. /// 0 = BAN_UNFAIR
  687. /// 1 = server closed -> MsgStringTable[4]
  688. /// 2 = ID already logged in -> MsgStringTable[5]
  689. /// 3 = timeout/too much lag -> MsgStringTable[241]
  690. /// 4 = server full -> MsgStringTable[264]
  691. /// 5 = underaged -> MsgStringTable[305]
  692. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  693. /// 9 = too many connections from this ip -> MsgStringTable[529]
  694. /// 10 = out of available time paid for -> MsgStringTable[530]
  695. /// 11 = BAN_PAY_SUSPEND
  696. /// 12 = BAN_PAY_CHANGE
  697. /// 13 = BAN_PAY_WRONGIP
  698. /// 14 = BAN_PAY_PNGAMEROOM
  699. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  700. /// 16 = BAN_JAPAN_REFUSE1
  701. /// 17 = BAN_JAPAN_REFUSE2
  702. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  703. /// 100 = BAN_PC_IP_UNFAIR
  704. /// 101 = BAN_PC_IP_COUNT_ALL
  705. /// 102 = BAN_PC_IP_COUNT
  706. /// 103 = BAN_GRAVITY_MEM_AGREE
  707. /// 104 = BAN_GAME_MEM_AGREE
  708. /// 105 = BAN_HAN_VALID
  709. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  710. /// 107 = BAN_OVER_CHARACTER_LIST
  711. /// 108 = BAN_IP_BLOCK
  712. /// 109 = BAN_INVALID_PWD_CNT
  713. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  714. /// ? = disconnected -> MsgStringTable[3]
  715. void clif_authfail_fd(int fd, int type)
  716. {
  717. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  718. return;
  719. WFIFOHEAD(fd, packet_len(0x81));
  720. WFIFOW(fd,0) = 0x81;
  721. WFIFOB(fd,2) = type;
  722. WFIFOSET(fd,packet_len(0x81));
  723. set_eof(fd);
  724. }
  725. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  726. /// 00b3 <type>.B
  727. /// type:
  728. /// 1 = disconnect, char-select
  729. /// ? = nothing
  730. void clif_charselectok(int id, uint8 ok)
  731. {
  732. struct map_session_data* sd;
  733. int fd;
  734. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  735. return;
  736. fd = sd->fd;
  737. WFIFOHEAD(fd,packet_len(0xb3));
  738. WFIFOW(fd,0) = 0xb3;
  739. WFIFOB(fd,2) = ok;
  740. WFIFOSET(fd,packet_len(0xb3));
  741. }
  742. /// Makes an item appear on the ground.
  743. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  744. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  745. /// 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)
  746. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  747. nullpo_retv(fitem);
  748. if( fitem->item.nameid == 0 ){
  749. return;
  750. }
  751. struct packet_dropflooritem p;
  752. p.PacketType = dropflooritemType;
  753. p.ITAID = fitem->bl.id;
  754. p.ITID = client_nameid( fitem->item.nameid );
  755. #if PACKETVER >= 20130000 /* not sure date */
  756. p.type = itemtype( fitem->item.nameid );
  757. #endif
  758. p.IsIdentified = fitem->item.identify ? 1 : 0;
  759. p.xPos = fitem->bl.x;
  760. p.yPos = fitem->bl.y;
  761. p.subX = fitem->subx;
  762. p.subY = fitem->suby;
  763. p.count = fitem->item.amount;
  764. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  765. if( canShowEffect ){
  766. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  767. if( dropEffect > 0 ){
  768. p.showdropeffect = 1;
  769. p.dropeffectmode = dropEffect - 1;
  770. }else if (battle_config.rndopt_drop_pillar != 0){
  771. uint8 optionCount = 0;
  772. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  773. if (fitem->item.option[i].id != 0) {
  774. optionCount++;
  775. }
  776. }
  777. if (optionCount > 0) {
  778. p.showdropeffect = 1;
  779. if (optionCount == 1)
  780. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  781. else if (optionCount == 2)
  782. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  783. else
  784. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  785. } else {
  786. p.showdropeffect = 0;
  787. p.dropeffectmode = DROPEFFECT_NONE;
  788. }
  789. } else {
  790. p.showdropeffect = 0;
  791. p.dropeffectmode = DROPEFFECT_NONE;
  792. }
  793. }else{
  794. p.showdropeffect = 0;
  795. p.dropeffectmode = DROPEFFECT_NONE;
  796. }
  797. #endif
  798. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  799. }
  800. /// Makes an item disappear from the ground.
  801. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  802. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  803. {
  804. unsigned char buf[16];
  805. nullpo_retv(fitem);
  806. WBUFW(buf,0) = 0xa1;
  807. WBUFL(buf,2) = fitem->bl.id;
  808. if ( !session_isActive( fd ) ){
  809. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  810. } else {
  811. WFIFOHEAD(fd,packet_len(0xa1));
  812. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  813. WFIFOSET(fd,packet_len(0xa1));
  814. }
  815. }
  816. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  817. /// 0080 <id>.L <type>.B
  818. /// type:
  819. /// 0 = out of sight
  820. /// 1 = died
  821. /// 2 = logged out
  822. /// 3 = teleport
  823. /// 4 = trickdead
  824. void clif_clearunit_single(int id, clr_type type, int fd)
  825. {
  826. WFIFOHEAD(fd, packet_len(0x80));
  827. WFIFOW(fd,0) = 0x80;
  828. WFIFOL(fd,2) = id;
  829. WFIFOB(fd,6) = type;
  830. WFIFOSET(fd, packet_len(0x80));
  831. }
  832. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  833. /// 0080 <id>.L <type>.B
  834. /// type:
  835. /// 0 = out of sight
  836. /// 1 = died
  837. /// 2 = logged out
  838. /// 3 = teleport
  839. /// 4 = trickdead
  840. void clif_clearunit_area(struct block_list* bl, clr_type type)
  841. {
  842. unsigned char buf[8];
  843. nullpo_retv(bl);
  844. WBUFW(buf,0) = 0x80;
  845. WBUFL(buf,2) = bl->id;
  846. WBUFB(buf,6) = type;
  847. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  848. if(disguised(bl)) {
  849. WBUFL(buf,2) = disguised_bl_id( bl->id );
  850. clif_send(buf, packet_len(0x80), bl, SELF);
  851. }
  852. }
  853. /// Used to make monsters with player-sprites disappear after dying
  854. /// like normal monsters, because the client does not remove those
  855. /// automatically.
  856. static TIMER_FUNC(clif_clearunit_delayed_sub){
  857. struct block_list *bl = (struct block_list *)data;
  858. clif_clearunit_area(bl, (clr_type) id);
  859. ers_free(delay_clearunit_ers,bl);
  860. return 0;
  861. }
  862. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  863. {
  864. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  865. memcpy (tbl, bl, sizeof (struct block_list));
  866. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  867. }
  868. void clif_get_weapon_view(struct map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  869. {
  870. if(sd->sc.option&OPTION_COSTUME)
  871. {
  872. *rhand = *lhand = 0;
  873. return;
  874. }
  875. #if PACKETVER < 4
  876. *rhand = sd->status.weapon;
  877. *lhand = sd->status.shield;
  878. #else
  879. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  880. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  881. {
  882. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  883. if (id->view_id > 0)
  884. *rhand = id->view_id;
  885. else
  886. *rhand = id->nameid;
  887. } else
  888. *rhand = 0;
  889. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  890. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  891. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  892. {
  893. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  894. if (id->view_id > 0)
  895. *lhand = id->view_id;
  896. else
  897. *lhand = id->nameid;
  898. } else
  899. *lhand = 0;
  900. #endif
  901. }
  902. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  903. static int clif_setlevel_sub(int lv) {
  904. if( lv < battle_config.max_lv ) {
  905. ;
  906. } else if( lv < battle_config.aura_lv ) {
  907. lv = battle_config.max_lv - 1;
  908. } else {
  909. lv = battle_config.max_lv;
  910. }
  911. return lv;
  912. }
  913. static int clif_setlevel(struct block_list* bl) {
  914. int lv = status_get_lv(bl);
  915. if( battle_config.client_limit_unit_lv&bl->type )
  916. return clif_setlevel_sub(lv);
  917. switch( bl->type ) {
  918. case BL_NPC:
  919. case BL_PET:
  920. // npcs and pets do not have level
  921. return 0;
  922. }
  923. return lv;
  924. }
  925. /*==========================================
  926. * Prepares 'unit standing/spawning' packet
  927. *------------------------------------------*/
  928. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  929. nullpo_retv( bl );
  930. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  931. struct status_change* sc = status_get_sc( bl );
  932. struct view_data* vd = status_get_viewdata( bl );
  933. int g_id = status_get_guild_id( bl );
  934. #if PACKETVER < 20091103
  935. if( !pcdb_checkid( vd->class_ ) ){
  936. struct packet_idle_unit2 p;
  937. p.PacketType = idle_unit2Type;
  938. #if PACKETVER >= 20071106
  939. p.objecttype = clif_bl_type( bl, walking );
  940. #endif
  941. p.GID = bl->id;
  942. p.speed = status_get_speed( bl );
  943. p.bodyState = ( sc ) ? sc->opt1 : 0;
  944. p.healthState = ( sc ) ? sc->opt2 : 0;
  945. p.effectState = ( sc ) ? sc->option : 0;
  946. p.job = vd->class_;
  947. p.head = vd->hair_style;
  948. p.weapon = vd->weapon;
  949. p.accessory = vd->head_bottom;
  950. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  951. // The hell, why flags work like this?
  952. p.shield = status_get_emblem_id( bl );
  953. p.accessory2 = GetWord( g_id, 1 );
  954. p.accessory3 = GetWord( g_id, 0 );
  955. }else{
  956. p.shield = vd->shield;
  957. p.accessory2 = vd->head_top;
  958. p.accessory3 = vd->head_mid;
  959. }
  960. p.headpalette = vd->hair_color;
  961. p.bodypalette = vd->cloth_color;
  962. p.headDir = ( sd )? sd->head_dir : 0;
  963. p.GUID = g_id;
  964. p.GEmblemVer = status_get_emblem_id( bl );
  965. p.honor = ( sd ) ? sd->status.manner : 0;
  966. p.virtue = ( sc ) ? sc->opt3 : 0;
  967. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  968. p.sex = vd->sex;
  969. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  970. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  971. p.state = vd->dead_sit;
  972. p.clevel = clif_setlevel( bl );
  973. clif_send( &p, sizeof( p ), tbl, target );
  974. return;
  975. }
  976. #endif
  977. struct packet_idle_unit p;
  978. p.PacketType = idle_unitType;
  979. #if PACKETVER >= 20091103
  980. p.PacketLength = sizeof(p);
  981. p.objecttype = clif_bl_type( bl, walking );
  982. #endif
  983. #if PACKETVER >= 20131223
  984. p.AID = bl->id;
  985. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  986. #else
  987. p.GID = bl->id;
  988. #endif
  989. p.speed = status_get_speed(bl);
  990. p.bodyState = (sc) ? sc->opt1 : 0;
  991. p.healthState = (sc) ? sc->opt2 : 0;
  992. // npc option changed?
  993. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  994. struct map_session_data* sd = (struct map_session_data*)tbl;
  995. struct npc_data* nd = (struct npc_data*)bl;
  996. int option = (sc) ? sc->option : 0;
  997. if( !nd->vd.dead_sit ){
  998. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  999. option ^= OPTION_CLOAK;
  1000. }
  1001. }
  1002. p.effectState = option;
  1003. }else{
  1004. p.effectState = (sc) ? sc->option : 0;
  1005. }
  1006. p.job = vd->class_;
  1007. p.head = vd->hair_style;
  1008. p.weapon = vd->weapon;
  1009. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1010. p.shield = vd->shield;
  1011. #endif
  1012. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1013. // The hell, why flags work like this?
  1014. p.accessory = status_get_emblem_id( bl );
  1015. p.accessory2 = GetWord( g_id, 1 );
  1016. p.accessory3 = GetWord( g_id, 0 );
  1017. }else{
  1018. p.accessory = vd->head_bottom;
  1019. p.accessory2 = vd->head_top;
  1020. p.accessory3 = vd->head_mid;
  1021. }
  1022. p.headpalette = vd->hair_color;
  1023. p.bodypalette = vd->cloth_color;
  1024. p.headDir = (sd)? sd->head_dir : 0;
  1025. #if PACKETVER >= 20101124
  1026. p.robe = vd->robe;
  1027. #endif
  1028. p.GUID = g_id;
  1029. p.GEmblemVer = status_get_emblem_id( bl );
  1030. p.honor = (sd) ? sd->status.manner : 0;
  1031. p.virtue = (sc) ? sc->opt3 : 0;
  1032. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1033. p.sex = vd->sex;
  1034. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1035. p.xSize = p.ySize = (sd) ? 5 : 0;
  1036. p.state = vd->dead_sit;
  1037. p.clevel = clif_setlevel( bl );
  1038. #if PACKETVER >= 20080102
  1039. p.font = (sd) ? sd->status.font : 0;
  1040. #endif
  1041. #if PACKETVER >= 20120221
  1042. 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 ) ) ){
  1043. p.maxHP = status_get_max_hp(bl);
  1044. p.HP = status_get_hp(bl);
  1045. }else{
  1046. p.maxHP = -1;
  1047. p.HP = -1;
  1048. }
  1049. if( bl->type == BL_MOB ){
  1050. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1051. }else if( bl->type == BL_PET ){
  1052. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1053. }else{
  1054. p.isBoss = BOSSTYPE_NONE;
  1055. }
  1056. #endif
  1057. #if PACKETVER >= 20150513
  1058. p.body = vd->body_style;
  1059. #endif
  1060. /* Might be earlier, this is when the named item bug began */
  1061. #if PACKETVER >= 20131223
  1062. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1063. #endif
  1064. clif_send( &p, sizeof( p ), tbl, target );
  1065. // if disguised, send to self
  1066. if( disguised( bl ) ){
  1067. #if PACKETVER >= 20091103
  1068. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1069. #if PACKETVER >= 20131223
  1070. p.AID = disguised_bl_id( bl->id );
  1071. #else
  1072. p.GID = disguised_bl_id( bl->id );
  1073. #endif
  1074. #else
  1075. p.GID = disguised_bl_id( bl->id );
  1076. #endif
  1077. clif_send(&p, sizeof(p), bl, SELF);
  1078. }
  1079. }
  1080. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1081. nullpo_retv( bl );
  1082. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1083. struct status_change* sc = status_get_sc( bl );
  1084. struct view_data* vd = status_get_viewdata( bl );
  1085. int g_id = status_get_guild_id( bl );
  1086. #if PACKETVER < 20091103
  1087. if( !pcdb_checkid( vd->class_ ) ){
  1088. struct packet_spawn_unit2 p;
  1089. p.PacketType = spawn_unit2Type;
  1090. #if PACKETVER >= 20071106
  1091. p.objecttype = clif_bl_type( bl, false );
  1092. #endif
  1093. p.GID = bl->id;
  1094. p.speed = status_get_speed( bl );
  1095. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1096. p.healthState = ( sc ) ? sc->opt2 : 0;
  1097. p.effectState = ( sc ) ? sc->option : 0;
  1098. p.head = vd->hair_style;
  1099. p.weapon = vd->weapon;
  1100. p.accessory = vd->head_bottom;
  1101. p.job = vd->class_;
  1102. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1103. // The hell, why flags work like this?
  1104. p.shield = status_get_emblem_id( bl );
  1105. p.accessory2 = GetWord( g_id, 1 );
  1106. p.accessory3 = GetWord( g_id, 0 );
  1107. }else{
  1108. p.shield = vd->shield;
  1109. p.accessory2 = vd->head_top;
  1110. p.accessory3 = vd->head_mid;
  1111. }
  1112. p.headpalette = vd->hair_color;
  1113. p.bodypalette = vd->cloth_color;
  1114. p.headDir = ( sd ) ? sd->head_dir : 0;
  1115. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1116. p.sex = vd->sex;
  1117. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1118. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1119. clif_send( &p, sizeof( p ), bl, target );
  1120. return;
  1121. }
  1122. #endif
  1123. struct packet_spawn_unit p;
  1124. p.PacketType = spawn_unitType;
  1125. #if PACKETVER >= 20091103
  1126. p.PacketLength = sizeof(p);
  1127. p.objecttype = clif_bl_type( bl, false );
  1128. #endif
  1129. #if PACKETVER >= 20131223
  1130. p.AID = bl->id;
  1131. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1132. #else
  1133. p.GID = bl->id;
  1134. #endif
  1135. p.speed = status_get_speed( bl );
  1136. p.bodyState = (sc) ? sc->opt1 : 0;
  1137. p.healthState = (sc) ? sc->opt2 : 0;
  1138. p.effectState = (sc) ? sc->option : 0;
  1139. p.job = vd->class_;
  1140. p.head = vd->hair_style;
  1141. p.weapon = vd->weapon;
  1142. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1143. p.shield = vd->shield;
  1144. #endif
  1145. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1146. // The hell, why flags work like this?
  1147. p.accessory = status_get_emblem_id( bl );
  1148. p.accessory2 = GetWord( g_id, 1 );
  1149. p.accessory3 = GetWord( g_id, 0 );
  1150. }else{
  1151. p.accessory = vd->head_bottom;
  1152. p.accessory2 = vd->head_top;
  1153. p.accessory3 = vd->head_mid;
  1154. }
  1155. p.headpalette = vd->hair_color;
  1156. p.bodypalette = vd->cloth_color;
  1157. p.headDir = (sd)? sd->head_dir : 0;
  1158. #if PACKETVER >= 20101124
  1159. p.robe = vd->robe;
  1160. #endif
  1161. p.GUID = g_id;
  1162. p.GEmblemVer = status_get_emblem_id( bl );
  1163. p.honor = (sd) ? sd->status.manner : 0;
  1164. p.virtue = (sc) ? sc->opt3 : 0;
  1165. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1166. p.sex = vd->sex;
  1167. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1168. p.xSize = p.ySize = (sd) ? 5 : 0;
  1169. p.clevel = clif_setlevel( bl );
  1170. #if PACKETVER >= 20080102
  1171. p.font = (sd) ? sd->status.font : 0;
  1172. #endif
  1173. #if PACKETVER >= 20120221
  1174. 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 ) ) ){
  1175. p.maxHP = status_get_max_hp( bl );
  1176. p.HP = status_get_hp( bl );
  1177. }else{
  1178. p.maxHP = -1;
  1179. p.HP = -1;
  1180. }
  1181. if( bl->type == BL_MOB ){
  1182. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1183. }else if( bl->type == BL_PET ){
  1184. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1185. }else{
  1186. p.isBoss = BOSSTYPE_NONE;
  1187. }
  1188. #endif
  1189. #if PACKETVER >= 20150513
  1190. p.body = vd->body_style;
  1191. #endif
  1192. /* Might be earlier, this is when the named item bug began */
  1193. #if PACKETVER >= 20131223
  1194. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1195. #endif
  1196. if( disguised( bl ) ){
  1197. nullpo_retv( sd );
  1198. if( sd->status.class_ != sd->disguise ){
  1199. clif_send( &p, sizeof( p ), bl, target );
  1200. }
  1201. #if PACKETVER >= 20091103
  1202. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1203. #if PACKETVER >= 20131223
  1204. p.AID = disguised_bl_id( bl->id );
  1205. #else
  1206. p.GID = disguised_bl_id( bl->id );
  1207. #endif
  1208. #else
  1209. p.GID = disguised_bl_id( bl->id );
  1210. #endif
  1211. clif_send( &p, sizeof( p ), bl, SELF );
  1212. }else{
  1213. clif_send( &p, sizeof( p ), bl, target );
  1214. }
  1215. }
  1216. /*==========================================
  1217. * Prepares 'unit walking' packet
  1218. *------------------------------------------*/
  1219. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1220. nullpo_retv( bl );
  1221. nullpo_retv( ud );
  1222. struct map_session_data* sd;
  1223. struct status_change* sc = status_get_sc( bl );
  1224. struct view_data* vd = status_get_viewdata( bl );
  1225. struct packet_unit_walking p;
  1226. int g_id = status_get_guild_id(bl);
  1227. sd = BL_CAST(BL_PC, bl);
  1228. p.PacketType = unit_walkingType;
  1229. #if PACKETVER >= 20091103
  1230. p.PacketLength = sizeof(p);
  1231. #endif
  1232. #if PACKETVER >= 20071106
  1233. p.objecttype = clif_bl_type( bl, true );
  1234. #endif
  1235. #if PACKETVER >= 20131223
  1236. p.AID = bl->id;
  1237. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1238. #else
  1239. p.GID = bl->id;
  1240. #endif
  1241. p.speed = status_get_speed(bl);
  1242. p.bodyState = (sc) ? sc->opt1 : 0;
  1243. p.healthState = (sc) ? sc->opt2 : 0;
  1244. p.effectState = (sc) ? sc->option : 0;
  1245. p.job = vd->class_;
  1246. p.head = vd->hair_style;
  1247. p.weapon = vd->weapon;
  1248. p.accessory = vd->head_bottom;
  1249. p.moveStartTime = client_tick(gettick());
  1250. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1251. p.shield = vd->shield;
  1252. #endif
  1253. p.accessory2 = vd->head_top;
  1254. p.accessory3 = vd->head_mid;
  1255. p.headpalette = vd->hair_color;
  1256. p.bodypalette = vd->cloth_color;
  1257. p.headDir = (sd) ? sd->head_dir : 0;
  1258. #if PACKETVER >= 20101124
  1259. p.robe = vd->robe;
  1260. #endif
  1261. p.GUID = g_id;
  1262. p.GEmblemVer = status_get_emblem_id(bl);
  1263. p.honor = (sd) ? sd->status.manner : 0;
  1264. p.virtue = (sc) ? sc->opt3 : 0;
  1265. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1266. p.sex = vd->sex;
  1267. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1268. p.xSize = p.ySize = (sd) ? 5 : 0;
  1269. p.clevel = clif_setlevel(bl);
  1270. #if PACKETVER >= 20080102
  1271. p.font = (sd) ? sd->status.font : 0;
  1272. #endif
  1273. #if PACKETVER >= 20120221
  1274. 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 ) ) ){
  1275. p.maxHP = status_get_max_hp(bl);
  1276. p.HP = status_get_hp(bl);
  1277. } else {
  1278. p.maxHP = -1;
  1279. p.HP = -1;
  1280. }
  1281. if( bl->type == BL_MOB ){
  1282. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1283. }else if( bl->type == BL_PET ){
  1284. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1285. }else{
  1286. p.isBoss = BOSSTYPE_NONE;
  1287. }
  1288. #endif
  1289. #if PACKETVER >= 20150513
  1290. p.body = vd->body_style;
  1291. #endif
  1292. /* Might be earlier, this is when the named item bug began */
  1293. #if PACKETVER >= 20131223
  1294. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1295. #endif
  1296. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1297. // if disguised, send the info to self
  1298. if( disguised( bl ) ){
  1299. #if PACKETVER >= 20091103
  1300. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1301. #if PACKETVER >= 20131223
  1302. p.AID = disguised_bl_id( bl->id );
  1303. #else
  1304. p.GID = disguised_bl_id( bl->id );
  1305. #endif
  1306. #else
  1307. p.GID = disguised_bl_id( bl->id );
  1308. #endif
  1309. clif_send(&p,sizeof(p),bl,SELF);
  1310. }
  1311. }
  1312. //Modifies the buffer for disguise characters and sends it to self.
  1313. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1314. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1315. {
  1316. #if PACKETVER >= 20091103
  1317. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1318. WBUFL(buf,5)=-bl->id;
  1319. #elif PACKETVER >= 20071106
  1320. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1321. WBUFL(buf,3)=-bl->id;
  1322. #else
  1323. WBUFL(buf,2)=-bl->id;
  1324. #endif
  1325. clif_send(buf, len, bl, SELF);
  1326. }
  1327. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1328. /// 01b0 <id>.L <type>.B <value>.L
  1329. /// type:
  1330. /// unused
  1331. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1332. {
  1333. nullpo_retv(bl);
  1334. if(!pcdb_checkid(class_))
  1335. {// player classes yield missing sprites
  1336. unsigned char buf[16];
  1337. WBUFW(buf,0)=0x1b0;
  1338. WBUFL(buf,2)=bl->id;
  1339. WBUFB(buf,6)=type;
  1340. WBUFL(buf,7)=class_;
  1341. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1342. }
  1343. }
  1344. void clif_servantball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1345. struct PACKET_ZC_SPIRITS p = {};
  1346. p.PacketType = HEADER_ZC_SPIRITS;
  1347. p.AID = sd.bl.id;
  1348. p.num = sd.servantball;
  1349. if( target == nullptr ){
  1350. target = &sd.bl;
  1351. }
  1352. clif_send( &p, sizeof( p ), target, send_target );
  1353. }
  1354. void clif_abyssball( struct map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1355. struct PACKET_ZC_SPIRITS p = {};
  1356. p.PacketType = HEADER_ZC_SPIRITS;
  1357. p.AID = sd.bl.id;
  1358. p.num = sd.abyssball;
  1359. if( target == nullptr ){
  1360. target = &sd.bl;
  1361. }
  1362. clif_send( &p, sizeof( p ), target, send_target );
  1363. }
  1364. /// Notifies the client of an object's Millenium Shields.
  1365. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1366. {
  1367. nullpo_retv(sd);
  1368. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD) == nullptr)
  1369. return;
  1370. WFIFOHEAD(fd, packet_len(0x440));
  1371. WFIFOW(fd, 0) = 0x440;
  1372. WFIFOL(fd, 2) = sd->bl.id;
  1373. WFIFOW(fd, 6) = sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2;
  1374. WFIFOW(fd, 8) = 0;
  1375. WFIFOSET(fd, packet_len(0x440));
  1376. }
  1377. /*==========================================
  1378. * Kagerou/Oboro amulet spirit
  1379. *------------------------------------------*/
  1380. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1381. {
  1382. WFIFOHEAD(fd, packet_len(0x08cf));
  1383. WFIFOW(fd,0)=0x08cf;
  1384. WFIFOL(fd,2)=sd->bl.id;
  1385. WFIFOW(fd,6)=sd->spiritcharm_type;
  1386. WFIFOW(fd,8)=sd->spiritcharm;
  1387. WFIFOSET(fd, packet_len(0x08cf));
  1388. }
  1389. /*==========================================
  1390. * Enchanting Shadow / Shadow Scar Spirit
  1391. *------------------------------------------*/
  1392. void clif_enchantingshadow_spirit(unit_data &ud) {
  1393. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1394. PACKET_ZC_TARGET_SPIRITS p = {};
  1395. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1396. p.GID = ud.bl->id;
  1397. p.unknown_val = 0;
  1398. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1399. clif_send(&p, sizeof(p), ud.bl, AREA);
  1400. #endif
  1401. }
  1402. /*==========================================
  1403. * Run when player changes map / refreshes
  1404. * Tells its client to display all weather settings being used by this map
  1405. *------------------------------------------*/
  1406. static void clif_weather_check(struct map_session_data *sd)
  1407. {
  1408. int16 m = sd->bl.m;
  1409. int fd = sd->fd;
  1410. if (map_getmapflag(m, MF_SNOW)
  1411. || map_getmapflag(m, MF_CLOUDS)
  1412. || map_getmapflag(m, MF_FOG)
  1413. || map_getmapflag(m, MF_FIREWORKS)
  1414. || map_getmapflag(m, MF_SAKURA)
  1415. || map_getmapflag(m, MF_LEAVES)
  1416. || map_getmapflag(m, MF_CLOUDS2))
  1417. {
  1418. if (map_getmapflag(m, MF_SNOW))
  1419. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1420. if (map_getmapflag(m, MF_CLOUDS))
  1421. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1422. if (map_getmapflag(m, MF_CLOUDS2))
  1423. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1424. if (map_getmapflag(m, MF_FOG))
  1425. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1426. if (map_getmapflag(m, MF_FIREWORKS)) {
  1427. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1428. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1429. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1430. }
  1431. if (map_getmapflag(m, MF_SAKURA))
  1432. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1433. if (map_getmapflag(m, MF_LEAVES))
  1434. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1435. }
  1436. }
  1437. /**
  1438. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1439. **/
  1440. void clif_weather(int16 m)
  1441. {
  1442. struct s_mapiterator* iter;
  1443. struct map_session_data *sd=NULL;
  1444. iter = mapit_getallusers();
  1445. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1446. {
  1447. if( sd->bl.m == m )
  1448. clif_weather_check(sd);
  1449. }
  1450. mapit_free(iter);
  1451. }
  1452. /**
  1453. * Hide a NPC from the effects of Maya Purple card.
  1454. * @param bl: Block data
  1455. * @return True if NPC is disabled or false otherwise
  1456. */
  1457. static inline bool clif_npc_mayapurple(block_list *bl) {
  1458. nullpo_retr(false, bl);
  1459. if (bl->type == BL_NPC) {
  1460. npc_data *nd = map_id2nd(bl->id);
  1461. // TODO: Confirm if waitingroom cause any special cases
  1462. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1463. return true;
  1464. }
  1465. return false;
  1466. }
  1467. /**
  1468. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1469. **/
  1470. int clif_spawn( struct block_list *bl, bool walking ){
  1471. struct view_data *vd;
  1472. vd = status_get_viewdata(bl);
  1473. if( !vd || vd->class_ == JT_INVISIBLE )
  1474. return 0;
  1475. // Hide NPC from Maya Purple card
  1476. if (clif_npc_mayapurple(bl))
  1477. return 0;
  1478. if( bl->type == BL_NPC && !vd->dead_sit ){
  1479. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1480. }else{
  1481. clif_spawn_unit( bl, AREA_WOS );
  1482. }
  1483. if (vd->cloth_color)
  1484. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1485. if (vd->body_style)
  1486. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1487. switch (bl->type)
  1488. {
  1489. case BL_PC:
  1490. {
  1491. TBL_PC *sd = ((TBL_PC*)bl);
  1492. if (sd->spiritball > 0)
  1493. clif_spiritball(&sd->bl);
  1494. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1495. clif_millenniumshield(&sd->bl, sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2);
  1496. if (sd->soulball > 0)
  1497. clif_soulball(sd);
  1498. if (sd->servantball > 0)
  1499. clif_servantball( *sd );
  1500. if (sd->abyssball > 0)
  1501. clif_abyssball( *sd );
  1502. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1503. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1504. else if(sd->state.size==SZ_MEDIUM)
  1505. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1506. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1507. clif_sendbgemblem_area(sd);
  1508. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1509. clif_spiritcharm(sd);
  1510. if (sd->status.robe)
  1511. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1512. clif_efst_status_change_sub(bl, bl, AREA);
  1513. clif_hat_effects(sd,bl,AREA);
  1514. }
  1515. break;
  1516. case BL_MOB:
  1517. {
  1518. TBL_MOB *md = ((TBL_MOB*)bl);
  1519. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1520. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1521. else if(md->special_state.size==SZ_MEDIUM)
  1522. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1523. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1524. clif_summon_init(*md);
  1525. }
  1526. break;
  1527. case BL_NPC:
  1528. {
  1529. TBL_NPC *nd = ((TBL_NPC*)bl);
  1530. if( nd->size == SZ_BIG )
  1531. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1532. else if( nd->size == SZ_MEDIUM )
  1533. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1534. clif_efst_status_change_sub(bl, bl, AREA);
  1535. clif_progressbar_npc_area(nd);
  1536. }
  1537. break;
  1538. case BL_PET:
  1539. if (vd->head_bottom)
  1540. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1541. break;
  1542. }
  1543. return 0;
  1544. }
  1545. /// Sends information about owned homunculus to the client . [orn]
  1546. /// 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)
  1547. /// 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)
  1548. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1549. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1550. nullpo_retv( sd );
  1551. nullpo_retv( hd );
  1552. struct status_data *status = &hd->battle_status;
  1553. struct PACKET_ZC_PROPERTY_HOMUN p;
  1554. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1555. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1556. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1557. 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 );
  1558. p.level = hd->homunculus.level;
  1559. p.hunger = hd->homunculus.hunger;
  1560. p.intimacy = hd->homunculus.intimacy / 100;
  1561. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1562. p.itemId = 0; // equip id
  1563. #endif
  1564. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1565. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1566. p.hit = status->hit;
  1567. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1568. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1569. }else{
  1570. p.crit = status->cri / 10;
  1571. }
  1572. #ifdef RENEWAL
  1573. p.def = status->def + status->def2;
  1574. p.mdef = status->mdef + status->mdef2;
  1575. #else
  1576. p.def = status->def + status->vit;
  1577. p.mdef = status->mdef;
  1578. #endif
  1579. p.flee = status->flee;
  1580. p.amotion = (flag) ? 0 : status->amotion;
  1581. #if PACKETVER >= 20141016
  1582. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1583. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1584. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1585. p.hp = status->hp / ( status->max_hp / 100 );
  1586. p.maxHp = 100;
  1587. }else{
  1588. p.hp = status->hp;
  1589. p.maxHp = status->max_hp;
  1590. }
  1591. #else
  1592. if( status->max_hp > INT16_MAX ){
  1593. p.hp = status->hp / ( status->max_hp / 100 );
  1594. p.maxHp = 100;
  1595. }else{
  1596. p.hp = status->hp;
  1597. p.maxHp = status->max_hp;
  1598. }
  1599. #endif
  1600. if( status->max_sp > INT16_MAX ){
  1601. p.sp = status->sp / ( status->max_sp / 100 );
  1602. p.maxSp = 100;
  1603. }else{
  1604. p.sp = status->sp;
  1605. p.maxSp = status->max_sp;
  1606. }
  1607. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1608. p.exp = hd->homunculus.exp;
  1609. p.expNext = hd->exp_next;
  1610. #else
  1611. p.exp = (uint32)hd->homunculus.exp;
  1612. p.expNext = (uint32)hd->exp_next;
  1613. #endif
  1614. switch( hom_class2type( hd->homunculus.class_ ) ){
  1615. case HT_REG:
  1616. case HT_EVO:
  1617. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1618. p.expNext = 0;
  1619. }
  1620. break;
  1621. case HT_S:
  1622. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1623. p.expNext = 0;
  1624. }
  1625. break;
  1626. }
  1627. p.skillPoints = hd->homunculus.skillpts;
  1628. p.range = status_get_range( &hd->bl );
  1629. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1630. #endif
  1631. }
  1632. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1633. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1634. /// type:
  1635. /// unused
  1636. /// state:
  1637. /// 0 = pre-init
  1638. /// 1 = intimacy
  1639. /// 2 = hunger
  1640. /// 3 = accessory?
  1641. /// ? = ignored
  1642. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1643. { //[orn]
  1644. int fd = sd->fd;
  1645. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1646. hom_calc_skilltree(sd->hd, 0);
  1647. WFIFOHEAD(fd, packet_len(0x230));
  1648. WFIFOW(fd,0)=0x230;
  1649. WFIFOB(fd,2)=0;
  1650. WFIFOB(fd,3)=state;
  1651. WFIFOL(fd,4)=sd->hd->bl.id;
  1652. WFIFOL(fd,8)=param;
  1653. WFIFOSET(fd,packet_len(0x230));
  1654. }
  1655. int clif_homskillinfoblock(struct map_session_data *sd)
  1656. { //[orn]
  1657. struct homun_data *hd;
  1658. int fd = sd->fd;
  1659. int i, len=4;
  1660. nullpo_ret(sd);
  1661. hd = sd->hd;
  1662. if ( !hd )
  1663. return 0 ;
  1664. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1665. WFIFOW(fd,0)=0x235;
  1666. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1667. int id = hd->homunculus.hskill[i].id;
  1668. if( id != 0 ){
  1669. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1670. short idx = hom_skill_get_index(id);
  1671. if (idx == -1)
  1672. continue;
  1673. WFIFOW(fd,len ) = id;
  1674. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1675. WFIFOW(fd,len+4) = 0;
  1676. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1677. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1678. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1679. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1680. 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;
  1681. len+=37;
  1682. }
  1683. }
  1684. WFIFOW(fd,2)=len;
  1685. WFIFOSET(fd,len);
  1686. return 0;
  1687. }
  1688. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1689. { //[orn]
  1690. struct homun_data *hd;
  1691. int fd;
  1692. short idx = -1;
  1693. nullpo_retv(sd);
  1694. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1695. return;
  1696. fd = sd->fd;
  1697. hd = sd->hd;
  1698. WFIFOHEAD(fd, packet_len(0x239));
  1699. WFIFOW(fd,0) = 0x239;
  1700. WFIFOW(fd,2) = skill_id;
  1701. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1702. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1703. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1704. 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;
  1705. WFIFOSET(fd,packet_len(0x239));
  1706. }
  1707. /// Result of request to feed a homun/merc.
  1708. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1709. /// result:
  1710. /// 0 = failure
  1711. /// 1 = success
  1712. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1713. nullpo_retv( sd );
  1714. struct PACKET_ZC_FEED_MER p;
  1715. p.packetType = 0x22f;
  1716. p.result = fail;
  1717. p.itemId = client_nameid( foodid );
  1718. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1719. }
  1720. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1721. /// 0087 <walk start time>.L <walk data>.6B
  1722. void clif_walkok(struct map_session_data *sd)
  1723. {
  1724. int fd=sd->fd;
  1725. WFIFOHEAD(fd, packet_len(0x87));
  1726. WFIFOW(fd,0)=0x87;
  1727. WFIFOL(fd,2)=client_tick(gettick());
  1728. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1729. WFIFOSET(fd,packet_len(0x87));
  1730. }
  1731. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1732. struct status_change *sc = NULL;
  1733. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1734. clif_ally_only = true;
  1735. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1736. if(vd->cloth_color)
  1737. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1738. if(vd->body_style)
  1739. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1740. switch(bl->type) {
  1741. case BL_PC:
  1742. {
  1743. TBL_PC *sd = ((TBL_PC*)bl);
  1744. // clif_movepc(sd);
  1745. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1746. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1747. else if(sd->state.size==SZ_MEDIUM)
  1748. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1749. if (sd->status.robe)
  1750. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1751. }
  1752. break;
  1753. case BL_MOB:
  1754. {
  1755. TBL_MOB *md = ((TBL_MOB*)bl);
  1756. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1757. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1758. else if(md->special_state.size==SZ_MEDIUM)
  1759. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1760. }
  1761. break;
  1762. case BL_PET:
  1763. if(vd->head_bottom) // needed to display pet equip properly
  1764. clif_pet_equip_area((TBL_PET*)bl);
  1765. break;
  1766. }
  1767. clif_ally_only = false;
  1768. }
  1769. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1770. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1771. /// Note: unit must not be self
  1772. void clif_move(struct unit_data *ud)
  1773. {
  1774. unsigned char buf[16];
  1775. struct view_data* vd;
  1776. struct block_list* bl = ud->bl;
  1777. struct status_change *sc = NULL;
  1778. vd = status_get_viewdata(bl);
  1779. if (!vd )
  1780. return;
  1781. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1782. else if( vd->class_ == JT_INVISIBLE ){
  1783. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1784. if(disguised(bl)) {
  1785. WBUFW(buf,0)=0x86;
  1786. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1787. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1788. WBUFL(buf,12)=client_tick(gettick());
  1789. clif_send(buf, packet_len(0x86), bl, SELF);
  1790. }
  1791. return;
  1792. }
  1793. // Hide NPC from Maya Purple card
  1794. if (clif_npc_mayapurple(bl))
  1795. return;
  1796. if (ud->state.speed_changed) {
  1797. // Since we don't know how to update the speed of other objects,
  1798. // use the old walk packet to update the data.
  1799. ud->state.speed_changed = 0;
  1800. clif_move2(bl, vd, ud);
  1801. return;
  1802. }
  1803. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1804. clif_ally_only = true;
  1805. WBUFW(buf,0)=0x86;
  1806. WBUFL(buf,2)=bl->id;
  1807. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1808. WBUFL(buf,12)=client_tick(gettick());
  1809. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1810. if (disguised(bl)) {
  1811. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1812. clif_send(buf, packet_len(0x86), bl, SELF);
  1813. }
  1814. clif_ally_only = false;
  1815. }
  1816. /*==========================================
  1817. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1818. *------------------------------------------*/
  1819. static TIMER_FUNC(clif_delayquit){
  1820. struct map_session_data *sd = NULL;
  1821. //Remove player from map server
  1822. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1823. map_quit(sd);
  1824. return 0;
  1825. }
  1826. /*==========================================
  1827. *
  1828. *------------------------------------------*/
  1829. void clif_quitsave(int fd,struct map_session_data *sd) {
  1830. if (!battle_config.prevent_logout ||
  1831. sd->canlog_tick == 0 ||
  1832. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1833. map_quit(sd);
  1834. else if (session_isValid(sd->fd)) {
  1835. //Disassociate session from player (session is deleted after this function was called)
  1836. //And set a timer to make him quit later.
  1837. session[sd->fd]->session_data = NULL;
  1838. sd->fd = 0;
  1839. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1840. }
  1841. }
  1842. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1843. /// 0091 <map name>.16B <x>.W <y>.W
  1844. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1845. {
  1846. nullpo_retv(sd);
  1847. int fd = sd->fd;
  1848. WFIFOHEAD(fd,packet_len(0x91));
  1849. WFIFOW(fd,0) = 0x91;
  1850. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1851. WFIFOW(fd,18) = x;
  1852. WFIFOW(fd,20) = y;
  1853. WFIFOSET(fd,packet_len(0x91));
  1854. }
  1855. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1856. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1857. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1858. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1859. {
  1860. int fd;
  1861. #if PACKETVER >= 20170315
  1862. int cmd = 0xac7;
  1863. #else
  1864. int cmd = 0x92;
  1865. #endif
  1866. nullpo_retv(sd);
  1867. fd = sd->fd;
  1868. WFIFOHEAD(fd,packet_len(cmd));
  1869. WFIFOW(fd,0) = cmd;
  1870. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1871. WFIFOW(fd,18) = x;
  1872. WFIFOW(fd,20) = y;
  1873. WFIFOL(fd,22) = htonl(ip);
  1874. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1875. #if PACKETVER >= 20170315
  1876. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1877. #endif
  1878. WFIFOSET(fd,packet_len(cmd));
  1879. }
  1880. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1881. /// This function combines both calls and allows to simplify the calling code
  1882. void clif_blown(struct block_list *bl)
  1883. {
  1884. clif_slide(bl, bl->x, bl->y);
  1885. clif_fixpos(bl);
  1886. }
  1887. /// Visually moves(slides) a character to x,y. If the target cell
  1888. /// isn't walkable, the char doesn't move at all. If the char is
  1889. /// sitting it will stand up (ZC_STOPMOVE).
  1890. /// 0088 <id>.L <x>.W <y>.W
  1891. void clif_fixpos(struct block_list *bl)
  1892. {
  1893. unsigned char buf[10];
  1894. nullpo_retv(bl);
  1895. WBUFW(buf,0) = 0x88;
  1896. WBUFL(buf,2) = bl->id;
  1897. WBUFW(buf,6) = bl->x;
  1898. WBUFW(buf,8) = bl->y;
  1899. clif_send(buf, packet_len(0x88), bl, AREA);
  1900. if( disguised(bl) ) {
  1901. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1902. clif_send(buf, packet_len(0x88), bl, SELF);
  1903. }
  1904. }
  1905. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1906. /// 00c4 <shop id>.L
  1907. void clif_npcbuysell(struct map_session_data* sd, int id)
  1908. {
  1909. int fd;
  1910. nullpo_retv(sd);
  1911. fd=sd->fd;
  1912. WFIFOHEAD(fd, packet_len(0xc4));
  1913. WFIFOW(fd,0)=0xc4;
  1914. WFIFOL(fd,2)=id;
  1915. WFIFOSET(fd,packet_len(0xc4));
  1916. }
  1917. /// Presents list of items, that can be bought in an NPC shop.
  1918. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1919. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1920. nullpo_retv( sd );
  1921. nullpo_retv( nd );
  1922. int fd = sd->fd;
  1923. if( !session_isActive( fd ) ){
  1924. return;
  1925. }
  1926. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1927. WFIFOHEAD( fd, len );
  1928. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1929. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1930. int count = 0;
  1931. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1932. int val = nd->u.shop.shop_item[i].value;
  1933. p->items[count].price = val;
  1934. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1935. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1936. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1937. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1938. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1939. p->items[count].viewSprite = id->look;
  1940. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1941. #endif
  1942. count++;
  1943. }
  1944. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1945. WFIFOSET( fd, p->packetLength );
  1946. }
  1947. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1948. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1949. void clif_selllist(struct map_session_data *sd)
  1950. {
  1951. int fd,i,c=0,val;
  1952. struct npc_data *nd;
  1953. nullpo_retv(sd);
  1954. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1955. return;
  1956. fd=sd->fd;
  1957. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1958. WFIFOW(fd,0)=0xc7;
  1959. for( i = 0; i < MAX_INVENTORY; i++ )
  1960. {
  1961. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1962. {
  1963. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1964. continue;
  1965. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1966. val = 0;
  1967. else {
  1968. val = sd->inventory_data[i]->value_sell;
  1969. if( val < 0 )
  1970. continue;
  1971. }
  1972. WFIFOW(fd,4+c*10)=i+2;
  1973. WFIFOL(fd,6+c*10)=val;
  1974. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1975. c++;
  1976. }
  1977. }
  1978. WFIFOW(fd,2)=c*10+4;
  1979. WFIFOSET(fd,WFIFOW(fd,2));
  1980. }
  1981. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1982. /// 09d4
  1983. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1984. // TODO: State tracking?
  1985. sd->npc_shopid = 0;
  1986. }
  1987. /**
  1988. * Presents list of items, that can be sold to a Market shop.
  1989. * @author: Ind and Yommy
  1990. **/
  1991. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1992. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1993. #if PACKETVER >= 20131223
  1994. nullpo_retv( sd );
  1995. nullpo_retv( nd );
  1996. if( sd->state.trading ){
  1997. return;
  1998. }
  1999. int fd = sd->fd;
  2000. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  2001. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  2002. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2003. int count = 0;
  2004. for( int i = 0; i < nd->u.shop.count; i++ ){
  2005. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  2006. if( !item->nameid ){
  2007. continue;
  2008. }
  2009. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2010. if( !id ){
  2011. continue;
  2012. }
  2013. // Out of stock
  2014. if( item->qty == 0 ){
  2015. continue;
  2016. }
  2017. p->list[count].nameid = client_nameid( item->nameid );
  2018. p->list[count].type = itemtype( item->nameid );
  2019. p->list[count].price = item->value;
  2020. p->list[count].qty = item->qty;
  2021. p->list[count].weight = id->weight;
  2022. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2023. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2024. #endif
  2025. count++;
  2026. }
  2027. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2028. WFIFOSET( fd, p->packetLength );
  2029. sd->state.trading = 1;
  2030. #endif
  2031. }
  2032. /// Closes the Market shop window.
  2033. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  2034. nullpo_retv(sd);
  2035. sd->npc_shopid = 0;
  2036. sd->state.trading = 0;
  2037. }
  2038. /// Purchase item from Market shop.
  2039. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2040. void clif_npc_market_purchase_ack( struct map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2041. #if PACKETVER >= 20131223
  2042. nullpo_retv( sd );
  2043. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2044. nullpo_retv( nd );
  2045. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2046. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2047. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2048. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2049. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2050. #else
  2051. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2052. #endif
  2053. if( p->result ){
  2054. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2055. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2056. // Not found
  2057. if( j == nd->u.shop.count ){
  2058. continue;
  2059. }
  2060. p->list[count].ITID = client_nameid( list[i].nameid );
  2061. p->list[count].qty = list[i].qty;
  2062. p->list[count].price = nd->u.shop.shop_item[j].value;
  2063. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2064. count++;
  2065. }
  2066. }
  2067. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2068. #endif
  2069. }
  2070. /// Purchase item from Market shop.
  2071. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2072. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  2073. #if PACKETVER >= 20131223
  2074. nullpo_retv( sd );
  2075. if( !sd->npc_shopid ){
  2076. return;
  2077. }
  2078. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2079. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2080. std::vector<s_npc_buy_list> items;
  2081. items.reserve( count );
  2082. for( int i = 0; i < count; i++ ){
  2083. s_npc_buy_list item = {};
  2084. item.nameid = p->list[i].ITID;
  2085. item.qty = p->list[i].qty;
  2086. items.push_back( item );
  2087. }
  2088. e_purchase_result res = npc_buylist( sd, items );
  2089. clif_npc_market_purchase_ack( sd, res, items );
  2090. #endif
  2091. }
  2092. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2093. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2094. /// Client behavior (dialog window):
  2095. /// - disable mouse targeting
  2096. /// - open the dialog window
  2097. /// - set npcid of dialog window (0 by default)
  2098. /// - if set to clear on next mes, clear contents
  2099. /// - append this text
  2100. void clif_scriptmes( struct map_session_data& sd, uint32 npcid, const char *mes ){
  2101. struct PACKET_ZC_SAY_DIALOG* p = (struct PACKET_ZC_SAY_DIALOG*)packet_buffer;
  2102. int16 length = (int16)( strlen( mes ) + 1 );
  2103. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2104. p->PacketLength = sizeof( *p ) + length;
  2105. p->NpcID = npcid;
  2106. safestrncpy( p->message, mes, length );
  2107. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2108. }
  2109. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2110. /// 00b5 <npc id>.L
  2111. /// Client behavior (dialog window):
  2112. /// - disable mouse targeting
  2113. /// - open the dialog window
  2114. /// - add 'next' button
  2115. /// When 'next' is pressed:
  2116. /// - 00B9 <npcid of dialog window>.L
  2117. /// - set to clear on next mes
  2118. /// - remove 'next' button
  2119. void clif_scriptnext( struct map_session_data& sd, uint32 npcid ){
  2120. struct PACKET_ZC_WAIT_DIALOG p = {};
  2121. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2122. p.NpcID = npcid;
  2123. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2124. }
  2125. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2126. /// 00b6 <npc id>.L
  2127. /// Client behavior:
  2128. /// - if dialog window is open:
  2129. /// - remove 'next' button
  2130. /// - add 'close' button
  2131. /// - else:
  2132. /// - enable mouse targeting
  2133. /// - close the dialog window
  2134. /// - close the menu window
  2135. /// When 'close' is pressed:
  2136. /// - enable mouse targeting
  2137. /// - close the dialog window
  2138. /// - close the menu window
  2139. /// - 0146 <npcid of dialog window>.L
  2140. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2141. {
  2142. int fd;
  2143. nullpo_retv(sd);
  2144. fd=sd->fd;
  2145. WFIFOHEAD(fd, packet_len(0xb6));
  2146. WFIFOW(fd,0)=0xb6;
  2147. WFIFOL(fd,2)=npcid;
  2148. WFIFOSET(fd,packet_len(0xb6));
  2149. }
  2150. /**
  2151. * Close script when player is idle
  2152. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2153. * @author [Ind/Hercules]
  2154. * @param sd : player pointer
  2155. * @param npcid : npc gid to close
  2156. */
  2157. void clif_scriptclear( struct map_session_data& sd, int npcid ){
  2158. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2159. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2160. p.GID = npcid;
  2161. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2162. }
  2163. /*==========================================
  2164. *
  2165. *------------------------------------------*/
  2166. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2167. unsigned char *buf;
  2168. int fd = sd->fd;
  2169. sd->state.using_fake_npc = 1;
  2170. WFIFOHEAD(fd, packet_len(0x78));
  2171. buf = WFIFOP(fd,0);
  2172. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2173. WBUFW(buf,0)=0x78;
  2174. #if PACKETVER >= 20071106
  2175. WBUFB(buf,2) = 0; // object type
  2176. buf = WFIFOP(fd,1);
  2177. #endif
  2178. WBUFL(buf,2)=npcid;
  2179. WBUFW(buf,14)=111;
  2180. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2181. WBUFB(buf,49)=5;
  2182. WBUFB(buf,50)=5;
  2183. WFIFOSET(fd, packet_len(0x78));
  2184. }
  2185. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2186. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2187. /// Client behavior:
  2188. /// - disable mouse targeting
  2189. /// - close the menu window
  2190. /// - open the menu window
  2191. /// - add options to the menu (separated in the text by ":")
  2192. /// - set npcid of menu window
  2193. /// - if dialog window is open:
  2194. /// - remove 'next' button
  2195. /// When 'ok' is pressed:
  2196. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2197. /// - close the menu window
  2198. /// When 'cancel' is pressed:
  2199. /// - 00B8 <npcid of menu window>.L <-1>.B
  2200. /// - enable mouse targeting
  2201. /// - close a bunch of windows...
  2202. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2203. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2204. /// TODO investigate behavior of other windows [FlavioJS]
  2205. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2206. {
  2207. int fd = sd->fd;
  2208. int slen = strlen(mes) + 9;
  2209. struct block_list *bl = NULL;
  2210. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2211. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2212. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2213. clif_sendfakenpc(sd, npcid);
  2214. WFIFOHEAD(fd, slen);
  2215. WFIFOW(fd,0)=0xb7;
  2216. WFIFOW(fd,2)=slen;
  2217. WFIFOL(fd,4)=npcid;
  2218. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2219. WFIFOSET(fd,WFIFOW(fd,2));
  2220. }
  2221. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2222. /// 0142 <npc id>.L
  2223. /// Client behavior (inputnum window):
  2224. /// - if npcid exists in the client:
  2225. /// - open the inputnum window
  2226. /// - set npcid of inputnum window
  2227. /// When 'ok' is pressed:
  2228. /// - if inputnum window has text:
  2229. /// - if npcid exists in the client:
  2230. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2231. /// - close inputnum window
  2232. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2233. {
  2234. int fd;
  2235. struct block_list *bl = NULL;
  2236. nullpo_retv(sd);
  2237. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2238. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2239. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2240. clif_sendfakenpc(sd, npcid);
  2241. fd=sd->fd;
  2242. WFIFOHEAD(fd, packet_len(0x142));
  2243. WFIFOW(fd,0)=0x142;
  2244. WFIFOL(fd,2)=npcid;
  2245. WFIFOSET(fd,packet_len(0x142));
  2246. }
  2247. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2248. /// 01d4 <npc id>.L
  2249. /// Client behavior (inputstr window):
  2250. /// - if npcid is 0 or npcid exists in the client:
  2251. /// - open the inputstr window
  2252. /// - set npcid of inputstr window
  2253. /// When 'ok' is pressed:
  2254. /// - if inputstr window has text and isn't an insult(manner.txt):
  2255. /// - if npcid is 0 or npcid exists in the client:
  2256. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2257. /// - close inputstr window
  2258. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2259. {
  2260. int fd;
  2261. struct block_list *bl = NULL;
  2262. nullpo_retv(sd);
  2263. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2264. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2265. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2266. clif_sendfakenpc(sd, npcid);
  2267. fd=sd->fd;
  2268. WFIFOHEAD(fd, packet_len(0x1d4));
  2269. WFIFOW(fd,0)=0x1d4;
  2270. WFIFOL(fd,2)=npcid;
  2271. WFIFOSET(fd,packet_len(0x1d4));
  2272. }
  2273. /// Marks a position on client's minimap (ZC_COMPASS).
  2274. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2275. /// npc id:
  2276. /// is ignored in the client
  2277. /// type:
  2278. /// 0 = display mark for 15 seconds
  2279. /// 1 = display mark until dead or teleported
  2280. /// 2 = remove mark
  2281. /// color:
  2282. /// 0x00RRGGBB
  2283. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2284. {
  2285. int fd;
  2286. nullpo_retv(sd);
  2287. fd=sd->fd;
  2288. WFIFOHEAD(fd, packet_len(0x144));
  2289. WFIFOW(fd,0)=0x144;
  2290. WFIFOL(fd,2)=npc_id;
  2291. WFIFOL(fd,6)=type;
  2292. WFIFOL(fd,10)=x;
  2293. WFIFOL(fd,14)=y;
  2294. WFIFOB(fd,18)=id;
  2295. WFIFOL(fd,19)=color;
  2296. WFIFOSET(fd,packet_len(0x144));
  2297. }
  2298. /// Displays an illustration image.
  2299. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2300. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2301. /// type:
  2302. /// 0 = bottom left corner
  2303. /// 1 = bottom middle
  2304. /// 2 = bottom right corner
  2305. /// 3 = middle of screen, inside a movable window
  2306. /// 4 = middle of screen, movable with a close button, chrome-less
  2307. /// 255 = clear all displayed cutins
  2308. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2309. {
  2310. int fd;
  2311. nullpo_retv(sd);
  2312. fd=sd->fd;
  2313. WFIFOHEAD(fd, packet_len(0x1b3));
  2314. WFIFOW(fd,0)=0x1b3;
  2315. strncpy(WFIFOCP(fd,2),image,64);
  2316. WFIFOB(fd,66)=type;
  2317. WFIFOSET(fd,packet_len(0x1b3));
  2318. }
  2319. /*==========================================
  2320. * Fills in card data from the given item and into the buffer. [Skotlex]
  2321. *------------------------------------------*/
  2322. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2323. nullpo_retv( buf );
  2324. // Blank data
  2325. if( item == nullptr ){
  2326. buf->card[0] = 0;
  2327. buf->card[1] = 0;
  2328. buf->card[2] = 0;
  2329. buf->card[3] = 0;
  2330. return;
  2331. }
  2332. // Pet eggs
  2333. if( item->card[0] == CARD0_PET ){
  2334. buf->card[0] = 0;
  2335. buf->card[1] = 0;
  2336. // Pet intimacy
  2337. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2338. buf->card[2] = item->card[3] >> 1;
  2339. // Pet renamed flag
  2340. buf->card[3] = item->card[3] & 1;
  2341. return;
  2342. }
  2343. // Forged/created items
  2344. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2345. buf->card[0] = item->card[0];
  2346. buf->card[1] = item->card[1];
  2347. buf->card[2] = item->card[2];
  2348. buf->card[3] = item->card[3];
  2349. return;
  2350. }
  2351. int i = 0, j;
  2352. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2353. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2354. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2355. }
  2356. // Normal items.
  2357. for( int k = 0; k < 4; k++, i++ ){
  2358. if( item->card[i] > 0 ){
  2359. buf->card[k] = client_nameid( item->card[i] );
  2360. }else{
  2361. buf->card[k] = 0;
  2362. }
  2363. }
  2364. }
  2365. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2366. /// A maximum of 5 random options can be supported.
  2367. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2368. nullpo_retr( 0, it );
  2369. uint8 count = 0;
  2370. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2371. if( it->option[i].id ){
  2372. buf[i].index = it->option[i].id; // OptIndex
  2373. buf[i].value = it->option[i].value; // Value
  2374. buf[i].param = it->option[i].param; // Param1
  2375. count++;
  2376. }else{
  2377. buf[i].index = 0;
  2378. buf[i].value = 0;
  2379. buf[i].param = 0;
  2380. }
  2381. }
  2382. #if MAX_ITEM_RDM_OPT < 5
  2383. for( ; i < 5; i++ ){
  2384. buf[i].index = 0; // OptIndex
  2385. buf[i].value = 0; // Value
  2386. buf[i].param = 0; // Param1
  2387. }
  2388. #endif
  2389. return count;
  2390. }
  2391. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2392. /// 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)
  2393. /// 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)
  2394. /// 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)
  2395. /// 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)
  2396. /// 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)
  2397. /// 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)
  2398. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2399. nullpo_retv( sd );
  2400. int fd = sd->fd;
  2401. if( !session_isActive( fd ) ){
  2402. return;
  2403. }
  2404. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2405. if( fail ){
  2406. p = {};
  2407. }else{
  2408. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2409. return;
  2410. }
  2411. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2412. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2413. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2414. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2415. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2416. p.location = pc_equippoint(sd,n);
  2417. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2418. #if PACKETVER >= 20061218
  2419. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2420. #if PACKETVER >= 20071002
  2421. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2422. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2423. */
  2424. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2425. #if PACKETVER >= 20150226
  2426. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2427. #if PACKETVER >= 20160921
  2428. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2429. p.look = sd->inventory_data[n]->look;
  2430. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2431. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2432. #endif
  2433. #endif
  2434. #endif
  2435. #endif
  2436. #endif
  2437. }
  2438. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2439. p.Index = client_index( n );
  2440. p.count = amount;
  2441. p.result = fail;
  2442. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2443. }
  2444. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2445. /// 00af <index>.W <amount>.W
  2446. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2447. {
  2448. int fd;
  2449. nullpo_retv(sd);
  2450. fd=sd->fd;
  2451. WFIFOHEAD(fd, packet_len(0xaf));
  2452. WFIFOW(fd,0)=0xaf;
  2453. WFIFOW(fd,2)=n+2;
  2454. WFIFOW(fd,4)=amount;
  2455. WFIFOSET(fd,packet_len(0xaf));
  2456. }
  2457. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2458. /// 07fa <delete type>.W <index>.W <amount>.W
  2459. /// delete type:
  2460. /// 0 = Normal
  2461. /// 1 = Item used for a skill
  2462. /// 2 = Refine failed
  2463. /// 3 = Material changed
  2464. /// 4 = Moved to storage
  2465. /// 5 = Moved to cart
  2466. /// 6 = Item sold
  2467. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2468. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2469. {
  2470. #if PACKETVER < 20091117
  2471. clif_dropitem(sd,n,amount);
  2472. #else
  2473. int fd;
  2474. nullpo_retv(sd);
  2475. fd=sd->fd;
  2476. WFIFOHEAD(fd, packet_len(0x7fa));
  2477. WFIFOW(fd,0)=0x7fa;
  2478. WFIFOW(fd,2)=reason;
  2479. WFIFOW(fd,4)=n+2;
  2480. WFIFOW(fd,6)=amount;
  2481. WFIFOSET(fd,packet_len(0x7fa));
  2482. #endif
  2483. }
  2484. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2485. nullpo_retv( p );
  2486. nullpo_retv( it );
  2487. nullpo_retv( id );
  2488. p->index = idx;
  2489. p->ITID = client_nameid( it->nameid );
  2490. p->type = itemtype( it->nameid );
  2491. #if PACKETVER < 20120925
  2492. p->IsIdentified = it->identify ? 1 : 0;
  2493. #endif
  2494. p->location = eqp_pos;
  2495. p->WearState = it->equip;
  2496. #if PACKETVER < 20120925
  2497. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2498. #endif
  2499. p->RefiningLevel = it->refine;
  2500. clif_addcards( &p->slot, it );
  2501. #if PACKETVER >= 20071002
  2502. p->HireExpireDate = it->expire_time;
  2503. #endif
  2504. #if PACKETVER >= 20080102
  2505. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2506. #endif
  2507. #if PACKETVER >= 20100629
  2508. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2509. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2510. #endif
  2511. #if PACKETVER >= 20120925
  2512. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2513. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2514. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2515. p->Flag.SpareBits = 0;
  2516. #endif
  2517. #if PACKETVER >= 20150226
  2518. p->option_count = clif_add_random_options( p->option_data, it );
  2519. #endif
  2520. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2521. p->enchantgrade = it->enchantgrade;
  2522. #endif
  2523. }
  2524. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2525. nullpo_retv(p);
  2526. nullpo_retv(i);
  2527. nullpo_retv(id);
  2528. p->index = idx;
  2529. p->ITID = client_nameid( i->nameid );
  2530. p->type = itemtype( i->nameid );
  2531. #if PACKETVER < 20120925
  2532. p->IsIdentified = i->identify ? 1 : 0;
  2533. #endif
  2534. p->count = i->amount;
  2535. p->WearState = id->equip;
  2536. #if PACKETVER >= 5
  2537. clif_addcards( &p->slot, i );
  2538. #endif
  2539. #if PACKETVER >= 20080102
  2540. p->HireExpireDate = i->expire_time;
  2541. #endif
  2542. #if PACKETVER >= 20120925
  2543. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2544. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2545. p->Flag.SpareBits = 0;
  2546. #endif
  2547. }
  2548. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2549. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2550. nullpo_retv(sd);
  2551. nullpo_retv(name);
  2552. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2553. memset(buf, 0, sizeof(buf));
  2554. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2555. p->packetType = HEADER_ZC_INVENTORY_START;
  2556. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2557. p->invType = type;
  2558. #endif
  2559. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2560. int strLen = (int)safestrnlen(name, 24) + 1;
  2561. if (strLen > 24)
  2562. strLen = 24;
  2563. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2564. p->packetLength = len;
  2565. safestrncpy(p->name, name, strLen);
  2566. #else
  2567. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2568. safestrncpy(p->name, name, NAME_LENGTH);
  2569. #endif
  2570. clif_send( p, len, &sd->bl, SELF );
  2571. #endif
  2572. }
  2573. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2574. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2575. nullpo_retv(sd);
  2576. struct PACKET_ZC_INVENTORY_END p;
  2577. p.packetType = HEADER_ZC_INVENTORY_END;
  2578. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2579. p.invType = type;
  2580. #endif
  2581. p.flag = 0;
  2582. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2583. #endif
  2584. }
  2585. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2586. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2587. void clif_inventorylist( struct map_session_data *sd ){
  2588. nullpo_retv( sd );
  2589. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2590. e_inventory_type type = INVTYPE_INVENTORY;
  2591. clif_inventoryStart( sd, type, "" );
  2592. #endif
  2593. static struct packet_itemlist_normal itemlist_normal;
  2594. static struct packet_itemlist_equip itemlist_equip;
  2595. int equip = 0;
  2596. int normal = 0;
  2597. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2598. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2599. continue;
  2600. }
  2601. // Non-stackable (Equippable)
  2602. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2603. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2604. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2605. itemlist_equip.PacketType = inventorylistequipType;
  2606. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2607. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2608. itemlist_equip.invType = type;
  2609. #endif
  2610. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2611. equip = 0;
  2612. }
  2613. // Stackable (Normal)
  2614. }else{
  2615. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2616. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2617. itemlist_normal.PacketType = inventorylistnormalType;
  2618. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2619. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2620. itemlist_normal.invType = type;
  2621. #endif
  2622. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2623. normal = 0;
  2624. }
  2625. }
  2626. }
  2627. if( normal ){
  2628. itemlist_normal.PacketType = inventorylistnormalType;
  2629. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2630. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2631. itemlist_normal.invType = type;
  2632. #endif
  2633. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2634. }
  2635. if( sd->equip_index[EQI_AMMO] >= 0 )
  2636. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2637. if( equip ) {
  2638. itemlist_equip.PacketType = inventorylistequipType;
  2639. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2640. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2641. itemlist_equip.invType = type;
  2642. #endif
  2643. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2644. }
  2645. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2646. clif_inventoryEnd( sd, type );
  2647. #endif
  2648. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2649. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2650. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2651. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2652. continue;
  2653. if ( sd->inventory.u.items_inventory[i].favorite )
  2654. clif_favorite_item(sd, i);
  2655. }
  2656. #endif
  2657. }
  2658. //Required when items break/get-repaired. Only sends equippable item list.
  2659. void clif_equiplist( struct map_session_data *sd ){
  2660. // TODO: implement again => only send equip part
  2661. clif_inventorylist( sd );
  2662. }
  2663. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2664. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2665. e_inventory_type type = INVTYPE_STORAGE;
  2666. clif_inventoryStart( sd, type, storename );
  2667. #endif
  2668. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2669. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2670. int equip = 0;
  2671. int normal = 0;
  2672. for( int i = 0; i < items_length; i++ ){
  2673. if( items[i].nameid == 0 ){
  2674. continue;
  2675. }
  2676. struct item_data* id = itemdb_search( items[i].nameid );
  2677. // Non-stackable (Equippable)
  2678. if( !itemdb_isstackable2( id ) ){
  2679. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2680. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2681. storage_itemlist_equip.PacketType = storageListEquipType;
  2682. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2683. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2684. storage_itemlist_equip.invType = type;
  2685. #elif PACKETVER >= 20120925
  2686. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2687. #endif
  2688. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2689. equip = 0;
  2690. }
  2691. // Stackable (Normal)
  2692. }else{
  2693. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2694. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2695. storage_itemlist_normal.PacketType = storageListNormalType;
  2696. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2697. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2698. storage_itemlist_normal.invType = type;
  2699. #elif PACKETVER >= 20120925
  2700. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2701. #endif
  2702. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2703. normal = 0;
  2704. }
  2705. }
  2706. }
  2707. if( normal ){
  2708. storage_itemlist_normal.PacketType = storageListNormalType;
  2709. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2710. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2711. storage_itemlist_normal.invType = type;
  2712. #elif PACKETVER >= 20120925
  2713. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2714. #endif
  2715. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2716. }
  2717. if( equip ) {
  2718. storage_itemlist_equip.PacketType = storageListEquipType;
  2719. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2720. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2721. storage_itemlist_equip.invType = type;
  2722. #elif PACKETVER >= 20120925
  2723. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2724. #endif
  2725. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2726. }
  2727. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2728. clif_inventoryEnd( sd, type );
  2729. #endif
  2730. }
  2731. void clif_cartlist( struct map_session_data *sd ){
  2732. nullpo_retv( sd );
  2733. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2734. e_inventory_type type = INVTYPE_CART;
  2735. clif_inventoryStart( sd, type, "" );
  2736. #endif
  2737. static struct packet_itemlist_normal itemlist_normal;
  2738. static struct packet_itemlist_equip itemlist_equip;
  2739. int normal = 0;
  2740. int equip = 0;
  2741. for( int i = 0; i < MAX_CART; i++ ){
  2742. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2743. continue;
  2744. }
  2745. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2746. // Non-stackable (Equippable)
  2747. if( !itemdb_isstackable2(id) ){
  2748. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2749. // Stackable (Normal)
  2750. }else{
  2751. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2752. }
  2753. }
  2754. if( normal ){
  2755. itemlist_normal.PacketType = cartlistnormalType;
  2756. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2757. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2758. itemlist_normal.invType = type;
  2759. #endif
  2760. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2761. }
  2762. if( equip ){
  2763. itemlist_equip.PacketType = cartlistequipType;
  2764. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2765. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2766. itemlist_equip.invType = type;
  2767. #endif
  2768. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2769. }
  2770. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2771. clif_inventoryEnd( sd, type );
  2772. #endif
  2773. }
  2774. /// Removes cart (ZC_CARTOFF).
  2775. /// 012b
  2776. /// Client behaviour:
  2777. /// Closes the cart storage and removes all it's items from memory.
  2778. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2779. void clif_clearcart(int fd)
  2780. {
  2781. WFIFOHEAD(fd, packet_len(0x12b));
  2782. WFIFOW(fd,0) = 0x12b;
  2783. WFIFOSET(fd, packet_len(0x12b));
  2784. }
  2785. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2786. /// 01eb <account id>.L <x>.W <y>.W
  2787. void clif_guild_xy(struct map_session_data *sd)
  2788. {
  2789. unsigned char buf[10];
  2790. nullpo_retv(sd);
  2791. WBUFW(buf,0)=0x1eb;
  2792. WBUFL(buf,2)=sd->status.account_id;
  2793. WBUFW(buf,6)=sd->bl.x;
  2794. WBUFW(buf,8)=sd->bl.y;
  2795. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2796. }
  2797. /*==========================================
  2798. * Sends x/y dot to a single fd. [Skotlex]
  2799. *------------------------------------------*/
  2800. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2801. {
  2802. if( sd->bg_id )
  2803. return;
  2804. WFIFOHEAD(fd,packet_len(0x1eb));
  2805. WFIFOW(fd,0)=0x1eb;
  2806. WFIFOL(fd,2)=sd->status.account_id;
  2807. WFIFOW(fd,6)=sd->bl.x;
  2808. WFIFOW(fd,8)=sd->bl.y;
  2809. WFIFOSET(fd,packet_len(0x1eb));
  2810. }
  2811. // Guild XY locators [Valaris]
  2812. void clif_guild_xy_remove(struct map_session_data *sd)
  2813. {
  2814. unsigned char buf[10];
  2815. nullpo_retv(sd);
  2816. WBUFW(buf,0)=0x1eb;
  2817. WBUFL(buf,2)=sd->status.account_id;
  2818. WBUFW(buf,6)=-1;
  2819. WBUFW(buf,8)=-1;
  2820. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2821. }
  2822. /*==========================================
  2823. *
  2824. *------------------------------------------*/
  2825. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2826. struct map_session_data* sd = va_arg( ap, struct map_session_data* );
  2827. struct map_session_data* tsd = BL_CAST( BL_PC, bl );
  2828. nullpo_ret(sd);
  2829. nullpo_ret(tsd);
  2830. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2831. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2832. }
  2833. return 0;
  2834. }
  2835. /*==========================================
  2836. * Server tells all players that are allowed to view HP bars
  2837. * and are nearby 'sd' that 'sd' hp bar was updated.
  2838. *------------------------------------------*/
  2839. static int clif_hpmeter(struct map_session_data *sd)
  2840. {
  2841. nullpo_ret(sd);
  2842. 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);
  2843. return 0;
  2844. }
  2845. /**
  2846. * Send HP bar update to others.
  2847. * @param sd: Player invoking update
  2848. */
  2849. void clif_update_hp(map_session_data &sd) {
  2850. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2851. clif_hpmeter(&sd);
  2852. if (!battle_config.party_hp_mode && sd.status.party_id)
  2853. clif_party_hp( sd );
  2854. if (sd.bg_id)
  2855. clif_bg_hp(&sd);
  2856. }
  2857. /// Notifies client of a character parameter change.
  2858. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2859. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2860. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2861. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2862. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2863. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2864. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2865. /// TODO: Extract individual packets.
  2866. /// FIXME: Packet lengths from packet_len(cmd)
  2867. void clif_updatestatus(struct map_session_data *sd,int type)
  2868. {
  2869. int fd,len=8;
  2870. nullpo_retv(sd);
  2871. fd=sd->fd;
  2872. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2873. return;
  2874. WFIFOHEAD(fd, 14);
  2875. WFIFOW(fd,0)=0xb0;
  2876. WFIFOW(fd,2)=type;
  2877. switch(type){
  2878. // 00b0
  2879. case SP_WEIGHT:
  2880. pc_updateweightstatus(sd);
  2881. WFIFOHEAD(fd,14);
  2882. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2883. WFIFOW(fd,2)=type;
  2884. WFIFOL(fd,4)=sd->weight;
  2885. break;
  2886. case SP_MAXWEIGHT:
  2887. WFIFOL(fd,4)=sd->max_weight;
  2888. break;
  2889. case SP_SPEED:
  2890. WFIFOL(fd,4)=sd->battle_status.speed;
  2891. break;
  2892. case SP_BASELEVEL:
  2893. WFIFOL(fd,4)=sd->status.base_level;
  2894. break;
  2895. case SP_JOBLEVEL:
  2896. WFIFOL(fd,4)=sd->status.job_level;
  2897. break;
  2898. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2899. WFIFOL(fd,4)=sd->status.karma;
  2900. break;
  2901. case SP_MANNER:
  2902. WFIFOL(fd,4)=sd->status.manner;
  2903. break;
  2904. case SP_STATUSPOINT:
  2905. WFIFOL(fd,4)=sd->status.status_point;
  2906. break;
  2907. case SP_SKILLPOINT:
  2908. WFIFOL(fd,4)=sd->status.skill_point;
  2909. break;
  2910. case SP_HIT:
  2911. WFIFOL(fd,4)=sd->battle_status.hit;
  2912. break;
  2913. case SP_FLEE1:
  2914. WFIFOL(fd,4)=sd->battle_status.flee;
  2915. break;
  2916. case SP_FLEE2:
  2917. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2918. break;
  2919. case SP_MAXHP:
  2920. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2921. break;
  2922. case SP_MAXSP:
  2923. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2924. break;
  2925. case SP_HP:
  2926. // On officials the HP never go below 1, even if you die [Lemongrass]
  2927. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2928. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2929. break;
  2930. case SP_SP:
  2931. WFIFOL(fd,4)=sd->battle_status.sp;
  2932. break;
  2933. case SP_ASPD:
  2934. WFIFOL(fd,4)=sd->battle_status.amotion;
  2935. break;
  2936. case SP_ATK1:
  2937. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2938. break;
  2939. case SP_DEF1:
  2940. WFIFOL(fd,4)=pc_leftside_def(sd);
  2941. break;
  2942. case SP_MDEF1:
  2943. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2944. break;
  2945. case SP_ATK2:
  2946. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2947. break;
  2948. case SP_DEF2:
  2949. WFIFOL(fd,4)=pc_rightside_def(sd);
  2950. break;
  2951. case SP_MDEF2: {
  2952. //negative check (in case you have something like Berserk active)
  2953. int mdef2 = pc_rightside_mdef(sd);
  2954. WFIFOL(fd,4)=
  2955. #ifndef RENEWAL
  2956. ( mdef2 < 0 ) ? 0 :
  2957. #endif
  2958. mdef2;
  2959. }
  2960. break;
  2961. case SP_CRITICAL:
  2962. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2963. break;
  2964. case SP_MATK1:
  2965. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2966. break;
  2967. case SP_MATK2:
  2968. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2969. break;
  2970. case SP_ZENY:
  2971. WFIFOW(fd,0)=0xb1;
  2972. WFIFOL(fd,4)=sd->status.zeny;
  2973. break;
  2974. #if PACKETVER >= 20170830
  2975. case SP_BASEEXP:
  2976. WFIFOW(fd,0)=0xacb;
  2977. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2978. len = packet_len(0xacb);
  2979. break;
  2980. case SP_JOBEXP:
  2981. WFIFOW(fd,0)=0xacb;
  2982. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2983. len = packet_len(0xacb);
  2984. break;
  2985. case SP_NEXTBASEEXP:
  2986. WFIFOW(fd,0)=0xacb;
  2987. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2988. len = packet_len(0xacb);
  2989. break;
  2990. case SP_NEXTJOBEXP:
  2991. WFIFOW(fd,0)=0xacb;
  2992. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  2993. len = packet_len(0xacb);
  2994. break;
  2995. #else
  2996. case SP_BASEEXP:
  2997. WFIFOW(fd,0)=0xb1;
  2998. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  2999. break;
  3000. case SP_JOBEXP:
  3001. WFIFOW(fd,0)=0xb1;
  3002. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3003. break;
  3004. case SP_NEXTBASEEXP:
  3005. WFIFOW(fd,0)=0xb1;
  3006. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3007. break;
  3008. case SP_NEXTJOBEXP:
  3009. WFIFOW(fd,0)=0xb1;
  3010. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3011. break;
  3012. #endif
  3013. /**
  3014. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3015. **/
  3016. case SP_USTR:
  3017. case SP_UAGI:
  3018. case SP_UVIT:
  3019. case SP_UINT:
  3020. case SP_UDEX:
  3021. case SP_ULUK:
  3022. WFIFOW(fd,0)=0xbe;
  3023. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3024. len=5;
  3025. break;
  3026. /**
  3027. * Tells the client how far it is allowed to attack (weapon range)
  3028. **/
  3029. case SP_ATTACKRANGE:
  3030. WFIFOW(fd,0)=0x13a;
  3031. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3032. len=4;
  3033. break;
  3034. case SP_STR:
  3035. WFIFOW(fd,0)=0x141;
  3036. WFIFOL(fd,2)=type;
  3037. WFIFOL(fd,6)=sd->status.str;
  3038. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3039. len=14;
  3040. break;
  3041. case SP_AGI:
  3042. WFIFOW(fd,0)=0x141;
  3043. WFIFOL(fd,2)=type;
  3044. WFIFOL(fd,6)=sd->status.agi;
  3045. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3046. len=14;
  3047. break;
  3048. case SP_VIT:
  3049. WFIFOW(fd,0)=0x141;
  3050. WFIFOL(fd,2)=type;
  3051. WFIFOL(fd,6)=sd->status.vit;
  3052. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3053. len=14;
  3054. break;
  3055. case SP_INT:
  3056. WFIFOW(fd,0)=0x141;
  3057. WFIFOL(fd,2)=type;
  3058. WFIFOL(fd,6)=sd->status.int_;
  3059. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3060. len=14;
  3061. break;
  3062. case SP_DEX:
  3063. WFIFOW(fd,0)=0x141;
  3064. WFIFOL(fd,2)=type;
  3065. WFIFOL(fd,6)=sd->status.dex;
  3066. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3067. len=14;
  3068. break;
  3069. case SP_LUK:
  3070. WFIFOW(fd,0)=0x141;
  3071. WFIFOL(fd,2)=type;
  3072. WFIFOL(fd,6)=sd->status.luk;
  3073. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3074. len=14;
  3075. break;
  3076. case SP_CARTINFO:
  3077. WFIFOW(fd,0)=0x121;
  3078. WFIFOW(fd,2)=sd->cart_num;
  3079. WFIFOW(fd,4)=MAX_CART;
  3080. WFIFOL(fd,6)=sd->cart_weight;
  3081. WFIFOL(fd,10)=sd->cart_weight_max;
  3082. len=14;
  3083. break;
  3084. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3085. case SP_AP:
  3086. WFIFOL(fd, 4) = sd->battle_status.ap;
  3087. break;
  3088. case SP_TRAITPOINT:
  3089. WFIFOL(fd, 4) = sd->status.trait_point;
  3090. break;
  3091. case SP_MAXAP:
  3092. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3093. break;
  3094. case SP_POW:
  3095. WFIFOW(fd, 0) = 0x141;
  3096. WFIFOL(fd, 2) = type;
  3097. WFIFOL(fd, 6) = sd->status.pow;
  3098. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3099. len = 14;
  3100. break;
  3101. case SP_STA:
  3102. WFIFOW(fd, 0) = 0x141;
  3103. WFIFOL(fd, 2) = type;
  3104. WFIFOL(fd, 6) = sd->status.sta;
  3105. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3106. len = 14;
  3107. break;
  3108. case SP_WIS:
  3109. WFIFOW(fd, 0) = 0x141;
  3110. WFIFOL(fd, 2) = type;
  3111. WFIFOL(fd, 6) = sd->status.wis;
  3112. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3113. len = 14;
  3114. break;
  3115. case SP_SPL:
  3116. WFIFOW(fd, 0) = 0x141;
  3117. WFIFOL(fd, 2) = type;
  3118. WFIFOL(fd, 6) = sd->status.spl;
  3119. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3120. len = 14;
  3121. break;
  3122. case SP_CON:
  3123. WFIFOW(fd, 0) = 0x141;
  3124. WFIFOL(fd, 2) = type;
  3125. WFIFOL(fd, 6) = sd->status.con;
  3126. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3127. len = 14;
  3128. break;
  3129. case SP_CRT:
  3130. WFIFOW(fd, 0) = 0x141;
  3131. WFIFOL(fd, 2) = type;
  3132. WFIFOL(fd, 6) = sd->status.crt;
  3133. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3134. len = 14;
  3135. break;
  3136. case SP_UPOW:
  3137. case SP_USTA:
  3138. case SP_UWIS:
  3139. case SP_USPL:
  3140. case SP_UCON:
  3141. case SP_UCRT:
  3142. WFIFOW(fd, 0) = 0xbe;
  3143. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3144. len = 5;
  3145. break;
  3146. case SP_PATK:
  3147. WFIFOL(fd, 4) = sd->battle_status.patk;
  3148. break;
  3149. case SP_SMATK:
  3150. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3151. break;
  3152. case SP_RES:
  3153. WFIFOL(fd, 4) = sd->battle_status.res;
  3154. break;
  3155. case SP_MRES:
  3156. WFIFOL(fd, 4) = sd->battle_status.mres;
  3157. break;
  3158. case SP_HPLUS:
  3159. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3160. break;
  3161. case SP_CRATE:
  3162. WFIFOL(fd, 4) = sd->battle_status.crate;
  3163. break;
  3164. #else
  3165. case SP_AP:
  3166. case SP_TRAITPOINT:
  3167. case SP_MAXAP:
  3168. case SP_POW:
  3169. case SP_STA:
  3170. case SP_WIS:
  3171. case SP_SPL:
  3172. case SP_CON:
  3173. case SP_CRT:
  3174. case SP_UPOW:
  3175. case SP_USTA:
  3176. case SP_UWIS:
  3177. case SP_USPL:
  3178. case SP_UCON:
  3179. case SP_UCRT:
  3180. case SP_PATK:
  3181. case SP_SMATK:
  3182. case SP_RES:
  3183. case SP_MRES:
  3184. case SP_HPLUS:
  3185. case SP_CRATE:
  3186. // 4th job status are not supported by older clients
  3187. return;
  3188. #endif
  3189. default:
  3190. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3191. return;
  3192. }
  3193. WFIFOSET(fd,len);
  3194. // Additional update packets that should be sent right after
  3195. switch( type ){
  3196. case SP_BASELEVEL:
  3197. if( sd->status.party_id ){
  3198. struct party_data* p;
  3199. int i;
  3200. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3201. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3202. if( i < MAX_PARTY ){
  3203. p->party.member[i].lv = sd->status.base_level;
  3204. clif_party_job_and_level( *sd );
  3205. }
  3206. }
  3207. }
  3208. break;
  3209. case SP_HP:
  3210. clif_update_hp(*sd);
  3211. break;
  3212. }
  3213. }
  3214. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3215. /// 01ab <account id>.L <var id>.W <value>.L
  3216. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3217. {
  3218. unsigned char buf[12];
  3219. nullpo_retv(sd);
  3220. WBUFW(buf,0)=0x1ab;
  3221. WBUFL(buf,2)=sd->bl.id;
  3222. WBUFW(buf,6)=type;
  3223. switch(type)
  3224. {
  3225. case SP_MANNER:
  3226. WBUFL(buf,8)=val;
  3227. break;
  3228. default:
  3229. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3230. return;
  3231. }
  3232. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3233. }
  3234. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3235. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3236. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3237. struct PACKET_ZC_SPRITE_CHANGE p;
  3238. p.packetType = sendLookType;
  3239. p.AID = id;
  3240. p.type = type;
  3241. p.val = val;
  3242. #if PACKETVER >= 4
  3243. p.val2 = val2;
  3244. #endif
  3245. clif_send( &p, sizeof( p ), bl, target );
  3246. }
  3247. /// Updates sprite/style properties of an object.
  3248. void clif_changelook(struct block_list *bl, int type, int val) {
  3249. struct map_session_data* sd;
  3250. struct status_change* sc;
  3251. struct view_data* vd;
  3252. enum send_target target = AREA;
  3253. int val2 = 0;
  3254. nullpo_retv(bl);
  3255. sd = BL_CAST(BL_PC, bl);
  3256. sc = status_get_sc(bl);
  3257. vd = status_get_viewdata(bl);
  3258. if( vd ) //temp hack to let Warp Portal change appearance
  3259. switch(type) {
  3260. case LOOK_WEAPON:
  3261. if (sd) {
  3262. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3263. val = vd->weapon;
  3264. }
  3265. else
  3266. vd->weapon = val;
  3267. break;
  3268. case LOOK_SHIELD:
  3269. if (sd) {
  3270. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3271. val = vd->shield;
  3272. }
  3273. else
  3274. vd->shield = val;
  3275. break;
  3276. case LOOK_BASE:
  3277. if (!sd)
  3278. break;
  3279. if ( val == JT_INVISIBLE )
  3280. return;
  3281. if (sd->sc.option&OPTION_COSTUME)
  3282. vd->weapon = vd->shield = 0;
  3283. if (!vd->cloth_color)
  3284. break;
  3285. if (sd) {
  3286. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3287. vd->cloth_color = 0;
  3288. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3289. vd->cloth_color = 0;
  3290. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3291. vd->cloth_color = 0;
  3292. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3293. vd->cloth_color = 0;
  3294. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3295. vd->cloth_color = 0;
  3296. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3297. vd->body_style = 0;
  3298. }
  3299. break;
  3300. case LOOK_HAIR:
  3301. vd->hair_style = val;
  3302. break;
  3303. case LOOK_HEAD_BOTTOM:
  3304. vd->head_bottom = val;
  3305. break;
  3306. case LOOK_HEAD_TOP:
  3307. vd->head_top = val;
  3308. break;
  3309. case LOOK_HEAD_MID:
  3310. vd->head_mid = val;
  3311. break;
  3312. case LOOK_HAIR_COLOR:
  3313. vd->hair_color = val;
  3314. break;
  3315. case LOOK_CLOTHES_COLOR:
  3316. if (val && sd) {
  3317. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3318. val = 0;
  3319. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3320. val = 0;
  3321. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3322. val = 0;
  3323. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3324. val = 0;
  3325. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3326. val = 0;
  3327. }
  3328. vd->cloth_color = val;
  3329. break;
  3330. case LOOK_SHOES:
  3331. #if PACKETVER > 3
  3332. if (sd) {
  3333. int n;
  3334. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3335. if(sd->inventory_data[n]->view_id > 0)
  3336. val = sd->inventory_data[n]->view_id;
  3337. else
  3338. val = sd->inventory.u.items_inventory[n].nameid;
  3339. } else
  3340. val = 0;
  3341. }
  3342. #endif
  3343. //Shoes? No packet uses this....
  3344. break;
  3345. case LOOK_BODY:
  3346. // unknown purpose
  3347. break;
  3348. case LOOK_ROBE:
  3349. #if PACKETVER < 20110111
  3350. return;
  3351. #else
  3352. vd->robe = val;
  3353. #endif
  3354. break;
  3355. case LOOK_BODY2:
  3356. #if PACKETVER < 20150513
  3357. return;
  3358. #else
  3359. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3360. val = 0;
  3361. vd->body_style = val;
  3362. #endif
  3363. break;
  3364. }
  3365. // prevent leaking the presence of GM-hidden objects
  3366. if( sc && sc->option&OPTION_INVISIBLE )
  3367. target = SELF;
  3368. #if PACKETVER < 4
  3369. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3370. #else
  3371. if (bl->type != BL_NPC) {
  3372. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3373. type = LOOK_WEAPON;
  3374. val = (vd ? vd->weapon : 0);
  3375. val2 = (vd ? vd->shield : 0);
  3376. }
  3377. if (disguised(bl)) {
  3378. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3379. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3380. } else
  3381. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3382. } else
  3383. unit_refresh(bl);
  3384. #endif
  3385. }
  3386. //Sends a change-base-look packet required for traps as they are triggered.
  3387. void clif_changetraplook(struct block_list *bl,int val) {
  3388. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3389. }
  3390. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3391. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3392. clif_sprite_change(bl, id, type, val, 0, target);
  3393. }
  3394. /// Character status (ZC_STATUS).
  3395. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3396. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3397. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3398. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3399. void clif_initialstatus(struct map_session_data *sd) {
  3400. int fd, mdef2;
  3401. unsigned char *buf;
  3402. nullpo_retv(sd);
  3403. fd=sd->fd;
  3404. WFIFOHEAD(fd, packet_len(0xbd));
  3405. buf = WFIFOP(fd,0);
  3406. WBUFW(buf,0) = 0xbd;
  3407. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3408. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3409. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3410. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3411. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3412. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3413. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3414. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3415. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3416. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3417. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3418. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3419. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3420. WBUFW(buf,16) = pc_leftside_atk(sd);
  3421. WBUFW(buf,18) = pc_rightside_atk(sd);
  3422. WBUFW(buf,20) = pc_rightside_matk(sd);
  3423. WBUFW(buf,22) = pc_leftside_matk(sd);
  3424. WBUFW(buf,24) = pc_leftside_def(sd);
  3425. WBUFW(buf,26) = pc_rightside_def(sd);
  3426. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3427. mdef2 = pc_rightside_mdef(sd);
  3428. WBUFW(buf,30) =
  3429. #ifndef RENEWAL
  3430. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3431. #endif
  3432. mdef2;
  3433. WBUFW(buf,32) = sd->battle_status.hit;
  3434. WBUFW(buf,34) = sd->battle_status.flee;
  3435. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3436. WBUFW(buf,38) = sd->battle_status.cri/10;
  3437. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3438. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3439. WFIFOSET(fd, packet_len(0xbd));
  3440. clif_updatestatus(sd, SP_STR);
  3441. clif_updatestatus(sd, SP_AGI);
  3442. clif_updatestatus(sd, SP_VIT);
  3443. clif_updatestatus(sd, SP_INT);
  3444. clif_updatestatus(sd, SP_DEX);
  3445. clif_updatestatus(sd, SP_LUK);
  3446. clif_updatestatus(sd, SP_ATTACKRANGE);
  3447. clif_updatestatus(sd, SP_ASPD);
  3448. #ifdef RENEWAL
  3449. clif_updatestatus(sd, SP_POW);
  3450. clif_updatestatus(sd, SP_STA);
  3451. clif_updatestatus(sd, SP_WIS);
  3452. clif_updatestatus(sd, SP_SPL);
  3453. clif_updatestatus(sd, SP_CON);
  3454. clif_updatestatus(sd, SP_CRT);
  3455. clif_updatestatus(sd, SP_PATK);
  3456. clif_updatestatus(sd, SP_SMATK);
  3457. clif_updatestatus(sd, SP_RES);
  3458. clif_updatestatus(sd, SP_MRES);
  3459. clif_updatestatus(sd, SP_HPLUS);
  3460. clif_updatestatus(sd, SP_CRATE);
  3461. clif_updatestatus(sd, SP_TRAITPOINT);
  3462. clif_updatestatus(sd, SP_AP);
  3463. clif_updatestatus(sd, SP_MAXAP);
  3464. clif_updatestatus(sd, SP_UPOW);
  3465. clif_updatestatus(sd, SP_USTA);
  3466. clif_updatestatus(sd, SP_UWIS);
  3467. clif_updatestatus(sd, SP_USPL);
  3468. clif_updatestatus(sd, SP_UCON);
  3469. clif_updatestatus(sd, SP_UCRT);
  3470. #endif
  3471. }
  3472. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3473. /// 013c <index>.W
  3474. void clif_arrowequip(struct map_session_data *sd,int val) {
  3475. int fd;
  3476. nullpo_retv(sd);
  3477. #if PACKETVER >= 20121128
  3478. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3479. #endif
  3480. fd=sd->fd;
  3481. WFIFOHEAD(fd, packet_len(0x013c));
  3482. WFIFOW(fd,0) = 0x013c;
  3483. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3484. WFIFOSET(fd, packet_len(0x013c));
  3485. }
  3486. /// Ammunition action message (ZC_ACTION_FAILURE).
  3487. /// 013b <type>.W
  3488. /// type:
  3489. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3490. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3491. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3492. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3493. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3494. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3495. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3496. int fd;
  3497. nullpo_retv(sd);
  3498. fd=sd->fd;
  3499. WFIFOHEAD(fd, packet_len(0x013b));
  3500. WFIFOW(fd,0) = 0x013b;
  3501. WFIFOW(fd,2) = type;
  3502. WFIFOSET(fd, packet_len(0x013b));
  3503. }
  3504. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3505. /// 01ad <packet len>.W { <name id>.W }*
  3506. void clif_arrow_create_list( struct map_session_data *sd ){
  3507. nullpo_retv( sd );
  3508. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3509. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3510. int count = 0;
  3511. for (const auto &it : skill_arrow_db) {
  3512. t_itemid nameid = it.second->nameid;
  3513. if( !item_db.exists( nameid ) ){
  3514. continue;
  3515. }
  3516. int index = pc_search_inventory( sd, nameid );
  3517. if( index < 0 ){
  3518. continue;
  3519. }
  3520. if( sd->inventory.u.items_inventory[index].equip ){
  3521. continue;
  3522. }
  3523. if( !sd->inventory.u.items_inventory[index].identify ){
  3524. continue;
  3525. }
  3526. p->items[count].itemId = client_nameid( nameid );
  3527. count++;
  3528. }
  3529. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3530. clif_send( p, p->packetLength, &sd->bl, SELF );
  3531. if( count > 0 ){
  3532. sd->menuskill_id = AC_MAKINGARROW;
  3533. sd->menuskill_val = count;
  3534. }
  3535. }
  3536. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3537. /// 00bc <status id>.W <result>.B <value>.B
  3538. /// status id:
  3539. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3540. /// result:
  3541. /// 0 = failure
  3542. /// 1 = success
  3543. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3544. int fd;
  3545. nullpo_retv(sd);
  3546. fd=sd->fd;
  3547. WFIFOHEAD(fd, packet_len(0xbc));
  3548. WFIFOW(fd,0) = 0xbc;
  3549. WFIFOW(fd,2) = type;
  3550. WFIFOB(fd,4) = ok;
  3551. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3552. WFIFOSET(fd, packet_len(0xbc));
  3553. }
  3554. /// Notifies the client about the result of a request to equip an item.
  3555. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3556. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3557. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3558. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3559. /// @ok: //inversed forv2 v5
  3560. /// 0 = failure
  3561. /// 1 = success
  3562. /// 2 = failure due to low level
  3563. void clif_equipitemack( struct map_session_data& sd, uint8 flag, int index, int pos ){
  3564. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3565. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3566. p.index = client_index( index );
  3567. p.wearLocation = pos;
  3568. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3569. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3570. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3571. }else{
  3572. p.wItemSpriteNumber = 0;
  3573. }
  3574. #endif
  3575. p.result = flag;
  3576. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3577. }
  3578. /// Notifies the client about the result of a request to take off an item.
  3579. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3580. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3581. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3582. /// @ok : //inversed for v2 v5
  3583. /// 0 = failure
  3584. /// 1 = success
  3585. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3586. {
  3587. int fd, header, offs = 0;
  3588. #if PACKETVER >= 20130000
  3589. header = 0x99a;
  3590. ok = ok ? 0 : 1;
  3591. #elif PACKETVER >= 20110824
  3592. header = 0x8d1;
  3593. ok = ok ? 0 : 1;
  3594. #else
  3595. header = 0xac;
  3596. #endif
  3597. nullpo_retv(sd);
  3598. fd=sd->fd;
  3599. WFIFOHEAD(fd, packet_len(header));
  3600. WFIFOW(fd,offs+0) = header;
  3601. WFIFOW(fd,offs+2) = n+2;
  3602. #if PACKETVER >= 20130000
  3603. WFIFOL(fd,offs+4) = pos;
  3604. offs += 2;
  3605. #else
  3606. WFIFOW(fd,offs+4) = pos;
  3607. #endif
  3608. WFIFOB(fd,offs+6) = ok;
  3609. WFIFOSET(fd, packet_len(header));
  3610. }
  3611. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3612. /// 019b <id>.L <effect id>.L
  3613. /// effect id:
  3614. /// 0 = base level up
  3615. /// 1 = job level up
  3616. /// 2 = refine failure
  3617. /// 3 = refine success
  3618. /// 4 = game over
  3619. /// 5 = pharmacy success
  3620. /// 6 = pharmacy failure
  3621. /// 7 = base level up (super novice)
  3622. /// 8 = job level up (super novice)
  3623. /// 9 = base level up (taekwon)
  3624. void clif_misceffect(struct block_list* bl,int type)
  3625. {
  3626. unsigned char buf[32];
  3627. nullpo_retv(bl);
  3628. WBUFW(buf,0) = 0x19b;
  3629. WBUFL(buf,2) = bl->id;
  3630. WBUFL(buf,6) = type;
  3631. clif_send(buf,packet_len(0x19b),bl,AREA);
  3632. }
  3633. /// Notifies clients in the area of a state change.
  3634. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3635. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3636. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3637. nullpo_retv( bl );
  3638. struct status_change* sc = status_get_sc( bl );
  3639. //How can an option change if there's no sc?
  3640. if( sc == nullptr ){
  3641. return;
  3642. }
  3643. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3644. struct PACKET_ZC_STATE_CHANGE p;
  3645. p.packetType = HEADER_ZC_STATE_CHANGE;
  3646. p.AID = bl->id;
  3647. p.bodyState = sc->opt1;
  3648. p.healthState = sc->opt2;
  3649. p.effectState = sc->option;
  3650. p.isPKModeON = sd ? sd->status.karma : false;
  3651. if( target == nullptr ){
  3652. if( disguised( bl ) ){
  3653. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3654. p.AID = disguised_bl_id( p.AID );
  3655. clif_send( &p, sizeof( p ), bl, SELF );
  3656. p.AID = disguised_bl_id( p.AID );
  3657. p.effectState = OPTION_INVISIBLE;
  3658. clif_send( &p, sizeof( p ), bl, SELF );
  3659. }else{
  3660. clif_send( &p, sizeof( p ), bl, AREA );
  3661. }
  3662. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3663. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3664. if( sc->getSCE(SC_PROVOKE) ){
  3665. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3666. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3667. }
  3668. }else{
  3669. if( disguised( bl ) ){
  3670. p.AID = disguised_bl_id( p.AID );
  3671. clif_send( &p, sizeof( p ), target, SELF );
  3672. p.AID = disguised_bl_id( p.AID );
  3673. p.effectState = OPTION_INVISIBLE;
  3674. clif_send( &p, sizeof( p ), target, SELF );
  3675. }else{
  3676. clif_send( &p, sizeof( p ), target, SELF );
  3677. }
  3678. }
  3679. }
  3680. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3681. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3682. void clif_changeoption2(struct block_list* bl)
  3683. {
  3684. unsigned char buf[20];
  3685. struct status_change *sc;
  3686. sc = status_get_sc(bl);
  3687. if (!sc) return; //How can an option change if there's no sc?
  3688. WBUFW(buf,0) = 0x28a;
  3689. WBUFL(buf,2) = bl->id;
  3690. WBUFL(buf,6) = sc->option;
  3691. WBUFL(buf,10) = clif_setlevel(bl);
  3692. WBUFL(buf,14) = sc->opt3;
  3693. if(disguised(bl)) {
  3694. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3695. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3696. clif_send(buf,packet_len(0x28a),bl,SELF);
  3697. WBUFL(buf,2) = bl->id;
  3698. WBUFL(buf,6) = OPTION_INVISIBLE;
  3699. clif_send(buf,packet_len(0x28a),bl,SELF);
  3700. } else
  3701. clif_send(buf,packet_len(0x28a),bl,AREA);
  3702. }
  3703. /// Notifies the client about the result of an item use request.
  3704. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3705. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3706. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3707. nullpo_retv( sd );
  3708. int fd = sd->fd;
  3709. if( !session_isActive( fd ) ){
  3710. return;
  3711. }
  3712. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3713. return;
  3714. }
  3715. struct PACKET_ZC_USE_ITEM_ACK p;
  3716. p.packetType = useItemAckType;
  3717. p.index = index + 2;
  3718. #if PACKETVER > 3
  3719. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3720. p.AID = sd->bl.id;
  3721. #endif
  3722. p.amount = amount;
  3723. p.result = ok;
  3724. if( !ok ){
  3725. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3726. }else{
  3727. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3728. }
  3729. }
  3730. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3731. /// 00d6 <flag>.B
  3732. /// flag:
  3733. /// 0 = Room has been successfully created (opens chat room)
  3734. /// 1 = Room limit exceeded
  3735. /// 2 = Same room already exists
  3736. void clif_createchat(struct map_session_data* sd, int flag)
  3737. {
  3738. int fd;
  3739. nullpo_retv(sd);
  3740. fd = sd->fd;
  3741. WFIFOHEAD(fd,packet_len(0xd6));
  3742. WFIFOW(fd,0) = 0xd6;
  3743. WFIFOB(fd,2) = flag;
  3744. WFIFOSET(fd,packet_len(0xd6));
  3745. }
  3746. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3747. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3748. /// type:
  3749. /// 0 = private (password protected)
  3750. /// 1 = public
  3751. /// 2 = arena (npc waiting room)
  3752. /// 3 = PK zone (non-clickable)
  3753. void clif_dispchat(struct chat_data* cd, int fd)
  3754. {
  3755. unsigned char buf[128];
  3756. uint8 type;
  3757. if( cd == NULL || cd->owner == NULL )
  3758. return;
  3759. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3760. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3761. : 1;
  3762. WBUFW(buf, 0) = 0xd7;
  3763. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3764. WBUFL(buf, 4) = cd->owner->id;
  3765. WBUFL(buf, 8) = cd->bl.id;
  3766. WBUFW(buf,12) = cd->limit;
  3767. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3768. WBUFB(buf,16) = type;
  3769. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3770. if( session_isActive(fd) ) {
  3771. WFIFOHEAD(fd,WBUFW(buf,2));
  3772. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3773. WFIFOSET(fd,WBUFW(buf,2));
  3774. } else {
  3775. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3776. }
  3777. }
  3778. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3779. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3780. /// type:
  3781. /// 0 = private (password protected)
  3782. /// 1 = public
  3783. /// 2 = arena (npc waiting room)
  3784. /// 3 = PK zone (non-clickable)
  3785. void clif_changechatstatus(struct chat_data* cd)
  3786. {
  3787. unsigned char buf[128];
  3788. uint8 type;
  3789. if( cd == NULL || cd->usersd[0] == NULL )
  3790. return;
  3791. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3792. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3793. : 1;
  3794. WBUFW(buf, 0) = 0xdf;
  3795. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3796. WBUFL(buf, 4) = cd->owner->id;
  3797. WBUFL(buf, 8) = cd->bl.id;
  3798. WBUFW(buf,12) = cd->limit;
  3799. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3800. WBUFB(buf,16) = type;
  3801. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3802. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3803. }
  3804. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3805. /// 00d8 <chat id>.L
  3806. void clif_clearchat(struct chat_data *cd,int fd)
  3807. {
  3808. unsigned char buf[32];
  3809. nullpo_retv(cd);
  3810. WBUFW(buf,0) = 0xd8;
  3811. WBUFL(buf,2) = cd->bl.id;
  3812. if( session_isActive(fd) ) {
  3813. WFIFOHEAD(fd,packet_len(0xd8));
  3814. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3815. WFIFOSET(fd,packet_len(0xd8));
  3816. } else {
  3817. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3818. }
  3819. }
  3820. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3821. /// 00da <result>.B
  3822. /// result:
  3823. /// 0 = room full
  3824. /// 1 = wrong password
  3825. /// 2 = kicked
  3826. /// 3 = success (no message)
  3827. /// 4 = no enough zeny
  3828. /// 5 = too low level
  3829. /// 6 = too high level
  3830. /// 7 = unsuitable job class
  3831. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3832. {
  3833. int fd;
  3834. nullpo_retv(sd);
  3835. fd = sd->fd;
  3836. WFIFOHEAD(fd,packet_len(0xda));
  3837. WFIFOW(fd,0) = 0xda;
  3838. WFIFOB(fd,2) = flag;
  3839. WFIFOSET(fd,packet_len(0xda));
  3840. }
  3841. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3842. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3843. /// role:
  3844. /// 0 = owner (menu)
  3845. /// 1 = normal
  3846. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3847. {
  3848. int fd;
  3849. int i,t;
  3850. nullpo_retv(sd);
  3851. nullpo_retv(cd);
  3852. fd = sd->fd;
  3853. if (!session_isActive(fd))
  3854. return;
  3855. t = (int)(cd->owner->type == BL_NPC);
  3856. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3857. WFIFOW(fd, 0) = 0xdb;
  3858. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3859. WFIFOL(fd, 4) = cd->bl.id;
  3860. if(cd->owner->type == BL_NPC){
  3861. WFIFOL(fd, 30) = 1;
  3862. WFIFOL(fd, 8) = 0;
  3863. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3864. for (i = 0; i < cd->users; i++) {
  3865. WFIFOL(fd, 8+(i+1)*28) = 1;
  3866. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3867. }
  3868. }else{
  3869. for (i = 0; i < cd->users; i++) {
  3870. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3871. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3872. }
  3873. }
  3874. WFIFOSET(fd, WFIFOW(fd, 2));
  3875. }
  3876. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3877. /// 00dc <users>.W <name>.24B
  3878. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3879. {
  3880. unsigned char buf[29];
  3881. nullpo_retv(sd);
  3882. nullpo_retv(cd);
  3883. WBUFW(buf, 0) = 0xdc;
  3884. WBUFW(buf, 2) = cd->users;
  3885. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3886. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3887. }
  3888. /// Announce the new owner (ZC_ROLE_CHANGE).
  3889. /// 00e1 <role>.L <nick>.24B
  3890. /// role:
  3891. /// 0 = owner (menu)
  3892. /// 1 = normal
  3893. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3894. {
  3895. unsigned char buf[64];
  3896. nullpo_retv(sd);
  3897. nullpo_retv(cd);
  3898. WBUFW(buf, 0) = 0xe1;
  3899. WBUFL(buf, 2) = 1;
  3900. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3901. WBUFW(buf,30) = 0xe1;
  3902. WBUFL(buf,32) = 0;
  3903. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3904. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3905. }
  3906. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3907. /// 00dd <users>.W <nick>.24B <flag>.B
  3908. /// flag:
  3909. /// 0 = left
  3910. /// 1 = kicked
  3911. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3912. {
  3913. unsigned char buf[32];
  3914. nullpo_retv(sd);
  3915. nullpo_retv(cd);
  3916. WBUFW(buf, 0) = 0xdd;
  3917. WBUFW(buf, 2) = cd->users-1;
  3918. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3919. WBUFB(buf,28) = flag;
  3920. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3921. }
  3922. /// Opens a trade request window from char 'name'.
  3923. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3924. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3925. void clif_traderequest(struct map_session_data* sd, const char* name)
  3926. {
  3927. int fd = sd->fd;
  3928. #if PACKETVER < 6
  3929. WFIFOHEAD(fd,packet_len(0xe5));
  3930. WFIFOW(fd,0) = 0xe5;
  3931. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3932. WFIFOSET(fd,packet_len(0xe5));
  3933. #else
  3934. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3935. if( !tsd ) return;
  3936. WFIFOHEAD(fd,packet_len(0x1f4));
  3937. WFIFOW(fd,0) = 0x1f4;
  3938. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3939. WFIFOL(fd,26) = tsd->status.char_id;
  3940. WFIFOW(fd,30) = tsd->status.base_level;
  3941. WFIFOSET(fd,packet_len(0x1f4));
  3942. #endif
  3943. }
  3944. /// Reply to a trade-request.
  3945. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3946. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3947. /// result:
  3948. /// 0 = Char is too far
  3949. /// 1 = Character does not exist
  3950. /// 2 = Trade failed
  3951. /// 3 = Accept
  3952. /// 4 = Cancel
  3953. /// 5 = Busy
  3954. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3955. {
  3956. int fd = sd->fd;
  3957. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3958. if( PACKETVER < 6 || !tsd ) {
  3959. WFIFOHEAD(fd,packet_len(0xe7));
  3960. WFIFOW(fd,0) = 0xe7;
  3961. WFIFOB(fd,2) = type;
  3962. WFIFOSET(fd,packet_len(0xe7));
  3963. } else {
  3964. WFIFOHEAD(fd,packet_len(0x1f5));
  3965. WFIFOW(fd,0) = 0x1f5;
  3966. WFIFOB(fd,2) = type;
  3967. WFIFOL(fd,3) = tsd->status.char_id;
  3968. WFIFOW(fd,7) = tsd->status.base_level;
  3969. WFIFOSET(fd,packet_len(0x1f5));
  3970. }
  3971. }
  3972. /// Notifies the client about an item from other player in current trade.
  3973. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3974. /// 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)
  3975. /// 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)
  3976. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3977. nullpo_retv( sd );
  3978. nullpo_retv( tsd );
  3979. int fd = tsd->fd;
  3980. if( !session_isActive( fd ) ){
  3981. return;
  3982. }
  3983. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3984. if( index ){
  3985. index = server_index( index );
  3986. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3987. return;
  3988. }
  3989. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3990. #if PACKETVER >= 20100223
  3991. p.itemType = sd->inventory_data[index]->type;
  3992. #endif
  3993. p.identified = sd->inventory.u.items_inventory[index].identify;
  3994. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3995. p.refine = sd->inventory.u.items_inventory[index].refine;
  3996. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3997. #if PACKETVER >= 20150226
  3998. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3999. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4000. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4001. p.look = sd->inventory_data[index]->look;
  4002. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4003. #endif
  4004. #endif
  4005. }else{
  4006. p = {};
  4007. }
  4008. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4009. p.amount = amount;
  4010. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4011. }
  4012. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4013. /// 00ea <index>.W <result>.B
  4014. /// result:
  4015. /// 0 = success
  4016. /// 1 = overweight
  4017. /// 2 = trade canceled
  4018. void clif_tradeitemok(struct map_session_data& sd, int index, e_exitem_add_result result)
  4019. {
  4020. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4021. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4022. p.index = client_index(index);
  4023. p.result = static_cast<uint8>(result);
  4024. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4025. }
  4026. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4027. /// 00ec <who>.B
  4028. /// who:
  4029. /// 0 = self
  4030. /// 1 = other player
  4031. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  4032. {
  4033. int fd;
  4034. nullpo_retv(sd);
  4035. fd = sd->fd;
  4036. WFIFOHEAD(fd,packet_len(0xec));
  4037. WFIFOW(fd,0) = 0xec;
  4038. WFIFOB(fd,2) = fail;
  4039. WFIFOSET(fd,packet_len(0xec));
  4040. }
  4041. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4042. /// 00ee
  4043. void clif_tradecancelled(struct map_session_data* sd)
  4044. {
  4045. int fd;
  4046. nullpo_retv(sd);
  4047. fd = sd->fd;
  4048. WFIFOHEAD(fd,packet_len(0xee));
  4049. WFIFOW(fd,0) = 0xee;
  4050. WFIFOSET(fd,packet_len(0xee));
  4051. }
  4052. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4053. /// 00f0 <result>.B
  4054. /// result:
  4055. /// 0 = success
  4056. /// 1 = failure
  4057. void clif_tradecompleted(struct map_session_data* sd, int fail)
  4058. {
  4059. int fd;
  4060. nullpo_retv(sd);
  4061. fd = sd->fd;
  4062. WFIFOHEAD(fd,packet_len(0xf0));
  4063. WFIFOW(fd,0) = 0xf0;
  4064. WFIFOB(fd,2) = fail;
  4065. WFIFOSET(fd,packet_len(0xf0));
  4066. }
  4067. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4068. /// 00f1
  4069. /// NOTE: Unknown purpose. Items are not removed until the window is
  4070. /// refreshed (ex. by putting another item in there).
  4071. void clif_tradeundo(struct map_session_data* sd)
  4072. {
  4073. int fd = sd->fd;
  4074. WFIFOHEAD(fd,packet_len(0xf1));
  4075. WFIFOW(fd,0) = 0xf1;
  4076. WFIFOSET(fd,packet_len(0xf1));
  4077. }
  4078. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4079. /// 00f2 <current count>.W <max count>.W
  4080. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  4081. {
  4082. int fd;
  4083. nullpo_retv(sd);
  4084. fd=sd->fd;
  4085. WFIFOHEAD(fd,packet_len(0xf2));
  4086. WFIFOW(fd,0) = 0xf2;
  4087. WFIFOW(fd,2) = amount;
  4088. WFIFOW(fd,4) = max_amount;
  4089. WFIFOSET(fd,packet_len(0xf2));
  4090. }
  4091. /// Notifies the client of an item being added to the storage.
  4092. /// 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)
  4093. /// 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)
  4094. /// 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)
  4095. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  4096. nullpo_retv( sd );
  4097. nullpo_retv( i );
  4098. int fd = sd->fd;
  4099. if( !session_isActive( fd ) ){
  4100. return;
  4101. }
  4102. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4103. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4104. p.index = client_storage_index( index ); // index
  4105. p.amount = amount; // amount
  4106. p.itemId = client_nameid( i->nameid ); // id
  4107. #if PACKETVER >= 5
  4108. p.itemType = itemtype( i->nameid ); //type
  4109. #endif
  4110. p.identified = i->identify; //identify flag
  4111. p.damaged = i->attribute; // attribute
  4112. p.refine = i->refine; //refine
  4113. clif_addcards( &p.slot, i );
  4114. #if PACKETVER >= 20150226
  4115. clif_add_random_options( p.option_data, i );
  4116. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4117. p.enchantgrade = i->enchantgrade;
  4118. #endif
  4119. #endif
  4120. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4121. }
  4122. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4123. /// 00f6 <index>.W <amount>.L
  4124. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4125. {
  4126. int fd;
  4127. nullpo_retv(sd);
  4128. fd=sd->fd;
  4129. WFIFOHEAD(fd,packet_len(0xf6));
  4130. WFIFOW(fd,0)=0xf6; // Storage item removed
  4131. WFIFOW(fd,2)=client_storage_index(index);
  4132. WFIFOL(fd,4)=amount;
  4133. WFIFOSET(fd,packet_len(0xf6));
  4134. }
  4135. /// Closes storage (ZC_CLOSE_STORE).
  4136. /// 00f8
  4137. void clif_storageclose(struct map_session_data* sd)
  4138. {
  4139. int fd;
  4140. nullpo_retv(sd);
  4141. fd=sd->fd;
  4142. WFIFOHEAD(fd,packet_len(0xf8));
  4143. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4144. WFIFOSET(fd,packet_len(0xf8));
  4145. }
  4146. /// Notifies clients in an area of a player's souls.
  4147. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4148. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4149. /// 0b73 <id>.L <amount>.W
  4150. void clif_soulball( struct map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4151. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4152. struct PACKET_ZC_SOULENERGY p = {};
  4153. p.PacketType = HEADER_ZC_SOULENERGY;
  4154. #else
  4155. struct PACKET_ZC_SPIRITS p = {};
  4156. p.PacketType = HEADER_ZC_SPIRITS;
  4157. #endif
  4158. p.AID = sd->bl.id;
  4159. p.num = sd->soulball;
  4160. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4161. }
  4162. /*==========================================
  4163. * Server tells 'sd' player client the abouts of 'dstsd' player
  4164. *------------------------------------------*/
  4165. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4166. {
  4167. struct block_list *d_bl;
  4168. int i;
  4169. if( dstsd->chatID ) {
  4170. struct chat_data *cd = NULL;
  4171. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4172. clif_dispchat(cd,sd->fd);
  4173. } else if( dstsd->state.vending )
  4174. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4175. else if( dstsd->state.buyingstore )
  4176. clif_buyingstore_entry( *dstsd, &sd->bl );
  4177. if(dstsd->spiritball > 0)
  4178. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4179. if (dstsd->sc.getSCE(SC_MILLENNIUMSHIELD))
  4180. clif_millenniumshield_single(sd->fd, dstsd);
  4181. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4182. clif_spiritcharm_single(sd->fd, dstsd);
  4183. if (dstsd->soulball > 0)
  4184. clif_soulball( dstsd, &sd->bl, SELF );
  4185. if (dstsd->servantball > 0)
  4186. clif_servantball( *dstsd, &sd->bl, SELF );
  4187. if (dstsd->abyssball > 0)
  4188. clif_abyssball( *dstsd, &sd->bl, SELF );
  4189. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4190. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4191. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4192. )
  4193. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4194. // display link (sd - dstsd) to sd
  4195. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4196. if( i < MAX_DEVOTION )
  4197. clif_devotion(&sd->bl, sd);
  4198. // display links (dstsd - devotees) to sd
  4199. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4200. if( i < MAX_DEVOTION )
  4201. clif_devotion(&dstsd->bl, sd);
  4202. // display link (dstsd - crusader) to sd
  4203. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != NULL )
  4204. clif_devotion(d_bl, sd);
  4205. }
  4206. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4207. struct unit_data *ud;
  4208. struct view_data *vd;
  4209. bool option = false;
  4210. unsigned int option_val = 0;
  4211. vd = status_get_viewdata(bl);
  4212. if (!vd || vd->class_ == JT_INVISIBLE)
  4213. return;
  4214. // Hide NPC from Maya Purple card
  4215. if (clif_npc_mayapurple(bl))
  4216. return;
  4217. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4218. // Do not send anything
  4219. return;
  4220. }
  4221. ud = unit_bl2ud(bl);
  4222. if( ud && ud->walktimer != INVALID_TIMER ){
  4223. clif_set_unit_walking( bl, sd, ud, SELF );
  4224. }else{
  4225. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4226. }
  4227. if (vd->cloth_color)
  4228. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4229. if (vd->body_style)
  4230. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4231. switch (bl->type)
  4232. {
  4233. case BL_PC:
  4234. {
  4235. TBL_PC* tsd = (TBL_PC*)bl;
  4236. clif_getareachar_pc(sd, tsd);
  4237. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4238. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4239. else if(tsd->state.size==SZ_MEDIUM)
  4240. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4241. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4242. clif_sendbgemblem_single(sd->fd,tsd);
  4243. if ( tsd->status.robe )
  4244. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4245. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4246. clif_hat_effects(sd,bl,SELF);
  4247. }
  4248. break;
  4249. case BL_MER: // Devotion Effects
  4250. if( ((TBL_MER*)bl)->devotion_flag )
  4251. clif_devotion(bl, sd);
  4252. break;
  4253. case BL_NPC:
  4254. {
  4255. TBL_NPC* nd = (TBL_NPC*)bl;
  4256. if( nd->chat_id )
  4257. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4258. if( nd->size == SZ_BIG )
  4259. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4260. else if( nd->size == SZ_MEDIUM )
  4261. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4262. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4263. clif_progressbar_npc(nd, sd);
  4264. }
  4265. break;
  4266. case BL_MOB:
  4267. {
  4268. TBL_MOB* md = (TBL_MOB*)bl;
  4269. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4270. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4271. else if(md->special_state.size==SZ_MEDIUM)
  4272. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4273. #if PACKETVER >= 20120404
  4274. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4275. int i;
  4276. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4277. if( md->dmglog[i].id == sd->status.char_id )
  4278. clif_monster_hp_bar(md, sd->fd);
  4279. }
  4280. #endif
  4281. }
  4282. break;
  4283. case BL_PET:
  4284. if (vd->head_bottom)
  4285. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4286. break;
  4287. }
  4288. }
  4289. //Modifies the type of damage according to status changes [Skotlex]
  4290. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4291. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4292. {
  4293. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4294. }
  4295. /*==========================================
  4296. * Estimates walk delay based on the damage criteria. [Skotlex]
  4297. *------------------------------------------*/
  4298. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4299. {
  4300. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4301. return 0;
  4302. if (bl->type == BL_PC) {
  4303. if (battle_config.pc_walk_delay_rate != 100)
  4304. delay = delay*battle_config.pc_walk_delay_rate/100;
  4305. } else
  4306. if (battle_config.walk_delay_rate != 100)
  4307. delay = delay*battle_config.walk_delay_rate/100;
  4308. if (div_ > 1) //Multi-hit skills mean higher delays.
  4309. delay += battle_config.multihit_delay*(div_-1);
  4310. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4311. }
  4312. /*========================================== [Playtester]
  4313. * Returns hallucination damage the client displays
  4314. *------------------------------------------*/
  4315. static int clif_hallucination_damage()
  4316. {
  4317. int digit = rnd() % 5 + 1;
  4318. switch (digit)
  4319. {
  4320. case 1:
  4321. return (rnd() % 10);
  4322. case 2:
  4323. return (rnd() % 100);
  4324. case 3:
  4325. return (rnd() % 1000);
  4326. case 4:
  4327. return (rnd() % 10000);
  4328. }
  4329. return (rnd() % 32767);
  4330. }
  4331. /// Sends a 'damage' packet (src performs action on dst)
  4332. /// 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)
  4333. /// 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)
  4334. /// 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)
  4335. /// type:
  4336. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4337. /// 1 = pick up item
  4338. /// 2 = sit down
  4339. /// 3 = stand up
  4340. /// 4 = damage (endure)
  4341. /// 5 = (splash?)
  4342. /// 6 = (skill?)
  4343. /// 7 = (repeat damage?)
  4344. /// 8 = multi-hit damage
  4345. /// 9 = multi-hit damage (endure)
  4346. /// 10 = critical hit
  4347. /// 11 = lucky dodge
  4348. /// 12 = (touch skill?)
  4349. /// 13 = multi-hit critical
  4350. 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)
  4351. {
  4352. unsigned char buf[34];
  4353. struct status_change *sc;
  4354. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4355. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4356. #if PACKETVER < 20071113
  4357. const int cmd = 0x8a;
  4358. int offset = 0;
  4359. #elif PACKETVER < 20131223
  4360. const int cmd = 0x2e1;
  4361. int offset = 2;
  4362. #else
  4363. const int cmd = 0x8c8;
  4364. int offset = 3;
  4365. #endif
  4366. nullpo_ret(src);
  4367. nullpo_ret(dst);
  4368. if (type != DMG_MULTI_HIT_CRITICAL)
  4369. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4370. sc = status_get_sc(dst);
  4371. if(sc && sc->count) {
  4372. if(sc->getSCE(SC_HALLUCINATION)) {
  4373. damage = clif_hallucination_damage();
  4374. if(damage2) damage2 = clif_hallucination_damage();
  4375. }
  4376. }
  4377. WBUFW(buf,0) = cmd;
  4378. WBUFL(buf,2) = src->id;
  4379. WBUFL(buf,6) = dst->id;
  4380. WBUFL(buf,10) = client_tick(tick);
  4381. WBUFL(buf,14) = sdelay;
  4382. WBUFL(buf,18) = ddelay;
  4383. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4384. #if PACKETVER < 20071113
  4385. WBUFW(buf,22) = damage ? div : 0;
  4386. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4387. #else
  4388. WBUFL(buf, 22) = damage ? div : 0;
  4389. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4390. #endif
  4391. } else {
  4392. #if PACKETVER < 20071113
  4393. WBUFW(buf,22) = min(damage, INT16_MAX);
  4394. WBUFW(buf,27+offset) = damage2;
  4395. #else
  4396. WBUFL(buf,22) = damage;
  4397. WBUFL(buf,27+offset) = damage2;
  4398. #endif
  4399. }
  4400. #if PACKETVER >= 20131223
  4401. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4402. #endif
  4403. WBUFW(buf,24+offset) = div;
  4404. WBUFB(buf,26+offset) = type;
  4405. if(disguised(dst)) {
  4406. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4407. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4408. clif_send(buf, packet_len(cmd), dst, SELF);
  4409. } else
  4410. clif_send(buf, packet_len(cmd), dst, AREA);
  4411. if(disguised(src)) {
  4412. WBUFL(buf,2) = disguised_bl_id( src->id );
  4413. if (disguised(dst))
  4414. WBUFL(buf,6) = dst->id;
  4415. #if PACKETVER < 20071113
  4416. if(damage > 0) WBUFW(buf,22) = -1;
  4417. if(damage2 > 0) WBUFW(buf,27) = -1;
  4418. #else
  4419. if(damage > 0) WBUFL(buf,22) = -1;
  4420. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4421. #endif
  4422. clif_send(buf,packet_len(cmd),src,SELF);
  4423. }
  4424. if(src == dst) {
  4425. unit_setdir(src, unit_getdir(src));
  4426. }
  4427. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4428. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4429. //Return adjusted can't walk delay for further processing.
  4430. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4431. }
  4432. /*==========================================
  4433. * src picks up dst
  4434. *------------------------------------------*/
  4435. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4436. {
  4437. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4438. unsigned char buf[32];
  4439. nullpo_retv(src);
  4440. nullpo_retv(dst);
  4441. WBUFW(buf, 0) = 0x8a;
  4442. WBUFL(buf, 2) = src->id;
  4443. WBUFL(buf, 6) = dst->id;
  4444. WBUFB(buf,26) = 1;
  4445. clif_send(buf, packet_len(0x8a), src, AREA);
  4446. }
  4447. /*==========================================
  4448. * inform clients in area that `bl` is sitting
  4449. *------------------------------------------*/
  4450. void clif_sitting(struct block_list* bl)
  4451. {
  4452. unsigned char buf[32];
  4453. nullpo_retv(bl);
  4454. WBUFW(buf, 0) = 0x8a;
  4455. WBUFL(buf, 2) = bl->id;
  4456. WBUFB(buf,26) = 2;
  4457. clif_send(buf, packet_len(0x8a), bl, AREA);
  4458. if(disguised(bl)) {
  4459. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4460. clif_send(buf, packet_len(0x8a), bl, SELF);
  4461. }
  4462. }
  4463. /*==========================================
  4464. * inform clients in area that `bl` is standing
  4465. *------------------------------------------*/
  4466. void clif_standing(struct block_list* bl)
  4467. {
  4468. unsigned char buf[32];
  4469. nullpo_retv(bl);
  4470. WBUFW(buf, 0) = 0x8a;
  4471. WBUFL(buf, 2) = bl->id;
  4472. WBUFB(buf,26) = 3;
  4473. clif_send(buf, packet_len(0x8a), bl, AREA);
  4474. if(disguised(bl)) {
  4475. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4476. clif_send(buf, packet_len(0x8a), bl, SELF);
  4477. }
  4478. }
  4479. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4480. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4481. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4482. {
  4483. unsigned char buf[32];
  4484. WBUFW(buf,0) = 0x192;
  4485. WBUFW(buf,2) = x;
  4486. WBUFW(buf,4) = y;
  4487. WBUFW(buf,6) = type;
  4488. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4489. if( session_isActive(fd) )
  4490. {
  4491. WFIFOHEAD(fd,packet_len(0x192));
  4492. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4493. WFIFOSET(fd,packet_len(0x192));
  4494. }
  4495. else
  4496. {
  4497. struct block_list dummy_bl;
  4498. dummy_bl.type = BL_NUL;
  4499. dummy_bl.x = x;
  4500. dummy_bl.y = y;
  4501. dummy_bl.m = m;
  4502. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4503. }
  4504. }
  4505. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4506. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4507. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4508. nullpo_retv( sd );
  4509. nullpo_retv( fitem );
  4510. struct PACKET_ZC_ITEM_ENTRY p;
  4511. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4512. p.AID = fitem->bl.id;
  4513. p.itemId = client_nameid( fitem->item.nameid );
  4514. p.identify = fitem->item.identify;
  4515. p.x = fitem->bl.x;
  4516. p.y = fitem->bl.y;
  4517. p.amount = fitem->item.amount;
  4518. p.subX = fitem->subx;
  4519. p.subY = fitem->suby;
  4520. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4521. }
  4522. /// Notifes client about Graffiti
  4523. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4524. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4525. unsigned char buf[128];
  4526. nullpo_retv(bl);
  4527. nullpo_retv(unit);
  4528. WBUFW(buf, 0) = 0x1c9;
  4529. WBUFL(buf, 2) = unit->bl.id;
  4530. WBUFL(buf, 6) = unit->group->src_id;
  4531. WBUFW(buf,10) = unit->bl.x;
  4532. WBUFW(buf,12) = unit->bl.y;
  4533. WBUFB(buf,14) = unit->group->unit_id;
  4534. WBUFB(buf,15) = 1;
  4535. WBUFB(buf,16) = 1;
  4536. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4537. clif_send(buf,packet_len(0x1c9),bl,target);
  4538. }
  4539. /// Notifies the client of a skill unit.
  4540. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4541. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4542. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4543. /// 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)
  4544. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4545. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4546. unsigned char buf[128];
  4547. nullpo_retv(bl);
  4548. nullpo_retv(unit);
  4549. if (bl->type == BL_PC)
  4550. fd = ((TBL_PC*)bl)->fd;
  4551. if (unit->group->state.guildaura)
  4552. return;
  4553. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4554. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4555. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4556. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4557. else
  4558. unit_id = unit->group->unit_id;
  4559. if (!visible)
  4560. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4561. #if PACKETVER >= 3
  4562. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4563. clif_graffiti(bl, unit, target);
  4564. return;
  4565. }
  4566. #endif
  4567. #if PACKETVER <= 20120702
  4568. header = 0x011f;
  4569. //#if PACKETVER < 20110718
  4570. // header = 0x011f;
  4571. //#elif PACKETVER < 20121212
  4572. // header = 0x08c7;
  4573. #elif PACKETVER < 20130731
  4574. header = 0x099f;
  4575. #else
  4576. header = 0x09ca;
  4577. #endif
  4578. len = packet_len(header);
  4579. WBUFW(buf,pos) = header;
  4580. if (header != 0x011f) {
  4581. WBUFW(buf, pos+2) = len;
  4582. pos += 2;
  4583. }
  4584. WBUFL(buf,pos+2) = unit->bl.id;
  4585. WBUFL(buf,pos+6) = unit->group->src_id;
  4586. WBUFW(buf,pos+10) = unit->bl.x;
  4587. WBUFW(buf,pos+12) = unit->bl.y;
  4588. switch (header) {
  4589. case 0x011f:
  4590. WBUFB(buf,pos+14) = unit_id;
  4591. WBUFB(buf,pos+15) = visible;
  4592. break;
  4593. case 0x08c7:
  4594. WBUFB(buf,pos+14) = unit_id;
  4595. WBUFW(buf,pos+15) = unit->range;
  4596. WBUFB(buf,pos+17) = visible;
  4597. break;
  4598. case 0x099f:
  4599. WBUFL(buf,pos+14) = unit_id;
  4600. WBUFW(buf,pos+18) = unit->range;
  4601. WBUFB(buf,pos+20) = visible;
  4602. break;
  4603. case 0x09ca:
  4604. WBUFL(buf,pos+14) = unit_id;
  4605. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4606. WBUFB(buf,pos+19) = visible;
  4607. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4608. break;
  4609. }
  4610. clif_send(buf, len, bl, target);
  4611. if (unit->group->skill_id == WZ_ICEWALL)
  4612. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4613. }
  4614. /// 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)
  4615. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4616. unsigned char buf[128];
  4617. nullpo_retv(bl);
  4618. WBUFW(buf, 0) = 0x09ca;
  4619. WBUFW(buf, 2) = packet_len(0x09ca);
  4620. WBUFL(buf, 4) = 1000;
  4621. WBUFL(buf, 8) = 2000;
  4622. WBUFW(buf, 12) = x;
  4623. WBUFW(buf, 14) = y;
  4624. WBUFL(buf, 16) = unit_id;
  4625. WBUFB(buf, 20) = (unsigned char)range;
  4626. WBUFB(buf, 21) = 1;
  4627. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4628. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4629. }
  4630. /*==========================================
  4631. * Server tells client to remove unit of id 'unit->bl.id'
  4632. *------------------------------------------*/
  4633. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4634. {
  4635. nullpo_retv(unit);
  4636. WFIFOHEAD(fd,packet_len(0x120));
  4637. WFIFOW(fd, 0)=0x120;
  4638. WFIFOL(fd, 2)=unit->bl.id;
  4639. WFIFOSET(fd,packet_len(0x120));
  4640. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4641. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4642. }
  4643. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4644. /// 0120 <id>.L
  4645. void clif_skill_delunit(struct skill_unit *unit)
  4646. {
  4647. unsigned char buf[16];
  4648. nullpo_retv(unit);
  4649. WBUFW(buf, 0)=0x120;
  4650. WBUFL(buf, 2)=unit->bl.id;
  4651. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4652. }
  4653. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4654. /// 01ac <id>.L
  4655. /// Only affects units with class [139,153] client-side.
  4656. void clif_skillunit_update(struct block_list* bl)
  4657. {
  4658. unsigned char buf[6];
  4659. nullpo_retv(bl);
  4660. WBUFW(buf,0) = 0x1ac;
  4661. WBUFL(buf,2) = bl->id;
  4662. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4663. }
  4664. /*==========================================
  4665. *
  4666. *------------------------------------------*/
  4667. static int clif_getareachar(struct block_list* bl,va_list ap)
  4668. {
  4669. struct map_session_data *sd;
  4670. nullpo_ret(bl);
  4671. sd=va_arg(ap,struct map_session_data*);
  4672. if (!clif_session_isValid(sd))
  4673. return 0;
  4674. switch(bl->type){
  4675. case BL_ITEM:
  4676. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4677. break;
  4678. case BL_SKILL:
  4679. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4680. break;
  4681. default:
  4682. if(&sd->bl == bl)
  4683. break;
  4684. clif_getareachar_unit(sd,bl);
  4685. break;
  4686. }
  4687. return 0;
  4688. }
  4689. /*==========================================
  4690. * tbl has gone out of view-size of bl
  4691. *------------------------------------------*/
  4692. int clif_outsight(struct block_list *bl,va_list ap)
  4693. {
  4694. struct block_list *tbl;
  4695. struct view_data *vd;
  4696. TBL_PC *sd, *tsd;
  4697. tbl=va_arg(ap,struct block_list*);
  4698. if(bl == tbl) return 0;
  4699. sd = BL_CAST(BL_PC, bl);
  4700. tsd = BL_CAST(BL_PC, tbl);
  4701. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4702. nullpo_ret(bl);
  4703. switch(bl->type){
  4704. case BL_PC:
  4705. if(sd->vd.class_ != JT_INVISIBLE)
  4706. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4707. if(sd->chatID){
  4708. struct chat_data *cd;
  4709. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4710. if(cd->usersd[0]==sd)
  4711. clif_dispchat(cd,tsd->fd);
  4712. }
  4713. if(sd->state.vending)
  4714. clif_closevendingboard(bl,tsd->fd);
  4715. if(sd->state.buyingstore)
  4716. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4717. break;
  4718. case BL_ITEM:
  4719. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4720. break;
  4721. case BL_SKILL:
  4722. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4723. break;
  4724. case BL_NPC:
  4725. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4726. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4727. break;
  4728. default:
  4729. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4730. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4731. break;
  4732. }
  4733. }
  4734. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4735. nullpo_ret(tbl);
  4736. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4737. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4738. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4739. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4740. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4741. }
  4742. return 0;
  4743. }
  4744. /*==========================================
  4745. * tbl has come into view of bl
  4746. *------------------------------------------*/
  4747. int clif_insight(struct block_list *bl,va_list ap)
  4748. {
  4749. struct block_list *tbl;
  4750. TBL_PC *sd, *tsd;
  4751. tbl=va_arg(ap,struct block_list*);
  4752. if (bl == tbl) return 0;
  4753. sd = BL_CAST(BL_PC, bl);
  4754. tsd = BL_CAST(BL_PC, tbl);
  4755. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4756. switch(bl->type){
  4757. case BL_ITEM:
  4758. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4759. break;
  4760. case BL_SKILL:
  4761. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4762. break;
  4763. default:
  4764. clif_getareachar_unit(tsd,bl);
  4765. break;
  4766. }
  4767. }
  4768. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4769. clif_getareachar_unit(sd,tbl);
  4770. }
  4771. return 0;
  4772. }
  4773. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4774. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4775. void clif_skillinfoblock(struct map_session_data *sd)
  4776. {
  4777. int fd;
  4778. int i,len,id;
  4779. nullpo_retv(sd);
  4780. fd = sd->fd;
  4781. if (!session_isActive(fd))
  4782. return;
  4783. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4784. WFIFOW(fd,0) = 0x10f;
  4785. bool haveCallPartnerSkill = false;
  4786. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4787. {
  4788. if( (id = sd->status.skill[i].id) != 0 )
  4789. {
  4790. // workaround for bugreport:5348
  4791. if (len + 37 > 8192)
  4792. break;
  4793. // skip WE_CALLPARTNER and send it in special way
  4794. if (id == WE_CALLPARTNER) {
  4795. haveCallPartnerSkill = true;
  4796. continue;
  4797. }
  4798. WFIFOW(fd,len) = id;
  4799. WFIFOL(fd,len+2) = skill_get_inf(id);
  4800. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4801. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4802. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4803. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4804. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4805. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4806. else
  4807. WFIFOB(fd,len+36) = 0;
  4808. len += 37;
  4809. }
  4810. }
  4811. WFIFOW(fd,2)=len;
  4812. WFIFOSET(fd,len);
  4813. // adoption fix
  4814. if (haveCallPartnerSkill) {
  4815. clif_addskill(sd, WE_CALLPARTNER);
  4816. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4817. }
  4818. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4819. for ( ; i < MAX_SKILL; i++)
  4820. {
  4821. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4822. {
  4823. clif_addskill(sd, id);
  4824. clif_skillinfo(sd, id, 0);
  4825. }
  4826. }
  4827. }
  4828. /**
  4829. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4830. **/
  4831. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4832. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4833. void clif_addskill(struct map_session_data *sd, int skill_id)
  4834. {
  4835. nullpo_retv(sd);
  4836. int fd = sd->fd;
  4837. uint16 idx = skill_get_index(skill_id);
  4838. if (!session_isActive(fd) || !idx)
  4839. return;
  4840. if( sd->status.skill[idx].id <= 0 )
  4841. return;
  4842. WFIFOHEAD(fd, packet_len(0x111));
  4843. WFIFOW(fd,0) = 0x111;
  4844. WFIFOW(fd,2) = skill_id;
  4845. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4846. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4847. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4848. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4849. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4850. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4851. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4852. else
  4853. WFIFOB(fd,38) = 0;
  4854. WFIFOSET(fd,packet_len(0x111));
  4855. }
  4856. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4857. /// 0441 <skill id>.W
  4858. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4859. {
  4860. #if PACKETVER >= 20081217
  4861. nullpo_retv(sd);
  4862. int fd = sd->fd;
  4863. uint16 idx = skill_get_index(skill_id);
  4864. if (!session_isActive(fd) || !idx)
  4865. return;
  4866. WFIFOHEAD(fd,packet_len(0x441));
  4867. WFIFOW(fd,0) = 0x441;
  4868. WFIFOW(fd,2) = skill_id;
  4869. WFIFOSET(fd,packet_len(0x441));
  4870. #endif
  4871. clif_skillinfoblock(sd);
  4872. }
  4873. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4874. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4875. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4876. nullpo_retv(sd);
  4877. int fd = sd->fd;
  4878. uint16 idx = skill_get_index(skill_id);
  4879. if (!session_isActive(fd) || !idx)
  4880. return;
  4881. WFIFOHEAD(fd, packet_len(0x10e));
  4882. WFIFOW(fd, 0) = 0x10e;
  4883. WFIFOW(fd, 2) = skill_id;
  4884. WFIFOW(fd, 4) = lv;
  4885. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4886. WFIFOW(fd, 8) = range;
  4887. WFIFOB(fd, 10) = upgradable;
  4888. WFIFOSET(fd, packet_len(0x10e));
  4889. }
  4890. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4891. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4892. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4893. {
  4894. nullpo_retv(sd);
  4895. const int fd = sd->fd;
  4896. uint16 idx = skill_get_index(skill_id);
  4897. if (!session_isActive(fd) || !idx)
  4898. return;
  4899. WFIFOHEAD(fd,packet_len(0x7e1));
  4900. WFIFOW(fd,0) = 0x7e1;
  4901. WFIFOW(fd,2) = skill_id;
  4902. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4903. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4904. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4905. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4906. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4907. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4908. else
  4909. WFIFOB(fd,14) = 0;
  4910. WFIFOSET(fd,packet_len(0x7e1));
  4911. }
  4912. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4913. #if PACKETVER >= 20151223
  4914. if( !battle_config.show_skill_scale ){
  4915. return;
  4916. }
  4917. struct PACKET_ZC_SKILL_SCALE p;
  4918. p.PacketType = skillscale;
  4919. p.AID = src_id;
  4920. p.skill_id = skill_id;
  4921. p.skill_lv = skill_lv;
  4922. p.x = x;
  4923. p.y = y;
  4924. p.casttime = casttime;
  4925. if( disguised( bl ) ){
  4926. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4927. p.AID = disguised_bl_id( bl->id );
  4928. clif_send( &p, sizeof( p ), bl, SELF );
  4929. }else{
  4930. clif_send( &p, sizeof( p ), bl, AREA );
  4931. }
  4932. #endif
  4933. }
  4934. /// Notifies clients in area, that an object is about to use a skill.
  4935. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4936. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4937. /// property:
  4938. /// 0 = Yellow cast aura
  4939. /// 1 = Water elemental cast aura
  4940. /// 2 = Earth elemental cast aura
  4941. /// 3 = Fire elemental cast aura
  4942. /// 4 = Wind elemental cast aura
  4943. /// 5 = Poison elemental cast aura
  4944. /// 6 = Holy elemental cast aura
  4945. /// ? = like 0
  4946. /// is disposable:
  4947. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4948. /// 1 = no text
  4949. 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)
  4950. {
  4951. #if PACKETVER < 20091124
  4952. const int cmd = 0x13e;
  4953. #else
  4954. const int cmd = 0x7fb;
  4955. #endif
  4956. unsigned char buf[32];
  4957. WBUFW(buf,0) = cmd;
  4958. WBUFL(buf,2) = src_id;
  4959. WBUFL(buf,6) = dst_id;
  4960. WBUFW(buf,10) = dst_x;
  4961. WBUFW(buf,12) = dst_y;
  4962. WBUFW(buf,14) = skill_id;
  4963. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4964. WBUFL(buf,20) = casttime;
  4965. #if PACKETVER >= 20091124
  4966. WBUFB(buf,24) = 0; // isDisposable
  4967. #endif
  4968. if (disguised(bl)) {
  4969. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4970. WBUFL(buf,2) = disguised_bl_id( src_id );
  4971. clif_send(buf,packet_len(cmd), bl, SELF);
  4972. } else
  4973. clif_send(buf,packet_len(cmd), bl, AREA);
  4974. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4975. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4976. }
  4977. }
  4978. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4979. /// 01b9 <id>.L
  4980. void clif_skillcastcancel(struct block_list* bl)
  4981. {
  4982. unsigned char buf[16];
  4983. nullpo_retv(bl);
  4984. WBUFW(buf,0) = 0x1b9;
  4985. WBUFL(buf,2) = bl->id;
  4986. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4987. }
  4988. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4989. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4990. /// num (only used when skill id = NV_BASIC and cause = 0):
  4991. /// 0 = "skill failed" MsgStringTable[159]
  4992. /// 1 = "no emotions" MsgStringTable[160]
  4993. /// 2 = "no sit" MsgStringTable[161]
  4994. /// 3 = "no chat" MsgStringTable[162]
  4995. /// 4 = "no party" MsgStringTable[163]
  4996. /// 5 = "no shout" MsgStringTable[164]
  4997. /// 6 = "no PKing" MsgStringTable[165]
  4998. /// 7 = "no alligning" MsgStringTable[383]
  4999. /// ? = ignored
  5000. /// cause:
  5001. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5002. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5003. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5004. /// "skill failed" MsgStringTable[204] (otherwise)
  5005. /// ... = @see enum useskill_fail_cause
  5006. /// ? = ignored
  5007. ///
  5008. /// if(result!=0) doesn't display any of the previous messages
  5009. /// Note: when this packet is received an unknown flag is always set to 0,
  5010. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5011. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5012. nullpo_retv( sd );
  5013. int fd = sd->fd;
  5014. if( !session_isActive( fd ) ){
  5015. return;
  5016. }
  5017. if(battle_config.display_skill_fail&1)
  5018. return; //Disable all skill failed messages
  5019. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5020. return; //Disable delay failed messages
  5021. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5022. return;
  5023. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5024. return;
  5025. struct PACKET_ZC_ACK_TOUSESKILL p;
  5026. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5027. p.skillId = skill_id;
  5028. p.btype = btype;
  5029. p.itemId = itemId;
  5030. p.flag = 0; // 0 - failed
  5031. p.cause = cause;
  5032. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5033. }
  5034. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5035. /// 043d <skill ID>.W <tick>.L
  5036. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  5037. {
  5038. #if PACKETVER>=20081112
  5039. int fd;
  5040. nullpo_retv(sd);
  5041. fd=sd->fd;
  5042. WFIFOHEAD(fd,packet_len(0x43d));
  5043. WFIFOW(fd,0) = 0x43d;
  5044. WFIFOW(fd,2) = skill_id;
  5045. WFIFOL(fd,4) = client_tick(tick);
  5046. WFIFOSET(fd,packet_len(0x43d));
  5047. #endif
  5048. }
  5049. /// Skill attack effect and damage.
  5050. /// 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)
  5051. /// 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)
  5052. 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)
  5053. {
  5054. unsigned char buf[64];
  5055. struct status_change *sc;
  5056. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5057. nullpo_ret(src);
  5058. nullpo_ret(dst);
  5059. type = clif_calc_delay(type,div,damage,ddelay);
  5060. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5061. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5062. damage = clif_hallucination_damage();
  5063. }
  5064. #if PACKETVER < 3
  5065. WBUFW(buf,0)=0x114;
  5066. WBUFW(buf,2)=skill_id;
  5067. WBUFL(buf,4)=src->id;
  5068. WBUFL(buf,8)=dst->id;
  5069. WBUFL(buf,12)=client_tick(tick);
  5070. WBUFL(buf,16)=sdelay;
  5071. WBUFL(buf,20)=ddelay;
  5072. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5073. WBUFW(buf,24)=damage?div:0;
  5074. } else {
  5075. WBUFW(buf,24)=damage;
  5076. }
  5077. WBUFW(buf,26)=skill_lv;
  5078. WBUFW(buf,28)=div;
  5079. WBUFB(buf,30)=type;
  5080. if (disguised(dst)) {
  5081. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5082. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5083. clif_send(buf,packet_len(0x114),dst,SELF);
  5084. } else
  5085. clif_send(buf,packet_len(0x114),dst,AREA);
  5086. if(disguised(src)) {
  5087. WBUFL(buf,4)=disguised_bl_id(src->id);
  5088. if (disguised(dst))
  5089. WBUFL(buf,8)=dst->id;
  5090. if(damage > 0)
  5091. WBUFW(buf,24)=-1;
  5092. clif_send(buf,packet_len(0x114),src,SELF);
  5093. }
  5094. #else
  5095. WBUFW(buf,0)=0x1de;
  5096. WBUFW(buf,2)=skill_id;
  5097. WBUFL(buf,4)=src->id;
  5098. WBUFL(buf,8)=dst->id;
  5099. WBUFL(buf,12)=client_tick(tick);
  5100. WBUFL(buf,16)=sdelay;
  5101. WBUFL(buf,20)=ddelay;
  5102. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5103. WBUFL(buf,24)=damage?div:0;
  5104. } else {
  5105. WBUFL(buf,24)=damage;
  5106. }
  5107. WBUFW(buf,28)=skill_lv;
  5108. WBUFW(buf,30)=div;
  5109. // For some reason, late 2013 and newer clients have
  5110. // a issue that causes players and monsters to endure
  5111. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5112. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5113. #if PACKETVER < 20131223
  5114. WBUFB(buf,32)=type;
  5115. #else
  5116. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5117. #endif
  5118. if (disguised(dst)) {
  5119. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5120. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5121. clif_send(buf,packet_len(0x1de),dst,SELF);
  5122. } else
  5123. clif_send(buf,packet_len(0x1de),dst,AREA);
  5124. if(disguised(src)) {
  5125. WBUFL(buf,4)=disguised_bl_id(src->id);
  5126. if (disguised(dst))
  5127. WBUFL(buf,8)=dst->id;
  5128. if(damage > 0)
  5129. WBUFL(buf,24)=-1;
  5130. clif_send(buf,packet_len(0x1de),src,SELF);
  5131. }
  5132. #endif
  5133. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5134. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5135. }
  5136. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5137. /// 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
  5138. /*
  5139. 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)
  5140. {
  5141. unsigned char buf[64];
  5142. struct status_change *sc;
  5143. nullpo_ret(src);
  5144. nullpo_ret(dst);
  5145. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5146. type = clif_calc_delay(type,div,damage,ddelay);
  5147. sc = status_get_sc(dst);
  5148. if(sc && sc->count) {
  5149. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5150. damage = clif_hallucination_damage();
  5151. }
  5152. WBUFW(buf,0)=0x115;
  5153. WBUFW(buf,2)=skill_id;
  5154. WBUFL(buf,4)=src->id;
  5155. WBUFL(buf,8)=dst->id;
  5156. WBUFL(buf,12)=client_tick(tick);
  5157. WBUFL(buf,16)=sdelay;
  5158. WBUFL(buf,20)=ddelay;
  5159. WBUFW(buf,24)=dst->x;
  5160. WBUFW(buf,26)=dst->y;
  5161. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5162. WBUFW(buf,28)=damage?div:0;
  5163. } else {
  5164. WBUFW(buf,28)=damage;
  5165. }
  5166. WBUFW(buf,30)=skill_lv;
  5167. WBUFW(buf,32)=div;
  5168. WBUFB(buf,34)=type;
  5169. clif_send(buf,packet_len(0x115),src,AREA);
  5170. if(disguised(src)) {
  5171. WBUFL(buf,4)=disguised_bl_id(src->id);
  5172. if(damage > 0)
  5173. WBUFW(buf,28)=-1;
  5174. clif_send(buf,packet_len(0x115),src,SELF);
  5175. }
  5176. if (disguised(dst)) {
  5177. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5178. if (disguised(src))
  5179. WBUFL(buf,4)=src->id;
  5180. else if(damage > 0)
  5181. WBUFW(buf,28)=-1;
  5182. clif_send(buf,packet_len(0x115),dst,SELF);
  5183. }
  5184. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5185. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5186. }
  5187. */
  5188. /// Non-damaging skill effect
  5189. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5190. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5191. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5192. {
  5193. unsigned char buf[17];
  5194. #if PACKETVER < 20130731
  5195. const int cmd = 0x11a;
  5196. #else
  5197. const int cmd = 0x9cb;
  5198. #endif
  5199. int offset = 0;
  5200. bool success = ( tick != 0 );
  5201. nullpo_ret(dst);
  5202. WBUFW(buf,0) = cmd;
  5203. WBUFW(buf,2) = skill_id;
  5204. #if PACKETVER < 20130731
  5205. WBUFW(buf,4) = min(heal, INT16_MAX);
  5206. #else
  5207. WBUFL(buf,4) = min(heal, INT32_MAX);
  5208. offset += 2;
  5209. #endif
  5210. WBUFL(buf,6+offset) = dst->id;
  5211. WBUFL(buf,10+offset) = src ? src->id : 0;
  5212. WBUFB(buf,14+offset) = success;
  5213. if (disguised(dst)) {
  5214. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5215. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5216. clif_send(buf, packet_len(cmd), dst, SELF);
  5217. } else
  5218. clif_send(buf, packet_len(cmd), dst, AREA);
  5219. if(src && disguised(src)) {
  5220. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5221. if (disguised(dst))
  5222. WBUFL(buf,6+offset) = dst->id;
  5223. clif_send(buf, packet_len(cmd), src, SELF);
  5224. }
  5225. return success;
  5226. }
  5227. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5228. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5229. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5230. {
  5231. unsigned char buf[32];
  5232. nullpo_retv(src);
  5233. WBUFW(buf,0)=0x117;
  5234. WBUFW(buf,2)=skill_id;
  5235. WBUFL(buf,4)=src->id;
  5236. WBUFW(buf,8)=val;
  5237. WBUFW(buf,10)=x;
  5238. WBUFW(buf,12)=y;
  5239. WBUFL(buf,14)=client_tick(tick);
  5240. if(disguised(src)) {
  5241. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5242. WBUFL(buf,4)=disguised_bl_id(src->id);
  5243. clif_send(buf,packet_len(0x117),src,SELF);
  5244. } else
  5245. clif_send(buf,packet_len(0x117),src,AREA);
  5246. }
  5247. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5248. /// 011c <skill id>.W { <map name>.16B }*4
  5249. 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)
  5250. {
  5251. int fd;
  5252. nullpo_retv(sd);
  5253. fd = sd->fd;
  5254. WFIFOHEAD(fd,packet_len(0x11c));
  5255. WFIFOW(fd,0) = 0x11c;
  5256. WFIFOW(fd,2) = skill_id;
  5257. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5258. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5259. else // normal map name
  5260. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5261. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5262. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5263. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5264. WFIFOSET(fd,packet_len(0x11c));
  5265. sd->menuskill_id = skill_id;
  5266. if (skill_id == AL_WARP) {
  5267. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5268. sd->state.workinprogress = WIP_DISABLE_ALL;
  5269. } else
  5270. sd->menuskill_val = skill_lv;
  5271. }
  5272. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5273. /// 011e <type>.B
  5274. /// type:
  5275. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5276. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5277. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5278. ///
  5279. /// @param sd Who receives the message
  5280. /// @param type What message
  5281. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5282. {
  5283. int fd;
  5284. nullpo_retv(sd);
  5285. fd=sd->fd;
  5286. WFIFOHEAD(fd,packet_len(0x11e));
  5287. WFIFOW(fd,0)=0x11e;
  5288. WFIFOB(fd,2)=type;
  5289. WFIFOSET(fd,packet_len(0x11e));
  5290. }
  5291. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5292. /// 0189 <type>.W
  5293. /// type:
  5294. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5295. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5296. ///
  5297. /// @param sd Who receives the message
  5298. /// @param type What message
  5299. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5300. {
  5301. int fd;
  5302. nullpo_retv(sd);
  5303. fd=sd->fd;
  5304. WFIFOHEAD(fd,packet_len(0x189));
  5305. WFIFOW(fd,0)=0x189;
  5306. WFIFOW(fd,2)=type;
  5307. WFIFOSET(fd,packet_len(0x189));
  5308. }
  5309. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5310. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5311. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5312. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5313. {
  5314. struct status_data *status;
  5315. unsigned char buf[64];
  5316. int i, fix;
  5317. nullpo_retv(sd);
  5318. nullpo_retv(dst);
  5319. if( dst->type != BL_MOB )
  5320. return;
  5321. status = status_get_status_data(dst);
  5322. WBUFW(buf, 0)=0x18c;
  5323. WBUFW(buf, 2)=status_get_class(dst);
  5324. WBUFW(buf, 4)=status_get_lv(dst);
  5325. WBUFW(buf, 6)=status->size;
  5326. WBUFL(buf, 8)=status->hp;
  5327. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5328. +(battle_config.estimation_type&2?status->def2:0);
  5329. WBUFW(buf,14)=status->race;
  5330. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5331. +(battle_config.estimation_type&2?status->mdef2:0);
  5332. WBUFW(buf,18)= status->def_ele;
  5333. for(i=0;i<9;i++)
  5334. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5335. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5336. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5337. }
  5338. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5339. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5340. /// material id:
  5341. /// unused by the client
  5342. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5343. nullpo_retv(sd);
  5344. int fd = sd->fd;
  5345. if( !session_isActive( fd ) ){
  5346. return;
  5347. }
  5348. if (sd->menuskill_id == skill_id)
  5349. return; //Avoid resending the menu twice or more times...
  5350. if (skill_id == GC_CREATENEWPOISON)
  5351. skill_id = GC_RESEARCHNEWPOISON;
  5352. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5353. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5354. p->packetType = 0x18d;
  5355. int count = 0;
  5356. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5357. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5358. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5359. )
  5360. {
  5361. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5362. p->items[count].material[0] = 0;
  5363. p->items[count].material[1] = 0;
  5364. p->items[count].material[2] = 0;
  5365. count++;
  5366. }
  5367. }
  5368. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5369. WFIFOSET( fd, p->packetLength );
  5370. if( count > 0 ){
  5371. sd->menuskill_id = skill_id;
  5372. sd->menuskill_val = trigger;
  5373. return;
  5374. }
  5375. }
  5376. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5377. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5378. /// mk type:
  5379. /// 1 = cooking
  5380. /// 2 = arrow
  5381. /// 3 = elemental
  5382. /// 4 = GN_MIX_COOKING
  5383. /// 5 = GN_MAKEBOMB
  5384. /// 6 = GN_S_PHARMACY
  5385. /// 7 = MT_M_MACHINE - Unconfirmed
  5386. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5387. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5388. nullpo_retv( sd );
  5389. // Avoid resending the menu twice or more times...
  5390. if( sd->menuskill_id == skill_id ){
  5391. return;
  5392. }
  5393. int fd = sd->fd;
  5394. if( !session_isActive( fd ) ){
  5395. return;
  5396. }
  5397. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5398. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5399. p->packetType = 0x25a;
  5400. p->makeItem = list_type; // list type
  5401. int count = 0;
  5402. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5403. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5404. continue;
  5405. }
  5406. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5407. count++;
  5408. }
  5409. if( count > 0 || skill_id == AM_PHARMACY ){
  5410. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5411. WFIFOSET( fd, p->packetLength );
  5412. sd->menuskill_id = skill_id;
  5413. sd->menuskill_val = trigger;
  5414. sd->menuskill_val2 = qty; // amount.
  5415. }else{
  5416. clif_menuskill_clear(sd);
  5417. #if PACKETVER >= 20090922
  5418. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5419. #else
  5420. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5421. WFIFOSET( fd, p->packetLength );
  5422. #endif
  5423. }
  5424. }
  5425. /// Notifies clients of a status change.
  5426. /// 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)]
  5427. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5428. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5429. /// @param bl: Sends packet to clients around this object
  5430. /// @param id: ID of object that has this effect
  5431. /// @param type: Status icon (see efst_types)
  5432. /// @param flag: 1:Active, 0:Inactive
  5433. /// @param tick_total: Total duration in ms
  5434. /// @param tick: Remaining duration in ms
  5435. /// @param val1: Value 1
  5436. /// @param val2: Value 2
  5437. /// @param val3: Value 3
  5438. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, t_tick tick_total, t_tick tick, int val1, int val2, int val3)
  5439. {
  5440. nullpo_retv(bl);
  5441. if (type == EFST_BLANK) //It shows nothing on the client...
  5442. return;
  5443. if (type == EFST_POSTDELAY && tick == 0)
  5444. return;
  5445. if (!(status_efst_get_bl_type((efst_type)type) & bl->type)) // only send status changes that actually matter to the client
  5446. return;
  5447. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5448. // Older clients display normal riding icon.
  5449. if (type == EFST_MADOGEAR)
  5450. type = EFST_RIDING;
  5451. #endif
  5452. packet_status_change p = { 0 };
  5453. map_session_data *sd = BL_CAST(BL_PC, bl);
  5454. if (battle_config.display_status_timers > 0) {
  5455. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5456. switch (type) {
  5457. case EFST_LUNARSTANCE:
  5458. case EFST_UNIVERSESTANCE:
  5459. case EFST_SUNSTANCE:
  5460. case EFST_STARSTANCE:
  5461. tick = 200;
  5462. break;
  5463. default:
  5464. if (tick < 0)
  5465. tick = 9999; // this is indeed what official servers do
  5466. break;
  5467. }
  5468. }
  5469. p.PacketType = status_changeType;
  5470. p.index = type;
  5471. p.AID = id;
  5472. p.state = (uint8)flag;
  5473. #if PACKETVER >= 20090121
  5474. if (battle_config.display_status_timers > 0) {
  5475. #if PACKETVER >= 20120618
  5476. p.Total = client_tick(tick_total);
  5477. #endif
  5478. p.Left = client_tick(tick);
  5479. p.val1 = val1;
  5480. p.val2 = val2;
  5481. p.val3 = val3;
  5482. }
  5483. #endif
  5484. clif_send(&p, sizeof(p), bl, pc_isinvisible(sd) ? SELF : AREA);
  5485. }
  5486. /* Sends status effect to clients around the bl
  5487. * @param bl: Object that has the effect
  5488. * @param type: Status icon (see efst_types)
  5489. * @param flag: 1:Active, 0:Inactive
  5490. * @param tick_total: Total duration in ms
  5491. * @param val1: Value 1
  5492. * @param val2: Value 2
  5493. * @param val3: Value 3
  5494. */
  5495. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick_total, int val1, int val2, int val3) {
  5496. clif_status_change_sub(bl, bl->id, type, flag, tick_total, tick_total, val1, val2, val3);
  5497. }
  5498. /**
  5499. * Send any active EFST to those around.
  5500. * @param tbl: Unit to send the packet to
  5501. * @param bl: Objects walking into view
  5502. * @param target: Client send type
  5503. */
  5504. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5505. nullpo_retv(bl);
  5506. struct sc_display_entry **sc_display;
  5507. unsigned char sc_display_count;
  5508. bool spheres_sent;
  5509. switch( bl->type ){
  5510. case BL_PC: {
  5511. struct map_session_data* sd = (struct map_session_data*)bl;
  5512. sc_display = sd->sc_display;
  5513. sc_display_count = sd->sc_display_count;
  5514. spheres_sent = !sd->state.connect_new;
  5515. }
  5516. break;
  5517. case BL_NPC: {
  5518. struct npc_data* nd = (struct npc_data*)bl;
  5519. sc_display = nd->sc_display;
  5520. sc_display_count = nd->sc_display_count;
  5521. spheres_sent = true;
  5522. }
  5523. break;
  5524. default:
  5525. return;
  5526. }
  5527. for (unsigned char i = 0; i < sc_display_count; i++) {
  5528. enum sc_type type = sc_display[i]->type;
  5529. struct status_change *sc = status_get_sc(bl);
  5530. const TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : nullptr);
  5531. t_tick tick_total = 0, tick = 0, cur_tick = gettick();
  5532. tick_total = DIFF_TICK(sc->data[type]->tick_total, cur_tick);
  5533. if (td != nullptr)
  5534. tick = DIFF_TICK(td->tick, cur_tick);
  5535. // Status changes that need special handling
  5536. switch( type ){
  5537. case SC_SPHERE_1:
  5538. case SC_SPHERE_2:
  5539. case SC_SPHERE_3:
  5540. case SC_SPHERE_4:
  5541. case SC_SPHERE_5:
  5542. if( spheres_sent ){
  5543. target = AREA_WOS;
  5544. }
  5545. break;
  5546. case SC_HELLS_PLANT:
  5547. if( sc && sc->getSCE(type) ){
  5548. tick = sc->getSCE(type)->val4;
  5549. }
  5550. break;
  5551. }
  5552. #if PACKETVER > 20120418
  5553. clif_efst_status_change(tbl, bl->id, target, status_db.getIcon(type), tick_total, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5554. #else
  5555. clif_status_change_sub(tbl, bl->id, status_db.getIcon(type), 1, tick, tick sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5556. #endif
  5557. }
  5558. }
  5559. /// Notifies the client when a player enters the screen with an active EFST.
  5560. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5561. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5562. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, t_tick tick_total, t_tick tick, int val1, int val2, int val3) {
  5563. #if PACKETVER >= 20111108
  5564. nullpo_retv(bl);
  5565. if (type == EFST_BLANK)
  5566. return;
  5567. if (tick < 0)
  5568. tick = 9999;
  5569. PACKET_EFST_SET_ENTER p = { 0 };
  5570. p.PacketType = HEADER_ZC_EFST_SET_ENTER;
  5571. p.GID = tid;
  5572. p.type = type;
  5573. p.remaining = client_tick(tick);
  5574. #if PACKETVER >= 20120618
  5575. p.total = client_tick(tick_total);
  5576. #endif
  5577. p.val1 = val1;
  5578. p.val2 = val2;
  5579. p.val3 = val3;
  5580. clif_send(&p, sizeof(p), bl, target);
  5581. #endif
  5582. }
  5583. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5584. /// 008e <packet len>.W <message>.?B
  5585. void clif_displaymessage(const int fd, const char* mes)
  5586. {
  5587. nullpo_retv(mes);
  5588. if( session_isActive( fd ) ){
  5589. char *message, *line;
  5590. message = aStrdup(mes);
  5591. line = strtok(message, "\n");
  5592. while(line != NULL) {
  5593. #if PACKETVER == 20141022
  5594. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5595. /** so we redirect to ZC_NPC_CHAT **/
  5596. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5597. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5598. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5599. if (len > 0) {
  5600. WFIFOHEAD(fd, 13 + len);
  5601. WFIFOW(fd, 0) = 0x2C1;
  5602. WFIFOW(fd, 2) = 13 + len;
  5603. WFIFOL(fd, 4) = 0;
  5604. WFIFOL(fd, 8) = color;
  5605. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5606. WFIFOSET(fd, WFIFOW(fd, 2));
  5607. }
  5608. #else
  5609. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5610. int len = strnlen(line, CHAT_SIZE_MAX);
  5611. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5612. WFIFOHEAD(fd, 5 + len);
  5613. WFIFOW(fd,0) = 0x8e;
  5614. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5615. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5616. WFIFOSET(fd, 5 + len);
  5617. }
  5618. #endif
  5619. line = strtok(NULL, "\n");
  5620. }
  5621. aFree(message);
  5622. }
  5623. }
  5624. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5625. /// 009a <packet len>.W <message>.?B
  5626. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5627. {
  5628. nullpo_retv(mes);
  5629. if (len < 2)
  5630. return;
  5631. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5632. p->packetType = HEADER_ZC_BROADCAST;
  5633. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5634. if( ( type&BC_BLUE ) != 0 ){
  5635. const char* color = "blue";
  5636. int16 length = (int16)strlen( color );
  5637. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5638. strcpy( p->message, color );
  5639. strncpy( &p->message[length], mes, len );
  5640. p->PacketLength += length;
  5641. }else if( ( type&BC_WOE ) != 0 ){
  5642. const char* color = "ssss";
  5643. int16 length = (int16)strlen( color );
  5644. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5645. strcpy( p->message, color );
  5646. strncpy( &p->message[length], mes, len );
  5647. p->PacketLength += length;
  5648. }else{
  5649. strncpy( p->message, mes, len );
  5650. }
  5651. clif_send( p, p->PacketLength, bl, target );
  5652. }
  5653. /*==========================================
  5654. * Displays a message on a 'bl' to all it's nearby clients
  5655. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5656. *------------------------------------------*/
  5657. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5658. nullpo_retv(bl);
  5659. nullpo_retv(message);
  5660. int16 len = (int16)( strlen( message ) + 1 );
  5661. if( len > CHAT_SIZE_MAX ) {
  5662. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5663. len = CHAT_SIZE_MAX;
  5664. }
  5665. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5666. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5667. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5668. p->GID = bl->id;
  5669. safestrncpy( p->Message, message, len );
  5670. clif_send( p, p->PacketLength, bl, target );
  5671. }
  5672. /// Send broadcast message with font formatting.
  5673. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5674. 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)
  5675. {
  5676. nullpo_retv(mes);
  5677. if (len < 2)
  5678. return;
  5679. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5680. p->packetType = HEADER_ZC_BROADCAST2;
  5681. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5682. p->fontColor = fontColor;
  5683. p->fontType = fontType;
  5684. p->fontSize = fontSize;
  5685. p->fontAlign = fontAlign;
  5686. p->fontY = fontY;
  5687. strncpy( p->message, mes, len );
  5688. clif_send( p, p->PacketLength, bl, target );
  5689. }
  5690. /*
  5691. * Display *msg to all *users in channel
  5692. */
  5693. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5694. DBIterator *iter;
  5695. struct map_session_data *user;
  5696. unsigned short msg_len = 0, len = 0;
  5697. unsigned char buf[CHAT_SIZE_MAX];
  5698. if (!channel || !msg)
  5699. return;
  5700. msg_len = (unsigned short)(strlen(msg) + 1);
  5701. if( msg_len > sizeof(buf)-12 ) {
  5702. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5703. msg_len = sizeof(buf)-12;
  5704. }
  5705. WBUFW(buf,0) = 0x2C1;
  5706. WBUFW(buf,2) = (len = msg_len + 12);
  5707. WBUFL(buf,4) = 0;
  5708. WBUFL(buf,8) = color;
  5709. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5710. iter = db_iterator(channel->users);
  5711. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5712. clif_send(buf, len, &user->bl, SELF);
  5713. }
  5714. dbi_destroy(iter);
  5715. }
  5716. /// Displays heal effect.
  5717. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5718. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5719. /// var id:
  5720. /// 5 = HP (SP_HP)
  5721. /// 7 = SP (SP_SP)
  5722. /// ? = ignored
  5723. void clif_heal(int fd,int type,int val) {
  5724. #if PACKETVER < 20141022
  5725. const int cmd = 0x13d;
  5726. #else
  5727. const int cmd = 0xa27;
  5728. #endif
  5729. WFIFOHEAD(fd, packet_len(cmd));
  5730. WFIFOW(fd,0) = cmd;
  5731. WFIFOW(fd,2) = type;
  5732. #if PACKETVER < 20141022
  5733. WFIFOW(fd,4) = min(val, INT16_MAX);
  5734. #else
  5735. WFIFOL(fd,4) = min(val, INT32_MAX);
  5736. #endif
  5737. WFIFOSET(fd, packet_len(cmd));
  5738. }
  5739. /// Displays resurrection effect (ZC_RESURRECTION).
  5740. /// 0148 <id>.L <type>.W
  5741. /// type:
  5742. /// ignored
  5743. void clif_resurrection(struct block_list *bl,int type)
  5744. {
  5745. unsigned char buf[16];
  5746. nullpo_retv(bl);
  5747. WBUFW(buf,0)=0x148;
  5748. WBUFL(buf,2)=bl->id;
  5749. WBUFW(buf,6)=0;
  5750. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5751. if (disguised(bl))
  5752. clif_spawn(bl);
  5753. }
  5754. /// Sets the map property
  5755. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5756. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5757. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5758. {
  5759. #if PACKETVER >= 20121010
  5760. short cmd = 0x99b;
  5761. unsigned char buf[8];
  5762. #else
  5763. short cmd = 0x199;
  5764. unsigned char buf[4];
  5765. #endif
  5766. WBUFW(buf,0)=cmd;
  5767. WBUFW(buf,2)=property;
  5768. #if PACKETVER >= 20121010
  5769. struct map_data *mapdata = map_getmapdata(bl->m);
  5770. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  5771. WBUFL(buf,4) = ((mapdata->flag[MF_PVP] || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5772. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5773. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5774. ((mapdata->flag[MF_FORCEMINEFFECT] || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5775. ((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
  5776. ((mapdata->flag[MF_PVP])<<5)| // COUNT_PK - Show the PvP counter
  5777. ((mapdata->flag[MF_PARTYLOCK])<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5778. ((mapdata->flag[MF_BATTLEGROUND])<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5779. ((mapdata->flag[MF_NOCOSTUME])<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5780. ((!mapdata->flag[MF_NOUSECART])<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5781. ((!mapdata->flag[MF_NOSUNMOONSTARMIRACLE])<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5782. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5783. #endif
  5784. clif_send(buf,packet_len(cmd),bl,t);
  5785. }
  5786. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5787. /// 01d6 <type>.W
  5788. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5789. {
  5790. int fd;
  5791. nullpo_retv(sd);
  5792. fd=sd->fd;
  5793. WFIFOHEAD(fd,packet_len(0x1D6));
  5794. WFIFOW(fd,0)=0x1D6;
  5795. WFIFOW(fd,2)=type;
  5796. WFIFOSET(fd,packet_len(0x1D6));
  5797. }
  5798. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5799. /// 019a <id>.L <ranking>.L <total>.L
  5800. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5801. {
  5802. if(type == 2) {
  5803. int fd = sd->fd;
  5804. WFIFOHEAD(fd,packet_len(0x19a));
  5805. WFIFOW(fd,0) = 0x19a;
  5806. WFIFOL(fd,2) = sd->bl.id;
  5807. WFIFOL(fd,6) = pvprank;
  5808. WFIFOL(fd,10) = pvpnum;
  5809. WFIFOSET(fd,packet_len(0x19a));
  5810. } else {
  5811. unsigned char buf[32];
  5812. WBUFW(buf,0) = 0x19a;
  5813. WBUFL(buf,2) = sd->bl.id;
  5814. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5815. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5816. else
  5817. WBUFL(buf,6) = pvprank;
  5818. WBUFL(buf,10) = pvpnum;
  5819. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5820. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5821. else if(!type)
  5822. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5823. else
  5824. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5825. }
  5826. }
  5827. /*==========================================
  5828. *
  5829. *------------------------------------------*/
  5830. void clif_map_property_mapall(int map_idx, enum map_property property)
  5831. {
  5832. struct block_list bl;
  5833. bl.id = 0;
  5834. bl.type = BL_NUL;
  5835. bl.m = map_idx;
  5836. clif_map_property( &bl, property, ALL_SAMEMAP );
  5837. }
  5838. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5839. /// 0188 <result>.W <index>.W <refine>.W
  5840. /// result:
  5841. /// 0 = success
  5842. /// 1 = failure
  5843. /// 2 = downgrade
  5844. void clif_refine(int fd, int fail, int index, int val)
  5845. {
  5846. WFIFOHEAD(fd,packet_len(0x188));
  5847. WFIFOW(fd,0)=0x188;
  5848. WFIFOW(fd,2)=fail;
  5849. WFIFOW(fd,4)=index+2;
  5850. WFIFOW(fd,6)=val;
  5851. WFIFOSET(fd,packet_len(0x188));
  5852. }
  5853. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5854. /// 0223 <result>.L <nameid>.W
  5855. /// result:
  5856. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5857. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5858. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5859. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5860. void clif_upgrademessage( struct map_session_data* sd, int result, t_itemid item_id ){
  5861. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5862. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5863. p.result = result;
  5864. p.itemId = client_nameid( item_id );
  5865. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5866. }
  5867. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5868. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5869. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5870. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5871. int fd;
  5872. nullpo_retv(sd);
  5873. fd = sd->fd;
  5874. #if PACKETVER < 20091104
  5875. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5876. WFIFOW(fd,0) = 0x97;
  5877. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5878. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5879. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5880. WFIFOSET(fd,WFIFOW(fd,2));
  5881. #else
  5882. struct map_session_data *ssd = map_nick2sd(nick,false);
  5883. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5884. WFIFOW(fd,0) = 0x97;
  5885. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5886. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5887. // If it is not a message from the server or a player from another map-server
  5888. if( ssd ){
  5889. gmlvl = pc_get_group_level(ssd);
  5890. }
  5891. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5892. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5893. WFIFOSET(fd,WFIFOW(fd,2));
  5894. #endif
  5895. }
  5896. /// Inform the player about the result of his whisper action
  5897. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5898. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5899. /// result:
  5900. /// 0 = success to send wisper
  5901. /// 1 = target character is not loged in
  5902. /// 2 = ignored by target
  5903. /// 3 = everyone ignored by target
  5904. void clif_wis_end(int fd, int result)
  5905. {
  5906. struct map_session_data *sd = (session_isActive(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5907. #if PACKETVER < 20131223
  5908. const int cmd = 0x98;
  5909. #else
  5910. const int cmd = 0x9df;
  5911. #endif
  5912. if (!sd)
  5913. return;
  5914. WFIFOHEAD(fd,packet_len(cmd));
  5915. WFIFOW(fd,0) = cmd;
  5916. WFIFOB(fd,2) = (char)result;
  5917. #if PACKETVER >= 20131223
  5918. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5919. #endif
  5920. WFIFOSET(fd,packet_len(cmd));
  5921. }
  5922. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5923. /// 0194 <char id>.L <name>.24B
  5924. /// 0af7 <flag>.W <char id>.L <name>.24B
  5925. void clif_solved_charname(int fd, int charid, const char* name)
  5926. {
  5927. #if PACKETVER >= 20180221
  5928. WFIFOHEAD(fd,packet_len(0xaf7));
  5929. WFIFOW(fd,0) = 0xaf7;
  5930. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5931. WFIFOL(fd,4) = charid;
  5932. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5933. WFIFOSET(fd,packet_len(0x0af7));
  5934. #else
  5935. WFIFOHEAD(fd,packet_len(0x194));
  5936. WFIFOW(fd,0)=0x194;
  5937. WFIFOL(fd,2)=charid;
  5938. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5939. WFIFOSET(fd,packet_len(0x194));
  5940. #endif
  5941. }
  5942. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5943. /// 017b <packet len>.W { <name id>.W }*
  5944. void clif_use_card(struct map_session_data *sd,int idx)
  5945. {
  5946. int i,c,ep;
  5947. int fd=sd->fd;
  5948. nullpo_retv(sd);
  5949. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5950. return;
  5951. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5952. return; //Avoid parsing invalid item indexes (no card/no item)
  5953. ep=sd->inventory_data[idx]->equip;
  5954. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5955. WFIFOW(fd,0)=0x17b;
  5956. for(i=c=0;i<MAX_INVENTORY;i++){
  5957. int j;
  5958. if(sd->inventory_data[i] == NULL)
  5959. continue;
  5960. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5961. continue;
  5962. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5963. continue;
  5964. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5965. continue;
  5966. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5967. continue;
  5968. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5969. continue;
  5970. 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.
  5971. continue;
  5972. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5973. if( j == sd->inventory_data[i]->slots ) // No room
  5974. continue;
  5975. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5976. continue;
  5977. WFIFOW(fd,4+c*2)=i+2;
  5978. c++;
  5979. }
  5980. if( !c ) return; // no item is available for card insertion
  5981. WFIFOW(fd,2)=4+c*2;
  5982. WFIFOSET(fd,WFIFOW(fd,2));
  5983. }
  5984. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5985. /// 017d <equip index>.W <card index>.W <result>.B
  5986. /// result:
  5987. /// 0 = success
  5988. /// 1 = failure
  5989. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5990. {
  5991. int fd;
  5992. nullpo_retv(sd);
  5993. fd=sd->fd;
  5994. WFIFOHEAD(fd,packet_len(0x17d));
  5995. WFIFOW(fd,0)=0x17d;
  5996. WFIFOW(fd,2)=idx_equip+2;
  5997. WFIFOW(fd,4)=idx_card+2;
  5998. WFIFOB(fd,6)=flag;
  5999. WFIFOSET(fd,packet_len(0x17d));
  6000. }
  6001. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6002. /// 0177 <packet len>.W { <index>.W }*
  6003. void clif_item_identify_list(struct map_session_data *sd)
  6004. {
  6005. int i,c;
  6006. int fd;
  6007. nullpo_retv(sd);
  6008. fd=sd->fd;
  6009. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6010. WFIFOW(fd,0)=0x177;
  6011. for(i=c=0;i<MAX_INVENTORY;i++){
  6012. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6013. WFIFOW(fd,c*2+4)=client_index(i);
  6014. c++;
  6015. }
  6016. }
  6017. if(c > 0) {
  6018. WFIFOW(fd,2)=c*2+4;
  6019. WFIFOSET(fd,WFIFOW(fd,2));
  6020. sd->menuskill_id = MC_IDENTIFY;
  6021. sd->menuskill_val = c;
  6022. sd->state.workinprogress = WIP_DISABLE_ALL;
  6023. }
  6024. }
  6025. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6026. /// 0179 <index>.W <result>.B
  6027. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  6028. {
  6029. int fd;
  6030. nullpo_retv(sd);
  6031. fd=sd->fd;
  6032. WFIFOHEAD(fd,packet_len(0x179));
  6033. WFIFOW(fd, 0)=0x179;
  6034. WFIFOW(fd, 2)=idx+2;
  6035. WFIFOB(fd, 4)=flag;
  6036. WFIFOSET(fd,packet_len(0x179));
  6037. }
  6038. /// Presents a list of items that can be repaired.
  6039. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6040. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  6041. nullpo_retv( sd );
  6042. nullpo_retv( dstsd );
  6043. int fd = sd->fd;
  6044. if( !session_isActive( fd ) ){
  6045. return;
  6046. }
  6047. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6048. // Preallocate the maximum size
  6049. WFIFOHEAD( fd, len );
  6050. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6051. int c = 0;
  6052. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6053. 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)){
  6054. p->items[c].index = i;
  6055. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6056. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6057. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6058. c++;
  6059. }
  6060. }
  6061. if( c > 0 ){
  6062. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6063. // Recalculate real length
  6064. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6065. p->packetLength = len;
  6066. WFIFOSET( fd, len );
  6067. sd->menuskill_id = BS_REPAIRWEAPON;
  6068. sd->menuskill_val = dstsd->bl.id;
  6069. sd->menuskill_val2 = lv;
  6070. }else{
  6071. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6072. }
  6073. }
  6074. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6075. /// 01fe <index>.W <result>.B
  6076. /// index:
  6077. /// ignored (inventory index)
  6078. /// result:
  6079. /// 0 = Item repair success.
  6080. /// 1 = Item repair failure.
  6081. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  6082. {
  6083. int fd;
  6084. nullpo_retv(sd);
  6085. fd = sd->fd;
  6086. WFIFOHEAD(fd,packet_len(0x1fe));
  6087. WFIFOW(fd, 0)=0x1fe;
  6088. WFIFOW(fd, 2)=idx+2;
  6089. WFIFOB(fd, 4)=flag;
  6090. WFIFOSET(fd,packet_len(0x1fe));
  6091. }
  6092. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6093. /// 02bb <equip location>.W <account id>.L
  6094. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  6095. {
  6096. int fd = sd->fd;
  6097. WFIFOHEAD(fd,packet_len(0x2bb));
  6098. WFIFOW(fd,0) = 0x2bb;
  6099. WFIFOW(fd,2) = position;
  6100. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6101. WFIFOSET(fd,packet_len(0x2bb));
  6102. }
  6103. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6104. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6105. void clif_item_refine_list( struct map_session_data *sd ){
  6106. nullpo_retv( sd );
  6107. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6108. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6109. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6110. int refine_item[MAX_WEAPON_LEVEL];
  6111. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6112. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6113. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6114. #ifdef RENEWAL
  6115. refine_item[4] = -1;
  6116. #endif
  6117. int count = 0;
  6118. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6119. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6120. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6121. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6122. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6123. p->items[count].index = client_index( i );
  6124. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6125. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6126. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6127. count++;
  6128. }
  6129. }
  6130. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6131. clif_send( p, p->packetLength, &sd->bl, SELF );
  6132. if( count > 0 ){
  6133. sd->menuskill_id = WS_WEAPONREFINE;
  6134. sd->menuskill_val = skill_lv;
  6135. }
  6136. }
  6137. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6138. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6139. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6140. nullpo_retv( sd );
  6141. struct PACKET_ZC_AUTORUN_SKILL p;
  6142. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6143. p.skill_id = skill_id;
  6144. p.skill_type = skill_get_inf( skill_id );
  6145. p.skill_lv = skill_lv;
  6146. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6147. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6148. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6149. p.up_flag = false;
  6150. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6151. }
  6152. /// Adds an item to character's cart.
  6153. /// 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)
  6154. /// 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)
  6155. /// 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)
  6156. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  6157. nullpo_retv( sd );
  6158. int fd = sd->fd;
  6159. if( !session_isActive( fd ) ){
  6160. return;
  6161. }
  6162. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6163. return;
  6164. }
  6165. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6166. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6167. p.index = client_index( n );
  6168. p.amount = amount;
  6169. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6170. #if PACKETVER >= 5
  6171. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6172. #endif
  6173. p.identified = sd->cart.u.items_cart[n].identify;
  6174. p.damaged = sd->cart.u.items_cart[n].attribute;
  6175. p.refine = sd->cart.u.items_cart[n].refine;
  6176. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6177. #if PACKETVER >= 20150226
  6178. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6179. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6180. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6181. #endif
  6182. #endif
  6183. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6184. }
  6185. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6186. /* Acknowledge an item have been added to cart
  6187. * 012c <result>B
  6188. * result :
  6189. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6190. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6191. */
  6192. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6193. {
  6194. int fd;
  6195. unsigned char *buf;
  6196. nullpo_retv(sd);
  6197. fd = sd->fd;
  6198. buf = WFIFOP(fd,0);
  6199. WBUFW(buf,0) = 0x12c;
  6200. WBUFB(buf,2) = flag;
  6201. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6202. }
  6203. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6204. void clif_bank_open( struct map_session_data& sd ){
  6205. #if PACKETVER >= 20130717
  6206. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6207. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6208. p.unknown = 0;
  6209. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6210. #endif
  6211. }
  6212. /*
  6213. * Request to Open the banking system
  6214. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6215. */
  6216. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6217. //TODO check if preventing trade or stuff like that
  6218. //also mark something in case char ain't available for saving, should we check now ?
  6219. nullpo_retv(sd);
  6220. if( !battle_config.feature_banking ) {
  6221. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6222. return;
  6223. }
  6224. else {
  6225. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6226. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6227. if(sd->status.account_id == aid){
  6228. sd->state.banking = 1;
  6229. //request save ?
  6230. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6231. //on succes open bank ?
  6232. clif_bank_open( *sd );
  6233. }
  6234. }
  6235. }
  6236. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6237. void clif_bank_close( struct map_session_data& sd ){
  6238. #if PACKETVER >= 20130717
  6239. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6240. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6241. p.unknown = 0;
  6242. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6243. #endif
  6244. }
  6245. /*
  6246. * Request to close the banking system
  6247. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6248. */
  6249. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6250. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6251. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6252. nullpo_retv(sd);
  6253. if( !battle_config.feature_banking ) {
  6254. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6255. //still allow to go trough to not stuck player if we have disable it while they was in
  6256. }
  6257. if(sd->status.account_id == aid){
  6258. sd->state.banking = 0;
  6259. clif_bank_close( *sd );
  6260. }
  6261. }
  6262. /*
  6263. * Display how much we got in bank (I suppose)
  6264. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6265. */
  6266. void clif_Bank_Check( struct map_session_data& sd ){
  6267. #if PACKETVER >= 20130717
  6268. struct PACKET_ZC_BANKING_CHECK p = {};
  6269. p.packetType = HEADER_ZC_BANKING_CHECK;
  6270. p.money = sd.bank_vault;
  6271. p.reason = 0;
  6272. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6273. #endif
  6274. }
  6275. /*
  6276. * Requesting the data in bank
  6277. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6278. */
  6279. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6280. nullpo_retv(sd);
  6281. if( !battle_config.feature_banking ) {
  6282. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6283. return;
  6284. }
  6285. else {
  6286. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6287. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6288. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6289. clif_Bank_Check( *sd );
  6290. }
  6291. }
  6292. /*
  6293. * Acknowledge of deposit some money in bank
  6294. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6295. */
  6296. void clif_bank_deposit( struct map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6297. #if PACKETVER >= 20130717
  6298. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6299. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6300. p.money = sd.bank_vault;
  6301. p.zeny = sd.status.zeny;
  6302. p.reason = reason;
  6303. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6304. #endif
  6305. }
  6306. /*
  6307. * Request saving some money in bank
  6308. * @author : original [Yommy/Hercules]
  6309. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6310. */
  6311. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6312. nullpo_retv(sd);
  6313. if( !battle_config.feature_banking ) {
  6314. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6315. return;
  6316. }
  6317. else {
  6318. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6319. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6320. int money = RFIFOL(fd,info->pos[1]);
  6321. if(sd->status.account_id == aid){
  6322. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6323. clif_bank_deposit( *sd, reason );
  6324. }
  6325. }
  6326. }
  6327. /*
  6328. * Acknowledge of withdrawing some money from bank
  6329. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6330. */
  6331. void clif_bank_withdraw( struct map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6332. #if PACKETVER >= 20130717
  6333. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6334. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6335. p.reason = reason;
  6336. p.money = sd.bank_vault;
  6337. p.zeny = sd.status.zeny;
  6338. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6339. #endif
  6340. }
  6341. /*
  6342. * Request Withdrawing some money from bank
  6343. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6344. */
  6345. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6346. nullpo_retv(sd);
  6347. if( !battle_config.feature_banking ) {
  6348. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6349. return;
  6350. }
  6351. else {
  6352. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6353. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6354. int money = RFIFOL(fd,info->pos[1]);
  6355. if(sd->status.account_id == aid){
  6356. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6357. clif_bank_withdraw( *sd, reason );
  6358. }
  6359. }
  6360. }
  6361. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6362. /// 0125 <index>.W <amount>.L
  6363. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6364. {
  6365. int fd;
  6366. nullpo_retv(sd);
  6367. fd=sd->fd;
  6368. WFIFOHEAD(fd,packet_len(0x125));
  6369. WFIFOW(fd,0)=0x125;
  6370. WFIFOW(fd,2)=n+2;
  6371. WFIFOL(fd,4)=amount;
  6372. WFIFOSET(fd,packet_len(0x125));
  6373. }
  6374. /// Opens the shop creation menu (ZC_OPENSTORE).
  6375. /// 012d <num>.W
  6376. /// num:
  6377. /// number of allowed item slots
  6378. void clif_openvendingreq(struct map_session_data* sd, int num)
  6379. {
  6380. int fd;
  6381. nullpo_retv(sd);
  6382. fd = sd->fd;
  6383. WFIFOHEAD(fd,packet_len(0x12d));
  6384. WFIFOW(fd,0) = 0x12d;
  6385. WFIFOW(fd,2) = num;
  6386. WFIFOSET(fd,packet_len(0x12d));
  6387. }
  6388. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6389. /// 0131 <owner id>.L <message>.80B
  6390. void clif_showvendingboard( struct map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6391. if( tbl == nullptr ){
  6392. tbl = &sd.bl;
  6393. target = AREA_WOS;
  6394. }
  6395. struct PACKET_ZC_STORE_ENTRY p = {};
  6396. p.packetType = HEADER_ZC_STORE_ENTRY;
  6397. p.makerAID = sd.status.account_id;
  6398. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6399. clif_send( &p, sizeof( p ), tbl, target );
  6400. }
  6401. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6402. /// 0132 <owner id>.L
  6403. void clif_closevendingboard(struct block_list* bl, int fd)
  6404. {
  6405. unsigned char buf[16];
  6406. nullpo_retv(bl);
  6407. WBUFW(buf,0) = 0x132;
  6408. WBUFL(buf,2) = bl->id;
  6409. if( session_isActive(fd) ) {
  6410. WFIFOHEAD(fd,packet_len(0x132));
  6411. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6412. WFIFOSET(fd,packet_len(0x132));
  6413. } else {
  6414. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6415. }
  6416. }
  6417. /// Sends a list of items in a shop.
  6418. /// 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)
  6419. /// 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)
  6420. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6421. nullpo_retv( sd );
  6422. nullpo_retv( vsd );
  6423. nullpo_retv( vsd->vending );
  6424. int fd = sd->fd;
  6425. if( !session_isActive( fd ) ){
  6426. return;
  6427. }
  6428. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6429. WFIFOHEAD( fd, len );
  6430. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6431. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6432. p->packetLength = len;
  6433. p->AID = vsd->status.account_id;
  6434. #if PACKETVER >= 20100105
  6435. p->venderId = vsd->vender_id;
  6436. #endif
  6437. for( int i = 0; i < vsd->vend_num; i++ ){
  6438. int index = vsd->vending[i].index;
  6439. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6440. p->items[i].price = vsd->vending[i].value;
  6441. p->items[i].amount = vsd->vending[i].amount;
  6442. p->items[i].index = client_index( index );
  6443. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6444. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6445. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6446. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6447. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6448. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6449. #if PACKETVER >= 20150226
  6450. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6451. #if PACKETVER >= 20160921
  6452. p->items[i].location = pc_equippoint_sub( sd, data );
  6453. p->items[i].viewSprite = data->look;
  6454. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6455. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6456. #endif
  6457. #endif
  6458. #endif
  6459. }
  6460. WFIFOSET( fd, len );
  6461. }
  6462. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6463. /// 0135 <index>.W <amount>.W <result>.B
  6464. /// result:
  6465. /// 0 = success
  6466. /// 1 = not enough zeny
  6467. /// 2 = overweight
  6468. /// 4 = out of stock
  6469. /// 5 = "cannot use an npc shop while in a trade"
  6470. /// 6 = Because the store information was incorrect the item was not purchased.
  6471. /// 7 = No sales information.
  6472. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6473. {
  6474. int fd;
  6475. nullpo_retv(sd);
  6476. fd = sd->fd;
  6477. WFIFOHEAD(fd,packet_len(0x135));
  6478. WFIFOW(fd,0) = 0x135;
  6479. WFIFOW(fd,2) = index+2;
  6480. WFIFOW(fd,4) = amount;
  6481. WFIFOB(fd,6) = fail;
  6482. WFIFOSET(fd,packet_len(0x135));
  6483. }
  6484. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6485. /// 0a28 <Result>.B
  6486. /// result:
  6487. /// 0 = Successed
  6488. /// 1 = Failed
  6489. void clif_openvending_ack(struct map_session_data* sd, int result)
  6490. {
  6491. int fd;
  6492. nullpo_retv(sd);
  6493. fd = sd->fd;
  6494. WFIFOHEAD(fd, 3);
  6495. WFIFOW(fd,0) = 0xa28;
  6496. WFIFOB(fd,2) = result;
  6497. WFIFOSET(fd, 3);
  6498. }
  6499. /// Shop creation success.
  6500. /// 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)
  6501. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6502. nullpo_retv( sd );
  6503. nullpo_retv( vending );
  6504. int fd = sd->fd;
  6505. if( !session_isActive( fd ) ){
  6506. return;
  6507. }
  6508. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6509. WFIFOHEAD( fd, len );
  6510. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6511. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6512. p->packetLength = len;
  6513. p->AID = id;
  6514. for( int i = 0; i < sd->vend_num; i++ ) {
  6515. int index = vending[i].index;
  6516. p->items[i].price = vending[i].value;
  6517. p->items[i].index = client_index( index );
  6518. p->items[i].amount = vending[i].amount;
  6519. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6520. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6521. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6522. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6523. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6524. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6525. #if PACKETVER >= 20150226
  6526. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6527. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6528. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6529. #endif
  6530. #endif
  6531. }
  6532. WFIFOSET( fd, len );
  6533. #if PACKETVER >= 20141022
  6534. /// 0 = Successed
  6535. /// 1 = Failed
  6536. clif_openvending_ack( sd, 0 );
  6537. #endif
  6538. }
  6539. /// Inform merchant that someone has bought an item.
  6540. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6541. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6542. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6543. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6544. const int cmd = 0x137;
  6545. #else
  6546. const int cmd = 0x9e5;
  6547. #endif
  6548. int fd = sd->fd;
  6549. nullpo_retv(sd);
  6550. WFIFOHEAD(fd,packet_len(cmd));
  6551. WFIFOW(fd,0) = cmd;
  6552. WFIFOW(fd,2) = index+2;
  6553. WFIFOW(fd,4) = amount;
  6554. #if PACKETVER >= 20141016
  6555. WFIFOL(fd,6) = char_id; // GID
  6556. WFIFOL(fd,10) = (int)time(NULL); // Date
  6557. WFIFOL(fd,14) = zeny; // zeny
  6558. #endif
  6559. WFIFOSET(fd,packet_len(cmd));
  6560. }
  6561. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6562. /// 00fa <result>.B
  6563. /// result:
  6564. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6565. /// 1 = MsgStringTable[78]="party name already exists"
  6566. /// 2 = MsgStringTable[79]="already in a party"
  6567. /// 3 = cannot organize parties on this map
  6568. /// ? = nothing
  6569. void clif_party_created( struct map_session_data& sd, int result ){
  6570. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6571. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6572. p.result = result;
  6573. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6574. }
  6575. /// Adds new member to a party.
  6576. /// 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)
  6577. /// 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)
  6578. /// 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)
  6579. /// role:
  6580. /// 0 = leader
  6581. /// 1 = normal
  6582. /// state:
  6583. /// 0 = connected
  6584. /// 1 = disconnected
  6585. void clif_party_member_info( struct party_data& party, struct map_session_data& sd ){
  6586. int id = party_getmemberid( &party, &sd );
  6587. if( id < 0 ){
  6588. return;
  6589. }
  6590. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6591. p.packetType = partymemberinfo;
  6592. p.AID = sd.status.account_id;
  6593. #if PACKETVER >= 20171207
  6594. p.GID = sd.status.char_id;
  6595. #endif
  6596. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6597. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6598. p.class_ = sd.status.class_;
  6599. p.baseLevel = sd.status.base_level;
  6600. #endif
  6601. p.x = sd.bl.x;
  6602. p.y = sd.bl.y;
  6603. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6604. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6605. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6606. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6607. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6608. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6609. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6610. }
  6611. /// Sends party information (ZC_GROUP_LIST).
  6612. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6613. /// role:
  6614. /// 0 = leader
  6615. /// 1 = normal
  6616. /// state:
  6617. /// 0 = connected
  6618. /// 1 = disconnected
  6619. /// 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
  6620. void clif_party_info( struct party_data& party, struct map_session_data* sd ){
  6621. send_target target;
  6622. if( sd == nullptr ){
  6623. sd = party_getavailablesd( &party );
  6624. if( sd == nullptr ){
  6625. // Nobody is online to notify
  6626. return;
  6627. }
  6628. // Send to whole party
  6629. target = PARTY;
  6630. }else{
  6631. // Send only to self
  6632. target = SELF;
  6633. }
  6634. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6635. p->packetType = partyinfo;
  6636. p->packetLen = sizeof( *p );
  6637. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6638. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6639. struct party_member& m = party.party.member[i];
  6640. if( m.account_id == 0 ){
  6641. continue;
  6642. }
  6643. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6644. member.AID = m.account_id;
  6645. #if PACKETVER >= 20171207
  6646. member.GID = m.char_id;
  6647. #endif
  6648. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6649. mapindex_getmapname_ext( mapindex_id2name( m.map ), member.mapName );
  6650. member.leader = ( m.leader ) ? 0 : 1;
  6651. member.offline = ( m.online ) ? 0 : 1;
  6652. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6653. member.class_ = m.class_;
  6654. member.baseLevel = m.lv;
  6655. #endif
  6656. c++;
  6657. p->packetLen += sizeof( member );
  6658. }
  6659. clif_send( p, p->packetLen, &sd->bl, target );
  6660. }
  6661. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6662. /// 02c9 <flag>.B
  6663. /// flag:
  6664. /// 0 = allow party invites
  6665. /// 1 = auto-deny party invites
  6666. void clif_partyinvitationstate( struct map_session_data& sd ){
  6667. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6668. struct PACKET_ZC_PARTY_CONFIG p = {};
  6669. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6670. p.denyPartyInvites = 0; // TODO: not implemented
  6671. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6672. #endif
  6673. }
  6674. /// Party invitation request.
  6675. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6676. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6677. void clif_party_invite( struct map_session_data& sd, struct map_session_data& tsd ){
  6678. struct party_data* party = party_search( sd.status.party_id );
  6679. if( party == nullptr ){
  6680. return;
  6681. }
  6682. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6683. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6684. p.GRID = party->party.party_id;
  6685. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6686. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6687. }
  6688. /// Party invite result.
  6689. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6690. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6691. /// result=0 : char is already in a party -> MsgStringTable[80]
  6692. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6693. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6694. /// result=3 : party is full -> MsgStringTable[83]
  6695. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6696. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6697. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6698. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6699. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6700. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6701. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6702. void clif_party_invite_reply( struct map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6703. #if PACKETVER < 20070904
  6704. if( reply == PARTY_REPLY_OFFLINE ){
  6705. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6706. return;
  6707. }
  6708. #endif
  6709. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6710. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6711. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6712. p.result = reply;
  6713. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6714. }
  6715. /// Updates party settings.
  6716. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6717. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6718. /// exp option:
  6719. /// 0 = exp sharing disabled
  6720. /// 1 = exp sharing enabled
  6721. /// 2 = cannot change exp sharing
  6722. ///
  6723. /// flag:
  6724. /// 0 = send to party
  6725. /// 1 = send to sd
  6726. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6727. {
  6728. unsigned char buf[16];
  6729. #if PACKETVER < 20090603
  6730. const int cmd = 0x101;
  6731. #else
  6732. const int cmd = 0x7d8;
  6733. #endif
  6734. nullpo_retv(p);
  6735. if(!sd && flag==0){
  6736. int i;
  6737. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6738. if (i < MAX_PARTY)
  6739. sd = p->data[i].sd;
  6740. }
  6741. if(!sd) return;
  6742. WBUFW(buf,0)=cmd;
  6743. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6744. #if PACKETVER >= 20090603
  6745. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6746. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6747. #endif
  6748. if(flag==0)
  6749. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6750. else
  6751. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6752. }
  6753. /**
  6754. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6755. * @param sd Send the notification for this player
  6756. * @param account_id Account ID of kicked member
  6757. * @param name Name of kicked member
  6758. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6759. * @param target Send target
  6760. **/
  6761. 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 ){
  6762. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6763. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6764. p.AID = account_id;
  6765. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6766. p.result = result;
  6767. clif_send( &p, sizeof( p ), &sd.bl, target );
  6768. }
  6769. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6770. /// 0109 <packet len>.W <account id>.L <message>.?B
  6771. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6772. struct map_session_data* sd = party_getavailablesd( &party );
  6773. if( sd == nullptr ){
  6774. return;
  6775. }
  6776. if (len > CHAT_SIZE_MAX) {
  6777. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6778. len = CHAT_SIZE_MAX;
  6779. }
  6780. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6781. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6782. p->PacketLength = sizeof( *p ) + len;
  6783. p->AID = account_id;
  6784. safestrncpy( p->chatMsg, mes, len );
  6785. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6786. }
  6787. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6788. /// 0107 <account id>.L <x>.W <y>.W
  6789. void clif_party_xy( struct map_session_data& sd ){
  6790. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6791. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6792. p.AID = sd.status.account_id;
  6793. p.xPos = sd.bl.x;
  6794. p.yPos = sd.bl.y;
  6795. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6796. }
  6797. /*==========================================
  6798. * Sends x/y dot to a single fd. [Skotlex]
  6799. *------------------------------------------*/
  6800. void clif_party_xy_single( struct map_session_data& sd, struct map_session_data& tsd ){
  6801. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6802. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6803. p.AID = sd.status.account_id;
  6804. p.xPos = sd.bl.x;
  6805. p.yPos = sd.bl.y;
  6806. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6807. }
  6808. /// Updates HP bar of a party member.
  6809. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6810. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6811. void clif_party_hp( struct map_session_data& sd ){
  6812. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6813. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6814. p.AID = sd.status.account_id;
  6815. #if PACKETVER < 20100119
  6816. // To correctly display the %hp bar. [Skotlex]
  6817. if( sd.battle_status.max_hp > INT16_MAX ){
  6818. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6819. p.maxhp = 100;
  6820. }else{
  6821. p.hp = sd.battle_status.hp;
  6822. p.maxhp = sd.battle_status.max_hp;
  6823. }
  6824. #else
  6825. p.hp = sd.battle_status.hp;
  6826. p.maxhp = sd.battle_status.max_hp;
  6827. #endif
  6828. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6829. }
  6830. /// Notifies the party members of a character's death or revival.
  6831. /// 0AB2 <GID>.L <dead>.B
  6832. void clif_party_dead( struct map_session_data& sd ){
  6833. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6834. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6835. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6836. p.AID = sd.status.account_id;
  6837. p.isDead = pc_isdead( &sd );
  6838. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6839. #endif
  6840. }
  6841. /// Updates the job and level of a party member
  6842. /// 0abd <account id>.L <job>.W <level>.W
  6843. void clif_party_job_and_level( struct map_session_data& sd ){
  6844. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6845. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6846. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6847. p.AID = sd.status.account_id;
  6848. p.job = sd.status.class_;
  6849. p.level = sd.status.base_level;
  6850. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6851. #endif
  6852. }
  6853. /*==========================================
  6854. * Sends HP bar to a single fd. [Skotlex]
  6855. *------------------------------------------*/
  6856. void clif_hpmeter_single( struct map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6857. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6858. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6859. p.AID = id;
  6860. #if PACKETVER < 20100119
  6861. // To correctly display the %hp bar. [Skotlex]
  6862. if( maxhp > INT16_MAX ){
  6863. p.hp = hp / ( maxhp / 100 );
  6864. p.maxhp = 100;
  6865. }else{
  6866. p.hp = hp;
  6867. p.maxhp = maxhp;
  6868. }
  6869. #else
  6870. p.hp = hp;
  6871. p.maxhp = maxhp;
  6872. #endif
  6873. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6874. }
  6875. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6876. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6877. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6878. {
  6879. int fd;
  6880. nullpo_retv(sd);
  6881. nullpo_retv(bl);
  6882. fd=sd->fd;
  6883. WFIFOHEAD(fd,packet_len(0x139));
  6884. WFIFOW(fd, 0)=0x139;
  6885. WFIFOL(fd, 2)=bl->id;
  6886. WFIFOW(fd, 6)=bl->x;
  6887. WFIFOW(fd, 8)=bl->y;
  6888. WFIFOW(fd,10)=sd->bl.x;
  6889. WFIFOW(fd,12)=sd->bl.y;
  6890. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6891. WFIFOSET(fd,packet_len(0x139));
  6892. }
  6893. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6894. /// 018f <result>.W <name id>.W
  6895. /// result:
  6896. /// 0 = success
  6897. /// 1 = failure
  6898. /// 2 = success (alchemist)
  6899. /// 3 = failure (alchemist)
  6900. void clif_produceeffect(struct map_session_data* sd,int flag, t_itemid nameid){
  6901. nullpo_retv( sd );
  6902. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6903. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6904. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6905. p.result = flag;
  6906. p.itemId = client_nameid( nameid );
  6907. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6908. }
  6909. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6910. /// 019e
  6911. void clif_catch_process(struct map_session_data *sd)
  6912. {
  6913. int fd;
  6914. nullpo_retv(sd);
  6915. fd=sd->fd;
  6916. WFIFOHEAD(fd,packet_len(0x19e));
  6917. WFIFOW(fd,0)=0x19e;
  6918. WFIFOSET(fd,packet_len(0x19e));
  6919. }
  6920. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6921. /// 01a0 <result>.B
  6922. /// 0 = failure
  6923. /// 1 = success
  6924. void clif_pet_roulette(struct map_session_data *sd,int data)
  6925. {
  6926. int fd;
  6927. nullpo_retv(sd);
  6928. fd=sd->fd;
  6929. WFIFOHEAD(fd,packet_len(0x1a0));
  6930. WFIFOW(fd,0)=0x1a0;
  6931. WFIFOB(fd,2)=data;
  6932. WFIFOSET(fd,packet_len(0x1a0));
  6933. }
  6934. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6935. /// 01a6 <packet len>.W { <index>.W }*
  6936. void clif_sendegg(struct map_session_data *sd)
  6937. {
  6938. int i,n=0,fd;
  6939. nullpo_retv(sd);
  6940. fd=sd->fd;
  6941. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6942. clif_displaymessage(fd, msg_txt(sd,666));
  6943. return;
  6944. }
  6945. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6946. WFIFOW(fd,0)=0x1a6;
  6947. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6948. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  6949. sd->inventory_data[i]->type != IT_PETEGG ||
  6950. sd->inventory.u.items_inventory[i].amount <= 0)
  6951. continue;
  6952. WFIFOW(fd,n*2+4)=client_index(i);
  6953. n++;
  6954. }
  6955. WFIFOW(fd,2)=4+n*2;
  6956. WFIFOSET(fd,WFIFOW(fd,2));
  6957. sd->menuskill_id = SA_TAMINGMONSTER;
  6958. sd->menuskill_val = -1;
  6959. }
  6960. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6961. /// 01a4 <type>.B <id>.L <data>.L
  6962. /// type:
  6963. /// 0 = pre-init (data = 0)
  6964. /// 1 = intimacy (data = 0~4)
  6965. /// 2 = hunger (data = 0~4)
  6966. /// 3 = accessory
  6967. /// 4 = performance (data = 1~3: normal, 4: special)
  6968. /// 5 = hairstyle
  6969. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6970. ///
  6971. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6972. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6973. {
  6974. uint8 buf[16];
  6975. nullpo_retv(pd);
  6976. WBUFW(buf,0) = 0x1a4;
  6977. WBUFB(buf,2) = type;
  6978. WBUFL(buf,3) = pd->bl.id;
  6979. WBUFL(buf,7) = param;
  6980. if (sd)
  6981. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6982. else
  6983. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6984. }
  6985. /// Pet's base data (ZC_PROPERTY_PET).
  6986. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6987. void clif_send_petstatus(struct map_session_data *sd)
  6988. {
  6989. int fd;
  6990. struct s_pet *pet;
  6991. nullpo_retv(sd);
  6992. nullpo_retv(sd->pd);
  6993. fd=sd->fd;
  6994. pet = &sd->pd->pet;
  6995. WFIFOHEAD(fd,packet_len(0x1a2));
  6996. WFIFOW(fd,0)=0x1a2;
  6997. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6998. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6999. WFIFOW(fd,27)=pet->level;
  7000. WFIFOW(fd,29)=pet->hungry;
  7001. WFIFOW(fd,31)=pet->intimate;
  7002. WFIFOW(fd,33)=pet->equip;
  7003. #if PACKETVER >= 20081126
  7004. WFIFOW(fd,35)=pet->class_;
  7005. #endif
  7006. WFIFOSET(fd,packet_len(0x1a2));
  7007. }
  7008. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7009. /// 01aa <id>.L <data>.L
  7010. /// data:
  7011. /// @see CZ_PET_ACT.
  7012. void clif_pet_emotion(struct pet_data *pd,int param)
  7013. {
  7014. unsigned char buf[16];
  7015. nullpo_retv(pd);
  7016. memset(buf,0,packet_len(0x1aa));
  7017. WBUFW(buf,0)=0x1aa;
  7018. WBUFL(buf,2)=pd->bl.id;
  7019. WBUFL(buf,6)=param;
  7020. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7021. }
  7022. /// Result of request to feed a pet (ZC_FEED_PET).
  7023. /// 01a3 <result>.B <name id>.W
  7024. /// result:
  7025. /// 0 = failure
  7026. /// 1 = success
  7027. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  7028. nullpo_retv( sd );
  7029. struct PACKET_ZC_FEED_PET p;
  7030. p.packetType = 0x1a3;
  7031. p.result = fail;
  7032. p.itemId = client_nameid( foodid );
  7033. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7034. }
  7035. /// Send pet auto feed info.
  7036. void clif_pet_autofeed_status(struct map_session_data* sd, bool force) {
  7037. #if PACKETVER >= 20141008
  7038. nullpo_retv(sd);
  7039. if (force || battle_config.pet_autofeed_always) {
  7040. // Always send ON or OFF
  7041. if (sd->pd && battle_config.feature_pet_autofeed) {
  7042. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7043. }
  7044. else {
  7045. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7046. }
  7047. }
  7048. else {
  7049. // Only send when enabled
  7050. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7051. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7052. }
  7053. }
  7054. #endif
  7055. }
  7056. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7057. /// 01cd { <skill id>.L }*7
  7058. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  7059. {
  7060. nullpo_retv(sd);
  7061. int fd = sd->fd;
  7062. #ifdef RENEWAL
  7063. uint16 autospell_skill[][2] = {
  7064. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7065. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7066. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7067. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7068. };
  7069. int count = 0;
  7070. WFIFOHEAD(fd, 2 * 6 + 4);
  7071. WFIFOW(fd, 0) = 0x442;
  7072. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7073. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7074. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7075. count++;
  7076. }
  7077. }
  7078. WFIFOW(fd, 2) = 8 + count * 2;
  7079. WFIFOL(fd, 4) = count;
  7080. WFIFOSET(fd, WFIFOW(fd, 2));
  7081. #else
  7082. WFIFOHEAD(fd,packet_len(0x1cd));
  7083. WFIFOW(fd, 0)=0x1cd;
  7084. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7085. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7086. else
  7087. WFIFOL(fd,2)= 0x00000000;
  7088. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7089. WFIFOL(fd,6)= MG_COLDBOLT;
  7090. else
  7091. WFIFOL(fd,6)= 0x00000000;
  7092. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7093. WFIFOL(fd,10)= MG_FIREBOLT;
  7094. else
  7095. WFIFOL(fd,10)= 0x00000000;
  7096. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7097. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7098. else
  7099. WFIFOL(fd,14)= 0x00000000;
  7100. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7101. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7102. else
  7103. WFIFOL(fd,18)= 0x00000000;
  7104. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7105. WFIFOL(fd,22)= MG_FIREBALL;
  7106. else
  7107. WFIFOL(fd,22)= 0x00000000;
  7108. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7109. WFIFOL(fd,26)= MG_FROSTDIVER;
  7110. else
  7111. WFIFOL(fd,26)= 0x00000000;
  7112. WFIFOSET(fd,packet_len(0x1cd));
  7113. #endif
  7114. sd->menuskill_id = SA_AUTOSPELL;
  7115. sd->menuskill_val = skill_lv;
  7116. }
  7117. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7118. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7119. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7120. {
  7121. unsigned char buf[56];
  7122. nullpo_retv(src);
  7123. memset(buf,0,packet_len(0x1cf));
  7124. WBUFW(buf,0) = 0x1cf;
  7125. WBUFL(buf,2) = src->id;
  7126. if( src->type == BL_MER )
  7127. {
  7128. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7129. if( md && md->master && md->devotion_flag )
  7130. WBUFL(buf,6) = md->master->bl.id;
  7131. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7132. }
  7133. else
  7134. {
  7135. int i;
  7136. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7137. if( sd == NULL )
  7138. return;
  7139. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7140. WBUFL(buf,6+4*i) = sd->devotion[i];
  7141. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7142. }
  7143. if( tsd )
  7144. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7145. else
  7146. clif_send(buf, packet_len(0x1cf), src, AREA);
  7147. }
  7148. /// Notifies the client of an object's spirits.
  7149. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7150. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7151. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7152. nullpo_retv( bl );
  7153. struct PACKET_ZC_SPIRITS p = {};
  7154. p.PacketType = HEADER_ZC_SPIRITS;
  7155. p.AID = bl->id;
  7156. switch( bl->type ){
  7157. case BL_PC:
  7158. p.num = ( (struct map_session_data*)bl )->spiritball;
  7159. break;
  7160. case BL_HOM:
  7161. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7162. break;
  7163. }
  7164. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7165. }
  7166. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7167. /// 01d2 <account id>.L <delay>.L
  7168. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7169. {
  7170. unsigned char buf[32];
  7171. nullpo_retv(bl);
  7172. WBUFW(buf,0)=0x1d2;
  7173. WBUFL(buf,2)=bl->id;
  7174. WBUFL(buf,6)=client_tick(wait);
  7175. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7176. }
  7177. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7178. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7179. /// flag:
  7180. /// 0 = inactive
  7181. /// 1 = active
  7182. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7183. {
  7184. unsigned char buf[32];
  7185. nullpo_retv(src);
  7186. WBUFW(buf,0)=0x1d1;
  7187. WBUFL(buf,2)=src->id;
  7188. WBUFL(buf,6)=dst_id;
  7189. WBUFL(buf,10)=active;
  7190. clif_send(buf,packet_len(0x1d1),src,AREA);
  7191. }
  7192. /// MVP effect (ZC_MVP).
  7193. /// 010c <account id>.L
  7194. void clif_mvp_effect(struct map_session_data *sd)
  7195. {
  7196. unsigned char buf[16];
  7197. nullpo_retv(sd);
  7198. WBUFW(buf,0)=0x10c;
  7199. WBUFL(buf,2)=sd->bl.id;
  7200. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7201. }
  7202. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7203. /// 010a <name id>.W
  7204. void clif_mvp_item( struct map_session_data *sd, t_itemid nameid ){
  7205. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7206. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7207. p.itemId = client_nameid( nameid );
  7208. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7209. }
  7210. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7211. /// 010b <exp>.L
  7212. void clif_mvp_exp(struct map_session_data *sd, t_exp exp) {
  7213. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7214. if (battle_config.mvp_exp_reward_message) {
  7215. char e_msg[CHAT_SIZE_MAX];
  7216. sprintf(e_msg, msg_txt(sd, 717), exp);
  7217. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7218. }
  7219. #else
  7220. int fd;
  7221. nullpo_retv(sd);
  7222. fd = sd->fd;
  7223. WFIFOHEAD(fd, packet_len(0x10b));
  7224. WFIFOW(fd,0) = 0x10b;
  7225. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7226. WFIFOSET(fd, packet_len(0x10b));
  7227. #endif
  7228. }
  7229. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7230. /// 010d
  7231. ///
  7232. /// "You are the MVP, but cannot obtain the reward because
  7233. /// you are overweight."
  7234. void clif_mvp_noitem(struct map_session_data* sd)
  7235. {
  7236. int fd = sd->fd;
  7237. WFIFOHEAD(fd,packet_len(0x10d));
  7238. WFIFOW(fd,0) = 0x10d;
  7239. WFIFOSET(fd,packet_len(0x10d));
  7240. }
  7241. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7242. /// 0167 <result>.B
  7243. /// result:
  7244. /// 0 = "Guild has been created."
  7245. /// 1 = "You are already in a Guild."
  7246. /// 2 = "That Guild Name already exists."
  7247. /// 3 = "You need the neccessary item to create a Guild."
  7248. void clif_guild_created(struct map_session_data *sd,int flag)
  7249. {
  7250. int fd;
  7251. nullpo_retv(sd);
  7252. fd=sd->fd;
  7253. WFIFOHEAD(fd,packet_len(0x167));
  7254. WFIFOW(fd,0)=0x167;
  7255. WFIFOB(fd,2)=flag;
  7256. WFIFOSET(fd,packet_len(0x167));
  7257. }
  7258. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7259. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7260. /// mode:
  7261. /// &0x01 = allow invite
  7262. /// &0x10 = allow expel
  7263. void clif_guild_belonginfo( struct map_session_data& sd ){
  7264. if( sd.guild == nullptr ){
  7265. return;
  7266. }
  7267. struct guild& guild = *sd.guild;
  7268. int position = guild_getposition( &sd );
  7269. if( position < 0 ){
  7270. return;
  7271. }
  7272. struct PACKET_ZC_UPDATE_GDID p = {};
  7273. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7274. p.guildId = guild.guild_id;
  7275. p.emblemVersion = guild.emblem_id;
  7276. p.mode = guild.position[position].mode;
  7277. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7278. p.interSid = 0; // InterSID (unknown purpose)
  7279. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7280. #if PACKETVER_MAIN_NUM >= 20220216
  7281. p.masterGID = guild.member[0].char_id;
  7282. #endif
  7283. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7284. }
  7285. /// Guild member login notice.
  7286. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7287. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7288. /// status:
  7289. /// 0 = offline
  7290. /// 1 = online
  7291. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7292. {
  7293. unsigned char buf[64];
  7294. struct map_session_data* sd;
  7295. nullpo_retv(g);
  7296. WBUFW(buf, 0)=0x1f2;
  7297. WBUFL(buf, 2)=g->member[idx].account_id;
  7298. WBUFL(buf, 6)=g->member[idx].char_id;
  7299. WBUFL(buf,10)=flag;
  7300. if( ( sd = g->member[idx].sd ) != NULL )
  7301. {
  7302. WBUFW(buf,14) = sd->status.sex;
  7303. WBUFW(buf,16) = sd->status.hair;
  7304. WBUFW(buf,18) = sd->status.hair_color;
  7305. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7306. }
  7307. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7308. {
  7309. WBUFW(buf,14) = 0;
  7310. WBUFW(buf,16) = 0;
  7311. WBUFW(buf,18) = 0;
  7312. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7313. }
  7314. }
  7315. // Function `clif_guild_memberlogin_notice` sends info about
  7316. // logins and logouts of a guild member to the rest members.
  7317. // But at the 1st time (after a player login or map changing)
  7318. // the client won't show the message.
  7319. // So I suggest use this function for sending "first-time-info"
  7320. // to some player on entering the game or changing location.
  7321. // At next time the client would always show the message.
  7322. // The function sends all the statuses in the single packet
  7323. // to economize traffic. [LuzZza]
  7324. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7325. {
  7326. struct guild *g;
  7327. unsigned char buf[14*128];
  7328. int i, count=0, p_len;
  7329. nullpo_retv(sd);
  7330. p_len = packet_len(0x16d);
  7331. if(!(g = sd->guild))
  7332. return;
  7333. for(i=0; i<g->max_member; i++) {
  7334. if(g->member[i].account_id > 0 &&
  7335. g->member[i].account_id != sd->status.account_id) {
  7336. WBUFW(buf,count*p_len) = 0x16d;
  7337. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7338. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7339. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7340. count++;
  7341. }
  7342. }
  7343. clif_send(buf, p_len*count, &sd->bl, SELF);
  7344. }
  7345. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7346. /// 014e <menu flag>.L
  7347. /// menu flag:
  7348. /// 0x00 = Basic Info (always on)
  7349. /// &0x01 = Member manager
  7350. /// &0x02 = Positions
  7351. /// &0x04 = Skills
  7352. /// &0x10 = Expulsion list
  7353. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7354. /// &0x80 = Notice
  7355. void clif_guild_masterormember(struct map_session_data *sd)
  7356. {
  7357. int fd;
  7358. nullpo_retv(sd);
  7359. fd=sd->fd;
  7360. WFIFOHEAD(fd,packet_len(0x14e));
  7361. WFIFOW(fd,0) = 0x14e;
  7362. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7363. WFIFOSET(fd,packet_len(0x14e));
  7364. }
  7365. /// Guild basic information (Territories [Valaris])
  7366. /// 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)
  7367. /// 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)
  7368. /// 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)
  7369. void clif_guild_basicinfo( struct map_session_data& sd ){
  7370. if( sd.guild == nullptr ){
  7371. return;
  7372. }
  7373. struct guild& guild = *sd.guild;
  7374. struct PACKET_ZC_GUILD_INFO p = {};
  7375. p.PacketType = HEADER_ZC_GUILD_INFO;
  7376. p.GDID = guild.guild_id;
  7377. p.level = guild.guild_lv;
  7378. p.userNum = guild.connect_member;
  7379. p.maxUserNum = guild.max_member;
  7380. p.userAverageLevel = guild.average_lv;
  7381. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7382. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7383. p.point = 0; // Tax Points
  7384. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7385. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7386. p.emblemVersion = guild.emblem_id;
  7387. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7388. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( &guild ) ), sizeof( p.manageLand ) );
  7389. p.zeny = 0;
  7390. #if PACKETVER >= 20200902
  7391. p.masterGID = guild.member[0].char_id; // leader
  7392. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7393. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7394. p.masterGID = guild.member[0].char_id; // leader
  7395. #else
  7396. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7397. #endif
  7398. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7399. }
  7400. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7401. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7402. void clif_guild_allianceinfo(struct map_session_data *sd)
  7403. {
  7404. int fd,i,c;
  7405. struct guild *g;
  7406. nullpo_retv(sd);
  7407. if( (g = sd->guild) == NULL )
  7408. return;
  7409. fd = sd->fd;
  7410. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7411. WFIFOW(fd, 0)=0x14c;
  7412. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7413. struct guild_alliance *a=&g->alliance[i];
  7414. if(a->guild_id>0){
  7415. WFIFOL(fd,c*32+4)=a->opposition;
  7416. WFIFOL(fd,c*32+8)=a->guild_id;
  7417. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7418. c++;
  7419. }
  7420. }
  7421. WFIFOW(fd, 2)=c*32+4;
  7422. WFIFOSET(fd,WFIFOW(fd,2));
  7423. }
  7424. /// Guild member manager information
  7425. /// 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)
  7426. /// state:
  7427. /// 0 = offline
  7428. /// 1 = online
  7429. /// memo:
  7430. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7431. /// 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)
  7432. void clif_guild_memberlist( struct map_session_data& sd ){
  7433. if( sd.guild == nullptr ){
  7434. return;
  7435. }
  7436. struct guild& guild = *sd.guild;
  7437. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7438. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7439. p->packetLength = sizeof( *p );
  7440. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7441. struct guild_member& member = guild.member[i];
  7442. if( member.account_id == 0 ){
  7443. continue;
  7444. }
  7445. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7446. member_info.AID = member.account_id;
  7447. member_info.GID = member.char_id;
  7448. member_info.head = member.hair;
  7449. member_info.headPalette = member.hair_color;
  7450. member_info.sex = member.gender;
  7451. member_info.job = member.class_;
  7452. member_info.level = member.lv;
  7453. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7454. member_info.currentState = member.online;
  7455. member_info.positionID = member.position;
  7456. #if PACKETVER >= 20200902
  7457. member_info.lastLoginTime = member.last_login;
  7458. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7459. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7460. member_info.lastLoginTime = member.last_login;
  7461. #else
  7462. memset( member_info.intro, 0, sizeof( member_info.intro ) ); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  7463. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7464. #endif
  7465. c++;
  7466. p->packetLength += sizeof( member_info );
  7467. }
  7468. clif_send( p, p->packetLength, &sd.bl, SELF );
  7469. }
  7470. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7471. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7472. void clif_guild_positionnamelist(struct map_session_data *sd)
  7473. {
  7474. int i,fd;
  7475. struct guild *g;
  7476. nullpo_retv(sd);
  7477. if( (g = sd->guild) == NULL )
  7478. return;
  7479. fd = sd->fd;
  7480. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7481. WFIFOW(fd, 0)=0x166;
  7482. for(i=0;i<MAX_GUILDPOSITION;i++){
  7483. WFIFOL(fd,i*28+4)=i;
  7484. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7485. }
  7486. WFIFOW(fd,2)=i*28+4;
  7487. WFIFOSET(fd,WFIFOW(fd,2));
  7488. }
  7489. /// Guild position information (ZC_POSITION_INFO).
  7490. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7491. /// mode:
  7492. /// &0x01 = allow invite
  7493. /// &0x10 = allow expel
  7494. /// ranking:
  7495. /// TODO
  7496. void clif_guild_positioninfolist(struct map_session_data *sd)
  7497. {
  7498. int i,fd;
  7499. struct guild *g;
  7500. nullpo_retv(sd);
  7501. if( (g = sd->guild) == NULL )
  7502. return;
  7503. fd = sd->fd;
  7504. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7505. WFIFOW(fd, 0)=0x160;
  7506. for(i=0;i<MAX_GUILDPOSITION;i++){
  7507. struct guild_position *p=&g->position[i];
  7508. WFIFOL(fd,i*16+ 4)=i;
  7509. WFIFOL(fd,i*16+ 8)=p->mode;
  7510. WFIFOL(fd,i*16+12)=i;
  7511. WFIFOL(fd,i*16+16)=p->exp_mode;
  7512. }
  7513. WFIFOW(fd, 2)=i*16+4;
  7514. WFIFOSET(fd,WFIFOW(fd,2));
  7515. }
  7516. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7517. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7518. /// mode:
  7519. /// &0x01 = allow invite
  7520. /// &0x10 = allow expel
  7521. /// ranking:
  7522. /// TODO
  7523. void clif_guild_positionchanged(struct guild *g,int idx)
  7524. {
  7525. // FIXME: This packet is intended to update the clients after a
  7526. // commit of position info changes, not sending one packet per
  7527. // position.
  7528. struct map_session_data *sd;
  7529. unsigned char buf[128];
  7530. nullpo_retv(g);
  7531. WBUFW(buf, 0)=0x174;
  7532. WBUFW(buf, 2)=44; // packet len
  7533. // GUILD_REG_POSITION_INFO{
  7534. WBUFL(buf, 4)=idx;
  7535. WBUFL(buf, 8)=g->position[idx].mode;
  7536. WBUFL(buf,12)=idx;
  7537. WBUFL(buf,16)=g->position[idx].exp_mode;
  7538. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7539. // }*
  7540. if( (sd=guild_getavailablesd(g))!=NULL )
  7541. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7542. }
  7543. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7544. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7545. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7546. {
  7547. // FIXME: This packet is intended to update the clients after a
  7548. // commit of member position assignment changes, not sending one
  7549. // packet per position.
  7550. struct map_session_data *sd;
  7551. unsigned char buf[64];
  7552. nullpo_retv(g);
  7553. WBUFW(buf, 0)=0x156;
  7554. WBUFW(buf, 2)=16; // packet len
  7555. // MEMBER_POSITION_INFO{
  7556. WBUFL(buf, 4)=g->member[idx].account_id;
  7557. WBUFL(buf, 8)=g->member[idx].char_id;
  7558. WBUFL(buf,12)=g->member[idx].position;
  7559. // }*
  7560. if( (sd=guild_getavailablesd(g))!=NULL )
  7561. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7562. }
  7563. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7564. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7565. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7566. {
  7567. int fd;
  7568. nullpo_retv(sd);
  7569. nullpo_retv(g);
  7570. fd = sd->fd;
  7571. if( g->emblem_len <= 0 )
  7572. return;
  7573. WFIFOHEAD(fd,g->emblem_len+12);
  7574. WFIFOW(fd,0)=0x152;
  7575. WFIFOW(fd,2)=g->emblem_len+12;
  7576. WFIFOL(fd,4)=g->guild_id;
  7577. WFIFOL(fd,8)=g->emblem_id;
  7578. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7579. WFIFOSET(fd,WFIFOW(fd,2));
  7580. }
  7581. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7582. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7583. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7584. void clif_guild_emblem_area(struct block_list* bl)
  7585. {
  7586. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7587. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7588. PACKET_ZC_CHANGE_GUILD p{};
  7589. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7590. p.guild_id = status_get_guild_id(bl);
  7591. p.emblem_id = status_get_emblem_id(bl);
  7592. #if PACKETVER < 20190724
  7593. p.aid = bl->id;
  7594. #else
  7595. p.unknown = 0;
  7596. #endif
  7597. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7598. }
  7599. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7600. /// 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 }*
  7601. void clif_guild_skillinfo(struct map_session_data* sd)
  7602. {
  7603. int fd;
  7604. struct guild* g;
  7605. int i,c;
  7606. nullpo_retv(sd);
  7607. if( (g = sd->guild) == NULL )
  7608. return;
  7609. fd = sd->fd;
  7610. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7611. WFIFOW(fd,0) = 0x0162;
  7612. WFIFOW(fd,4) = g->skill_point;
  7613. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7614. {
  7615. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7616. {
  7617. int id = g->skill[i].id;
  7618. int p = 6 + c*37;
  7619. WFIFOW(fd,p+0) = id;
  7620. WFIFOL(fd,p+2) = skill_get_inf(id);
  7621. WFIFOW(fd,p+6) = g->skill[i].lv;
  7622. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7623. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7624. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7625. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7626. c++;
  7627. }
  7628. }
  7629. WFIFOW(fd,2) = 6 + c*37;
  7630. WFIFOSET(fd,WFIFOW(fd,2));
  7631. }
  7632. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7633. /// 016f <subject>.60B <notice>.120B
  7634. void clif_guild_notice(struct map_session_data* sd)
  7635. {
  7636. struct guild* g;
  7637. nullpo_retv(sd);
  7638. nullpo_retv(g = sd->guild);
  7639. int fd = sd->fd;
  7640. if ( !session_isActive(fd) )
  7641. return;
  7642. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7643. return;
  7644. WFIFOHEAD(fd,packet_len(0x16f));
  7645. WFIFOW(fd,0) = 0x16f;
  7646. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7647. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7648. WFIFOSET(fd,packet_len(0x16f));
  7649. }
  7650. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7651. /// 016a <guild id>.L <guild name>.24B
  7652. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7653. {
  7654. int fd;
  7655. nullpo_retv(sd);
  7656. nullpo_retv(g);
  7657. fd=sd->fd;
  7658. WFIFOHEAD(fd,packet_len(0x16a));
  7659. WFIFOW(fd,0)=0x16a;
  7660. WFIFOL(fd,2)=g->guild_id;
  7661. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7662. WFIFOSET(fd,packet_len(0x16a));
  7663. }
  7664. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7665. /// 0169 <answer>.B
  7666. /// answer:
  7667. /// 0 = Already in guild.
  7668. /// 1 = Offer rejected.
  7669. /// 2 = Offer accepted.
  7670. /// 3 = Guild full.
  7671. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7672. {
  7673. int fd;
  7674. nullpo_retv(sd);
  7675. fd=sd->fd;
  7676. WFIFOHEAD(fd,packet_len(0x169));
  7677. WFIFOW(fd,0)=0x169;
  7678. WFIFOB(fd,2)=flag;
  7679. WFIFOSET(fd,packet_len(0x169));
  7680. }
  7681. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7682. /// 015a <char name>.24B <reason>.40B
  7683. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7684. {
  7685. unsigned char buf[128];
  7686. nullpo_retv(sd);
  7687. WBUFW(buf, 0)=0x15a;
  7688. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7689. memcpy(WBUFP(buf,26),mes,40);
  7690. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7691. }
  7692. /// Notifies clients of a guild of an expelled member.
  7693. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7694. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7695. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7696. {
  7697. unsigned char buf[128];
  7698. #if PACKETVER < 20100803
  7699. const unsigned short cmd = 0x15c;
  7700. #else
  7701. const unsigned short cmd = 0x839;
  7702. #endif
  7703. nullpo_retv(sd);
  7704. WBUFW(buf,0) = cmd;
  7705. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7706. safestrncpy(WBUFCP(buf,26), mes, 40);
  7707. #if PACKETVER < 20100803
  7708. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7709. #endif
  7710. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7711. }
  7712. /// Guild expulsion list (ZC_BAN_LIST).
  7713. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7714. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7715. void clif_guild_expulsionlist(struct map_session_data* sd)
  7716. {
  7717. #if PACKETVER < 20100803
  7718. const int offset = NAME_LENGTH*2+40;
  7719. #else
  7720. const int offset = NAME_LENGTH+40;
  7721. #endif
  7722. int fd, i, c = 0;
  7723. struct guild* g;
  7724. nullpo_retv(sd);
  7725. if( (g = sd->guild) == NULL )
  7726. return;
  7727. fd = sd->fd;
  7728. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7729. WFIFOW(fd,0) = 0x163;
  7730. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7731. {
  7732. struct guild_expulsion* e = &g->expulsion[i];
  7733. if( e->account_id > 0 )
  7734. {
  7735. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7736. #if PACKETVER < 20100803
  7737. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7738. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7739. #else
  7740. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7741. #endif
  7742. c++;
  7743. }
  7744. }
  7745. WFIFOW(fd,2) = 4 + c*offset;
  7746. WFIFOSET(fd,WFIFOW(fd,2));
  7747. }
  7748. /// Guild chat message (ZC_GUILD_CHAT).
  7749. /// 017f <packet len>.W <message>.?B
  7750. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7751. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7752. struct map_session_data *sd;
  7753. uint8 buf[256];
  7754. if( len == 0 )
  7755. {
  7756. return;
  7757. }
  7758. else if( len > sizeof(buf)-5 )
  7759. {
  7760. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7761. len = sizeof(buf)-5;
  7762. }
  7763. WBUFW(buf, 0) = 0x17f;
  7764. WBUFW(buf, 2) = len + 5;
  7765. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7766. if ((sd = guild_getavailablesd(g)) != NULL)
  7767. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7768. }
  7769. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7770. /// 0171 <inviter account id>.L <guild name>.24B
  7771. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7772. {
  7773. int fd;
  7774. nullpo_retv(sd);
  7775. fd=sd->fd;
  7776. WFIFOHEAD(fd,packet_len(0x171));
  7777. WFIFOW(fd,0)=0x171;
  7778. WFIFOL(fd,2)=account_id;
  7779. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7780. WFIFOSET(fd,packet_len(0x171));
  7781. }
  7782. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7783. /// 0173 <answer>.B
  7784. /// answer:
  7785. /// 0 = Already allied.
  7786. /// 1 = You rejected the offer.
  7787. /// 2 = You accepted the offer.
  7788. /// 3 = They have too any alliances.
  7789. /// 4 = You have too many alliances.
  7790. /// 5 = Alliances are disabled.
  7791. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7792. {
  7793. int fd;
  7794. nullpo_retv(sd);
  7795. fd=sd->fd;
  7796. WFIFOHEAD(fd,packet_len(0x173));
  7797. WFIFOW(fd,0)=0x173;
  7798. WFIFOL(fd,2)=flag;
  7799. WFIFOSET(fd,packet_len(0x173));
  7800. }
  7801. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7802. /// 0184 <other guild id>.L <relation>.L
  7803. /// relation:
  7804. /// 0 = Ally
  7805. /// 1 = Enemy
  7806. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7807. {
  7808. nullpo_retv(sd);
  7809. int fd = sd->fd;
  7810. if ( !session_isActive(fd) )
  7811. return;
  7812. WFIFOHEAD(fd,packet_len(0x184));
  7813. WFIFOW(fd,0)=0x184;
  7814. WFIFOL(fd,2)=guild_id;
  7815. WFIFOL(fd,6)=flag;
  7816. WFIFOSET(fd,packet_len(0x184));
  7817. }
  7818. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7819. /// 0181 <result>.B
  7820. /// result:
  7821. /// 0 = Antagonist has been set.
  7822. /// 1 = Guild has too many Antagonists.
  7823. /// 2 = Already set as an Antagonist.
  7824. /// 3 = Antagonists are disabled.
  7825. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7826. {
  7827. int fd;
  7828. nullpo_retv(sd);
  7829. fd=sd->fd;
  7830. WFIFOHEAD(fd,packet_len(0x181));
  7831. WFIFOW(fd,0)=0x181;
  7832. WFIFOB(fd,2)=flag;
  7833. WFIFOSET(fd,packet_len(0x181));
  7834. }
  7835. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7836. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7837. /*
  7838. void clif_guild_allianceadded(struct guild *g,int idx)
  7839. {
  7840. unsigned char buf[64];
  7841. WBUFW(buf,0)=0x185;
  7842. WBUFL(buf,2)=g->alliance[idx].opposition;
  7843. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7844. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7845. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7846. }
  7847. */
  7848. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7849. /// 015e <reason>.L
  7850. /// 0 = success
  7851. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7852. /// 2 = there are still members in the guild
  7853. void clif_guild_broken(struct map_session_data *sd,int flag)
  7854. {
  7855. int fd;
  7856. nullpo_retv(sd);
  7857. fd=sd->fd;
  7858. WFIFOHEAD(fd,packet_len(0x15e));
  7859. WFIFOW(fd,0)=0x15e;
  7860. WFIFOL(fd,2)=flag;
  7861. WFIFOSET(fd,packet_len(0x15e));
  7862. }
  7863. /// Displays emotion on an object (ZC_EMOTION).
  7864. /// 00c0 <id>.L <type>.B
  7865. /// type:
  7866. /// enum emotion_type
  7867. void clif_emotion(struct block_list *bl,int type)
  7868. {
  7869. unsigned char buf[8];
  7870. nullpo_retv(bl);
  7871. WBUFW(buf,0)=0xc0;
  7872. WBUFL(buf,2)=bl->id;
  7873. WBUFB(buf,6)=type;
  7874. clif_send(buf,packet_len(0xc0),bl,AREA);
  7875. }
  7876. /// Displays the contents of a talkiebox trap.
  7877. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7878. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7879. nullpo_retv( bl );
  7880. nullpo_retv( talkie );
  7881. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7882. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7883. p.aid = bl->id;
  7884. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7885. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7886. }
  7887. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7888. /// 01ea <id>.L
  7889. void clif_wedding_effect(struct block_list *bl)
  7890. {
  7891. unsigned char buf[6];
  7892. nullpo_retv(bl);
  7893. WBUFW(buf,0) = 0x1ea;
  7894. WBUFL(buf,2) = bl->id;
  7895. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7896. }
  7897. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7898. /// 01e6 <partner name>.24B
  7899. void clif_callpartner(struct map_session_data& sd)
  7900. {
  7901. PACKET_ZC_COUPLENAME p = { 0 };
  7902. p.packetType = HEADER_ZC_COUPLENAME;
  7903. if( sd.status.partner_id ) {
  7904. struct map_session_data *p_sd = pc_get_partner(&sd);
  7905. if (p_sd != nullptr && !p_sd->state.autotrade)
  7906. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  7907. else
  7908. p.name[0] = 0;
  7909. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7910. p.name[0] = 0;
  7911. }
  7912. clif_send(&p, sizeof(p), &sd.bl, AREA);
  7913. }
  7914. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7915. /// 01e4
  7916. /// This packet while still implemented by the client is no longer being officially used.
  7917. /*
  7918. void clif_marriage_process(struct map_session_data *sd)
  7919. {
  7920. int fd;
  7921. nullpo_retv(sd);
  7922. fd=sd->fd;
  7923. WFIFOHEAD(fd,packet_len(0x1e4));
  7924. WFIFOW(fd,0)=0x1e4;
  7925. WFIFOSET(fd,packet_len(0x1e4));
  7926. }
  7927. */
  7928. /// Notice of divorce (ZC_DIVORCE).
  7929. /// 0205 <partner name>.24B
  7930. void clif_divorced(struct map_session_data* sd, const char* name)
  7931. {
  7932. int fd;
  7933. nullpo_retv(sd);
  7934. fd=sd->fd;
  7935. WFIFOHEAD(fd,packet_len(0x205));
  7936. WFIFOW(fd,0)=0x205;
  7937. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7938. WFIFOSET(fd, packet_len(0x205));
  7939. }
  7940. /// Marriage proposal (ZC_REQ_COUPLE).
  7941. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7942. /// This packet while still implemented by the client is no longer being officially used.
  7943. /*
  7944. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7945. {
  7946. nullpo_retv(sd);
  7947. WFIFOHEAD(fd,packet_len(0x1e2));
  7948. WFIFOW(fd,0) = 0x1e2;
  7949. WFIFOL(fd,2) = ssd->status.account_id;
  7950. WFIFOL(fd,6) = ssd->status.char_id;
  7951. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7952. WFIFOSET(fd, packet_len(0x1e2));
  7953. }
  7954. */
  7955. /*==========================================
  7956. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7957. *------------------------------------------*/
  7958. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7959. {
  7960. unsigned char buf[256];
  7961. if( len == 0 ) {
  7962. return;
  7963. } else if( len > sizeof(buf)-5 ) {
  7964. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7965. len = sizeof(buf)-5;
  7966. }
  7967. WBUFW(buf, 0) = 0x17f;
  7968. WBUFW(buf, 2) = len + 5;
  7969. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7970. clif_send(buf, WBUFW(buf,2), src, target);
  7971. }
  7972. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7973. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7974. /// 00cd <result>.B
  7975. /// result:
  7976. /// 0 = failure
  7977. /// 1 = success
  7978. void clif_GM_kickack(struct map_session_data *sd, int id)
  7979. {
  7980. int fd;
  7981. nullpo_retv(sd);
  7982. fd = sd->fd;
  7983. WFIFOHEAD(fd,packet_len(0xcd));
  7984. WFIFOW(fd,0) = 0xcd;
  7985. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7986. WFIFOSET(fd, packet_len(0xcd));
  7987. }
  7988. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7989. {
  7990. nullpo_retv(tsd);
  7991. if (sd == NULL)
  7992. tsd->state.keepshop = true;
  7993. if (session_isActive(tsd->fd))
  7994. clif_authfail_fd(tsd->fd, 15);
  7995. else
  7996. map_quit(tsd);
  7997. if (sd)
  7998. clif_GM_kickack(sd, tsd->status.account_id);
  7999. }
  8000. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8001. /// 014a <result>.L
  8002. /// result:
  8003. /// 0 = "A manner point has been successfully aligned."
  8004. /// 1 = MP_FAILURE_EXHAUST
  8005. /// 2 = MP_FAILURE_ALREADY_GIVING
  8006. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8007. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8008. /// 5 = "You got a good point from %s."
  8009. void clif_manner_message(struct map_session_data* sd, uint32 type)
  8010. {
  8011. int fd;
  8012. nullpo_retv(sd);
  8013. fd = sd->fd;
  8014. WFIFOHEAD(fd,packet_len(0x14a));
  8015. WFIFOW(fd,0) = 0x14a;
  8016. WFIFOL(fd,2) = type;
  8017. WFIFOSET(fd, packet_len(0x14a));
  8018. }
  8019. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8020. /// 014b <type>.B <GM name>.24B
  8021. /// type:
  8022. /// 0 = positive (unmute)
  8023. /// 1 = negative (mute)
  8024. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  8025. {
  8026. int fd;
  8027. nullpo_retv(sd);
  8028. nullpo_retv(tsd);
  8029. fd = tsd->fd;
  8030. WFIFOHEAD(fd,packet_len(0x14b));
  8031. WFIFOW(fd,0) = 0x14b;
  8032. WFIFOB(fd,2) = type;
  8033. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8034. WFIFOSET(fd, packet_len(0x14b));
  8035. }
  8036. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8037. /// 00d1 <type>.B <result>.B
  8038. /// type:
  8039. /// 0 = /ex (deny)
  8040. /// 1 = /in (allow)
  8041. /// result:
  8042. /// 0 = success
  8043. /// 1 = failure
  8044. /// 2 = too many blocks
  8045. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  8046. {
  8047. int fd;
  8048. nullpo_retv(sd);
  8049. fd=sd->fd;
  8050. WFIFOHEAD(fd,packet_len(0xd1));
  8051. WFIFOW(fd,0)=0xd1;
  8052. WFIFOB(fd,2)=type;
  8053. WFIFOB(fd,3)=flag;
  8054. WFIFOSET(fd,packet_len(0xd1));
  8055. }
  8056. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8057. /// 00d2 <type>.B <result>.B
  8058. /// type:
  8059. /// 0 = /exall (deny)
  8060. /// 1 = /inall (allow)
  8061. /// result:
  8062. /// 0 = success
  8063. /// 1 = failure
  8064. void clif_wisall(struct map_session_data *sd,int type,int flag)
  8065. {
  8066. int fd;
  8067. nullpo_retv(sd);
  8068. fd=sd->fd;
  8069. WFIFOHEAD(fd,packet_len(0xd2));
  8070. WFIFOW(fd,0)=0xd2;
  8071. WFIFOB(fd,2)=type;
  8072. WFIFOB(fd,3)=flag;
  8073. WFIFOSET(fd,packet_len(0xd2));
  8074. }
  8075. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8076. /// 07fe <bgm>.24B
  8077. void clif_playBGM( struct map_session_data& sd, const char* name ){
  8078. #if PACKETVER_MAIN_NUM >= 20220504
  8079. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8080. int16 length = (int16)( strlen( name ) + 1 );
  8081. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8082. p->PacketLength = sizeof( *p ) + length;
  8083. p->playType = 0; // TODO: implement, send loop for the time being
  8084. safestrncpy( p->bgm, name, length );
  8085. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8086. #elif PACKETVER >= 20091201
  8087. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8088. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8089. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8090. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8091. #endif
  8092. }
  8093. /// Plays/stops a wave sound (ZC_SOUND).
  8094. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8095. /// file name:
  8096. /// relative to data\wav
  8097. /// act:
  8098. /// 0 = play (once)
  8099. /// 1 = play (repeat, does not work)
  8100. /// 2 = stops all sound instances of file name (does not work)
  8101. /// term:
  8102. /// unknown purpose, only relevant to act = 1
  8103. /// npc id:
  8104. /// The accustic direction of the sound is determined by the
  8105. /// relative position of the NPC to the player (3D sound).
  8106. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8107. struct PACKET_ZC_SOUND p = {};
  8108. p.PacketType = HEADER_ZC_SOUND;
  8109. safestrncpy( p.name, name, sizeof( p.name ) );
  8110. p.act = type;
  8111. p.term = 0; // TODO: implement
  8112. p.AID = bl.id;
  8113. clif_send( &p, sizeof( p ), &bl, target );
  8114. }
  8115. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8116. /// 01f3 <id>.L <effect id>.L
  8117. /// effect id:
  8118. /// @see doc/effect_list.txt
  8119. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8120. {
  8121. unsigned char buf[24];
  8122. nullpo_retv(bl);
  8123. memset(buf, 0, packet_len(0x1f3));
  8124. WBUFW(buf,0) = 0x1f3;
  8125. WBUFL(buf,2) = bl->id;
  8126. WBUFL(buf,6) = type;
  8127. clif_send(buf, packet_len(0x1f3), bl, target);
  8128. if (disguised(bl)) {
  8129. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8130. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8131. }
  8132. }
  8133. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8134. {
  8135. WFIFOHEAD(fd,10);
  8136. WFIFOW(fd,0) = 0x1f3;
  8137. WFIFOL(fd,2) = bl->id;
  8138. WFIFOL(fd,6) = type;
  8139. WFIFOSET(fd,10);
  8140. }
  8141. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8142. /// 0284 <id>.L <effect id>.L <num data>.L
  8143. /// effect id:
  8144. /// @see doc/effect_list.txt
  8145. /// num data:
  8146. /// effect-dependent value
  8147. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8148. {
  8149. uint8 buf[14];
  8150. WBUFW(buf,0) = 0x284;
  8151. WBUFL(buf,2) = bl->id;
  8152. WBUFL(buf,6) = effect_id;
  8153. WBUFL(buf,10) = num;
  8154. clif_send(buf, packet_len(0x284), bl, target);
  8155. if( disguised(bl) )
  8156. {
  8157. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8158. clif_send(buf, packet_len(0x284), bl, SELF);
  8159. }
  8160. }
  8161. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8162. {
  8163. #if PACKETVER >= 20181002
  8164. nullpo_retv( bl_src );
  8165. nullpo_retv( bl_target );
  8166. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8167. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8168. p.aid = bl_src->id;
  8169. p.effectId = effect;
  8170. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8171. if( disguised(bl_src) )
  8172. {
  8173. p.aid = disguised_bl_id( bl_src->id );
  8174. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8175. }
  8176. #endif
  8177. }
  8178. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8179. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8180. 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) {
  8181. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8182. uint8 buf[CHAT_SIZE_MAX];
  8183. nullpo_retv(bl);
  8184. if (msg_len > sizeof(buf) - 12) {
  8185. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8186. msg_len = sizeof(buf) - 12;
  8187. }
  8188. if (rgb2bgr)
  8189. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8190. WBUFW(buf,0) = 0x2C1;
  8191. WBUFW(buf,2) = msg_len + 12;
  8192. WBUFL(buf,4) = bl->id;
  8193. WBUFL(buf,8) = color;
  8194. memcpy(WBUFCP(buf,12), msg, msg_len);
  8195. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8196. }
  8197. /**
  8198. * Notifies the client that the storage window is still open
  8199. *
  8200. * Should only be used in cases where the client closed the
  8201. * storage window without server's consent
  8202. */
  8203. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8204. // Notify the client that the storage is open
  8205. if( sd->state.storage_flag == 1 ) {
  8206. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8207. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8208. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8209. }
  8210. // Notify the client that the gstorage is open otherwise it will
  8211. // remain locked forever and nobody will be able to access it
  8212. if( sd->state.storage_flag == 2 ) {
  8213. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8214. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8215. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8216. else {
  8217. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8218. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8219. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8220. }
  8221. }
  8222. // Notify the client that the premium storage is open
  8223. if (sd->state.storage_flag == 3) {
  8224. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8225. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8226. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8227. }
  8228. }
  8229. // refresh the client's screen, getting rid of any effects
  8230. void clif_refresh(struct map_session_data *sd)
  8231. {
  8232. nullpo_retv(sd);
  8233. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8234. clif_inventorylist(sd);
  8235. clif_equipswitch_list(sd);
  8236. if(pc_iscarton(sd)) {
  8237. clif_cartlist(sd);
  8238. clif_updatestatus(sd,SP_CARTINFO);
  8239. }
  8240. clif_updatestatus(sd,SP_WEIGHT);
  8241. clif_updatestatus(sd,SP_MAXWEIGHT);
  8242. clif_updatestatus(sd,SP_STR);
  8243. clif_updatestatus(sd,SP_AGI);
  8244. clif_updatestatus(sd,SP_VIT);
  8245. clif_updatestatus(sd,SP_INT);
  8246. clif_updatestatus(sd,SP_DEX);
  8247. clif_updatestatus(sd,SP_LUK);
  8248. #ifdef RENEWAL
  8249. clif_updatestatus(sd,SP_POW);
  8250. clif_updatestatus(sd,SP_STA);
  8251. clif_updatestatus(sd,SP_WIS);
  8252. clif_updatestatus(sd,SP_SPL);
  8253. clif_updatestatus(sd,SP_CON);
  8254. clif_updatestatus(sd,SP_CRT);
  8255. #endif
  8256. if (sd->spiritball)
  8257. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8258. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  8259. clif_millenniumshield_single(sd->fd, sd);
  8260. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8261. clif_spiritcharm_single(sd->fd, sd);
  8262. if (sd->soulball)
  8263. clif_soulball( sd, &sd->bl, SELF );
  8264. if (sd->servantball)
  8265. clif_servantball( *sd, &sd->bl, SELF );
  8266. if (sd->abyssball)
  8267. clif_abyssball( *sd, &sd->bl, SELF );
  8268. if (sd->vd.cloth_color)
  8269. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8270. if (sd->vd.body_style)
  8271. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8272. if(hom_is_active(sd->hd))
  8273. clif_send_homdata(sd,SP_ACK,0);
  8274. if( sd->md ) {
  8275. clif_mercenary_info(sd);
  8276. clif_mercenary_skillblock(sd);
  8277. }
  8278. if( sd->ed )
  8279. clif_elemental_info(sd);
  8280. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8281. clif_weather_check(sd);
  8282. if( sd->chatID )
  8283. chat_leavechat(sd,0);
  8284. if( sd->state.vending )
  8285. clif_openvending(sd, sd->bl.id, sd->vending);
  8286. if( pc_issit(sd) )
  8287. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8288. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8289. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8290. else
  8291. clif_changed_dir(&sd->bl, SELF);
  8292. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8293. //Issue #2143
  8294. //Cancel Trading State
  8295. if (sd->state.trading)
  8296. trade_tradecancel(sd);
  8297. //Cancel Buying/Selling State
  8298. if (sd->state.buyingstore)
  8299. buyingstore_close(sd);
  8300. mail_clear(sd);
  8301. clif_loadConfirm( sd );
  8302. if( disguised(&sd->bl) ) {/* refresh-da */
  8303. short disguise = sd->disguise;
  8304. pc_disguise(sd, 0);
  8305. pc_disguise(sd, disguise);
  8306. }
  8307. clif_refresh_storagewindow(sd);
  8308. }
  8309. /// Updates the object's (bl) name on client.
  8310. /// Used to update when a char leaves a party/guild. [Skotlex]
  8311. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8312. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8313. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8314. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8315. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8316. nullpo_retv( src );
  8317. nullpo_retv( bl );
  8318. switch( bl->type ){
  8319. case BL_PC: {
  8320. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8321. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8322. packet.gid = bl->id;
  8323. map_session_data *sd = (map_session_data *)bl;
  8324. //Requesting your own "shadow" name. [Skotlex]
  8325. if( src == bl && target == SELF && sd->disguise ){
  8326. packet.gid = -bl->id;
  8327. }
  8328. if( sd->fakename[0] ) {
  8329. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8330. clif_send( &packet, sizeof(packet), src, target );
  8331. return;
  8332. }
  8333. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8334. party_data *p = nullptr;
  8335. if( sd->status.party_id ){
  8336. p = party_search( sd->status.party_id );
  8337. }
  8338. // do not display party unless the player is also in a guild
  8339. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8340. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8341. }
  8342. if( sd->guild ){
  8343. int position;
  8344. // Will get the position of the guild the player is in
  8345. position = guild_getposition( sd );
  8346. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8347. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8348. }else if( sd->clan ){
  8349. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8350. }
  8351. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8352. packet.title_id = sd->status.title_id; // Title ID
  8353. #endif
  8354. clif_send(&packet, sizeof(packet), src, target);
  8355. }
  8356. break;
  8357. //[blackhole89]
  8358. case BL_HOM:
  8359. case BL_MER:
  8360. case BL_PET:
  8361. case BL_NPC:
  8362. case BL_ELEM: {
  8363. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8364. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8365. packet.gid = bl->id;
  8366. switch (bl->type) {
  8367. case BL_HOM:
  8368. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8369. break;
  8370. case BL_MER:
  8371. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8372. break;
  8373. case BL_PET:
  8374. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8375. break;
  8376. case BL_NPC:
  8377. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8378. break;
  8379. case BL_ELEM:
  8380. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8381. break;
  8382. }
  8383. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8384. unit_data *ud = unit_bl2ud(bl);
  8385. if (ud != nullptr) {
  8386. memcpy(packet.title, ud->title, NAME_LENGTH);
  8387. packet.groupId = ud->group_id;
  8388. }
  8389. #endif
  8390. clif_send(&packet, sizeof(packet), src, target);
  8391. }
  8392. break;
  8393. case BL_MOB: {
  8394. mob_data *md = (mob_data *)bl;
  8395. if( md->guardian_data && md->guardian_data->guild_id ){
  8396. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8397. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8398. packet.gid = bl->id;
  8399. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8400. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8401. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8402. clif_send(&packet, sizeof(packet), src, target);
  8403. }else if( battle_config.show_mob_info ){
  8404. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8405. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8406. packet.gid = bl->id;
  8407. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8408. char mobhp[50], *str_p = mobhp;
  8409. if( battle_config.show_mob_info&4 ){
  8410. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8411. }
  8412. if( battle_config.show_mob_info&1 ){
  8413. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8414. }
  8415. if( battle_config.show_mob_info&2 ){
  8416. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8417. }
  8418. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8419. if( str_p != mobhp ){
  8420. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8421. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8422. }
  8423. clif_send(&packet, sizeof(packet), src, target);
  8424. } else {
  8425. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8426. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8427. packet.gid = bl->id;
  8428. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8429. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8430. unit_data *ud = unit_bl2ud(bl);
  8431. if (ud != nullptr) {
  8432. memcpy(packet.title, ud->title, NAME_LENGTH);
  8433. packet.groupId = ud->group_id;
  8434. }
  8435. #endif
  8436. clif_send(&packet, sizeof(packet), src, target);
  8437. }
  8438. }
  8439. break;
  8440. case BL_CHAT:
  8441. case BL_SKILL:
  8442. // Newer clients request this, but do not need an answer
  8443. return;
  8444. default:
  8445. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8446. return;
  8447. }
  8448. }
  8449. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8450. /// 01ff <id>.L <x>.W <y>.W
  8451. ///
  8452. /// Visually moves(instant) a character to x,y. The char moves even
  8453. /// when the target cell isn't walkable. If the char is sitting it
  8454. /// stays that way.
  8455. void clif_slide(struct block_list *bl, int x, int y)
  8456. {
  8457. unsigned char buf[10];
  8458. nullpo_retv(bl);
  8459. WBUFW(buf, 0) = 0x01ff;
  8460. WBUFL(buf, 2) = bl->id;
  8461. WBUFW(buf, 6) = x;
  8462. WBUFW(buf, 8) = y;
  8463. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8464. if( disguised(bl) )
  8465. {
  8466. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8467. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8468. }
  8469. }
  8470. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8471. /// 008d <packet len>.W <id>.L <message>.?B
  8472. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8473. {
  8474. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8475. int len_mes = strlen(mes)+1; //Account for \0
  8476. if (len_mes > sizeof(buf)-8) {
  8477. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8478. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8479. }
  8480. // send message to others
  8481. if (flag == AREA) {
  8482. WBUFW(buf,0) = 0x8d;
  8483. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8484. WBUFL(buf,4) = bl->id;
  8485. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8486. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8487. }
  8488. // send back message to the speaker
  8489. if( bl->type == BL_PC ) {
  8490. WBUFW(buf,0) = 0x8e;
  8491. WBUFW(buf, 2) = len_mes + 4;
  8492. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8493. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8494. }
  8495. }
  8496. /*==========================
  8497. * Minimap fix [Kevin]
  8498. * Remove dot from minimap
  8499. *--------------------------*/
  8500. void clif_party_xy_remove(struct map_session_data* sd)
  8501. {
  8502. nullpo_retv(sd);
  8503. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8504. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8505. p.AID = sd->status.account_id;
  8506. p.xPos = -1;
  8507. p.yPos = -1;
  8508. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8509. }
  8510. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8511. /// 0215 <msg id>.L
  8512. /// msg id:
  8513. /// 0x15 = End all negative status (PA_GOSPEL)
  8514. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8515. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8516. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8517. /// 0x19 = All stats +20 (PA_GOSPEL)
  8518. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8519. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8520. /// 0x1e = DEF +25% (PA_GOSPEL)
  8521. /// 0x1f = ATK +100% (PA_GOSPEL)
  8522. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8523. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8524. /// ? = nothing
  8525. void clif_gospel_info(struct map_session_data *sd, int type)
  8526. {
  8527. int fd=sd->fd;
  8528. WFIFOHEAD(fd,packet_len(0x215));
  8529. WFIFOW(fd,0)=0x215;
  8530. WFIFOL(fd,2)=type;
  8531. WFIFOSET(fd, packet_len(0x215));
  8532. }
  8533. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8534. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8535. /// result:
  8536. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8537. /// star:
  8538. /// 0 = Place of the Sun
  8539. /// 1 = Place of the Moon
  8540. /// 2 = Place of the Stars
  8541. /// 1 = Star Gladiator %s's %s: <mapname>
  8542. /// star:
  8543. /// 0 = Place of the Sun
  8544. /// 1 = Place of the Moon
  8545. /// 2 = Place of the Stars
  8546. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8547. /// star:
  8548. /// 0 = Target of the Sun
  8549. /// 1 = Target of the Moon
  8550. /// 2 = Target of the Stars
  8551. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8552. /// star:
  8553. /// 0 = Monster of the Sun
  8554. /// 1 = Monster of the Moon
  8555. /// 2 = Monster of the Stars
  8556. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8557. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8558. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8559. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8560. /// 40 = Target HP : <monster_id used as HP>
  8561. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8562. {
  8563. int fd = sd->fd;
  8564. WFIFOHEAD(fd,packet_len(0x20e));
  8565. WFIFOW(fd,0) = 0x20e;
  8566. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8567. WFIFOL(fd,26) = monster_id;
  8568. WFIFOB(fd,30) = star;
  8569. WFIFOB(fd,31) = result;
  8570. WFIFOSET(fd,packet_len(0x20e));
  8571. }
  8572. /*==========================================
  8573. * Info about Star Glaldiator save map [Komurka]
  8574. * type: 1: Information, 0: Map registered
  8575. *------------------------------------------*/
  8576. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8577. {
  8578. char mapname[MAP_NAME_LENGTH_EXT];
  8579. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8580. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8581. }
  8582. /*==========================================
  8583. * Info about Star Glaldiator hate mob [Komurka]
  8584. * type: 1: Register mob, 0: Information.
  8585. *------------------------------------------*/
  8586. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8587. {
  8588. if( pcdb_checkid(class_) ) {
  8589. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8590. } else if( mobdb_checkid(class_) ) {
  8591. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8592. } else {
  8593. 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);
  8594. }
  8595. }
  8596. /*==========================================
  8597. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8598. *------------------------------------------*/
  8599. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8600. {
  8601. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8602. }
  8603. /*==========================================
  8604. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8605. *------------------------------------------*/
  8606. void clif_feel_hate_reset(struct map_session_data *sd)
  8607. {
  8608. clif_starskill(sd, "", 0, 0, 30);
  8609. }
  8610. /// Send out reply to configuration change
  8611. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8612. /// type: see enum e_config_type
  8613. /// value:
  8614. /// false = disabled
  8615. /// true = enabled
  8616. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8617. int fd;
  8618. nullpo_retv(sd);
  8619. fd = sd->fd;
  8620. WFIFOHEAD(fd, packet_len(0x2d9));
  8621. WFIFOW(fd, 0) = 0x2d9;
  8622. WFIFOL(fd, 2) = type;
  8623. WFIFOL(fd, 6) = enabled;
  8624. WFIFOSET(fd, packet_len(0x2d9));
  8625. }
  8626. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8627. /// 02da <open equip window>.B
  8628. /// open equip window:
  8629. /// 0 = disabled
  8630. /// 1 = enabled
  8631. void clif_equipcheckbox(struct map_session_data* sd)
  8632. {
  8633. int fd;
  8634. nullpo_retv(sd);
  8635. fd = sd->fd;
  8636. WFIFOHEAD(fd, packet_len(0x2da));
  8637. WFIFOW(fd, 0) = 0x2da;
  8638. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8639. WFIFOSET(fd, packet_len(0x2da));
  8640. }
  8641. /// Sends info about a player's equipped items.
  8642. /// 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)
  8643. /// 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)
  8644. /// 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)
  8645. /// 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)
  8646. /// 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)
  8647. /// 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)
  8648. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8649. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8650. nullpo_retv( sd );
  8651. nullpo_retv( tsd );
  8652. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8653. int equip = 0;
  8654. for( int i = 0; i < EQI_MAX; i++ ){
  8655. int k = tsd->equip_index[i];
  8656. if( k >= 0 ){
  8657. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8658. continue;
  8659. }
  8660. if( !tsd->inventory.u.items_inventory[k].equip ){
  8661. continue;
  8662. }
  8663. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8664. continue;
  8665. }
  8666. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8667. }
  8668. }
  8669. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8670. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8671. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8672. p->job = tsd->status.class_;
  8673. p->head = tsd->vd.hair_style;
  8674. p->accessory = tsd->vd.head_bottom;
  8675. p->accessory2 = tsd->vd.head_mid;
  8676. p->accessory3 = tsd->vd.head_top;
  8677. #if PACKETVER >= 20110111
  8678. p->robe = tsd->vd.robe;
  8679. #endif
  8680. p->headpalette = tsd->vd.hair_color;
  8681. p->bodypalette = tsd->vd.cloth_color;
  8682. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8683. p->body2 = tsd->vd.body_style;
  8684. #endif
  8685. p->sex = tsd->vd.sex;
  8686. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8687. #endif
  8688. }
  8689. /// Display msgstringtable.txt string (ZC_MSG).
  8690. /// 0291 <message>.W
  8691. void clif_msg(struct map_session_data* sd, unsigned short id)
  8692. {
  8693. int fd;
  8694. nullpo_retv(sd);
  8695. fd = sd->fd;
  8696. WFIFOHEAD(fd, packet_len(0x291));
  8697. WFIFOW(fd, 0) = 0x291;
  8698. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8699. WFIFOSET(fd, packet_len(0x291));
  8700. }
  8701. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8702. /// 0x7e2 <message>.W <value>.L
  8703. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8704. {
  8705. int fd = sd->fd;
  8706. WFIFOHEAD(fd, packet_len(0x7e2));
  8707. WFIFOW(fd,0) = 0x7e2;
  8708. WFIFOW(fd,2) = id;
  8709. WFIFOL(fd,4) = value;
  8710. WFIFOSET(fd, packet_len(0x7e2));
  8711. }
  8712. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8713. /// 07e6 <skill id>.W <msg id>.L
  8714. ///
  8715. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8716. /// "[SkillName] Message"
  8717. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8718. {
  8719. int fd = sd->fd;
  8720. WFIFOHEAD(fd, packet_len(0x7e6));
  8721. WFIFOW(fd,0) = 0x7e6;
  8722. WFIFOW(fd,2) = skill_id;
  8723. WFIFOL(fd,4) = msg_id;
  8724. WFIFOSET(fd, packet_len(0x7e6));
  8725. }
  8726. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8727. /// 09cd <msg id>.W <color>.L
  8728. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8729. nullpo_retv(sd);
  8730. int fd = sd->fd;
  8731. WFIFOHEAD(fd, packet_len(0x9cd));
  8732. WFIFOW(fd, 0) = 0x9cd;
  8733. WFIFOW(fd, 2) = msg_id;
  8734. WFIFOL(fd, 4) = color;
  8735. WFIFOSET(fd, packet_len(0x9cd));
  8736. }
  8737. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8738. /// Returns true if the packet was parsed successfully.
  8739. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8740. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8741. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8742. const char* seperator = " : ";
  8743. int fd;
  8744. struct s_packet_db* info;
  8745. uint16 packetLength, inputLength;
  8746. const char *input, *name, *message;
  8747. size_t nameLength, messageLength;
  8748. fd = sd->fd;
  8749. info = &packet_db[RFIFOW(fd,0)];
  8750. packetLength = RFIFOW(fd,info->pos[0]);
  8751. input = RFIFOCP(fd,info->pos[1]);
  8752. // basic structure check for the 4-byte header
  8753. if( packetLength < 4 ){
  8754. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8755. return false;
  8756. }else{
  8757. inputLength = packetLength - 4;
  8758. }
  8759. // process <name> part of the packet
  8760. if( whisperFormat ) {
  8761. // name has fixed width
  8762. if( inputLength < NAME_LENGTH + 1 ) {
  8763. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8764. return false;
  8765. }
  8766. name = input;
  8767. // validate name
  8768. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8769. // only restriction is that the name must be zero-terminated
  8770. if( name[nameLength] != '\0' ) {
  8771. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8772. return false;
  8773. }
  8774. message = input + NAME_LENGTH;
  8775. messageLength = inputLength - NAME_LENGTH;
  8776. }else{
  8777. // name and message are separated by ' : '
  8778. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8779. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8780. // check if there's enough data provided
  8781. if( inputLength < nameLength + seperatorLength + 1 ){
  8782. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8783. return false;
  8784. }
  8785. name = input;
  8786. // validate name
  8787. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8788. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8789. {
  8790. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8791. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8792. set_eof(sd->fd); // Just kick them out to correct it.
  8793. return false;
  8794. }
  8795. message = input + nameLength + seperatorLength;
  8796. messageLength = inputLength - nameLength - seperatorLength;
  8797. }
  8798. #if PACKETVER < 20151001
  8799. // the declared length must match real length
  8800. if( messageLength != strnlen(message, messageLength)+1 ) {
  8801. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8802. return false;
  8803. }
  8804. // verify <message> part of the packet
  8805. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8806. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8807. return false;
  8808. }
  8809. #else
  8810. // No zero termination anymore
  8811. messageLength += 1;
  8812. #endif
  8813. // messages mustn't be too long
  8814. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8815. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8816. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8817. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8818. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8819. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8820. return false;
  8821. }
  8822. // If it is not a whisper message, set the name to the fakename of the player
  8823. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8824. strcpy( out_name, sd->fakename );
  8825. }else{
  8826. safestrncpy( out_name, name, nameLength + 1 );
  8827. }
  8828. safestrncpy( out_message, message, messageLength );
  8829. if( whisperFormat ){
  8830. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8831. out_full_message[nameLength] = '\0';
  8832. }else{
  8833. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8834. }
  8835. if( is_atcommand( fd, sd, out_message, 1 ) )
  8836. return false;
  8837. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8838. return false; //no "chatting" while muted.
  8839. if( battle_config.min_chat_delay ) { //[Skotlex]
  8840. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8841. return false;
  8842. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8843. }
  8844. if (battle_config.idletime_option&IDLE_CHAT)
  8845. sd->idletime = last_tick;
  8846. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8847. sd->idletime_hom = last_tick;
  8848. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8849. sd->idletime_mer = last_tick;
  8850. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8851. return true;
  8852. }
  8853. /**
  8854. * Displays a message if the player enters a PK Zone (during pk_mode)
  8855. * @param sd: Player data
  8856. */
  8857. inline void clif_pk_mode_message(struct map_session_data * sd)
  8858. {
  8859. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8860. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8861. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8862. char output[CHAT_SIZE_MAX];
  8863. // 1504: You've entered a PK Zone (safe until level %d).
  8864. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8865. battle_config.pk_min_level);
  8866. clif_showscript(&sd->bl, output, SELF);
  8867. } else {
  8868. // 1503: You've entered a PK Zone.
  8869. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8870. }
  8871. }
  8872. return;
  8873. }
  8874. // ---------------------
  8875. // clif_parse_wanttoconnect
  8876. // ---------------------
  8877. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8878. // error codes:
  8879. // 0 - Success
  8880. // 1 - Unknown packet_ver
  8881. // 2 - Invalid account_id
  8882. // 3 - Invalid char_id
  8883. // 4 - Invalid login_id1 (reserved)
  8884. // 5 - Invalid client_tick (reserved)
  8885. // 6 - Invalid sex
  8886. // Only the first 'invalid' error that appears is used.
  8887. static int clif_parse_WantToConnection_sub(int fd)
  8888. {
  8889. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8890. unsigned short cmd;
  8891. //By default, start searching on the default one.
  8892. cmd = RFIFOW(fd, 0);
  8893. packet_len = RFIFOREST(fd);
  8894. // FIXME: If the packet is not received at once, this will FAIL.
  8895. // Figure out, when it happens, that only part of the packet is
  8896. // received, or fix the function to be able to deal with that
  8897. // case.
  8898. if( packet_len != packet_db[cmd].len )
  8899. return 1; /* wrong length */
  8900. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8901. return 2; /* invalid account_id */
  8902. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8903. return 3; /* invalid char_id */
  8904. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8905. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8906. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8907. return 6; /* invalid sex */
  8908. else
  8909. return 0;
  8910. }
  8911. /// Request to connect to map-server.
  8912. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8913. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8914. /// There are various variants of this packet, some of them have padding between fields.
  8915. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8916. {
  8917. struct block_list* bl;
  8918. struct auth_node* node;
  8919. int cmd, account_id, char_id, login_id1, sex, err;
  8920. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8921. if (sd) {
  8922. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8923. return;
  8924. }
  8925. cmd = RFIFOW(fd, 0);
  8926. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8927. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8928. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8929. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8930. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8931. err = clif_parse_WantToConnection_sub(fd);
  8932. if( err ){ // connection rejected
  8933. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8934. err == 1 ? "." :
  8935. err == 2 ? ", possibly for having an invalid account_id." :
  8936. err == 3 ? ", possibly for having an invalid char_id." :
  8937. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8938. err == 4 ? ", possibly for having an invalid login_id1." :
  8939. err == 5 ? ", possibly for having an invalid client_tick." :
  8940. */
  8941. err == 6 ? ", possibly for having an invalid sex." :
  8942. ". ERROR invalid error code"));
  8943. WFIFOHEAD(fd,packet_len(0x6a));
  8944. WFIFOW(fd,0) = 0x6a;
  8945. WFIFOB(fd,2) = err;
  8946. WFIFOSET(fd,packet_len(0x6a));
  8947. #ifdef DUMP_INVALID_PACKET
  8948. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8949. #endif
  8950. RFIFOSKIP(fd, RFIFOREST(fd));
  8951. set_eof(fd);
  8952. return;
  8953. }
  8954. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8955. clif_authfail_fd(fd,1);// server closed
  8956. return;
  8957. }
  8958. //Check for double login.
  8959. bl = map_id2bl(account_id);
  8960. if(bl && bl->type != BL_PC) {
  8961. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8962. WFIFOHEAD(fd,packet_len(0x6a));
  8963. WFIFOW(fd,0) = 0x6a;
  8964. WFIFOB(fd,2) = 3; // Rejected by server
  8965. WFIFOSET(fd,packet_len(0x6a));
  8966. set_eof(fd);
  8967. return;
  8968. }
  8969. if (bl ||
  8970. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8971. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8972. {
  8973. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8974. return;
  8975. }
  8976. CREATE(sd, TBL_PC, 1);
  8977. // placement new
  8978. new(sd) map_session_data();
  8979. sd->fd = fd;
  8980. #ifdef PACKET_OBFUSCATION
  8981. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8982. #endif
  8983. session[fd]->session_data = sd;
  8984. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8985. #if PACKETVER < 20070521
  8986. WFIFOHEAD(fd,4);
  8987. WFIFOL(fd,0) = sd->bl.id;
  8988. WFIFOSET(fd,4);
  8989. #else
  8990. WFIFOHEAD(fd,packet_len(0x283));
  8991. WFIFOW(fd,0) = 0x283;
  8992. WFIFOL(fd,2) = sd->bl.id;
  8993. WFIFOSET(fd,packet_len(0x283));
  8994. #endif
  8995. chrif_authreq(sd,false);
  8996. }
  8997. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8998. /// 007d
  8999. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  9000. {
  9001. bool guild_notice = false;
  9002. if(sd->bl.prev != NULL)
  9003. return;
  9004. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9005. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9006. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9007. sd->state.connect_new = 0;
  9008. return;
  9009. }
  9010. if (sd->state.rewarp) { //Rewarp player.
  9011. sd->state.rewarp = 0;
  9012. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9013. return;
  9014. }
  9015. sd->state.warping = 0;
  9016. // look
  9017. #if PACKETVER < 4
  9018. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9019. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9020. #else
  9021. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9022. #endif
  9023. pc_set_costume_view(sd);
  9024. if(sd->vd.cloth_color)
  9025. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9026. if(sd->vd.body_style)
  9027. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9028. // item
  9029. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9030. pc_checkitem(sd);
  9031. clif_equipswitch_list(sd);
  9032. // cart
  9033. if(pc_iscarton(sd)) {
  9034. clif_cartlist(sd);
  9035. clif_updatestatus(sd,SP_CARTINFO);
  9036. }
  9037. // weight
  9038. clif_updatestatus(sd,SP_WEIGHT);
  9039. clif_updatestatus(sd,SP_MAXWEIGHT);
  9040. // guild
  9041. // (needs to go before clif_spawn() to show guild emblems correctly)
  9042. if(sd->status.guild_id)
  9043. guild_send_memberinfoshort(sd,1);
  9044. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9045. if(battle_config.pc_invincible_time > 0) {
  9046. if(mapdata_flag_gvg(mapdata))
  9047. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9048. else
  9049. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9050. }
  9051. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9052. map_spawnmobs(sd->bl.m);
  9053. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9054. mapdata->users_pvp++;
  9055. }
  9056. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9057. // reset the callshop flag if the player changes map
  9058. sd->state.callshop = 0;
  9059. if(map_addblock(&sd->bl))
  9060. return;
  9061. clif_spawn(&sd->bl);
  9062. // Party
  9063. // (needs to go after clif_spawn() to show hp bars correctly)
  9064. if(sd->status.party_id) {
  9065. party_send_movemap(sd);
  9066. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9067. }
  9068. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9069. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  9070. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9071. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  9072. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9073. sd->pvp_rank = 0;
  9074. sd->pvp_lastusers = 0;
  9075. sd->pvp_point = 5;
  9076. sd->pvp_won = 0;
  9077. sd->pvp_lost = 0;
  9078. }
  9079. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9080. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9081. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9082. else if (mapdata->flag[MF_GVG_DUNGEON])
  9083. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9084. else if( mapdata_flag_gvg(mapdata) )
  9085. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9086. else
  9087. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9088. // info about nearby objects
  9089. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9090. 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);
  9091. // pet
  9092. if( sd->pd ) {
  9093. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9094. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9095. pet_return_egg( sd, sd->pd );
  9096. } else {
  9097. if(map_addblock(&sd->pd->bl))
  9098. return;
  9099. clif_spawn(&sd->pd->bl);
  9100. clif_send_petdata(sd,sd->pd,0,0);
  9101. clif_send_petstatus(sd);
  9102. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9103. }
  9104. }
  9105. //homunculus [blackhole89]
  9106. if( hom_is_active(sd->hd) ) {
  9107. if(map_addblock(&sd->hd->bl))
  9108. return;
  9109. clif_spawn(&sd->hd->bl);
  9110. clif_send_homdata(sd,SP_ACK,0);
  9111. clif_hominfo(sd,sd->hd,1);
  9112. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9113. clif_homskillinfoblock(sd);
  9114. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9115. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9116. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9117. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9118. }
  9119. if( sd->md ) {
  9120. if(map_addblock(&sd->md->bl))
  9121. return;
  9122. clif_spawn(&sd->md->bl);
  9123. clif_mercenary_info(sd);
  9124. clif_mercenary_skillblock(sd);
  9125. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9126. }
  9127. if( sd->ed ) {
  9128. if (map_addblock(&sd->ed->bl))
  9129. return;
  9130. clif_spawn(&sd->ed->bl);
  9131. clif_elemental_info(sd);
  9132. clif_elemental_updatestatus(sd,SP_HP);
  9133. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9134. clif_elemental_updatestatus(sd,SP_SP);
  9135. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9136. }
  9137. if(sd->state.connect_new) {
  9138. int lv;
  9139. guild_notice = true;
  9140. clif_skillinfoblock(sd);
  9141. clif_hotkeys_send(sd,0);
  9142. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9143. clif_hotkeys_send(sd,1);
  9144. #endif
  9145. clif_updatestatus(sd,SP_BASEEXP);
  9146. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9147. clif_updatestatus(sd,SP_JOBEXP);
  9148. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9149. clif_updatestatus(sd,SP_SKILLPOINT);
  9150. clif_initialstatus(sd);
  9151. if (sd->sc.option&OPTION_FALCON)
  9152. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9153. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9154. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9155. else if (sd->sc.option&OPTION_WUGRIDER)
  9156. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9157. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9158. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9159. if(sd->status.manner < 0)
  9160. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9161. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9162. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9163. if(sd->bl.m == sd->feel_map[0].m
  9164. || sd->bl.m == sd->feel_map[1].m
  9165. || sd->bl.m == sd->feel_map[2].m)
  9166. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9167. }
  9168. if(sd->pd && sd->pd->pet.intimate > 900)
  9169. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9170. if(hom_is_active(sd->hd))
  9171. hom_init_timers(sd->hd);
  9172. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9173. sd->state.night = 1;
  9174. clif_status_load(&sd->bl, EFST_SKE, 1);
  9175. }
  9176. // Notify everyone that this char logged in [Skotlex].
  9177. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9178. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9179. //Login Event
  9180. npc_script_event(sd, NPCE_LOGIN);
  9181. }
  9182. // Set facing direction before check below to update client
  9183. if (battle_config.spawn_direction)
  9184. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9185. } else {
  9186. //For some reason the client "loses" these on warp/map-change.
  9187. clif_updatestatus(sd,SP_STR);
  9188. clif_updatestatus(sd,SP_AGI);
  9189. clif_updatestatus(sd,SP_VIT);
  9190. clif_updatestatus(sd,SP_INT);
  9191. clif_updatestatus(sd,SP_DEX);
  9192. clif_updatestatus(sd,SP_LUK);
  9193. #ifdef RENEWAL
  9194. clif_updatestatus(sd,SP_POW);
  9195. clif_updatestatus(sd,SP_STA);
  9196. clif_updatestatus(sd,SP_WIS);
  9197. clif_updatestatus(sd,SP_SPL);
  9198. clif_updatestatus(sd,SP_CON);
  9199. clif_updatestatus(sd,SP_CRT);
  9200. #endif
  9201. // abort currently running script
  9202. sd->state.using_fake_npc = 0;
  9203. sd->state.menu_or_input = 0;
  9204. sd->npc_menu = 0;
  9205. if(sd->npc_id)
  9206. npc_event_dequeue(sd);
  9207. }
  9208. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9209. clif_partyinvitationstate( *sd );
  9210. #if PACKETVER >= 20070918
  9211. clif_equipcheckbox(sd);
  9212. #endif
  9213. clif_pet_autofeed_status(sd,false);
  9214. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9215. #if PACKETVER >= 20170920
  9216. if( battle_config.homunculus_autofeed_always ){
  9217. // Always send ON or OFF
  9218. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9219. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9220. }else{
  9221. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9222. }
  9223. }else{
  9224. // Only send when enabled
  9225. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9226. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9227. }
  9228. }
  9229. #endif
  9230. clif_reputation_list( *sd );
  9231. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9232. clif_guild_notice(sd); // Displays after VIP
  9233. guild_notice = false; // Do not display it twice
  9234. }
  9235. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9236. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9237. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9238. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9239. }
  9240. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9241. { //Display night.
  9242. if( !sd->state.night )
  9243. {
  9244. sd->state.night = 1;
  9245. clif_status_load(&sd->bl, EFST_SKE, 1);
  9246. }
  9247. }
  9248. else if( sd->state.night )
  9249. { //Clear night display.
  9250. sd->state.night = 0;
  9251. clif_status_load(&sd->bl, EFST_SKE, 0);
  9252. }
  9253. if( mapdata->flag[MF_BATTLEGROUND] )
  9254. {
  9255. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9256. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9257. clif_bg_updatescore_single(sd);
  9258. }
  9259. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9260. {
  9261. char output[128];
  9262. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9263. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9264. }
  9265. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9266. mapdata->hpmeter_visible++;
  9267. sd->state.hpmeter_visible = 1;
  9268. }
  9269. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9270. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9271. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9272. #ifdef VIP_ENABLE
  9273. if (!sd->state.connect_new &&
  9274. !sd->vip.disableshowrate &&
  9275. sd->state.pmap != sd->bl.m &&
  9276. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9277. )
  9278. {
  9279. clif_display_pinfo( *sd );
  9280. }
  9281. #endif
  9282. // Instances do not need their own channels
  9283. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9284. channel_mjoin(sd); //join new map
  9285. clif_pk_mode_message(sd);
  9286. }
  9287. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9288. clif_guild_notice(sd); // Displays at end
  9289. }
  9290. mail_clear(sd);
  9291. /* Guild Aura Init */
  9292. if( sd->guild && sd->state.gmaster_flag ) {
  9293. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9294. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9295. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9296. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9297. }
  9298. if( sd->state.vending ) { /* show we have a vending */
  9299. clif_openvending(sd,sd->bl.id,sd->vending);
  9300. clif_showvendingboard( *sd );
  9301. }
  9302. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9303. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9304. npc_script_event(sd, NPCE_LOADMAP);
  9305. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9306. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9307. if (sd->sc.opt2) //Client loses these on warp.
  9308. clif_changeoption(&sd->bl);
  9309. if ((sd->sc.getSCE(SC_MONSTER_TRANSFORM) || sd->sc.getSCE(SC_ACTIVE_MONSTER_TRANSFORM)) && battle_config.mon_trans_disable_in_gvg && mapdata_flag_gvg2(mapdata)) {
  9310. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9311. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9312. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9313. }
  9314. clif_weather_check(sd);
  9315. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9316. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9317. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9318. else
  9319. sd->areanpc.clear();
  9320. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9321. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9322. pc_setdead(sd);
  9323. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9324. if(pc_isdead(sd))
  9325. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9326. else {
  9327. skill_usave_trigger(sd);
  9328. if (battle_config.spawn_direction)
  9329. clif_changed_dir(&sd->bl, SELF);
  9330. }
  9331. // Trigger skill effects if you appear standing on them
  9332. if(!battle_config.pc_invincible_time)
  9333. skill_unit_move(&sd->bl,gettick(),1);
  9334. pc_show_questinfo_reinit(sd);
  9335. pc_show_questinfo(sd);
  9336. #if PACKETVER >= 20150513
  9337. if( sd->mail.inbox.unread ){
  9338. clif_Mail_new(sd, 0, NULL, NULL);
  9339. }
  9340. #endif
  9341. sd->state.connect_new = 0;
  9342. sd->state.changemap = false;
  9343. }
  9344. /// Server's tick (ZC_NOTIFY_TIME).
  9345. /// 007f <time>.L
  9346. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9347. {
  9348. int fd = sd->fd;
  9349. WFIFOHEAD(fd,packet_len(0x7f));
  9350. WFIFOW(fd,0) = 0x7f;
  9351. WFIFOL(fd,2) = client_tick(time);
  9352. WFIFOSET(fd,packet_len(0x7f));
  9353. }
  9354. /// Request for server's tick.
  9355. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9356. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9357. /// There are various variants of this packet, some of them have padding between fields.
  9358. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9359. {
  9360. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9361. clif_notify_time(sd, gettick());
  9362. }
  9363. /// Sends hotkey bar.
  9364. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9365. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9366. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9367. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9368. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9369. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9370. nullpo_retv( sd );
  9371. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9372. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9373. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9374. if( tab == 0 ){
  9375. p.rotate = sd->status.hotkey_rowshift;
  9376. }else{
  9377. p.rotate = sd->status.hotkey_rowshift2;
  9378. }
  9379. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9380. p.tab = tab;
  9381. #endif
  9382. #endif
  9383. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9384. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9385. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9386. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9387. }
  9388. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9389. #endif
  9390. }
  9391. /// Request to update a position on the hotkey row bar
  9392. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9393. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9394. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9395. if( p->tab == 0 ){
  9396. sd->status.hotkey_rowshift = p->rowshift;
  9397. }else{
  9398. sd->status.hotkey_rowshift2 = p->rowshift;
  9399. }
  9400. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9401. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9402. sd->status.hotkey_rowshift = p->rowshift;
  9403. #endif
  9404. }
  9405. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9406. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9407. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9408. #ifdef HOTKEY_SAVING
  9409. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9410. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9411. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9412. if( idx >= MAX_HOTKEYS_DB ){
  9413. return;
  9414. }
  9415. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9416. sd->status.hotkeys[idx].id = p->hotkey.id;
  9417. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9418. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9419. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9420. const unsigned short idx = p->index;
  9421. if( idx >= MAX_HOTKEYS_DB ){
  9422. return;
  9423. }
  9424. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9425. sd->status.hotkeys[idx].id = p->hotkey.id;
  9426. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9427. #endif
  9428. #endif
  9429. }
  9430. /// Displays cast-like progress bar (ZC_PROGRESS).
  9431. /// 02f0 <color>.L <time>.L
  9432. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9433. {
  9434. int fd = sd->fd;
  9435. WFIFOHEAD(fd,packet_len(0x2f0));
  9436. WFIFOW(fd,0) = 0x2f0;
  9437. WFIFOL(fd,2) = color;
  9438. WFIFOL(fd,6) = second;
  9439. WFIFOSET(fd,packet_len(0x2f0));
  9440. }
  9441. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9442. /// 02f2
  9443. void clif_progressbar_abort(struct map_session_data * sd)
  9444. {
  9445. int fd = sd->fd;
  9446. WFIFOHEAD(fd,packet_len(0x2f2));
  9447. WFIFOW(fd,0) = 0x2f2;
  9448. WFIFOSET(fd,packet_len(0x2f2));
  9449. }
  9450. /// Notification from the client, that the progress bar has reached 100%.
  9451. /// 02f1 (CZ_PROGRESS)
  9452. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9453. // No progressbar active, ignore it
  9454. if( !sd->progressbar.npc_id ){
  9455. return;
  9456. }
  9457. int npc_id = sd->progressbar.npc_id;
  9458. bool closing = false;
  9459. // Check if the progress was canceled
  9460. if( gettick() < sd->progressbar.timeout && sd->st ){
  9461. closing = true;
  9462. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9463. // If a message window was open, offer a close button to the user
  9464. if( sd->st->mes_active ){
  9465. clif_scriptclose( sd, npc_id );
  9466. }
  9467. }
  9468. sd->progressbar.npc_id = 0;
  9469. sd->progressbar.timeout = 0;
  9470. sd->state.workinprogress = WIP_DISABLE_NONE;
  9471. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9472. sd->idletime = last_tick;
  9473. }
  9474. npc_scriptcont(sd, npc_id, closing);
  9475. }
  9476. /// Displays cast-like progress bar on a NPC
  9477. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9478. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9479. #if PACKETVER >= 20130821
  9480. unsigned char buf[14];
  9481. if( nd->progressbar.timeout > 0 ){
  9482. WBUFW(buf,0) = 0x9d1;
  9483. WBUFL(buf,2) = nd->bl.id;
  9484. WBUFL(buf,6) = nd->progressbar.color;
  9485. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9486. if( sd ){
  9487. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9488. }else{
  9489. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9490. }
  9491. }
  9492. #endif
  9493. }
  9494. /// Request to walk to a certain position on the current map.
  9495. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9496. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9497. /// There are various variants of this packet, some of them have padding between fields.
  9498. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9499. {
  9500. short x, y;
  9501. if (pc_isdead(sd)) {
  9502. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9503. return;
  9504. }
  9505. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9506. ; //You CAN walk on this OPT1 value.
  9507. else if (sd->progressbar.npc_id) {
  9508. clif_progressbar_abort(sd);
  9509. return; // First walk attempt cancels the progress bar
  9510. } else if (pc_cant_act(sd))
  9511. return;
  9512. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9513. return;
  9514. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9515. //A move command one cell west is only valid if the target cell is free
  9516. if(battle_config.official_cell_stack_limit > 0
  9517. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9518. return;
  9519. // Cloaking wall check is actually updated when you click to process next movement
  9520. // not when you move each cell. This is official behaviour.
  9521. if (sd->sc.getSCE(SC_CLOAKING))
  9522. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9523. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9524. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9525. pc_delinvincibletimer(sd);
  9526. //Set last idle time... [Skotlex]
  9527. if (battle_config.idletime_option&IDLE_WALK)
  9528. sd->idletime = last_tick;
  9529. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9530. sd->idletime_hom = last_tick;
  9531. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9532. sd->idletime_mer = last_tick;
  9533. unit_walktoxy(&sd->bl, x, y, 4);
  9534. }
  9535. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9536. /// 018b <result>.W
  9537. /// result:
  9538. /// 0 = disconnect (quit)
  9539. /// 1 = cannot disconnect (wait 10 seconds)
  9540. /// ? = ignored
  9541. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9542. {
  9543. int fd = sd->fd;
  9544. WFIFOHEAD(fd,packet_len(0x18b));
  9545. WFIFOW(fd,0) = 0x18b;
  9546. WFIFOW(fd,2) = result;
  9547. WFIFOSET(fd,packet_len(0x18b));
  9548. }
  9549. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9550. /// 018a <type>.W
  9551. /// type:
  9552. /// 0 = quit
  9553. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9554. {
  9555. /* Rovert's prevent logout option fixed [Valaris] */
  9556. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9557. if( !sd->sc.getSCE(SC_CLOAKING) && !sd->sc.getSCE(SC_HIDING) && !sd->sc.getSCE(SC_CHASEWALK) && !sd->sc.getSCE(SC_CLOAKINGEXCEED) && !sd->sc.getSCE(SC_SUHIDE) && !sd->sc.getSCE(SC_NEWMOON) &&
  9558. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9559. {
  9560. pc_damage_log_clear(sd,0);
  9561. clif_disconnect_ack(sd, 0);
  9562. flush_fifo( fd );
  9563. if( battle_config.drop_connection_on_quit ){
  9564. set_eof( fd );
  9565. }
  9566. } else {
  9567. clif_disconnect_ack(sd, 1);
  9568. }
  9569. }
  9570. /// Requesting unit's name.
  9571. /// 0094 <id>.L (CZ_REQNAME)
  9572. /// 0368 <id>.L (CZ_REQNAME2)
  9573. /// There are various variants of this packet, some of them have padding between fields.
  9574. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9575. {
  9576. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9577. struct block_list* bl;
  9578. //struct status_change *sc;
  9579. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9580. id = sd->bl.id;
  9581. bl = map_id2bl(id);
  9582. if( bl == NULL )
  9583. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9584. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9585. return; // Block namerequests past view range
  9586. // 'see people in GM hide' cheat detection
  9587. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9588. sc = status_get_sc(bl);
  9589. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9590. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9591. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9592. ) {
  9593. char gm_msg[256];
  9594. 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);
  9595. ShowWarning(gm_msg);
  9596. // information is sent to all online GMs
  9597. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9598. return;
  9599. }
  9600. */
  9601. clif_name(&sd->bl,bl,SELF);
  9602. }
  9603. /// Validates and processes global messages
  9604. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9605. /// There are various variants of this packet.
  9606. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9607. {
  9608. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9609. size_t length;
  9610. // validate packet and retrieve name and message
  9611. if( !clif_process_message(sd, false, name, message, output ) )
  9612. return;
  9613. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9614. channel_send(sd->gcbind,sd,message);
  9615. return;
  9616. }
  9617. // send message to others (using the send buffer for temp. storage)
  9618. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9619. length = strlen(output) + 1;
  9620. // send back message to the speaker
  9621. WFIFOHEAD(fd,4+length);
  9622. WFIFOW(fd,0) = 0x8e;
  9623. WFIFOW(fd,2) = (uint16)(4+length);
  9624. safestrncpy(WFIFOCP(fd,4), output, length );
  9625. WFIFOSET(fd, WFIFOW(fd,2));
  9626. #ifdef PCRE_SUPPORT
  9627. // trigger listening npcs
  9628. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9629. #endif
  9630. // Chat logging type 'O' / Global Chat
  9631. 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);
  9632. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9633. }
  9634. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9635. /// Request to warp to a map on given coordinates.
  9636. /// 0140 <map name>.16B <x>.W <y>.W
  9637. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9638. {
  9639. char command[MAP_NAME_LENGTH_EXT+25];
  9640. char* map_name;
  9641. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9642. map_name = RFIFOCP(fd,info->pos[0]);
  9643. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9644. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9645. RFIFOW(fd,info->pos[1]), //x
  9646. RFIFOW(fd,info->pos[2])); //y
  9647. is_atcommand(fd, sd, command, 1);
  9648. }
  9649. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9650. /// 009c <id>.L <head dir>.W <dir>.B
  9651. /// head dir:
  9652. /// 0 = straight
  9653. /// 1 = turned CW
  9654. /// 2 = turned CCW
  9655. /// dir:
  9656. /// 0 = north
  9657. /// 1 = northwest
  9658. /// 2 = west
  9659. /// 3 = southwest
  9660. /// 4 = south
  9661. /// 5 = southeast
  9662. /// 6 = east
  9663. /// 7 = northeast
  9664. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9665. {
  9666. unsigned char buf[64];
  9667. WBUFW(buf,0) = 0x9c;
  9668. WBUFL(buf,2) = bl->id;
  9669. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9670. WBUFB(buf,8) = unit_getdir(bl);
  9671. clif_send(buf, packet_len(0x9c), bl, target);
  9672. if (disguised(bl)) {
  9673. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9674. WBUFW(buf,6) = 0;
  9675. clif_send(buf, packet_len(0x9c), bl, SELF);
  9676. }
  9677. }
  9678. /// Request to change own body and head direction.
  9679. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9680. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9681. /// There are various variants of this packet, some of them have padding between fields.
  9682. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9683. {
  9684. unsigned char headdir, dir;
  9685. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9686. headdir = RFIFOB(fd,info->pos[0]);
  9687. dir = RFIFOB(fd,info->pos[1]);
  9688. pc_setdir(sd, dir, headdir);
  9689. clif_changed_dir(&sd->bl, AREA_WOS);
  9690. }
  9691. /// Request to show an emotion (CZ_REQ_EMOTION).
  9692. /// 00bf <type>.B
  9693. /// type:
  9694. /// @see enum emotion_type
  9695. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9696. {
  9697. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9698. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9699. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9700. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9701. return;
  9702. }
  9703. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9704. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9705. sd->emotionlasttime = time(NULL);
  9706. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9707. return;
  9708. }
  9709. sd->emotionlasttime = time(NULL);
  9710. if (battle_config.idletime_option&IDLE_EMOTION)
  9711. sd->idletime = last_tick;
  9712. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9713. sd->idletime_hom = last_tick;
  9714. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9715. sd->idletime_mer = last_tick;
  9716. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9717. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9718. return;
  9719. }
  9720. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9721. emoticon = rnd()%6+ET_DICE1;
  9722. }
  9723. clif_emotion(&sd->bl, emoticon);
  9724. } else
  9725. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9726. }
  9727. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9728. /// 00c2 <count>.L
  9729. void clif_user_count(struct map_session_data* sd, int count)
  9730. {
  9731. int fd = sd->fd;
  9732. WFIFOHEAD(fd,packet_len(0xc2));
  9733. WFIFOW(fd,0) = 0xc2;
  9734. WFIFOL(fd,2) = count;
  9735. WFIFOSET(fd,packet_len(0xc2));
  9736. }
  9737. /// /w /who (CZ_REQ_USER_COUNT).
  9738. /// Request to display amount of currently connected players.
  9739. /// 00c1
  9740. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9741. {
  9742. clif_user_count(sd, map_getusers());
  9743. }
  9744. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9745. {
  9746. if (pc_isdead(sd)) {
  9747. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9748. return;
  9749. }
  9750. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9751. if (action_type != 0x00 && action_type != 0x07) {
  9752. if (sd->sc.cant.interact)
  9753. return;
  9754. pc_stop_walking(sd, 1);
  9755. }
  9756. pc_stop_attack(sd);
  9757. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9758. target_id = sd->bl.id;
  9759. switch(action_type)
  9760. {
  9761. case 0x00: // once attack
  9762. case 0x07: // continuous attack
  9763. if( pc_cant_act(sd) )
  9764. return;
  9765. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9766. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9767. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9768. return;
  9769. }
  9770. }
  9771. pc_delinvincibletimer(sd);
  9772. if (battle_config.idletime_option&IDLE_ATTACK)
  9773. sd->idletime = last_tick;
  9774. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9775. sd->idletime_hom = last_tick;
  9776. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9777. sd->idletime_mer = last_tick;
  9778. unit_attack(&sd->bl, target_id, action_type != 0);
  9779. break;
  9780. case 0x02: // sitdown
  9781. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9782. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9783. break;
  9784. }
  9785. if(pc_issit(sd)) {
  9786. //Bugged client? Just refresh them.
  9787. clif_sitting(&sd->bl);
  9788. return;
  9789. }
  9790. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9791. break;
  9792. if (sd->sc.count && (
  9793. sd->sc.getSCE(SC_DANCING) ||
  9794. (sd->sc.getSCE(SC_GRAVITATION) && sd->sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9795. )) //No sitting during these states either.
  9796. break;
  9797. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9798. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9799. break;
  9800. }
  9801. if (battle_config.idletime_option&IDLE_SIT)
  9802. sd->idletime = last_tick;
  9803. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9804. sd->idletime_hom = last_tick;
  9805. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9806. sd->idletime_mer = last_tick;
  9807. pc_setsit(sd);
  9808. skill_sit(sd, true);
  9809. clif_sitting(&sd->bl);
  9810. break;
  9811. case 0x03: // standup
  9812. if (!pc_issit(sd)) {
  9813. //Bugged client? Just refresh them.
  9814. clif_standing(&sd->bl);
  9815. return;
  9816. }
  9817. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9818. break;
  9819. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9820. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9821. break;
  9822. }
  9823. if (pc_setstand(sd, false)) {
  9824. if (battle_config.idletime_option&IDLE_SIT)
  9825. sd->idletime = last_tick;
  9826. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9827. sd->idletime_hom = last_tick;
  9828. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9829. sd->idletime_mer = last_tick;
  9830. skill_sit(sd, false);
  9831. clif_standing(&sd->bl);
  9832. }
  9833. break;
  9834. }
  9835. }
  9836. /// Request for an action.
  9837. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9838. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9839. /// action:
  9840. /// 0 = attack
  9841. /// 1 = pick up item
  9842. /// 2 = sit down
  9843. /// 3 = stand up
  9844. /// 7 = continous attack
  9845. /// 12 = (touch skill?)
  9846. /// There are various variants of this packet, some of them have padding between fields.
  9847. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9848. {
  9849. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9850. clif_parse_ActionRequest_sub(sd,
  9851. RFIFOB(fd,info->pos[1]),
  9852. RFIFOL(fd,info->pos[0]),
  9853. gettick()
  9854. );
  9855. }
  9856. /// Response to the death/system menu (CZ_RESTART).
  9857. /// 00b2 <type>.B
  9858. /// type:
  9859. /// 0 = restart (respawn)
  9860. /// 1 = char-select (disconnect)
  9861. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9862. {
  9863. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9864. case 0x00:
  9865. pc_respawn(sd,CLR_OUTSIGHT);
  9866. break;
  9867. case 0x01:
  9868. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9869. if( !sd->sc.getSCE(SC_CLOAKING) && !sd->sc.getSCE(SC_HIDING) && !sd->sc.getSCE(SC_CHASEWALK) && !sd->sc.getSCE(SC_CLOAKINGEXCEED) && !sd->sc.getSCE(SC_SUHIDE) && !sd->sc.getSCE(SC_NEWMOON) &&
  9870. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9871. { //Send to char-server for character selection.
  9872. pc_damage_log_clear(sd,0);
  9873. chrif_charselectreq(sd, session[fd]->client_addr);
  9874. } else {
  9875. clif_disconnect_ack(sd, 1);
  9876. }
  9877. break;
  9878. }
  9879. }
  9880. /// Validates and processes whispered messages (CZ_WHISPER).
  9881. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9882. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9883. {
  9884. struct map_session_data* dstsd;
  9885. int i;
  9886. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9887. // validate packet and retrieve name and message
  9888. if( !clif_process_message( sd, true, target, message, output ) )
  9889. return;
  9890. // Chat logging type 'W' / Whisper
  9891. 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);
  9892. //-------------------------------------------------------//
  9893. // Lordalfa - Paperboy - To whisper NPC commands //
  9894. //-------------------------------------------------------//
  9895. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9896. {
  9897. char* str = target+4; //Skip the NPC: string part.
  9898. struct npc_data* npc;
  9899. if ((npc = npc_name2id(str))) {
  9900. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9901. char *split;
  9902. char event[EVENT_NAME_LENGTH];
  9903. str = message;
  9904. // skip codepage indicator, if detected
  9905. if( str[0] == '|' && strlen(str) >= 4 )
  9906. str += 3;
  9907. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9908. split = strchr(str,'#');
  9909. if( split == NULL ) { // use the remaining string
  9910. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9911. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9912. split_data[i][0] = '\0';
  9913. break;
  9914. }
  9915. *split = '\0';
  9916. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9917. str = split+1;
  9918. }
  9919. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9920. char variablename[CHAT_SIZE_MAX];
  9921. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9922. set_var_str( sd, variablename, split_data[i] );
  9923. }
  9924. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9925. npc_event(sd,event,0); // Calls the NPC label
  9926. return;
  9927. }
  9928. } else if( target[0] == '#' ) {
  9929. struct Channel *channel = NULL;
  9930. char* chname = target;
  9931. channel = channel_name2channel(chname,sd,3);
  9932. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9933. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9934. channel_send(channel,sd,message);
  9935. }
  9936. else if( channel->pass[0] == '\0') { //no pass needed
  9937. if (channel_join(channel,sd)==0)
  9938. channel_send(channel,sd,message); //join success
  9939. }
  9940. else {
  9941. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9942. }
  9943. return;
  9944. }
  9945. }
  9946. // searching destination character
  9947. dstsd = map_nick2sd(target,false);
  9948. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9949. // player is not on this map-server
  9950. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9951. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9952. // and if we ask for 'Test', we must not contact 'test' player
  9953. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9954. intif_wis_message(sd, target, message, strlen(message) + 1);
  9955. return;
  9956. }
  9957. // if player ignores everyone
  9958. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9959. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9960. clif_wis_end(fd, 1); // 1: target character is not logged in
  9961. else
  9962. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9963. return;
  9964. }
  9965. // if player is autotrading
  9966. if (dstsd->state.autotrade == 1){
  9967. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9968. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9969. return;
  9970. }
  9971. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9972. // if player ignores the source character
  9973. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9974. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9975. clif_wis_end(fd, 2); // 2: ignored by target
  9976. return;
  9977. }
  9978. }
  9979. // notify sender of success
  9980. clif_wis_end(fd, 0); // 0: success to send wisper
  9981. // Normal message
  9982. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9983. }
  9984. /// /b /nb (CZ_BROADCAST).
  9985. /// Request to broadcast a message on whole server.
  9986. /// 0099 <packet len>.W <text>.?B 00
  9987. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9988. char command[CHAT_SIZE_MAX+11];
  9989. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9990. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9991. char* msg = RFIFOCP(fd,info->pos[1]);
  9992. // as the length varies depending on the command used, just block unreasonably long strings
  9993. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9994. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9995. is_atcommand(fd, sd, command, 1);
  9996. }
  9997. /// Request to pick up an item.
  9998. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9999. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10000. /// There are various variants of this packet, some of them have padding between fields.
  10001. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  10002. {
  10003. struct flooritem_data *fitem;
  10004. int map_object_id;
  10005. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10006. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10007. do {
  10008. if (pc_isdead(sd)) {
  10009. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10010. break;
  10011. }
  10012. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10013. break;
  10014. if (pc_cant_act(sd))
  10015. break;
  10016. if (!pc_takeitem(sd, fitem))
  10017. break;
  10018. return;
  10019. } while (0);
  10020. // Client REQUIRES a fail packet or you can no longer pick items.
  10021. clif_additem(sd,0,0,6);
  10022. }
  10023. /// Request to drop an item.
  10024. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10025. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10026. /// There are various variants of this packet, some of them have padding between fields.
  10027. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  10028. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10029. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10030. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10031. for(;;) {
  10032. if (pc_isdead(sd))
  10033. break;
  10034. if (pc_cant_act2(sd) || sd->npc_id)
  10035. break;
  10036. if (sd->sc.cant.drop)
  10037. break;
  10038. if (!pc_dropitem(sd, item_index, item_amount))
  10039. break;
  10040. if (battle_config.idletime_option&IDLE_DROPITEM)
  10041. sd->idletime = last_tick;
  10042. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10043. sd->idletime_hom = last_tick;
  10044. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10045. sd->idletime_mer = last_tick;
  10046. return;
  10047. }
  10048. //Because the client does not like being ignored.
  10049. clif_dropitem(sd, item_index,0);
  10050. }
  10051. /// Request to use an item.
  10052. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10053. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10054. /// There are various variants of this packet, some of them have padding between fields.
  10055. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  10056. {
  10057. int n;
  10058. if (pc_isdead(sd)) {
  10059. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10060. return;
  10061. }
  10062. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10063. clif_msg(sd, WORK_IN_PROGRESS);
  10064. return;
  10065. }
  10066. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10067. if (battle_config.idletime_option&IDLE_USEITEM)
  10068. sd->idletime = last_tick;
  10069. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10070. sd->idletime_hom = last_tick;
  10071. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10072. sd->idletime_mer = last_tick;
  10073. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10074. if(n <0 || n >= MAX_INVENTORY)
  10075. return;
  10076. if (!pc_useitem(sd,n))
  10077. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10078. }
  10079. /// Request to equip an item
  10080. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10081. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10082. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  10083. {
  10084. int index;
  10085. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10086. if(pc_isdead(sd)) {
  10087. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10088. return;
  10089. }
  10090. index = RFIFOW(fd,info->pos[0])-2;
  10091. if (index < 0 || index >= MAX_INVENTORY)
  10092. return; //Out of bounds check.
  10093. if(sd->npc_id && !sd->npc_item_flag) {
  10094. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10095. return;
  10096. } else if (sd->state.storage_flag || sd->sc.opt1)
  10097. ; //You can equip/unequip stuff while storage is open/under status changes
  10098. else if (pc_cant_act2(sd))
  10099. return;
  10100. if(!sd->inventory.u.items_inventory[index].identify) {
  10101. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10102. return;
  10103. }
  10104. if(!sd->inventory_data[index])
  10105. return;
  10106. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10107. pet_equipitem(sd,index);
  10108. return;
  10109. }
  10110. if (battle_config.idletime_option&IDLE_USEITEM)
  10111. sd->idletime = last_tick;
  10112. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10113. sd->idletime_hom = last_tick;
  10114. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10115. sd->idletime_mer = last_tick;
  10116. //Client doesn't send the position for ammo.
  10117. if(sd->inventory_data[index]->type == IT_AMMO)
  10118. pc_equipitem(sd,index,EQP_AMMO);
  10119. else {
  10120. int req_pos;
  10121. #if PACKETVER >= 20120925
  10122. req_pos = RFIFOL(fd,info->pos[1]);
  10123. #else
  10124. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10125. #endif
  10126. pc_equipitem(sd,index,req_pos);
  10127. }
  10128. }
  10129. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10130. /// 00ab <index>.W
  10131. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  10132. {
  10133. int index;
  10134. if(pc_isdead(sd)) {
  10135. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10136. return;
  10137. }
  10138. if (sd->npc_id && !sd->npc_item_flag) {
  10139. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10140. return;
  10141. } else if (sd->state.storage_flag || sd->sc.opt1)
  10142. ; //You can equip/unequip stuff while storage is open/under status changes
  10143. else if (pc_cant_act2(sd))
  10144. return;
  10145. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10146. if (battle_config.idletime_option&IDLE_USEITEM)
  10147. sd->idletime = last_tick;
  10148. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10149. sd->idletime_hom = last_tick;
  10150. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10151. sd->idletime_mer = last_tick;
  10152. pc_unequipitem(sd,index,1);
  10153. }
  10154. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10155. /// 0090 <id>.L <type>.B
  10156. /// type:
  10157. /// 1 = click
  10158. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10159. {
  10160. struct block_list *bl;
  10161. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10162. if(pc_isdead(sd)) {
  10163. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10164. return;
  10165. }
  10166. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10167. #ifdef RENEWAL
  10168. clif_msg( sd, WORK_IN_PROGRESS );
  10169. #endif
  10170. return;
  10171. }
  10172. if( sd->state.mail_writing )
  10173. return;
  10174. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10175. //type = RFIFOB(fd,info->pos[1]);
  10176. if (!bl) return;
  10177. switch (bl->type) {
  10178. case BL_MOB:
  10179. case BL_PC:
  10180. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10181. break;
  10182. case BL_NPC:
  10183. #ifdef RENEWAL
  10184. 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
  10185. clif_msg(sd, WORK_IN_PROGRESS);
  10186. break;
  10187. }
  10188. #endif
  10189. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10190. struct npc_data* nd = (struct npc_data*)bl;
  10191. // Progressbar is running
  10192. if( nd->progressbar.timeout > 0 ){
  10193. return;
  10194. }
  10195. npc_click(sd,nd);
  10196. }
  10197. break;
  10198. }
  10199. }
  10200. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10201. /// 00c5 <id>.L <type>.B
  10202. /// type:
  10203. /// 0 = buy
  10204. /// 1 = sell
  10205. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10206. {
  10207. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10208. if (sd->state.trading)
  10209. return;
  10210. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10211. }
  10212. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10213. /// 00ca <result>.B
  10214. /// result:
  10215. /// 0 = "The deal has successfully completed."
  10216. /// 1 = "You do not have enough zeny."
  10217. /// 2 = "You are over your Weight Limit."
  10218. /// 3 = "Out of the maximum capacity, you have too many items."
  10219. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10220. /// 10 = "Props open-air store sales will be traded in RODEX"
  10221. /// 11 = "The exchange failed."
  10222. /// 12 = "The exchange was well done."
  10223. /// 13 = "The item is already sold and out of stock."
  10224. /// 14 = "There is not enough goods to exchange."
  10225. void clif_npc_buy_result( struct map_session_data* sd, e_purchase_result result ){
  10226. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10227. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10228. p.result = (uint8)result;
  10229. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10230. }
  10231. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10232. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10233. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10234. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10235. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10236. e_purchase_result result;
  10237. if( sd->state.trading || !sd->npc_shopid )
  10238. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10239. else{
  10240. std::vector<s_npc_buy_list> items = {};
  10241. items.reserve( n );
  10242. for( uint16 i = 0; i < n; i++ ){
  10243. s_npc_buy_list item = {};
  10244. item.nameid = p->items[i].itemId;
  10245. item.qty = p->items[i].amount;
  10246. items.push_back( item );
  10247. }
  10248. result = npc_buylist( sd, items );
  10249. }
  10250. sd->npc_shopid = 0; //Clear shop data.
  10251. clif_npc_buy_result(sd, result);
  10252. }
  10253. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10254. /// 00cb <result>.B
  10255. /// result:
  10256. /// 0 = "The deal has successfully completed."
  10257. /// 1 = "The deal has failed."
  10258. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10259. {
  10260. int fd = sd->fd;
  10261. WFIFOHEAD(fd,packet_len(0xcb));
  10262. WFIFOW(fd,0) = 0xcb;
  10263. WFIFOB(fd,2) = result;
  10264. WFIFOSET(fd,packet_len(0xcb));
  10265. }
  10266. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10267. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10268. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10269. {
  10270. int fail=0,n;
  10271. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10272. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10273. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10274. if (sd->state.trading || !sd->npc_shopid)
  10275. fail = 1;
  10276. else
  10277. fail = npc_selllist(sd, n, p->sellList);
  10278. sd->npc_shopid = 0; //Clear shop data.
  10279. clif_npc_sell_result(sd, fail);
  10280. }
  10281. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10282. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10283. /// type:
  10284. /// 0 = private
  10285. /// 1 = public
  10286. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10287. {
  10288. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10289. int len = RFIFOW(fd,info->pos[0])-15;
  10290. int limit = RFIFOW(fd,info->pos[1]);
  10291. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10292. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10293. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10294. char s_password[CHATROOM_PASS_SIZE];
  10295. char s_title[CHATROOM_TITLE_SIZE];
  10296. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10297. return;
  10298. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10299. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10300. return;
  10301. }
  10302. if( npc_isnear(&sd->bl) ) {
  10303. // uncomment to send msg_txt.
  10304. //char output[150];
  10305. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10306. //clif_displaymessage(sd->fd, output);
  10307. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10308. return;
  10309. }
  10310. if( len <= 0 )
  10311. return; // invalid input
  10312. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10313. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10314. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10315. }
  10316. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10317. /// 00d9 <chat ID>.L <passwd>.8B
  10318. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10319. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10320. int chatid = RFIFOL(fd,info->pos[0]);
  10321. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10322. chat_joinchat(sd,chatid,password);
  10323. }
  10324. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10325. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10326. /// type:
  10327. /// 0 = private
  10328. /// 1 = public
  10329. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10330. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10331. int len = RFIFOW(fd,info->pos[0])-15;
  10332. int limit = RFIFOW(fd,info->pos[1]);
  10333. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10334. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10335. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10336. char s_password[CHATROOM_PASS_SIZE];
  10337. char s_title[CHATROOM_TITLE_SIZE];
  10338. if( len <= 0 )
  10339. return; // invalid input
  10340. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10341. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10342. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10343. }
  10344. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10345. /// 00e0 <role>.L <nick>.24B
  10346. /// role:
  10347. /// 0 = owner
  10348. /// 1 = normal
  10349. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10350. {
  10351. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10352. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10353. }
  10354. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10355. /// 00e2 <name>.24B
  10356. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10357. {
  10358. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10359. }
  10360. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10361. /// 00e3
  10362. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10363. {
  10364. chat_leavechat(sd,0);
  10365. }
  10366. //Handles notifying asker and rejecter of what has just ocurred.
  10367. //Type is used to determine the correct msg_txt to use:
  10368. //0:
  10369. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10370. {
  10371. const char* msg;
  10372. char output[256];
  10373. // Your request has been rejected by autoreject option.
  10374. msg = msg_txt(sd,392);
  10375. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10376. //Notice that a request was rejected.
  10377. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10378. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10379. }
  10380. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10381. /// 00e4 <account id>.L
  10382. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10383. {
  10384. struct map_session_data *t_sd;
  10385. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10386. if(!sd->chatID && pc_cant_act(sd))
  10387. return; //You can trade while in a chatroom.
  10388. if(t_sd){
  10389. // @noask [LuzZza]
  10390. if(t_sd->state.noask) {
  10391. clif_noask_sub(sd, t_sd, 0);
  10392. return;
  10393. }
  10394. if (t_sd->state.mail_writing) {
  10395. int old = sd->trade_partner;
  10396. // Fake trading
  10397. sd->trade_partner = t_sd->status.account_id;
  10398. clif_tradestart(sd, 5);
  10399. // Restore old state
  10400. sd->trade_partner = old;
  10401. return;
  10402. }
  10403. }
  10404. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10405. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10406. return;
  10407. }
  10408. trade_traderequest(sd,t_sd);
  10409. }
  10410. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10411. /// 00e6 <result>.B
  10412. /// result:
  10413. /// 3 = accepted
  10414. /// 4 = rejected
  10415. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10416. {
  10417. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10418. }
  10419. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10420. /// 00e8 <index>.W <amount>.L
  10421. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10422. {
  10423. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10424. short index = RFIFOW(fd,info->pos[0]);
  10425. int amount = RFIFOL(fd,info->pos[1]);
  10426. if( index == 0 )
  10427. trade_tradeaddzeny(sd, amount);
  10428. else
  10429. trade_tradeadditem(sd, server_index(index), (short)amount);
  10430. }
  10431. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10432. /// 00eb
  10433. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10434. {
  10435. trade_tradeok(sd);
  10436. }
  10437. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10438. /// 00ed
  10439. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10440. {
  10441. trade_tradecancel(sd);
  10442. }
  10443. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10444. /// 00ef
  10445. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10446. {
  10447. trade_tradecommit(sd);
  10448. }
  10449. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10450. /// 0118
  10451. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10452. {
  10453. pc_stop_attack(sd);
  10454. if (sd) sd->ud.state.attack_continue = 0;
  10455. }
  10456. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10457. /// 0126 <index>.W <amount>.L
  10458. void clif_parse_PutItemToCart( int fd, struct map_session_data *sd ){
  10459. if (pc_istrading(sd))
  10460. return;
  10461. if (!pc_iscarton(sd))
  10462. return;
  10463. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10464. return;
  10465. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10466. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10467. }
  10468. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10469. /// 0127 <index>.W <amount>.L
  10470. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10471. {
  10472. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10473. if (!pc_iscarton(sd))
  10474. return;
  10475. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10476. return;
  10477. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10478. }
  10479. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10480. /// 012a
  10481. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10482. {
  10483. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10484. #ifdef NEW_CARTS
  10485. && sd->sc.getSCE(SC_PUSH_CART) )
  10486. pc_setcart(sd,0);
  10487. #else
  10488. )
  10489. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10490. #endif
  10491. else // priority to remove this option before we can clear cart
  10492. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10493. }
  10494. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10495. /// 097f <Length>.W <identity>.L <type>.B
  10496. void clif_SelectCart(struct map_session_data *sd) {
  10497. #if PACKETVER >= 20150826
  10498. int i = 0, carts = 3;
  10499. int fd = sd->fd;
  10500. WFIFOHEAD(fd,8 + carts);
  10501. WFIFOW(fd,0) = 0x97f;
  10502. WFIFOW(fd,2) = 8 + carts;
  10503. WFIFOL(fd,4) = sd->status.account_id;
  10504. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10505. for( i = 0; i < carts; i++ ) {
  10506. WFIFOB(fd,8 + i) = 10 + i;
  10507. }
  10508. WFIFOSET(fd,8 + carts);
  10509. #endif
  10510. }
  10511. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10512. /// 0980 <identity>.L <type>.B
  10513. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10514. #if PACKETVER >= 20150826
  10515. int type;
  10516. // Check identity
  10517. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10518. return;
  10519. type = (int)RFIFOB(fd,6);
  10520. // Check type
  10521. if( type < 10 || type > 12 )
  10522. return;
  10523. pc_setcart(sd, type);
  10524. #endif
  10525. }
  10526. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10527. /// 01af <num>.W
  10528. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10529. {// TODO: State tracking?
  10530. int type;
  10531. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10532. return;
  10533. #ifdef RENEWAL
  10534. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10535. clif_msg(sd, WORK_IN_PROGRESS);
  10536. return;
  10537. }
  10538. #endif
  10539. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10540. if(
  10541. #ifdef NEW_CARTS
  10542. #if PACKETVER >= 20191106
  10543. (type == 13 && sd->status.base_level > 100) ||
  10544. #endif
  10545. (type == 9 && sd->status.base_level > 130) ||
  10546. (type == 8 && sd->status.base_level > 120) ||
  10547. (type == 7 && sd->status.base_level > 110) ||
  10548. (type == 6 && sd->status.base_level > 100) ||
  10549. #endif
  10550. (type == 5 && sd->status.base_level > 90) ||
  10551. (type == 4 && sd->status.base_level > 80) ||
  10552. (type == 3 && sd->status.base_level > 65) ||
  10553. (type == 2 && sd->status.base_level > 40) ||
  10554. (type == 1))
  10555. pc_setcart(sd, type);
  10556. }
  10557. /// Request to increase status (CZ_STATUS_CHANGE).
  10558. /// 00bb <status id>.W <amount>.B
  10559. /// status id:
  10560. /// SP_STR ~ SP_LUK
  10561. /// amount:
  10562. /// Old clients always send 1 for this, even when using /str+ and the like.
  10563. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10564. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10565. {
  10566. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10567. if( increase_amount < 0 ) {
  10568. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10569. fd, increase_amount);
  10570. }
  10571. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10572. }
  10573. /// Request to increase trait status.
  10574. /// 0b24 <status id>.W <amount>.W
  10575. /// status id:
  10576. /// SP_POW ~ SP_CON
  10577. /// amount:
  10578. /// The amount to increase the trait status
  10579. void clif_parse_traitstatus_up( int fd, struct map_session_data *sd ){
  10580. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10581. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10582. if( p->amount < 0 ){
  10583. 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 );
  10584. return;
  10585. }
  10586. pc_traitstatusup( sd, p->type, p->amount );
  10587. #endif
  10588. }
  10589. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10590. /// 0112 <skill id>.W
  10591. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10592. {
  10593. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10594. }
  10595. 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)
  10596. {
  10597. int lv;
  10598. if( !hd )
  10599. return;
  10600. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10601. clif_emotion(&hd->bl, ET_THINK);
  10602. return;
  10603. }
  10604. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10605. target_id = hd->bl.id;
  10606. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10607. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10608. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10609. clif_emotion(&hd->bl, ET_THINK);
  10610. if (hd->master)
  10611. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10612. return;
  10613. }
  10614. lv = hom_checkskill(hd, skill_id);
  10615. if( skill_lv > lv )
  10616. skill_lv = lv;
  10617. if( skill_lv )
  10618. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10619. }
  10620. 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)
  10621. {
  10622. int lv;
  10623. if( !hd )
  10624. return;
  10625. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10626. clif_emotion(&hd->bl, ET_THINK);
  10627. return;
  10628. }
  10629. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10630. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10631. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10632. clif_emotion(&hd->bl, ET_THINK);
  10633. if (hd->master)
  10634. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10635. return;
  10636. }
  10637. #ifdef RENEWAL
  10638. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10639. #else
  10640. if (hd->sc.getSCE(SC_BASILICA))
  10641. #endif
  10642. return;
  10643. lv = hom_checkskill(hd, skill_id);
  10644. if( skill_lv > lv )
  10645. skill_lv = lv;
  10646. if( skill_lv )
  10647. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10648. }
  10649. 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)
  10650. {
  10651. int lv;
  10652. if( !md )
  10653. return;
  10654. if( skill_isNotOk_mercenary(skill_id, md) )
  10655. return;
  10656. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10657. target_id = md->bl.id;
  10658. if( md->ud.skilltimer != INVALID_TIMER )
  10659. {
  10660. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10661. }
  10662. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10663. return;
  10664. lv = mercenary_checkskill(md, skill_id);
  10665. if( skill_lv > lv )
  10666. skill_lv = lv;
  10667. if( skill_lv )
  10668. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10669. }
  10670. 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)
  10671. {
  10672. int lv;
  10673. if( !md )
  10674. return;
  10675. if( skill_isNotOk_mercenary(skill_id, md) )
  10676. return;
  10677. if( md->ud.skilltimer != INVALID_TIMER )
  10678. return;
  10679. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10680. {
  10681. if (md->master)
  10682. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10683. return;
  10684. }
  10685. #ifdef RENEWAL
  10686. if (md->sc.getSCE(SC_BASILICA_CELL))
  10687. #else
  10688. if (md->sc.getSCE(SC_BASILICA))
  10689. #endif
  10690. return;
  10691. lv = mercenary_checkskill(md, skill_id);
  10692. if( skill_lv > lv )
  10693. skill_lv = lv;
  10694. if( skill_lv )
  10695. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10696. }
  10697. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10698. t_tick tick = gettick();
  10699. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10700. int inf = skill_get_inf(skill_id);
  10701. if (inf&INF_GROUND_SKILL || !inf)
  10702. return; //Using a ground/passive skill on a target? WRONG.
  10703. if (sd->state.block_action & PCBLOCK_SKILL) {
  10704. clif_msg(sd, WORK_IN_PROGRESS);
  10705. return;
  10706. }
  10707. if( SKILL_CHK_HOMUN(skill_id) ) {
  10708. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10709. return;
  10710. }
  10711. if( SKILL_CHK_MERC(skill_id) ) {
  10712. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10713. return;
  10714. }
  10715. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10716. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10717. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10718. sd->idletime = last_tick;
  10719. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10720. sd->idletime_hom = last_tick;
  10721. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10722. sd->idletime_mer = last_tick;
  10723. if( sd->npc_id ){
  10724. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10725. #ifdef RENEWAL
  10726. clif_msg( sd, WORK_IN_PROGRESS );
  10727. #endif
  10728. return;
  10729. }
  10730. }
  10731. if ((pc_cant_act2(sd) || sd->chatID) &&
  10732. skill_id != RK_REFRESH &&
  10733. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10734. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10735. return;
  10736. if( pc_issit(sd) )
  10737. return;
  10738. if( skill_isNotOk(skill_id, sd) )
  10739. return;
  10740. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10741. target_id = sd->bl.id; // never trust the client
  10742. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10743. target_id = sd->bl.id;
  10744. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10745. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10746. return;
  10747. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10748. if( sd->skillitem != skill_id ) {
  10749. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10750. return;
  10751. }
  10752. }
  10753. if( sd->sc.option&OPTION_COSTUME )
  10754. return;
  10755. #ifndef RENEWAL
  10756. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10757. return; // On basilica only caster can use Basilica again to stop it.
  10758. #endif
  10759. if( sd->menuskill_id ) {
  10760. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10761. clif_menuskill_clear(sd); //Cancel pet capture.
  10762. }else if( sd->menuskill_id == SG_FEEL ){
  10763. clif_menuskill_clear( sd ); // Cancel selection
  10764. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10765. return; //Can't use skills while a menu is open.
  10766. }
  10767. if( sd->skillitem == skill_id ) {
  10768. if( skill_lv != sd->skillitemlv )
  10769. skill_lv = sd->skillitemlv;
  10770. if( !(inf&INF_SELF_SKILL) )
  10771. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10772. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10773. return;
  10774. }
  10775. sd->skillitem = sd->skillitemlv = 0;
  10776. if( SKILL_CHK_GUILD(skill_id) ) {
  10777. if( sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING )
  10778. skill_lv = guild_checkskill(sd->guild, skill_id);
  10779. else
  10780. skill_lv = 0;
  10781. } else {
  10782. if( skill_id != ALL_EQSWITCH ){
  10783. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10784. }
  10785. }
  10786. pc_delinvincibletimer(sd);
  10787. if( skill_lv )
  10788. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10789. }
  10790. /// Request to use a targeted skill.
  10791. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10792. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10793. /// There are various variants of this packet, some of them have padding between fields.
  10794. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10795. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10796. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10797. }
  10798. /*==========================================
  10799. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10800. *------------------------------------------*/
  10801. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10802. {
  10803. t_tick tick = gettick();
  10804. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10805. return; //Using a target skill on the ground? WRONG.
  10806. if (sd->state.block_action & PCBLOCK_SKILL) {
  10807. clif_msg(sd, WORK_IN_PROGRESS);
  10808. return;
  10809. }
  10810. if( SKILL_CHK_HOMUN(skill_id) ) {
  10811. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10812. return;
  10813. }
  10814. if( SKILL_CHK_MERC(skill_id) ) {
  10815. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10816. return;
  10817. }
  10818. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10819. #ifdef RENEWAL
  10820. clif_msg( sd, WORK_IN_PROGRESS );
  10821. #endif
  10822. return;
  10823. }
  10824. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10825. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10826. sd->idletime = last_tick;
  10827. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10828. sd->idletime_hom = last_tick;
  10829. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10830. sd->idletime_mer = last_tick;
  10831. if( skill_isNotOk(skill_id, sd) )
  10832. return;
  10833. if( skillmoreinfo != -1 ) {
  10834. if( pc_issit(sd) ) {
  10835. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10836. return;
  10837. }
  10838. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10839. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10840. }
  10841. if( sd->ud.skilltimer != INVALID_TIMER )
  10842. return;
  10843. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10844. if( sd->skillitem != skill_id ) {
  10845. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10846. return;
  10847. }
  10848. }
  10849. if( sd->sc.option&OPTION_COSTUME )
  10850. return;
  10851. #ifndef RENEWAL
  10852. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10853. return; // On basilica only caster can use Basilica again to stop it.
  10854. #endif
  10855. if( sd->menuskill_id ) {
  10856. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10857. clif_menuskill_clear(sd); //Cancel pet capture.
  10858. }else if( sd->menuskill_id == SG_FEEL ){
  10859. clif_menuskill_clear( sd ); // Cancel selection
  10860. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10861. return; //Can't use skills while a menu is open.
  10862. }
  10863. pc_delinvincibletimer(sd);
  10864. if( sd->skillitem == skill_id ) {
  10865. if( skill_lv != sd->skillitemlv )
  10866. skill_lv = sd->skillitemlv;
  10867. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10868. } else {
  10869. int lv;
  10870. sd->skillitem = sd->skillitemlv = 0;
  10871. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10872. if( skill_lv > lv )
  10873. skill_lv = lv;
  10874. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10875. }
  10876. }
  10877. }
  10878. /// Request to use a ground skill.
  10879. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10880. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10881. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10882. /// There are various variants of this packet, some of them have padding between fields.
  10883. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10884. {
  10885. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10886. if (pc_cant_act(sd))
  10887. return;
  10888. if (pc_issit(sd))
  10889. return;
  10890. clif_parse_UseSkillToPosSub(fd, sd,
  10891. RFIFOW(fd,info->pos[0]), //skill lv
  10892. RFIFOW(fd,info->pos[1]), //skill num
  10893. RFIFOW(fd,info->pos[2]), //pos x
  10894. RFIFOW(fd,info->pos[3]), //pos y
  10895. // TODO: find out what this is intended to do
  10896. //RFIFOB(fd, info->pos[4])
  10897. -1 //Skill more info.
  10898. );
  10899. }
  10900. /// Request to use a ground skill with text.
  10901. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10902. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10903. /// There are various variants of this packet, some of them have padding between fields.
  10904. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10905. {
  10906. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10907. if (pc_cant_act(sd))
  10908. return;
  10909. if (pc_issit(sd))
  10910. return;
  10911. clif_parse_UseSkillToPosSub(fd, sd,
  10912. RFIFOW(fd,info->pos[0]), //Skill lv
  10913. RFIFOW(fd,info->pos[1]), //Skill num
  10914. RFIFOW(fd,info->pos[2]), //pos x
  10915. RFIFOW(fd,info->pos[3]), //pos y
  10916. info->pos[4] //skill more info
  10917. );
  10918. }
  10919. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10920. /// 011b <skill id>.W <map name>.16B
  10921. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10922. {
  10923. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10924. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10925. char map_name[MAP_NAME_LENGTH];
  10926. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10927. sd->state.workinprogress = WIP_DISABLE_NONE;
  10928. if(skill_id != sd->menuskill_id)
  10929. return;
  10930. //It is possible to use teleport with the storage window open bugreport:8027
  10931. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10932. clif_menuskill_clear(sd);
  10933. return;
  10934. }
  10935. pc_delinvincibletimer(sd);
  10936. skill_castend_map(sd,skill_id,map_name);
  10937. }
  10938. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10939. /// 011d
  10940. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10941. {
  10942. if (!pc_isdead(sd))
  10943. pc_memo(sd,-1);
  10944. }
  10945. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10946. /// 018e <name id>.W { <material id>.W }*3
  10947. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10948. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10949. switch( sd->menuskill_id ) {
  10950. case -1:
  10951. case AM_PHARMACY:
  10952. case RK_RUNEMASTERY:
  10953. case GC_RESEARCHNEWPOISON:
  10954. break;
  10955. default:
  10956. return;
  10957. }
  10958. if (pc_istrading(sd)) {
  10959. //Make it fail to avoid shop exploits where you sell something different than you see.
  10960. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10961. clif_menuskill_clear(sd);
  10962. return;
  10963. }
  10964. int produce_idx;
  10965. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10966. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10967. clif_menuskill_clear(sd);
  10968. }
  10969. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10970. /// 025b <mk type>.W <name id>.W
  10971. /// mk type:
  10972. /// 1 = cooking
  10973. /// 2 = arrow
  10974. /// 3 = elemental
  10975. /// 4 = GN_MIX_COOKING
  10976. /// 5 = GN_MAKEBOMB
  10977. /// 6 = GN_S_PHARMACY
  10978. /// 7 = MT_M_MACHINE - Unconfirmed
  10979. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  10980. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10981. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10982. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10983. short food_idx = -1;
  10984. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10985. return;
  10986. if (pc_istrading(sd)) {
  10987. //Make it fail to avoid shop exploits where you sell something different than you see.
  10988. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10989. clif_menuskill_clear(sd);
  10990. return;
  10991. }
  10992. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10993. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10994. clif_menuskill_clear(sd);
  10995. }
  10996. /// Answer to repair weapon item selection dialog
  10997. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10998. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10999. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  11000. // Hercules has wrong date -> use correct one here
  11001. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11002. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11003. #else
  11004. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11005. #endif
  11006. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11007. return;
  11008. if (pc_istrading(sd)) {
  11009. //Make it fail to avoid shop exploits where you sell something different than you see.
  11010. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11011. clif_menuskill_clear(sd);
  11012. return;
  11013. }
  11014. skill_repairweapon( sd, p->item.index );
  11015. clif_menuskill_clear(sd);
  11016. }
  11017. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11018. /// 0222 <index>.L
  11019. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  11020. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11021. return;
  11022. if (pc_istrading(sd)) {
  11023. //Make it fail to avoid shop exploits where you sell something different than you see.
  11024. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11025. clif_menuskill_clear(sd);
  11026. return;
  11027. }
  11028. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11029. clif_menuskill_clear(sd);
  11030. }
  11031. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11032. /// 00b8 <npc id>.L <choice>.B
  11033. /// choice:
  11034. /// 1~254 = menu item
  11035. /// 255 = cancel
  11036. /// NOTE: If there were more than 254 items in the list, choice
  11037. /// overflows to choice%256.
  11038. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  11039. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11040. int npc_id = RFIFOL(fd,info->pos[0]);
  11041. uint8 select = RFIFOB(fd,info->pos[1]);
  11042. #ifdef SECURE_NPCTIMEOUT
  11043. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11044. return;
  11045. #endif
  11046. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11047. TBL_NPC* nd = map_id2nd(npc_id);
  11048. 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);
  11049. clif_GM_kick(NULL,sd);
  11050. return;
  11051. }
  11052. sd->npc_menu = select;
  11053. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11054. sd->idletime = last_tick;
  11055. }
  11056. npc_scriptcont(sd,npc_id, false);
  11057. }
  11058. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11059. /// 00b9 <npc id>.L
  11060. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  11061. {
  11062. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11063. sd->idletime = last_tick;
  11064. }
  11065. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11066. }
  11067. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11068. /// 0143 <npc id>.L <value>.L
  11069. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  11070. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11071. int npcid = RFIFOL(fd,info->pos[0]);
  11072. int amount = (int)RFIFOL(fd,info->pos[1]);
  11073. sd->npc_amount = amount;
  11074. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11075. sd->idletime = last_tick;
  11076. }
  11077. npc_scriptcont(sd, npcid, false);
  11078. }
  11079. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11080. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11081. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  11082. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11083. int message_len = RFIFOW(fd,info->pos[0])-8;
  11084. int npcid = RFIFOL(fd,info->pos[1]);
  11085. const char* message = RFIFOCP(fd,info->pos[2]);
  11086. if( message_len <= 0 )
  11087. return; // invalid input
  11088. #if PACKETVER >= 20151001
  11089. message_len++;
  11090. #endif
  11091. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11092. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11093. sd->idletime = last_tick;
  11094. }
  11095. npc_scriptcont(sd, npcid, false);
  11096. }
  11097. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11098. /// 0146 <npc id>.L
  11099. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  11100. {
  11101. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11102. return;
  11103. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11104. sd->idletime = last_tick;
  11105. }
  11106. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11107. }
  11108. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11109. /// 0178 <index>.W
  11110. /// index:
  11111. /// -1 = cancel
  11112. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  11113. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11114. if (sd->menuskill_id != MC_IDENTIFY)
  11115. return;
  11116. // Ignore the request
  11117. // - Invalid item index
  11118. // - Invalid item ID or item doesn't exist
  11119. // - Item is already identified
  11120. if (idx < 0 || idx >= MAX_INVENTORY ||
  11121. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11122. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11123. sd->state.workinprogress = WIP_DISABLE_NONE;
  11124. clif_menuskill_clear(sd);
  11125. return;
  11126. }
  11127. skill_identify(sd, idx);
  11128. clif_menuskill_clear(sd);
  11129. }
  11130. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11131. /// 01ae <name id>.W
  11132. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  11133. if (pc_istrading(sd)) {
  11134. //Make it fail to avoid shop exploits where you sell something different than you see.
  11135. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11136. clif_menuskill_clear(sd);
  11137. return;
  11138. }
  11139. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11140. switch (sd->menuskill_id) {
  11141. case AC_MAKINGARROW:
  11142. skill_arrow_create(sd,p->itemId);
  11143. break;
  11144. case SA_CREATECON:
  11145. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11146. break;
  11147. case GC_POISONINGWEAPON:
  11148. skill_poisoningweapon(sd,p->itemId);
  11149. break;
  11150. case NC_MAGICDECOY:
  11151. skill_magicdecoy(sd,p->itemId);
  11152. break;
  11153. }
  11154. clif_menuskill_clear(sd);
  11155. }
  11156. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11157. /// 01ce <skill id>.L
  11158. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  11159. {
  11160. if (sd->menuskill_id != SA_AUTOSPELL)
  11161. return;
  11162. sd->state.workinprogress = WIP_DISABLE_NONE;
  11163. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11164. clif_menuskill_clear(sd);
  11165. }
  11166. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11167. /// 017a <card index>.W
  11168. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  11169. {
  11170. if (sd->state.trading != 0)
  11171. return;
  11172. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11173. }
  11174. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11175. /// 017c <card index>.W <equip index>.W
  11176. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  11177. {
  11178. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11179. if (sd->state.trading != 0)
  11180. return;
  11181. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11182. }
  11183. /// Request of character's name by char ID.
  11184. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11185. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11186. /// There are various variants of this packet, some of them have padding between fields.
  11187. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  11188. {
  11189. int charid;
  11190. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11191. map_reqnickdb(sd, charid);
  11192. }
  11193. /// /resetskill /resetstate (CZ_RESET).
  11194. /// Request to reset stats or skills.
  11195. /// 0197 <type>.W
  11196. /// type:
  11197. /// 0 = state
  11198. /// 1 = skill
  11199. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11200. char cmd[15];
  11201. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11202. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11203. else
  11204. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11205. is_atcommand(fd, sd, cmd, 1);
  11206. }
  11207. /// /lb /nlb (CZ_LOCALBROADCAST).
  11208. /// Request to broadcast a message on current map.
  11209. /// 019c <packet len>.W <text>.?B
  11210. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11211. {
  11212. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11213. char command[CHAT_SIZE_MAX+16];
  11214. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11215. char* msg = RFIFOCP(fd,info->pos[1]);
  11216. // as the length varies depending on the command used, just block unreasonably long strings
  11217. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11218. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11219. is_atcommand(fd, sd, command, 1);
  11220. }
  11221. /// Request to move an item from inventory to storage.
  11222. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11223. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11224. /// There are various variants of this packet, some of them have padding between fields.
  11225. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11226. {
  11227. int item_index, item_amount;
  11228. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11229. if (pc_istrading(sd))
  11230. return;
  11231. item_index = RFIFOW(fd,info->pos[0])-2;
  11232. item_amount = RFIFOL(fd,info->pos[1]);
  11233. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11234. return;
  11235. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11236. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11237. return;
  11238. }
  11239. if (sd->state.storage_flag == 1)
  11240. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11241. else
  11242. if (sd->state.storage_flag == 2)
  11243. storage_guild_storageadd(sd, item_index, item_amount);
  11244. else if (sd->state.storage_flag == 3)
  11245. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11246. }
  11247. /// Request to move an item from storage to inventory.
  11248. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11249. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11250. /// There are various variants of this packet, some of them have padding between fields.
  11251. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11252. {
  11253. int item_index, item_amount;
  11254. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11255. item_index = RFIFOW(fd,info->pos[0])-1;
  11256. item_amount = RFIFOL(fd,info->pos[1]);
  11257. if (sd->state.storage_flag == 1)
  11258. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11259. else if(sd->state.storage_flag == 2)
  11260. storage_guild_storageget(sd, item_index, item_amount);
  11261. else if(sd->state.storage_flag == 3)
  11262. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11263. }
  11264. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11265. /// 0129 <index>.W <amount>.L
  11266. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11267. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11268. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11269. int amount = RFIFOL(fd,info->pos[1]);
  11270. if( sd->state.vending )
  11271. return;
  11272. if (!pc_iscarton(sd))
  11273. return;
  11274. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11275. return;
  11276. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11277. return;
  11278. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11279. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11280. return;
  11281. }
  11282. if (sd->state.storage_flag == 1)
  11283. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11284. else if (sd->state.storage_flag == 2)
  11285. storage_guild_storageaddfromcart(sd, idx, amount);
  11286. else if (sd->state.storage_flag == 3)
  11287. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11288. }
  11289. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11290. /// 0128 <index>.W <amount>.L
  11291. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11292. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11293. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11294. int amount = RFIFOL(fd,info->pos[1]);
  11295. if( sd->state.vending )
  11296. return;
  11297. if (!pc_iscarton(sd))
  11298. return;
  11299. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11300. return;
  11301. if (sd->state.storage_flag == 1)
  11302. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11303. else
  11304. if (sd->state.storage_flag == 2)
  11305. storage_guild_storagegettocart(sd, idx, amount);
  11306. else if (sd->state.storage_flag == 3)
  11307. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11308. }
  11309. /// Request to close storage (CZ_CLOSE_STORE).
  11310. /// 00f7
  11311. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11312. {
  11313. if( sd->state.storage_flag == 1 )
  11314. storage_storageclose(sd);
  11315. else
  11316. if( sd->state.storage_flag == 2 )
  11317. storage_guild_storageclose(sd);
  11318. else if( sd->state.storage_flag == 3 )
  11319. storage_premiumStorage_close(sd);
  11320. }
  11321. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11322. /// 023a <info>.W
  11323. /// info:
  11324. /// 0 = password has not been set yet
  11325. /// 1 = storage is password-protected
  11326. /// 8 = too many wrong passwords
  11327. /// ? = ignored
  11328. /// NOTE: This packet is only available on certain non-kRO clients.
  11329. void clif_storagepassword(struct map_session_data* sd, short info)
  11330. {
  11331. int fd = sd->fd;
  11332. WFIFOHEAD(fd,packet_len(0x23a));
  11333. WFIFOW(fd,0) = 0x23a;
  11334. WFIFOW(fd,2) = info;
  11335. WFIFOSET(fd,packet_len(0x23a));
  11336. }
  11337. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11338. /// 023b <type>.W <password>.16B <new password>.16B
  11339. /// type:
  11340. /// 2 = change password
  11341. /// 3 = check password
  11342. /// NOTE: This packet is only available on certain non-kRO clients.
  11343. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11344. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11345. // int type = RFIFOW(fd,info->pos[0]);
  11346. // char* password = RFIFOP(fd,info->pos[1]);
  11347. // char* new_password = RFIFOP(fd,info->pos[2]);
  11348. // storage_changepass(sd,password,new_password);
  11349. }
  11350. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11351. /// 023c <result>.W <error count>.W
  11352. /// result:
  11353. /// 4 = password change success
  11354. /// 5 = password change failure
  11355. /// 6 = password check success
  11356. /// 7 = password check failure
  11357. /// 8 = too many wrong passwords
  11358. /// ? = ignored
  11359. /// NOTE: This packet is only available on certain non-kRO clients.
  11360. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11361. {
  11362. int fd = sd->fd;
  11363. WFIFOHEAD(fd,packet_len(0x23c));
  11364. WFIFOW(fd,0) = 0x23c;
  11365. WFIFOW(fd,2) = result;
  11366. WFIFOW(fd,4) = error_count;
  11367. WFIFOSET(fd,packet_len(0x23c));
  11368. }
  11369. /// Party creation request
  11370. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11371. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11372. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11373. name[NAME_LENGTH-1] = '\0';
  11374. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11375. clif_displaymessage(fd, msg_txt(sd,227));
  11376. return;
  11377. }
  11378. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11379. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11380. return;
  11381. }
  11382. party_create(sd,name,0,0);
  11383. }
  11384. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11385. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11386. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11387. char* name = RFIFOCP(fd,info->pos[0]);
  11388. int item1 = RFIFOB(fd,info->pos[1]);
  11389. int item2 = RFIFOB(fd,info->pos[2]);
  11390. name[NAME_LENGTH-1] = '\0';
  11391. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11392. clif_displaymessage(fd, msg_txt(sd,227));
  11393. return;
  11394. }
  11395. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11396. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11397. return;
  11398. }
  11399. party_create(sd,name,item1,item2);
  11400. }
  11401. /// Party invitation request
  11402. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11403. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11404. {
  11405. struct map_session_data *t_sd;
  11406. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11407. clif_displaymessage(fd, msg_txt(sd,227));
  11408. return;
  11409. }
  11410. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11411. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11412. clif_noask_sub(sd, t_sd, 1);
  11413. return;
  11414. }
  11415. party_invite(sd, t_sd);
  11416. }
  11417. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11418. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11419. struct map_session_data *t_sd;
  11420. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11421. name[NAME_LENGTH-1] = '\0';
  11422. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11423. clif_displaymessage(fd, msg_txt(sd,227));
  11424. return;
  11425. }
  11426. t_sd = map_nick2sd(name,false);
  11427. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11428. clif_noask_sub(sd, t_sd, 1);
  11429. return;
  11430. }
  11431. party_invite(sd, t_sd);
  11432. }
  11433. /// Party invitation reply
  11434. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11435. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11436. /// flag:
  11437. /// 0 = reject
  11438. /// 1 = accept
  11439. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11440. {
  11441. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11442. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11443. RFIFOL(fd,info->pos[1]));
  11444. }
  11445. //(CZ_PARTY_JOIN_REQ_ACK)
  11446. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11447. {
  11448. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11449. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11450. RFIFOB(fd,info->pos[1]));
  11451. }
  11452. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11453. /// 0100
  11454. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11455. {
  11456. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11457. clif_displaymessage(fd, msg_txt(sd,227));
  11458. return;
  11459. }
  11460. party_leave(sd);
  11461. }
  11462. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11463. /// 0103 <account id>.L <char name>.24B
  11464. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11465. {
  11466. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11467. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11468. clif_displaymessage(fd, msg_txt(sd,227));
  11469. return;
  11470. }
  11471. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11472. RFIFOCP(fd,info->pos[1]));
  11473. }
  11474. /// Request to change party options.
  11475. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11476. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11477. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11478. {
  11479. struct party_data *p;
  11480. int i,expflag;
  11481. int cmd = RFIFOW(fd,0);
  11482. struct s_packet_db* info = &packet_db[cmd];
  11483. if( !sd->status.party_id )
  11484. return;
  11485. p = party_search(sd->status.party_id);
  11486. if( p == NULL )
  11487. return;
  11488. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11489. if( i == MAX_PARTY )
  11490. return; //Shouldn't happen
  11491. if( !p->party.member[i].leader )
  11492. return;
  11493. expflag = RFIFOL(fd,info->pos[0]);
  11494. if(cmd == 0x0102){ //Client can't change the item-field
  11495. party_changeoption(sd, expflag, p->party.item);
  11496. }
  11497. else {
  11498. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11499. party_changeoption(sd, expflag, itemflag);
  11500. }
  11501. }
  11502. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11503. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11504. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11505. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11506. // validate packet and retrieve name and message
  11507. if( !clif_process_message( sd, false, name, message, output ) )
  11508. return;
  11509. party_send_message(sd, output, strlen(output) + 1 );
  11510. }
  11511. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11512. /// 07da <account id>.L
  11513. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11514. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11515. }
  11516. /// Party Booking in KRO [Spiria]
  11517. ///
  11518. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11519. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11520. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11521. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11522. short level = RFIFOW(fd,info->pos[0]);
  11523. short mapid = RFIFOW(fd,info->pos[1]);
  11524. int idxpbj = info->pos[2];
  11525. short job[MAX_PARTY_BOOKING_JOBS];
  11526. int i;
  11527. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11528. job[i] = RFIFOB(fd,idxpbj+i*2);
  11529. party_booking_register(sd, level, mapid, job);
  11530. }
  11531. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11532. /// 0803 <result>.W
  11533. /// result:
  11534. /// 0 = success
  11535. /// 1 = failure
  11536. /// 2 = already registered
  11537. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11538. {
  11539. int fd = sd->fd;
  11540. WFIFOHEAD(fd,packet_len(0x803));
  11541. WFIFOW(fd,0) = 0x803;
  11542. WFIFOW(fd,2) = flag;
  11543. WFIFOSET(fd,packet_len(0x803));
  11544. }
  11545. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11546. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11547. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11548. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11549. short level = RFIFOW(fd,info->pos[0]);
  11550. short mapid = RFIFOW(fd,info->pos[1]);
  11551. short job = RFIFOW(fd,info->pos[2]);
  11552. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11553. short resultcount = RFIFOW(fd,info->pos[4]);
  11554. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11555. }
  11556. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11557. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11558. /// more results:
  11559. /// 0 = no
  11560. /// 1 = yes
  11561. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11562. {
  11563. int i, j;
  11564. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11565. struct party_booking_ad_info *pb_ad;
  11566. WFIFOHEAD(fd,size*count + 5);
  11567. WFIFOW(fd,0) = 0x805;
  11568. WFIFOW(fd,2) = size*count + 5;
  11569. WFIFOB(fd,4) = more_result;
  11570. for(i=0; i<count; i++)
  11571. {
  11572. pb_ad = results[i];
  11573. WFIFOL(fd,i*size+5) = pb_ad->index;
  11574. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11575. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11576. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11577. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11578. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11579. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11580. }
  11581. WFIFOSET(fd,WFIFOW(fd,2));
  11582. }
  11583. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11584. /// 0806
  11585. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11586. {
  11587. if(party_booking_delete(sd))
  11588. clif_PartyBookingDeleteAck(sd, 0);
  11589. }
  11590. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11591. /// 0807 <result>.W
  11592. /// result:
  11593. /// 0 = success
  11594. /// 1 = success (auto-removed expired ad)
  11595. /// 2 = failure
  11596. /// 3 = nothing registered
  11597. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11598. {
  11599. int fd = sd->fd;
  11600. WFIFOHEAD(fd,packet_len(0x807));
  11601. WFIFOW(fd,0) = 0x807;
  11602. WFIFOW(fd,2) = flag;
  11603. WFIFOSET(fd,packet_len(0x807));
  11604. }
  11605. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11606. /// 0808 { <job>.W }*6
  11607. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11608. {
  11609. short job[MAX_PARTY_BOOKING_JOBS];
  11610. int i;
  11611. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11612. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11613. job[i] = RFIFOW(fd,idxpbu+i*2);
  11614. party_booking_update(sd, job);
  11615. }
  11616. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11617. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11618. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11619. {
  11620. int i;
  11621. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11622. if(pb_ad == NULL) return;
  11623. WBUFW(buf,0) = 0x809;
  11624. WBUFL(buf,2) = pb_ad->index;
  11625. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11626. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11627. WBUFW(buf,34) = pb_ad->p_detail.level;
  11628. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11629. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11630. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11631. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11632. }
  11633. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11634. /// 080a <index>.L { <job>.W }*6
  11635. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11636. {
  11637. int i;
  11638. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11639. if(pb_ad == NULL) return;
  11640. WBUFW(buf,0) = 0x80a;
  11641. WBUFL(buf,2) = pb_ad->index;
  11642. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11643. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11644. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11645. }
  11646. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11647. /// 080b <index>.L
  11648. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11649. {
  11650. uint8 buf[6];
  11651. WBUFW(buf,0) = 0x80b;
  11652. WBUFL(buf,2) = index;
  11653. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11654. }
  11655. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11656. /// 012e
  11657. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11658. {
  11659. vending_closevending(sd);
  11660. }
  11661. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11662. /// 0130 <account id>.L
  11663. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11664. {
  11665. if( sd->npc_id ) {// using an NPC
  11666. return;
  11667. }
  11668. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11669. }
  11670. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11671. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11672. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11673. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11674. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11675. // whether it fails or not, the buy window is closed
  11676. sd->vended_id = 0;
  11677. }
  11678. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11679. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11680. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11681. #if PACKETVER >= 20100105
  11682. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11683. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11684. // whether it fails or not, the buy window is closed
  11685. sd->vended_id = 0;
  11686. #endif
  11687. }
  11688. /// Confirm or cancel the shop preparation window.
  11689. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11690. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11691. /// result:
  11692. /// 0 = canceled
  11693. /// 1 = open
  11694. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11695. int cmd = RFIFOW(fd,0);
  11696. struct s_packet_db* info = &packet_db[cmd];
  11697. short len = (short)RFIFOW(fd,info->pos[0]);
  11698. const char* message = RFIFOCP(fd,info->pos[1]);
  11699. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11700. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11701. len -= 84;
  11702. }
  11703. else { //(CZ_REQ_OPENSTORE2)
  11704. bool flag;
  11705. len -= 85;
  11706. flag = RFIFOB(fd,info->pos[2]) != 0;
  11707. if (!flag) {
  11708. sd->state.prevend = 0;
  11709. sd->state.workinprogress = WIP_DISABLE_NONE;
  11710. }
  11711. }
  11712. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11713. return;
  11714. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11715. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11716. return;
  11717. }
  11718. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11719. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11720. return;
  11721. }
  11722. if( message[0] == '\0' ) // invalid input
  11723. return;
  11724. vending_openvending(sd, message, data, len/8, NULL);
  11725. }
  11726. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11727. /// 0165 <char id>.L <guild name>.24B
  11728. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11729. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11730. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11731. name[NAME_LENGTH-1] = '\0';
  11732. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11733. clif_displaymessage(fd, msg_txt(sd,228));
  11734. return;
  11735. }
  11736. if(sd->clan){
  11737. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11738. return;
  11739. }
  11740. guild_create(sd, name);
  11741. }
  11742. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11743. /// 014d
  11744. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11745. {
  11746. clif_guild_masterormember(sd);
  11747. }
  11748. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11749. /// 014f <type>.L
  11750. /// type:
  11751. /// 0 = basic info
  11752. /// 1 = member manager
  11753. /// 2 = positions
  11754. /// 3 = skills
  11755. /// 4 = expulsion list
  11756. /// 5 = unknown (GM_ALLGUILDLIST)
  11757. /// 6 = notice
  11758. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11759. {
  11760. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11761. if( !sd->status.guild_id && !sd->bg_id )
  11762. return;
  11763. switch( type )
  11764. {
  11765. case 0: // Basic Information Guild, hostile alliance information
  11766. clif_guild_basicinfo( *sd );
  11767. clif_guild_allianceinfo(sd);
  11768. break;
  11769. case 1: // Members list, list job title
  11770. clif_guild_positionnamelist(sd);
  11771. clif_guild_memberlist( *sd );
  11772. break;
  11773. case 2: // List job title, title information list
  11774. clif_guild_positionnamelist(sd);
  11775. clif_guild_positioninfolist(sd);
  11776. break;
  11777. case 3: // Skill list
  11778. clif_guild_skillinfo(sd);
  11779. break;
  11780. case 4: // Expulsion list
  11781. clif_guild_expulsionlist(sd);
  11782. break;
  11783. default:
  11784. ShowError("clif: guild request info: unknown type %d\n", type);
  11785. break;
  11786. }
  11787. }
  11788. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11789. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11790. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11791. {
  11792. int i;
  11793. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11794. int len = RFIFOW(fd,info->pos[0]);
  11795. int idxgpos = info->pos[1];
  11796. if(!sd->state.gmaster_flag)
  11797. return;
  11798. for(i = idxgpos; i < len; i += 40 ){
  11799. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11800. }
  11801. }
  11802. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11803. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11804. void clif_parse_GuildChangeMemberPosition( int fd, struct map_session_data *sd ){
  11805. if(!sd->state.gmaster_flag)
  11806. return;
  11807. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11808. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11809. for( int16 i = 0; i < entries; i++ ){
  11810. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11811. // Guild leadership change
  11812. if( entry.position == 0 ){
  11813. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11814. clif_msg( sd, GUILD_MASTER_WOE );
  11815. return;
  11816. }
  11817. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11818. clif_msg( sd, GUILD_MASTER_DELAY );
  11819. return;
  11820. }
  11821. guild_gm_change( sd->status.guild_id, entry.CID );
  11822. // No further entries will be processed - the requesting player lost his guild master status
  11823. return;
  11824. }else if( entry.position > 0 ){
  11825. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11826. }
  11827. }
  11828. }
  11829. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11830. /// 0151 <guild id>.L
  11831. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11832. {
  11833. struct guild* g;
  11834. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11835. if( (g = guild_search(guild_id)) != NULL )
  11836. clif_guild_emblem(sd,g);
  11837. }
  11838. /// Validates data of a guild emblem (compressed bitmap)
  11839. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11840. EMBVALIDATE_SUCCESS = 0,
  11841. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11842. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11843. };
  11844. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11845. {
  11846. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11847. unsigned long buf_len = sizeof(buf);
  11848. int offset = 0;
  11849. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11850. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11851. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11852. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11853. ))
  11854. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11855. if(inter_config.emblem_transparency_limit != 100) {
  11856. int i, transcount = 1, tmp[3];
  11857. for(i = offset; i < buf_len-1; i++) {
  11858. int j = i%3;
  11859. tmp[j] = RBUFL(buf,i);
  11860. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11861. transcount++;
  11862. }
  11863. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11864. return EMBVALIDATE_ERR_TRANSPARENCY;
  11865. }
  11866. return EMBVALIDATE_SUCCESS;
  11867. }
  11868. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11869. /// 0153 <packet len>.W <emblem data>.?B
  11870. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11871. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11872. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11873. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11874. int emb_val=0;
  11875. if( !emblem_len || !sd->state.gmaster_flag )
  11876. return;
  11877. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11878. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11879. return;
  11880. }
  11881. emb_val = clif_validate_emblem(emblem, emblem_len);
  11882. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11883. 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);
  11884. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11885. return;
  11886. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11887. char output[128];
  11888. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11889. 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"
  11890. return;
  11891. }
  11892. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11893. }
  11894. /// Request to update the guild emblem id (version, according to Gravity)
  11895. /// 0b46 <guild id>.L <version>.L
  11896. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11897. nullpo_retv(sd);
  11898. #if PACKETVER >= 20190724
  11899. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11900. guild* g = sd->guild;
  11901. if (g == nullptr || g->guild_id != p->guild_id)
  11902. return;
  11903. if (!sd->state.gmaster_flag)
  11904. return;
  11905. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11906. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11907. return;
  11908. }
  11909. guild_change_emblem_version(sd, p->version);
  11910. #endif
  11911. }
  11912. /// Guild notice update request (CZ_GUILD_NOTICE).
  11913. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11914. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11915. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11916. int guild_id = RFIFOL(fd,info->pos[0]);
  11917. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11918. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11919. if(!sd->state.gmaster_flag)
  11920. return;
  11921. // compensate for some client defects when using multilanguage mode
  11922. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11923. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11924. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11925. guild_change_notice(sd, guild_id, msg1, msg2);
  11926. }
  11927. // Helper function for guild invite functions
  11928. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11929. {
  11930. if (t_sd == NULL) // not online or does not exist
  11931. return 1;
  11932. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11933. clif_displaymessage(fd, msg_txt(sd,228));
  11934. return 1;
  11935. }
  11936. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11937. clif_noask_sub(sd, t_sd, 2);
  11938. return 1;
  11939. }
  11940. // Players in a clan can not join a guild
  11941. if(t_sd && t_sd->clan){
  11942. return 1;
  11943. }
  11944. guild_invite(sd, t_sd);
  11945. return 0;
  11946. }
  11947. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11948. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11949. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11950. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11951. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11952. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11953. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11954. if (clif_sub_guild_invite(fd, sd, t_sd))
  11955. return;
  11956. }
  11957. /// Guild invite request (/guildinvite)
  11958. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11959. void
  11960. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11961. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11962. if (clif_sub_guild_invite(fd, sd, t_sd))
  11963. return;
  11964. }
  11965. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11966. /// 016b <guild id>.L <answer>.L
  11967. /// answer:
  11968. /// 0 = refuse
  11969. /// 1 = accept
  11970. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11971. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11972. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11973. RFIFOL(fd,info->pos[1]));
  11974. }
  11975. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11976. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11977. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11978. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11979. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11980. clif_displaymessage(fd, msg_txt(sd,228));
  11981. return;
  11982. }
  11983. if( sd->bg_id ) {
  11984. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11985. return;
  11986. }
  11987. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11988. RFIFOL(fd,info->pos[1]),
  11989. RFIFOL(fd,info->pos[2]),
  11990. RFIFOCP(fd,info->pos[3]));
  11991. }
  11992. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11993. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11994. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11995. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11996. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11997. { // Guild locked.
  11998. clif_displaymessage(fd, msg_txt(sd,228));
  11999. return;
  12000. }
  12001. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12002. RFIFOL(fd,info->pos[1]),
  12003. RFIFOL(fd,info->pos[2]),
  12004. RFIFOCP(fd,info->pos[3]));
  12005. }
  12006. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12007. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12008. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  12009. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12010. // validate packet and retrieve name and message
  12011. if( !clif_process_message( sd, false, name, message, output ) )
  12012. return;
  12013. if( sd->bg_id )
  12014. bg_send_message(sd, output, strlen(output) );
  12015. else
  12016. guild_send_message(sd, output, strlen(output) );
  12017. }
  12018. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12019. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12020. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  12021. {
  12022. struct map_session_data *t_sd;
  12023. if(!sd->state.gmaster_flag)
  12024. return;
  12025. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12026. clif_displaymessage(fd, msg_txt(sd,228));
  12027. return;
  12028. }
  12029. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12030. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12031. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12032. // @noask [LuzZza]
  12033. if(t_sd && t_sd->state.noask) {
  12034. clif_noask_sub(sd, t_sd, 3);
  12035. return;
  12036. }
  12037. guild_reqalliance(sd,t_sd);
  12038. }
  12039. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12040. /// 0172 <inviter account id>.L <answer>.L
  12041. /// answer:
  12042. /// 0 = refuse
  12043. /// 1 = accept
  12044. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  12045. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12046. guild_reply_reqalliance(sd,
  12047. RFIFOL(fd,info->pos[0]),
  12048. RFIFOL(fd,info->pos[1]));
  12049. }
  12050. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12051. /// 0183 <opponent guild id>.L <relation>.L
  12052. /// relation:
  12053. /// 0 = Ally
  12054. /// 1 = Enemy
  12055. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  12056. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12057. if(!sd->state.gmaster_flag)
  12058. return;
  12059. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12060. clif_displaymessage(fd, msg_txt(sd,228));
  12061. return;
  12062. }
  12063. guild_delalliance(sd,
  12064. RFIFOL(fd,info->pos[0]),
  12065. RFIFOL(fd,info->pos[1]));
  12066. }
  12067. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12068. /// 0180 <account id>.L
  12069. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  12070. {
  12071. struct map_session_data *t_sd;
  12072. if(!sd->state.gmaster_flag)
  12073. return;
  12074. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12075. clif_displaymessage(fd, msg_txt(sd,228));
  12076. return;
  12077. }
  12078. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12079. // @noask [LuzZza]
  12080. if(t_sd && t_sd->state.noask) {
  12081. clif_noask_sub(sd, t_sd, 4);
  12082. return;
  12083. }
  12084. guild_opposition(sd,t_sd);
  12085. }
  12086. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12087. /// 015d <key>.40B
  12088. /// key:
  12089. /// now guild name; might have been (intended) email, since the
  12090. /// field name and size is same as the one in CH_DELETE_CHAR.
  12091. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  12092. {
  12093. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12094. clif_displaymessage(fd, msg_txt(sd,228));
  12095. return;
  12096. }
  12097. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12098. }
  12099. /// Pet
  12100. ///
  12101. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12102. /// 01a1 <type>.B
  12103. /// type:
  12104. /// 0 = pet information
  12105. /// 1 = feed
  12106. /// 2 = performance
  12107. /// 3 = return to egg
  12108. /// 4 = unequip accessory
  12109. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  12110. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12111. }
  12112. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12113. /// 019f <id>.L
  12114. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  12115. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12116. }
  12117. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12118. /// 01a7 <index>.W
  12119. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  12120. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12121. return;
  12122. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12123. clif_menuskill_clear(sd);
  12124. }
  12125. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12126. /// 01a9 <data>.L
  12127. /// data:
  12128. /// is either emotion (@see enum emotion_type) or a compound value
  12129. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12130. /// entry (given in parentheses) in data\pettalktable.xml
  12131. /// act id:
  12132. /// 0 = feeding
  12133. /// 1 = hunting
  12134. /// 2 = danger
  12135. /// 3 = dead
  12136. /// 4 = normal (stand)
  12137. /// 5 = special performance (perfor_s)
  12138. /// 6 = level up (levelup)
  12139. /// 7 = performance 1 (perfor_1)
  12140. /// 8 = performance 2 (perfor_2)
  12141. /// 9 = performance 3 (perfor_3)
  12142. /// 10 = log-in greeting (connect)
  12143. /// hungry value:
  12144. /// 0 = very hungry (hungry)
  12145. /// 1 = hungry (bit_hungry)
  12146. /// 2 = satisfied (noting)
  12147. /// 3 = stuffed (full)
  12148. /// 4 = full (so_full)
  12149. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  12150. {
  12151. if(sd->pd)
  12152. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12153. }
  12154. /// Request to change pet's name (CZ_RENAME_PET).
  12155. /// 01a5 <name>.24B
  12156. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  12157. {
  12158. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12159. }
  12160. /// /kill (CZ_DISCONNECT_CHARACTER).
  12161. /// Request to disconnect a character.
  12162. /// 00cc <account id>.L
  12163. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12164. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  12165. {
  12166. struct block_list *target;
  12167. int tid;
  12168. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12169. target = map_id2bl(tid);
  12170. if (!target) {
  12171. clif_GM_kickack(sd, 0);
  12172. return;
  12173. }
  12174. switch (target->type) {
  12175. case BL_PC:
  12176. {
  12177. char command[NAME_LENGTH+6];
  12178. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12179. is_atcommand(fd, sd, command, 1);
  12180. }
  12181. break;
  12182. /**
  12183. * This one does not invoke any atcommand, so we need to check for permissions.
  12184. */
  12185. case BL_MOB:
  12186. {
  12187. char command[100];
  12188. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12189. clif_GM_kickack(sd, 0);
  12190. return;
  12191. }
  12192. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12193. log_atcommand(sd, command);
  12194. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12195. }
  12196. break;
  12197. case BL_NPC:
  12198. {
  12199. struct npc_data* nd = (struct npc_data *)target;
  12200. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12201. npc_unload_duplicates(nd);
  12202. npc_unload(nd,true);
  12203. npc_read_event_script();
  12204. }
  12205. }
  12206. break;
  12207. default:
  12208. clif_GM_kickack(sd, 0);
  12209. }
  12210. }
  12211. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12212. /// Request to disconnect all characters.
  12213. /// 00ce
  12214. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12215. char cmd[15];
  12216. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12217. is_atcommand(fd, sd, cmd, 1);
  12218. }
  12219. /// /remove (CZ_REMOVE_AID).
  12220. /// Request to warp to a character with given login ID.
  12221. /// 01ba <account name>.24B
  12222. /// /shift (CZ_SHIFT).
  12223. /// Request to warp to a character with given name.
  12224. /// 01bb <char name>.24B
  12225. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12226. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12227. char *player_name;
  12228. char command[NAME_LENGTH+8];
  12229. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12230. player_name[NAME_LENGTH-1] = '\0';
  12231. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12232. is_atcommand(fd, sd, command, 1);
  12233. }
  12234. /// /remove (CZ_REMOVE_AID_SSO).
  12235. /// Request to warp to a character with given account ID.
  12236. /// 0843 <account id>.L
  12237. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12238. {
  12239. uint32 account_id;
  12240. struct map_session_data* pl_sd;
  12241. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12242. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12243. char command[NAME_LENGTH+8];
  12244. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12245. is_atcommand(fd, sd, command, 1);
  12246. }
  12247. }
  12248. /// /recall (CZ_RECALL).
  12249. /// Request to summon a player with given login ID to own position.
  12250. /// 01bc <account name>.24B
  12251. /// /summon (CZ_RECALL_GID).
  12252. /// Request to summon a player with given name to own position.
  12253. /// 01bd <char name>.24B
  12254. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12255. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12256. char *player_name;
  12257. char command [NAME_LENGTH+8];
  12258. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12259. player_name[NAME_LENGTH-1] = '\0';
  12260. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12261. is_atcommand(fd, sd, command, 1);
  12262. }
  12263. /// /recall (CZ_RECALL_SSO).
  12264. /// Request to summon a player with given account ID to own position.
  12265. /// 0842 <account id>.L
  12266. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12267. {
  12268. uint32 account_id;
  12269. struct map_session_data* pl_sd;
  12270. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12271. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12272. char command[NAME_LENGTH+8];
  12273. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12274. is_atcommand(fd, sd, command, 1);
  12275. }
  12276. }
  12277. /// /item /monster (CZ_ITEM_CREATE).
  12278. /// Request to execute GM commands.
  12279. /// Usage:
  12280. /// /item n - summon n monster or acquire n item/s
  12281. /// /item money - grants 2147483647 zenies
  12282. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12283. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12284. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12285. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12286. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12287. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12288. /// 013f <item/mob name>.24B
  12289. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12290. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12291. {
  12292. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12293. int mob_id = 0;
  12294. StringBuf command;
  12295. char *str;
  12296. //#if PACKETVER >= 20131218
  12297. // char str[100];
  12298. //#else
  12299. // char str[24];
  12300. //#endif
  12301. str = RFIFOCP(fd,info->pos[0]);
  12302. if (!str || str[0] == '\0')
  12303. return;
  12304. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12305. return;
  12306. trim(str);
  12307. // Zeny
  12308. if( strcmpi(str, "money") == 0 ) {
  12309. StringBuf_Init(&command);
  12310. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12311. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12312. StringBuf_Destroy(&command);
  12313. return;
  12314. }
  12315. std::shared_ptr<item_data> id = item_db.searchname( str );
  12316. // Item
  12317. if( id ){
  12318. StringBuf_Init(&command);
  12319. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12320. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12321. }else{
  12322. if (id->flag.guid)
  12323. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12324. else
  12325. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12326. }
  12327. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12328. StringBuf_Destroy(&command);
  12329. return;
  12330. }
  12331. // Monster
  12332. if ((mob_id = mobdb_searchname(str)) == 0)
  12333. mob_id = mobdb_checkid(atoi(str));
  12334. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12335. if( mob != nullptr ) {
  12336. StringBuf_Init(&command);
  12337. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12338. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12339. StringBuf_Destroy(&command);
  12340. return;
  12341. }
  12342. }
  12343. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12344. /// 019d <effect state>.L
  12345. /// effect state:
  12346. /// TODO: Any OPTION_* ?
  12347. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12348. char cmd[6];
  12349. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12350. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12351. is_atcommand(fd, sd, cmd, 1);
  12352. }
  12353. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12354. /// 0149 <account id>.L <type>.B <value>.W
  12355. /// type:
  12356. /// 0 = positive points
  12357. /// 1 = negative points
  12358. /// 2 = self mute (+10 minutes)
  12359. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12360. {
  12361. int id, type, value;
  12362. struct map_session_data *dstsd;
  12363. char command[NAME_LENGTH+15];
  12364. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12365. id = RFIFOL(fd,info->pos[0]);
  12366. type = RFIFOB(fd,info->pos[1]);
  12367. value = RFIFOW(fd,info->pos[2]);
  12368. if( type == 0 )
  12369. value = -value;
  12370. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12371. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12372. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12373. return;
  12374. dstsd = map_id2sd(id);
  12375. if( dstsd == NULL )
  12376. return;
  12377. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12378. is_atcommand(fd, sd, command, 1);
  12379. }
  12380. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12381. /// GM adjustment of a player's manner value by -60.
  12382. /// 0212 <char name>.24B
  12383. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12384. {
  12385. char command[NAME_LENGTH+15];
  12386. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12387. name[NAME_LENGTH-1] = '\0';
  12388. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12389. is_atcommand(fd, sd, command, 1);
  12390. }
  12391. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12392. /// 01e0 <account id>.L <account name>.24B
  12393. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12394. {
  12395. WFIFOHEAD(fd,packet_len(0x1e0));
  12396. WFIFOW(fd,0) = 0x1e0;
  12397. WFIFOL(fd,2) = account_id;
  12398. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12399. WFIFOSET(fd,packet_len(0x1e0));
  12400. }
  12401. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12402. /// 01df <account id>.L
  12403. //! TODO: Figure out how does this actually work
  12404. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12405. {
  12406. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12407. /*
  12408. char query[30];
  12409. safesnprintf(query,sizeof(query),"%d", account_id);
  12410. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12411. */
  12412. clif_account_name(fd, account_id, "");
  12413. }
  12414. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12415. /// GM single cell type change request.
  12416. /// 0198 <x>.W <y>.W <type>.W
  12417. /// type:
  12418. /// 0 = not walkable
  12419. /// 1 = walkable
  12420. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12421. {
  12422. int x,y,type;
  12423. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12424. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12425. return;
  12426. x = RFIFOW(fd,info->pos[0]);
  12427. y = RFIFOW(fd,info->pos[1]);
  12428. type = RFIFOW(fd,info->pos[2]);
  12429. map_setgatcell(sd->bl.m,x,y,type);
  12430. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12431. //FIXME: once players leave the map, the client 'forgets' this information.
  12432. }
  12433. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12434. /// Request to allow/deny whispers from a nick.
  12435. /// 00cf <nick>.24B <type>.B
  12436. /// type:
  12437. /// 0 = (/ex nick) deny speech from nick
  12438. /// 1 = (/in nick) allow speech from nick
  12439. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12440. {
  12441. char* nick;
  12442. uint8 type;
  12443. int i;
  12444. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12445. nick = RFIFOCP(fd,info->pos[0]);
  12446. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12447. type = RFIFOB(fd,info->pos[1]);
  12448. if( type == 0 ) { // Add name to ignore list (block)
  12449. if (strcmp(wisp_server_name, nick) == 0) {
  12450. clif_wisexin(sd, type, 1); // fail
  12451. return;
  12452. }
  12453. // try to find a free spot, while checking for duplicates at the same time
  12454. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12455. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12456. clif_wisexin(sd, type, 2); // too many blocks
  12457. return;
  12458. }
  12459. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12460. clif_wisexin(sd, type, 0); // Aegis reports success.
  12461. return;
  12462. }
  12463. //Insert in position i
  12464. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12465. } else { // Remove name from ignore list (unblock)
  12466. // find entry
  12467. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12468. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12469. clif_wisexin(sd, type, 1); // fail
  12470. return;
  12471. }
  12472. // move everything one place down to overwrite removed entry
  12473. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12474. // wipe last entry
  12475. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12476. }
  12477. clif_wisexin(sd, type, 0); // success
  12478. }
  12479. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12480. /// Request to allow/deny all whispers.
  12481. /// 00d0 <type>.B
  12482. /// type:
  12483. /// 0 = (/exall) deny all speech
  12484. /// 1 = (/inall) allow all speech
  12485. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12486. {
  12487. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12488. if( type == 0 ) {// Deny all
  12489. if( sd->state.ignoreAll ) {
  12490. flag = 1; // fail
  12491. } else {
  12492. sd->state.ignoreAll = 1;
  12493. flag = 0; // success
  12494. }
  12495. } else {//Unblock everyone
  12496. if( sd->state.ignoreAll ) {
  12497. sd->state.ignoreAll = 0;
  12498. flag = 0; // success
  12499. } else {
  12500. if (sd->ignore[0].name[0] != '\0')
  12501. { //Wipe the ignore list.
  12502. memset(sd->ignore, 0, sizeof(sd->ignore));
  12503. flag = 0; // success
  12504. } else {
  12505. flag = 1; // fail
  12506. }
  12507. }
  12508. }
  12509. clif_wisall(sd, type, flag);
  12510. }
  12511. /// Whisper ignore list (ZC_WHISPER_LIST).
  12512. /// 00d4 <packet len>.W { <char name>.24B }*
  12513. void clif_PMIgnoreList(struct map_session_data* sd)
  12514. {
  12515. int i, fd = sd->fd;
  12516. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12517. WFIFOW(fd,0) = 0xd4;
  12518. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12519. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12520. }
  12521. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12522. WFIFOSET(fd,WFIFOW(fd,2));
  12523. }
  12524. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12525. /// 00d3
  12526. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12527. {
  12528. clif_PMIgnoreList(sd);
  12529. }
  12530. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12531. /// 01e7
  12532. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12533. {
  12534. if (sd->state.doridori) return;
  12535. switch (sd->class_&MAPID_UPPERMASK) {
  12536. case MAPID_SOUL_LINKER:
  12537. case MAPID_STAR_GLADIATOR:
  12538. case MAPID_TAEKWON:
  12539. if (!sd->state.rest)
  12540. break;
  12541. case MAPID_SUPER_NOVICE:
  12542. case MAPID_SUPER_BABY:
  12543. case MAPID_SUPER_NOVICE_E:
  12544. case MAPID_SUPER_BABY_E:
  12545. sd->state.doridori=1;
  12546. break;
  12547. }
  12548. }
  12549. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12550. /// 01ed
  12551. /// Note: This packet is caused by 7 lines of any text, followed by
  12552. /// the prayer and an another line of any text. The prayer is
  12553. /// defined by lines 790~793 in data\msgstringtable.txt
  12554. /// "Dear angel, can you hear my voice?"
  12555. /// "I am" (space separated player name) "Super Novice~"
  12556. /// "Help me out~ Please~ T_T"
  12557. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12558. {
  12559. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12560. t_exp next = pc_nextbaseexp(sd);
  12561. if( next ) {
  12562. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12563. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12564. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12565. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12566. }
  12567. }
  12568. }
  12569. }
  12570. /// Friends List
  12571. ///
  12572. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12573. /// 0206 <account id>.L <char id>.L <state>.B
  12574. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12575. /// state:
  12576. /// 0 = online
  12577. /// 1 = offline
  12578. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12579. {
  12580. int i, fd = sd->fd;
  12581. //Seek friend.
  12582. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12583. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12584. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12585. return; //Not found
  12586. WFIFOHEAD(fd,packet_len(0x206));
  12587. WFIFOW(fd, 0) = 0x206;
  12588. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12589. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12590. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12591. #if PACKETVER >= 20180221
  12592. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12593. #endif
  12594. WFIFOSET(fd, packet_len(0x206));
  12595. }
  12596. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12597. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12598. {
  12599. uint32 account_id, char_id, online;
  12600. account_id = va_arg(ap, int);
  12601. char_id = va_arg(ap, int);
  12602. online = va_arg(ap, int);
  12603. clif_friendslist_toggle(sd, account_id, char_id, online);
  12604. return 0;
  12605. }
  12606. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12607. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12608. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12609. void clif_friendslist_send( struct map_session_data& sd ){
  12610. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12611. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12612. p->PacketLength = sizeof( *p );
  12613. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12614. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12615. f.AID = sd.status.friends[i].account_id;
  12616. f.CID = sd.status.friends[i].char_id;
  12617. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12618. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12619. #endif
  12620. c++;
  12621. p->PacketLength += sizeof( f );
  12622. }
  12623. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12624. // Sending the online players
  12625. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12626. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12627. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12628. }
  12629. }
  12630. }
  12631. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12632. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12633. /// result:
  12634. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12635. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12636. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12637. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12638. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12639. {
  12640. int fd;
  12641. nullpo_retv(sd);
  12642. fd = sd->fd;
  12643. WFIFOHEAD(fd,packet_len(0x209));
  12644. WFIFOW(fd,0) = 0x209;
  12645. WFIFOW(fd,2) = type;
  12646. if (f_sd) {
  12647. WFIFOL(fd,4) = f_sd->status.account_id;
  12648. WFIFOL(fd,8) = f_sd->status.char_id;
  12649. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12650. }
  12651. WFIFOSET(fd, packet_len(0x209));
  12652. }
  12653. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12654. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12655. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12656. {
  12657. int fd = sd->fd;
  12658. WFIFOHEAD(fd,packet_len(0x207));
  12659. WFIFOW(fd,0) = 0x207;
  12660. WFIFOL(fd,2) = account_id;
  12661. WFIFOL(fd,6) = char_id;
  12662. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12663. WFIFOSET(fd,packet_len(0x207));
  12664. }
  12665. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12666. /// 0202 <name>.24B
  12667. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12668. {
  12669. struct map_session_data *f_sd;
  12670. int i;
  12671. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12672. // Friend doesn't exist (no player with this name)
  12673. if (f_sd == NULL) {
  12674. clif_displaymessage(fd, msg_txt(sd,3));
  12675. return;
  12676. }
  12677. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12678. return;
  12679. }
  12680. // ensure that the request player's friend list is not full
  12681. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12682. if( i == MAX_FRIENDS ){
  12683. clif_friendslist_reqack(sd, f_sd, 2);
  12684. return;
  12685. }
  12686. // @noask [LuzZza]
  12687. if(f_sd->state.noask) {
  12688. clif_noask_sub(sd, f_sd, 5);
  12689. return;
  12690. }
  12691. // Friend already exists
  12692. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12693. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12694. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12695. return;
  12696. }
  12697. }
  12698. f_sd->friend_req = sd->status.char_id;
  12699. sd->friend_req = f_sd->status.char_id;
  12700. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12701. }
  12702. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12703. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12704. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12705. /// reply:
  12706. /// 0 = rejected
  12707. /// 1 = accepted
  12708. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12709. {
  12710. struct map_session_data *f_sd;
  12711. uint32 account_id;
  12712. char reply;
  12713. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12714. account_id = RFIFOL(fd,info->pos[0]);
  12715. //char_id = RFIFOL(fd,info->pos[1]);
  12716. #if PACKETVER < 6
  12717. reply = RFIFOB(fd,info->pos[2]);
  12718. #else
  12719. reply = RFIFOL(fd,info->pos[2]);
  12720. #endif
  12721. if( sd->bl.id == account_id ) {// adding oneself as friend
  12722. return;
  12723. }
  12724. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12725. if (f_sd == NULL)
  12726. return;
  12727. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12728. clif_friendslist_reqack(f_sd, sd, 1);
  12729. else {
  12730. int i;
  12731. // Find an empty slot
  12732. for (i = 0; i < MAX_FRIENDS; i++)
  12733. if (f_sd->status.friends[i].char_id == 0)
  12734. break;
  12735. if (i == MAX_FRIENDS) {
  12736. clif_friendslist_reqack(f_sd, sd, 2);
  12737. return;
  12738. }
  12739. f_sd->status.friends[i].account_id = sd->status.account_id;
  12740. f_sd->status.friends[i].char_id = sd->status.char_id;
  12741. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12742. clif_friendslist_reqack(f_sd, sd, 0);
  12743. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12744. if (battle_config.friend_auto_add) {
  12745. // Also add f_sd to sd's friendlist.
  12746. for (i = 0; i < MAX_FRIENDS; i++) {
  12747. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12748. return; //No need to add anything.
  12749. if (sd->status.friends[i].char_id == 0)
  12750. break;
  12751. }
  12752. if (i == MAX_FRIENDS) {
  12753. clif_friendslist_reqack(sd, f_sd, 2);
  12754. return;
  12755. }
  12756. sd->status.friends[i].account_id = f_sd->status.account_id;
  12757. sd->status.friends[i].char_id = f_sd->status.char_id;
  12758. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12759. clif_friendslist_reqack(sd, f_sd, 0);
  12760. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12761. }
  12762. }
  12763. }
  12764. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12765. /// 0203 <account id>.L <char id>.L
  12766. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12767. {
  12768. struct map_session_data *f_sd = NULL;
  12769. uint32 account_id, char_id;
  12770. int i, j;
  12771. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12772. account_id = RFIFOL(fd,info->pos[0]);
  12773. char_id = RFIFOL(fd,info->pos[1]);
  12774. // Search friend
  12775. for (i = 0; i < MAX_FRIENDS &&
  12776. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12777. if (i == MAX_FRIENDS) {
  12778. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12779. return;
  12780. }
  12781. //remove from friend's list first
  12782. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12783. for (i = 0; i < MAX_FRIENDS &&
  12784. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12785. if (i != MAX_FRIENDS) {
  12786. // move all chars up
  12787. for(j = i + 1; j < MAX_FRIENDS; j++)
  12788. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12789. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12790. //should the guy be notified of some message? we should add it here if so
  12791. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12792. WFIFOW(f_sd->fd,0) = 0x20a;
  12793. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12794. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12795. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12796. }
  12797. } else { //friend not online -- ask char server to delete from his friendlist
  12798. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12799. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12800. return;
  12801. }
  12802. }
  12803. // We can now delete from original requester
  12804. for (i = 0; i < MAX_FRIENDS &&
  12805. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12806. // move all chars up
  12807. for(j = i + 1; j < MAX_FRIENDS; j++)
  12808. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12809. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12810. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12811. WFIFOHEAD(fd,packet_len(0x20a));
  12812. WFIFOW(fd,0) = 0x20a;
  12813. WFIFOL(fd,2) = account_id;
  12814. WFIFOL(fd,6) = char_id;
  12815. WFIFOSET(fd, packet_len(0x20a));
  12816. }
  12817. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12818. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12819. void clif_PVPInfo(struct map_session_data* sd)
  12820. {
  12821. int fd = sd->fd;
  12822. WFIFOHEAD(fd,packet_len(0x210));
  12823. WFIFOW(fd,0) = 0x210;
  12824. WFIFOL(fd,2) = sd->status.char_id;
  12825. WFIFOL(fd,6) = sd->status.account_id;
  12826. WFIFOL(fd,10) = sd->pvp_won; // times won
  12827. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12828. WFIFOL(fd,18) = sd->pvp_point;
  12829. WFIFOSET(fd, packet_len(0x210));
  12830. }
  12831. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12832. /// 020f <char id>.L <account id>.L
  12833. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12834. {
  12835. // TODO: Is there a way to use this on an another player (char/acc id)?
  12836. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12837. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12838. clif_PVPInfo(sd);
  12839. }
  12840. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12841. /// 0254 <which>.B
  12842. /// which: (unused atm for security purpose)
  12843. /// 0 = sun
  12844. /// 1 = moon
  12845. /// 2 = star
  12846. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12847. {
  12848. int i;
  12849. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12850. if (sd->menuskill_id != SG_FEEL)
  12851. return;
  12852. i = sd->menuskill_val-1;
  12853. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12854. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12855. sd->feel_map[i].m = sd->bl.m;
  12856. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12857. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12858. // clif_misceffect2(&sd->bl, 0x1b0);
  12859. // clif_misceffect2(&sd->bl, 0x21f);
  12860. clif_feel_info(sd, i, 0);
  12861. clif_menuskill_clear(sd);
  12862. }
  12863. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12864. /// 0253 <which>.B
  12865. /// which:
  12866. /// 0 = sun
  12867. /// 1 = moon
  12868. /// 2 = star
  12869. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12870. {
  12871. WFIFOHEAD(fd,packet_len(0x253));
  12872. WFIFOW(fd,0)=0x253;
  12873. WFIFOB(fd,2)=TOB(skill_lv-1);
  12874. WFIFOSET(fd, packet_len(0x253));
  12875. sd->menuskill_id = SG_FEEL;
  12876. sd->menuskill_val = skill_lv;
  12877. }
  12878. /// Request to change homunculus' name (CZ_RENAME_MER).
  12879. /// 0231 <name>.24B
  12880. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12881. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12882. }
  12883. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12884. /// 0234 <id>.L
  12885. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12886. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12887. struct block_list *bl = NULL;
  12888. struct unit_data *ud = NULL;
  12889. if( sd->md && sd->md->bl.id == id )
  12890. bl = &sd->md->bl;
  12891. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12892. bl = &sd->hd->bl; // Moving Homunculus
  12893. else
  12894. return;
  12895. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12896. ud = unit_bl2ud(bl);
  12897. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12898. }
  12899. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12900. /// 0232 <id>.L <position data>.3B
  12901. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12902. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12903. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12904. struct block_list *bl = NULL;
  12905. short x, y;
  12906. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12907. if( sd->md && sd->md->bl.id == id )
  12908. bl = &sd->md->bl; // Moving Mercenary
  12909. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12910. bl = &sd->hd->bl; // Moving Homunculus
  12911. else
  12912. return;
  12913. unit_walktoxy(bl, x, y, 4);
  12914. }
  12915. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12916. /// 0233 <id>.L <target id>.L <action>.B
  12917. /// action:
  12918. /// always 0
  12919. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12920. {
  12921. struct block_list *bl = NULL;
  12922. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12923. int id = RFIFOL(fd,info->pos[0]);
  12924. int target_id = RFIFOL(fd,info->pos[1]);
  12925. int action_type = RFIFOB(fd,info->pos[2]);
  12926. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12927. bl = &sd->hd->bl;
  12928. else if( sd->md && sd->md->bl.id == id )
  12929. bl = &sd->md->bl;
  12930. else return;
  12931. unit_stop_attack(bl);
  12932. unit_attack(bl, target_id, action_type != 0);
  12933. }
  12934. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12935. /// 022d <type>.W <command>.B
  12936. /// type:
  12937. /// always 0
  12938. /// command:
  12939. /// 0 = homunculus information
  12940. /// 1 = feed
  12941. /// 2 = delete
  12942. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12943. { //[orn]
  12944. int cmd = RFIFOW(fd,0);
  12945. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12946. if(!hom_is_active(sd->hd))
  12947. return;
  12948. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12949. }
  12950. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12951. /// 0292
  12952. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12953. {
  12954. pc_revive_item(sd);
  12955. }
  12956. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12957. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12958. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12959. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12960. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12961. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12962. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12963. void clif_check(int fd, struct map_session_data* pl_sd)
  12964. {
  12965. WFIFOHEAD(fd,packet_len(0x214));
  12966. WFIFOW(fd, 0) = 0x214;
  12967. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12968. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12969. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12970. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12971. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12972. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12973. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12974. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12975. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12976. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12977. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12978. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12979. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12980. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12981. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12982. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12983. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12984. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12985. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12986. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12987. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12988. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12989. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12990. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12991. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12992. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12993. WFIFOSET(fd,packet_len(0x214));
  12994. }
  12995. /// /check (CZ_REQ_STATUS_GM).
  12996. /// Request character's status values.
  12997. /// 0213 <char name>.24B
  12998. void clif_parse_Check(int fd, struct map_session_data *sd)
  12999. {
  13000. char charname[NAME_LENGTH];
  13001. struct map_session_data* pl_sd;
  13002. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13003. return;
  13004. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13005. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13006. {
  13007. return;
  13008. }
  13009. clif_check(fd, pl_sd);
  13010. }
  13011. /// MAIL SYSTEM
  13012. /// By Zephyrus
  13013. ///
  13014. /// Notification about the result of adding an item to mail
  13015. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13016. /// result:
  13017. /// 0 = success
  13018. /// 1 = failure
  13019. /// 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)
  13020. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13021. /// result:
  13022. /// 0 = success
  13023. /// 1 = over weight
  13024. /// 2 = fatal error
  13025. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  13026. int fd = sd->fd;
  13027. #if PACKETVER < 20150513
  13028. WFIFOHEAD(fd,packet_len(0x255));
  13029. WFIFOW(fd,0) = 0x255;
  13030. WFIFOW(fd,2) = index;
  13031. WFIFOB(fd,4) = flag;
  13032. WFIFOSET(fd,packet_len(0x255));
  13033. #else
  13034. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13035. if( flag ){
  13036. memset( &p, 0, sizeof( p ) );
  13037. }else{
  13038. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13039. p.index = index;
  13040. p.count = amount;
  13041. p.itemId = client_nameid( item->nameid );
  13042. p.type = itemtype( item->nameid );
  13043. p.IsIdentified = item->identify ? 1 : 0;
  13044. p.IsDamaged = item->attribute ? 1 : 0;
  13045. p.refiningLevel = item->refine;
  13046. clif_addcards( &p.slot, item );
  13047. clif_add_random_options( p.optionData, item );
  13048. p.weight = 0;
  13049. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13050. if( sd->mail.item[i].nameid == 0 ){
  13051. continue;
  13052. }
  13053. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13054. }
  13055. p.favorite = item->favorite;
  13056. p.location = pc_equippoint( sd, server_index( index ) );
  13057. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13058. p.grade = item->enchantgrade;
  13059. #endif
  13060. }
  13061. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13062. p.result = flag;
  13063. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13064. #endif
  13065. }
  13066. /// Notification about the result of retrieving a mail attachment
  13067. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13068. /// result:
  13069. /// 0 = success
  13070. /// 1 = failure
  13071. /// 2 = too many items
  13072. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13073. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13074. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13075. #if PACKETVER < 20150513
  13076. int fd = sd->fd;
  13077. WFIFOHEAD(fd,packet_len(0x245));
  13078. WFIFOW(fd,0) = 0x245;
  13079. WFIFOB(fd,2) = result;
  13080. WFIFOSET(fd,packet_len(0x245));
  13081. #else
  13082. switch( type ){
  13083. case MAIL_ATT_ITEM:
  13084. case MAIL_ATT_ZENY:
  13085. break;
  13086. default:
  13087. return;
  13088. }
  13089. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13090. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13091. p.MailID = msg->id;
  13092. p.opentype = msg->type;
  13093. p.result = result;
  13094. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13095. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13096. #endif
  13097. }
  13098. /// Notification about the result of sending a mail
  13099. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13100. /// result:
  13101. /// 0 = success
  13102. /// 1 = recipinent does not exist
  13103. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13104. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  13105. #if PACKETVER < 20150513
  13106. int fd = sd->fd;
  13107. WFIFOHEAD(fd,packet_len(0x249));
  13108. WFIFOW(fd,0) = 0x249;
  13109. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13110. WFIFOSET(fd,packet_len(0x249));
  13111. #else
  13112. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13113. p.PacketType = rodexwriteresult;
  13114. p.result = result;
  13115. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13116. #endif
  13117. }
  13118. /// Notification about the result of deleting a mail.
  13119. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13120. /// result:
  13121. /// 0 = success
  13122. /// 1 = failure
  13123. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13124. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  13125. #if PACKETVER < 20150513
  13126. int fd = sd->fd;
  13127. WFIFOHEAD(fd, packet_len(0x257));
  13128. WFIFOW(fd,0) = 0x257;
  13129. WFIFOL(fd,2) = msg->id;
  13130. WFIFOW(fd,6) = !success;
  13131. WFIFOSET(fd, packet_len(0x257));
  13132. #else
  13133. // This is only a success notification
  13134. if( success ){
  13135. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13136. p.PacketType = rodexdelete;
  13137. p.opentype = msg->type;
  13138. p.MailID = msg->id;
  13139. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13140. }
  13141. #endif
  13142. }
  13143. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13144. /// 0274 <mail id>.L <result>.W
  13145. /// result:
  13146. /// 0 = success
  13147. /// 1 = failure
  13148. void clif_Mail_return(int fd, int mail_id, short fail)
  13149. {
  13150. WFIFOHEAD(fd,packet_len(0x274));
  13151. WFIFOW(fd,0) = 0x274;
  13152. WFIFOL(fd,2) = mail_id;
  13153. WFIFOW(fd,6) = fail;
  13154. WFIFOSET(fd,packet_len(0x274));
  13155. }
  13156. /// Notification about new mail.
  13157. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13158. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13159. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  13160. #if PACKETVER < 20150513
  13161. int fd = sd->fd;
  13162. WFIFOHEAD(fd,packet_len(0x24a));
  13163. WFIFOW(fd,0) = 0x24a;
  13164. WFIFOL(fd,2) = mail_id;
  13165. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13166. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13167. WFIFOSET(fd,packet_len(0x24a));
  13168. #else
  13169. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13170. p.PacketType = rodexicon;
  13171. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13172. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13173. #endif
  13174. }
  13175. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13176. /// 0260 <type>.L
  13177. /// type:
  13178. /// 0 = open
  13179. /// 1 = close
  13180. void clif_Mail_window(int fd, int flag)
  13181. {
  13182. WFIFOHEAD(fd,packet_len(0x260));
  13183. WFIFOW(fd,0) = 0x260;
  13184. WFIFOL(fd,2) = flag;
  13185. WFIFOSET(fd,packet_len(0x260));
  13186. }
  13187. /// Lists mails stored in inbox.
  13188. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13189. /// read:
  13190. /// 0 = unread
  13191. /// 1 = read
  13192. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13193. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13194. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13195. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13196. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13197. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13198. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13199. #if PACKETVER < 20150513
  13200. int fd = sd->fd;
  13201. struct mail_data *md = &sd->mail.inbox;
  13202. struct mail_message *msg;
  13203. int len, i, j;
  13204. len = 8 + (73 * md->amount);
  13205. WFIFOHEAD(fd,len);
  13206. WFIFOW(fd,0) = 0x240;
  13207. WFIFOW(fd,2) = len;
  13208. WFIFOL(fd,4) = md->amount;
  13209. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13210. {
  13211. msg = &md->msg[i];
  13212. if (msg->id < 1)
  13213. continue;
  13214. WFIFOL(fd,8+73*j) = msg->id;
  13215. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13216. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13217. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13218. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13219. j++;
  13220. }
  13221. WFIFOSET(fd,len);
  13222. if( md->full ) {// TODO: is this official?
  13223. char output[100];
  13224. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13225. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13226. }
  13227. #else
  13228. int fd = sd->fd;
  13229. struct mail_data *md = &sd->mail.inbox;
  13230. struct mail_message *msg;
  13231. int i, j, k, offset, titleLength;
  13232. uint8 mailType, amount, remaining;
  13233. uint32 now = (uint32)time(NULL);
  13234. #if PACKETVER >= 20170419
  13235. int cmd = 0xac2;
  13236. #elif PACKETVER >= 20160601
  13237. int cmd = 0xa7d;
  13238. #else
  13239. int cmd = 0x9f0;
  13240. #endif
  13241. if( battle_config.mail_daily_count ){
  13242. mail_refresh_remaining_amount(sd);
  13243. }
  13244. #if PACKETVER >= 20170419
  13245. // Always send all
  13246. i = md->amount;
  13247. #else
  13248. // If a starting mail id was sent
  13249. if( mailID != 0 ){
  13250. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13251. // Unknown mail
  13252. if( i == md->amount ){
  13253. // Ignore the request for now
  13254. return; // TODO: Should we just show the first page instead?
  13255. }
  13256. // It was actually the oldest/first mail, there is no further page
  13257. if( i == 0 ){
  13258. return;
  13259. }
  13260. // We actually want the next/older mail
  13261. i -= 1;
  13262. }else{
  13263. i = md->amount;
  13264. }
  13265. #endif
  13266. // Count the remaining mails from the starting mail or the beginning
  13267. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13268. for( j = i, remaining = 0; j >= 0; j-- ){
  13269. msg = &md->msg[j];
  13270. if (msg->id < 1)
  13271. continue;
  13272. #if PACKETVER < 20170419
  13273. if (msg->type != type)
  13274. continue;
  13275. #endif
  13276. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13277. continue;
  13278. remaining++;
  13279. }
  13280. #if PACKETVER >= 20170419
  13281. // Always send all
  13282. amount = remaining;
  13283. #else
  13284. if( remaining > MAIL_PAGE_SIZE ){
  13285. amount = MAIL_PAGE_SIZE;
  13286. }else{
  13287. amount = remaining;
  13288. }
  13289. #endif
  13290. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13291. WFIFOW(fd, 0) = cmd;
  13292. #if PACKETVER >= 20170419
  13293. WFIFOB(fd, 4) = 1; // Unknown
  13294. offset = 5;
  13295. #else
  13296. WFIFOB(fd, 4) = type;
  13297. WFIFOB(fd, 5) = amount;
  13298. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13299. offset = 7;
  13300. #endif
  13301. for( amount = 0; i >= 0; i-- ){
  13302. msg = &md->msg[i];
  13303. if (msg->id < 1)
  13304. continue;
  13305. #if PACKETVER < 20170419
  13306. if (msg->type != type)
  13307. continue;
  13308. #endif
  13309. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13310. continue;
  13311. #if PACKETVER >= 20170419
  13312. WFIFOB(fd, offset) = msg->type;
  13313. offset += 1;
  13314. #endif
  13315. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13316. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13317. mailType = MAIL_TYPE_TEXT; // Normal letter
  13318. if( msg->zeny > 0 ){
  13319. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13320. }
  13321. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13322. if( msg->item[k].nameid > 0 ){
  13323. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13324. break;
  13325. }
  13326. }
  13327. #if PACKETVER >= 20170419
  13328. // If it came from an npc?
  13329. if( !msg->send_id ){
  13330. mailType |= MAIL_TYPE_NPC;
  13331. }
  13332. #endif
  13333. WFIFOB(fd, offset + 9) = mailType;
  13334. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13335. #if PACKETVER < 20170419
  13336. // How much time has passed since you received the mail
  13337. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13338. offset += 4;
  13339. #endif
  13340. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13341. if( msg->scheduled_deletion > 0 ){
  13342. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13343. }else{
  13344. // Fake the scheduled deletion to one year in the future
  13345. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13346. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13347. }
  13348. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13349. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13350. offset += 40 + titleLength;
  13351. }
  13352. WFIFOW(fd, 2) = (int16)offset;
  13353. WFIFOSET(fd, offset);
  13354. #endif
  13355. }
  13356. /// Mail inbox list request.
  13357. /// 023f (CZ_MAIL_GET_LIST)
  13358. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13359. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13360. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13361. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13362. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13363. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13364. if( mail_invalid_operation( sd ) ){
  13365. return;
  13366. }
  13367. #if PACKETVER < 20150513
  13368. struct mail_data* md = &sd->mail.inbox;
  13369. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13370. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13371. else
  13372. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13373. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13374. mail_removezeny(sd, false);
  13375. #else
  13376. int cmd = RFIFOW(fd, 0);
  13377. #if PACKETVER < 20170419
  13378. uint8 openType = RFIFOB(fd, 2);
  13379. uint64 mailId = RFIFOQ(fd, 3);
  13380. #else
  13381. uint8 openType;
  13382. uint64 mailId = RFIFOQ(fd, 2);
  13383. int i;
  13384. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13385. if( i == MAIL_MAX_INBOX ){
  13386. openType = MAIL_INBOX_NORMAL;
  13387. mailId = 0;
  13388. }else{
  13389. openType = sd->mail.inbox.msg[i].type;
  13390. mailId = 0;
  13391. }
  13392. #endif
  13393. switch( openType ){
  13394. case MAIL_INBOX_NORMAL:
  13395. case MAIL_INBOX_ACCOUNT:
  13396. case MAIL_INBOX_RETURNED:
  13397. break;
  13398. default:
  13399. // Unknown type: ignore request
  13400. return;
  13401. }
  13402. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13403. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13404. return;
  13405. }
  13406. // If it is not a next page request
  13407. if( cmd != 0x9ee ){
  13408. mailId = 0;
  13409. }
  13410. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13411. #endif
  13412. }
  13413. /// Opens a mail
  13414. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13415. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13416. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13417. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13418. /// { }*n
  13419. // TODO: Packet description => for repeated block
  13420. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13421. int i, fd = sd->fd;
  13422. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13423. if( i == MAIL_MAX_INBOX ) {
  13424. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13425. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13426. return;
  13427. } else {
  13428. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13429. struct item *item;
  13430. int msg_len = strlen(msg->body);
  13431. if( msg_len == 0 ) {
  13432. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13433. msg_len = strlen(msg->body);
  13434. }
  13435. #if PACKETVER < 20150513
  13436. item = &msg->item[0];
  13437. int len = 101 + msg_len;
  13438. WFIFOHEAD(fd,len);
  13439. WFIFOW(fd,0) = 0x242;
  13440. WFIFOW(fd,2) = len;
  13441. WFIFOL(fd,4) = msg->id;
  13442. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13443. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13444. WFIFOL(fd,72) = 0;
  13445. WFIFOL(fd,76) = msg->zeny;
  13446. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13447. if( item->nameid && data != nullptr ) {
  13448. WFIFOL(fd,80) = item->amount;
  13449. WFIFOW(fd,84) = client_nameid( item->nameid );
  13450. WFIFOW(fd,86) = itemtype( item->nameid );
  13451. WFIFOB(fd,88) = item->identify;
  13452. WFIFOB(fd,89) = item->attribute;
  13453. WFIFOB(fd,90) = item->refine;
  13454. WFIFOW(fd,91) = item->card[0];
  13455. WFIFOW(fd,93) = item->card[1];
  13456. WFIFOW(fd,95) = item->card[2];
  13457. WFIFOW(fd,97) = item->card[3];
  13458. } else // no item, set all to zero
  13459. memset(WFIFOP(fd,80), 0x00, 19);
  13460. WFIFOB(fd,99) = (unsigned char)msg_len;
  13461. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13462. WFIFOSET(fd,len);
  13463. #else
  13464. msg_len += 1; // Zero Termination
  13465. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13466. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13467. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13468. p->opentype = msg->type;
  13469. p->MailID = msg->id;
  13470. p->TextcontentsLength = msg_len;
  13471. p->zeny = msg->zeny;
  13472. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13473. p->PacketLength += p->TextcontentsLength;
  13474. p->ItemCnt = 0;
  13475. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13476. item = &msg->item[j];
  13477. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13478. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13479. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13480. mailitem->ITID = client_nameid( item->nameid );
  13481. mailitem->count = item->amount;
  13482. mailitem->type = itemtype( item->nameid );
  13483. mailitem->IsIdentified = item->identify ? 1 : 0;
  13484. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13485. mailitem->refiningLevel = item->refine;
  13486. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13487. mailitem->viewSprite = data->look;
  13488. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13489. clif_addcards( &mailitem->slot, item );
  13490. clif_add_random_options( mailitem->option_data, item );
  13491. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13492. mailitem->grade = item->enchantgrade;
  13493. #endif
  13494. p->PacketLength += sizeof( *mailitem );
  13495. p->ItemCnt++;
  13496. }
  13497. }
  13498. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13499. #endif
  13500. if (msg->status == MAIL_UNREAD) {
  13501. msg->status = MAIL_READ;
  13502. intif_Mail_read(mail_id);
  13503. clif_parse_Mail_refreshinbox(fd, sd);
  13504. sd->mail.inbox.unread--;
  13505. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13506. }
  13507. }
  13508. }
  13509. /// Request to open a mail.
  13510. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13511. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13512. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13513. #if PACKETVER < 20150513
  13514. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13515. #else
  13516. //uint8 openType = RFIFOB(fd, 2);
  13517. int mail_id = (int)RFIFOQ(fd, 3);
  13518. #endif
  13519. if( mail_id <= 0 )
  13520. return;
  13521. if( mail_invalid_operation(sd) )
  13522. return;
  13523. clif_Mail_read(sd, mail_id);
  13524. }
  13525. /// Allow a player to begin writing a mail
  13526. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13527. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13528. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13529. p.PacketType = rodexopenwrite;
  13530. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13531. p.result = success;
  13532. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13533. }
  13534. /// Request to start writing a mail
  13535. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13536. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13537. char name[NAME_LENGTH];
  13538. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13539. if( mail_invalid_operation( sd ) ){
  13540. return;
  13541. }
  13542. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13543. clif_send_Mail_beginwrite_ack(sd, name, false);
  13544. return;
  13545. }
  13546. mail_clear(sd);
  13547. sd->state.mail_writing = true;
  13548. clif_send_Mail_beginwrite_ack(sd, name,true);
  13549. }
  13550. /// Notification that the client cancelled writing a mail
  13551. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13552. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13553. sd->state.mail_writing = false;
  13554. }
  13555. /// Give the client information about the recipient, if available
  13556. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13557. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13558. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13559. #if PACKETVER >= 20141119
  13560. PACKET_ZC_CHECKNAME p = { 0 };
  13561. p.PacketType = HEADER_ZC_CHECKNAME;
  13562. p.CharId = char_id;
  13563. p.Class = class_;
  13564. p.BaseLevel = level;
  13565. #if PACKETVER >= 20160302
  13566. strncpy(p.Name, name, NAME_LENGTH);
  13567. #endif
  13568. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13569. #endif
  13570. }
  13571. /// Request information about the recipient
  13572. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13573. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13574. #if PACKETVER >= 20140423
  13575. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13576. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13577. #else
  13578. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13579. #endif
  13580. static char name[NAME_LENGTH];
  13581. if( mail_invalid_operation( sd ) ){
  13582. return;
  13583. }
  13584. safestrncpy(name, p->Name, NAME_LENGTH);
  13585. intif_mail_checkreceiver(sd, name);
  13586. #endif
  13587. }
  13588. /// Request to receive mail's attachment.
  13589. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13590. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13591. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13592. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13593. int i;
  13594. struct mail_message* msg;
  13595. #if PACKETVER < 20150513
  13596. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13597. int attachment = MAIL_ATT_ALL;
  13598. #else
  13599. uint16 packet_id = RFIFOW(fd, 0);
  13600. int mail_id = (int)RFIFOQ(fd, 2);
  13601. //int openType = RFIFOB(fd, 10);
  13602. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13603. #endif
  13604. if( !chrif_isconnected() )
  13605. return;
  13606. if( mail_id <= 0 )
  13607. return;
  13608. if( mail_invalid_operation(sd) )
  13609. return;
  13610. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13611. if( i == MAIL_MAX_INBOX )
  13612. return;
  13613. msg = &sd->mail.inbox.msg[i];
  13614. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13615. attachment &= ~MAIL_ATT_ZENY;
  13616. }
  13617. if( attachment&MAIL_ATT_ITEM ){
  13618. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13619. // No items were found
  13620. if( i == MAIL_MAX_ITEM ){
  13621. attachment &= ~MAIL_ATT_ITEM;
  13622. }
  13623. }
  13624. // Either no attachment requested at all or there are no zeny or items in the mail
  13625. if( attachment == MAIL_ATT_NONE ){
  13626. return;
  13627. }
  13628. if( attachment&MAIL_ATT_ZENY ){
  13629. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13630. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13631. return;
  13632. }else{
  13633. // Store the pending zeny (required for the "retrieve all" feature)
  13634. sd->mail.pending_zeny += msg->zeny;
  13635. // To make sure another request fails
  13636. msg->zeny = 0;
  13637. }
  13638. }
  13639. if( attachment&MAIL_ATT_ITEM ){
  13640. int slots = 0, totalweight = 0;
  13641. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13642. struct item* item = &msg->item[i];
  13643. if( item->nameid > 0 && item->amount > 0 ){
  13644. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13645. if(data == nullptr)
  13646. continue;
  13647. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13648. case CHKADDITEM_NEW:
  13649. slots += data->inventorySlotNeeded( item->amount );
  13650. break;
  13651. case CHKADDITEM_OVERAMOUNT:
  13652. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13653. return;
  13654. }
  13655. totalweight += data->weight * item->amount;
  13656. }
  13657. }
  13658. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13659. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13660. return;
  13661. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13662. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13663. return;
  13664. }
  13665. // To make sure another request fails
  13666. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13667. // Store the pending weight (required for the "retrieve all" feature)
  13668. sd->mail.pending_weight += totalweight;
  13669. // Store the pending slots (required for the "retrieve all" feature)
  13670. sd->mail.pending_slots += slots;
  13671. }
  13672. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13673. }
  13674. /// Request to delete a mail.
  13675. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13676. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13677. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13678. #if PACKETVER < 20150513
  13679. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13680. #else
  13681. //int openType = RFIFOB(fd, 2);
  13682. int mail_id = (int)RFIFOQ(fd, 3);
  13683. #endif
  13684. int i, j;
  13685. if( !chrif_isconnected() )
  13686. return;
  13687. if( mail_id <= 0 )
  13688. return;
  13689. if( mail_invalid_operation(sd) )
  13690. return;
  13691. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13692. if (i < MAIL_MAX_INBOX) {
  13693. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13694. // can't delete mail without removing zeny first
  13695. if( msg->zeny > 0 ){
  13696. clif_mail_delete(sd, msg, false);
  13697. return;
  13698. }
  13699. // can't delete mail without removing attachment(s) first
  13700. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13701. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13702. clif_mail_delete(sd, msg, false);
  13703. return;
  13704. }
  13705. }
  13706. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13707. sd->mail.inbox.unread--;
  13708. clif_Mail_new(sd,0,NULL,NULL);
  13709. }
  13710. }
  13711. }
  13712. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13713. /// 0273 <mail id>.L <receive name>.24B
  13714. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13715. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13716. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13717. //ShowDump( p, sizeof( p ) );
  13718. int mail_id = p->msgId;
  13719. // not supported for now
  13720. return;
  13721. #else
  13722. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13723. #endif
  13724. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13725. int i;
  13726. if( mail_id <= 0 )
  13727. return;
  13728. if( mail_invalid_operation(sd) )
  13729. return;
  13730. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13731. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13732. intif_Mail_return(sd->status.char_id, mail_id);
  13733. else
  13734. clif_Mail_return(sd->fd, mail_id, 1);
  13735. }
  13736. /// Request to add an item or Zeny to mail.
  13737. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13738. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13739. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13740. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13741. uint16 idx = RFIFOW(fd,info->pos[0]);
  13742. #if PACKETVER < 20150513
  13743. int amount = RFIFOL(fd,info->pos[1]);
  13744. #else
  13745. int amount = RFIFOW(fd,info->pos[1]);
  13746. #endif
  13747. unsigned char flag;
  13748. if( !chrif_isconnected() )
  13749. return;
  13750. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13751. return;
  13752. if (sd->inventory_data[server_index(idx)] == nullptr)
  13753. return;
  13754. if( mail_invalid_operation( sd ) ){
  13755. return;
  13756. }
  13757. flag = mail_setitem(sd, idx, amount);
  13758. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13759. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13760. }else{
  13761. clif_Mail_setattachment(sd,idx,amount,flag);
  13762. }
  13763. }
  13764. /// Remove an item from a mail
  13765. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13766. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13767. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13768. p.PacketType = rodexremoveitem;
  13769. p.result = success;
  13770. p.index = index;
  13771. p.cnt = amount;
  13772. int total = 0;
  13773. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13774. if( sd->mail.item[i].nameid == 0 ){
  13775. break;
  13776. }
  13777. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13778. }
  13779. p.weight = total;
  13780. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13781. }
  13782. /// Request to reset mail item and/or Zeny
  13783. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13784. /// type:
  13785. /// 0 = reset all
  13786. /// 1 = remove item
  13787. /// 2 = remove zeny
  13788. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13789. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13790. {
  13791. #if PACKETVER < 20150513
  13792. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13793. if (type == 0 || type == 1)
  13794. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13795. if (type == 0 || type == 2)
  13796. mail_removezeny(sd, false);
  13797. #else
  13798. uint16 index = RFIFOW(fd, 2);
  13799. uint16 count = RFIFOW(fd, 4);
  13800. mail_removeitem(sd,0,index,count);
  13801. #endif
  13802. }
  13803. /// Request to send mail
  13804. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13805. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13806. /// 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)
  13807. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13808. #if PACKETVER < 20150513
  13809. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13810. if( !chrif_isconnected() )
  13811. return;
  13812. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13813. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13814. return;
  13815. }
  13816. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13817. #else
  13818. uint16 length = RFIFOW(fd, 2);
  13819. if( length < 0x3e ){
  13820. ShowWarning("Too short...\n");
  13821. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13822. return;
  13823. }
  13824. if( mail_invalid_operation( sd ) ){
  13825. return;
  13826. }
  13827. // Forged request without a begin writing packet?
  13828. if( !sd->state.mail_writing ){
  13829. return; // Ignore it
  13830. }
  13831. char receiver[NAME_LENGTH];
  13832. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13833. // char sender[NAME_LENGTH];
  13834. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13835. uint64 zeny = RFIFOQ(fd, 52);
  13836. uint16 titleLength = RFIFOW(fd, 60);
  13837. uint16 textLength = RFIFOW(fd, 62);
  13838. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13839. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13840. char title[MAIL_TITLE_LENGTH];
  13841. char text[MAIL_BODY_LENGTH];
  13842. #if PACKETVER <= 20160330
  13843. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13844. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13845. #else
  13846. // 64 = <char id>.L
  13847. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13848. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13849. #endif
  13850. if( zeny > 0 ){
  13851. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13852. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13853. return;
  13854. }
  13855. }
  13856. mail_send(sd, receiver, title, text, realTextLength);
  13857. #endif
  13858. }
  13859. /// AUCTION SYSTEM
  13860. /// By Zephyrus
  13861. ///
  13862. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13863. /// 025f <type>.L
  13864. /// type:
  13865. /// 0 = open
  13866. /// 1 = close
  13867. void clif_Auction_openwindow(struct map_session_data *sd)
  13868. {
  13869. int fd = sd->fd;
  13870. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13871. return;
  13872. if( !battle_config.feature_auction )
  13873. return;
  13874. WFIFOHEAD(fd,packet_len(0x25f));
  13875. WFIFOW(fd,0) = 0x25f;
  13876. WFIFOL(fd,2) = 0;
  13877. WFIFOSET(fd,packet_len(0x25f));
  13878. }
  13879. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13880. /// 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 }*
  13881. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13882. {
  13883. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13884. struct auction_data auction;
  13885. WFIFOHEAD(fd,12 + (count * 83));
  13886. WFIFOW(fd,0) = 0x252;
  13887. WFIFOW(fd,2) = 12 + (count * 83);
  13888. WFIFOL(fd,4) = pages;
  13889. WFIFOL(fd,8) = count;
  13890. for( i = 0; i < count; i++ ) {
  13891. int k = 12 + (i * 83);
  13892. memcpy(&auction, RBUFP(buf,i * len), len);
  13893. WFIFOL(fd,k) = auction.auction_id;
  13894. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13895. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13896. WFIFOL(fd,30+k) = auction.type;
  13897. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13898. WFIFOB(fd,36+k) = auction.item.identify;
  13899. WFIFOB(fd,37+k) = auction.item.attribute;
  13900. WFIFOB(fd,38+k) = auction.item.refine;
  13901. WFIFOW(fd,39+k) = auction.item.card[0];
  13902. WFIFOW(fd,41+k) = auction.item.card[1];
  13903. WFIFOW(fd,43+k) = auction.item.card[2];
  13904. WFIFOW(fd,45+k) = auction.item.card[3];
  13905. WFIFOL(fd,47+k) = auction.price;
  13906. WFIFOL(fd,51+k) = auction.buynow;
  13907. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13908. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13909. }
  13910. WFIFOSET(fd,WFIFOW(fd,2));
  13911. }
  13912. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13913. /// 0256 <index>.W <result>.B
  13914. /// result:
  13915. /// 0 = success
  13916. /// 1 = failure
  13917. static void clif_Auction_setitem(int fd, int index, bool fail)
  13918. {
  13919. WFIFOHEAD(fd,packet_len(0x256));
  13920. WFIFOW(fd,0) = 0x256;
  13921. WFIFOW(fd,2) = index;
  13922. WFIFOB(fd,4) = fail;
  13923. WFIFOSET(fd,packet_len(0x256));
  13924. }
  13925. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13926. /// 024b <type>.W
  13927. /// type:
  13928. /// 0 = create (any other action in auction window)
  13929. /// 1 = cancel (cancel pressed on register tab)
  13930. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13931. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13932. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13933. if( sd->auction.amount > 0 )
  13934. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13935. sd->auction.amount = 0;
  13936. }
  13937. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13938. /// 024c <index>.W <count>.L
  13939. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13940. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13941. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13942. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13943. if( !battle_config.feature_auction )
  13944. return;
  13945. if( sd->auction.amount > 0 )
  13946. sd->auction.amount = 0;
  13947. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13948. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13949. return;
  13950. }
  13951. 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.
  13952. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13953. return;
  13954. }
  13955. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  13956. 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) )
  13957. { // Consumable or pets are not allowed
  13958. clif_Auction_setitem(sd->fd, idx, true);
  13959. return;
  13960. }
  13961. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13962. !sd->inventory.u.items_inventory[idx].identify ||
  13963. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13964. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13965. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13966. clif_Auction_setitem(sd->fd, idx, true);
  13967. return;
  13968. }
  13969. sd->auction.index = idx;
  13970. sd->auction.amount = amount;
  13971. clif_Auction_setitem(fd, idx + 2, false);
  13972. }
  13973. /// Result from an auction action (ZC_AUCTION_RESULT).
  13974. /// 0250 <result>.B
  13975. /// result:
  13976. /// 0 = You have failed to bid into the auction
  13977. /// 1 = You have successfully bid in the auction
  13978. /// 2 = The auction has been canceled
  13979. /// 3 = An auction with at least one bidder cannot be canceled
  13980. /// 4 = You cannot register more than 5 items in an auction at a time
  13981. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13982. /// 6 = You have won the auction
  13983. /// 7 = You have failed to win the auction
  13984. /// 8 = You do not have enough Zeny
  13985. /// 9 = You cannot place more than 5 bids at a time
  13986. void clif_Auction_message(int fd, unsigned char flag)
  13987. {
  13988. WFIFOHEAD(fd,packet_len(0x250));
  13989. WFIFOW(fd,0) = 0x250;
  13990. WFIFOB(fd,2) = flag;
  13991. WFIFOSET(fd,packet_len(0x250));
  13992. }
  13993. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13994. /// 025e <result>.W
  13995. /// result:
  13996. /// 0 = You have ended the auction
  13997. /// 1 = You cannot end the auction
  13998. /// 2 = Auction ID is incorrect
  13999. void clif_Auction_close(int fd, unsigned char flag)
  14000. {
  14001. WFIFOHEAD(fd,packet_len(0x25e));
  14002. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14003. WFIFOW(fd,2) = flag;
  14004. WFIFOSET(fd,packet_len(0x25e));
  14005. }
  14006. /// Request to add an auction (CZ_AUCTION_ADD).
  14007. /// 024d <now money>.L <max money>.L <delete hour>.W
  14008. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  14009. {
  14010. struct auction_data auction;
  14011. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14012. if( !battle_config.feature_auction )
  14013. return;
  14014. auction.price = RFIFOL(fd,info->pos[0]);
  14015. auction.buynow = RFIFOL(fd,info->pos[1]);
  14016. auction.hours = RFIFOW(fd,info->pos[2]);
  14017. // Invalid Situations...
  14018. if( sd->auction.amount < 1 ) {
  14019. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14020. return;
  14021. }
  14022. if( auction.price >= auction.buynow ) {
  14023. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14024. return;
  14025. }
  14026. if( auction.hours < 1 || auction.hours > 48 ) {
  14027. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14028. return;
  14029. }
  14030. // Auction checks...
  14031. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14032. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14033. clif_Auction_message(fd, 2); // The auction has been canceled
  14034. return;
  14035. }
  14036. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14037. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14038. return;
  14039. }
  14040. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14041. auction.buynow = battle_config.auction_maximumprice;
  14042. if( auction.price >= auction.buynow )
  14043. auction.price = auction.buynow - 1;
  14044. }
  14045. auction.auction_id = 0;
  14046. auction.seller_id = sd->status.char_id;
  14047. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14048. auction.buyer_id = 0;
  14049. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14050. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14051. {
  14052. clif_Auction_message(fd, 2); // The auction has been canceled
  14053. return;
  14054. }
  14055. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14056. if( id == nullptr )
  14057. { // Just in case
  14058. clif_Auction_message(fd, 2); // The auction has been canceled
  14059. return;
  14060. }
  14061. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14062. auction.type = id->type;
  14063. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14064. auction.item.amount = 1;
  14065. auction.timestamp = 0;
  14066. if( !intif_Auction_register(&auction) )
  14067. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14068. else
  14069. {
  14070. int zeny = auction.hours*battle_config.auction_feeperhour;
  14071. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14072. sd->auction.amount = 0;
  14073. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  14074. }
  14075. }
  14076. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14077. /// 024e <auction id>.L
  14078. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  14079. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14080. intif_Auction_cancel(sd->status.char_id, auction_id);
  14081. }
  14082. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14083. /// 025d <auction id>.L
  14084. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  14085. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14086. intif_Auction_close(sd->status.char_id, auction_id);
  14087. }
  14088. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14089. /// 024f <auction id>.L <money>.L
  14090. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  14091. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14092. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14093. int bid = RFIFOL(fd,info->pos[1]);
  14094. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14095. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14096. return;
  14097. }
  14098. if( bid <= 0 )
  14099. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14100. else if( bid > sd->status.zeny )
  14101. clif_Auction_message(fd, 8); // You do not have enough zeny
  14102. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14103. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14104. else {
  14105. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  14106. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14107. }
  14108. }
  14109. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14110. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14111. /// search type:
  14112. /// 0 = armor
  14113. /// 1 = weapon
  14114. /// 2 = card
  14115. /// 3 = misc
  14116. /// 4 = name search
  14117. /// 5 = auction id search
  14118. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  14119. char search_text[NAME_LENGTH];
  14120. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14121. short type = RFIFOW(fd,info->pos[0]);
  14122. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14123. int page = RFIFOW(fd,info->pos[3]);
  14124. if( !battle_config.feature_auction )
  14125. return;
  14126. clif_parse_Auction_cancelreg(fd, sd);
  14127. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14128. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14129. }
  14130. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14131. /// 025c <type>.W
  14132. /// type:
  14133. /// 0 = sell (own auctions)
  14134. /// 1 = buy (own bids)
  14135. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  14136. {
  14137. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14138. if( !battle_config.feature_auction )
  14139. return;
  14140. clif_parse_Auction_cancelreg(fd, sd);
  14141. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14142. }
  14143. /// CASH/POINT SHOP
  14144. ///
  14145. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  14146. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14147. nullpo_retv( sd );
  14148. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14149. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14150. p.cashPoints = sd->cashPoints;
  14151. p.kafraPoints = sd->kafraPoints;
  14152. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14153. p.tab = tab;
  14154. #endif
  14155. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14156. #endif
  14157. }
  14158. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  14159. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14160. nullpo_retv( sd );
  14161. int tab = 0;
  14162. #if PACKETVER >= 20191224
  14163. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14164. tab = p->tab;
  14165. #endif
  14166. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14167. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14168. return;
  14169. }
  14170. sd->state.cashshop_open = true;
  14171. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14172. clif_cashshop_open( sd, tab );
  14173. #endif
  14174. }
  14175. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  14176. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14177. sd->state.cashshop_open = false;
  14178. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14179. // No need to do anything here
  14180. #endif
  14181. }
  14182. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14183. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14184. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  14185. // [4144] packet exists only in 2011 and was dropped after
  14186. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14187. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14188. int j;
  14189. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  14190. return;
  14191. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  14192. WFIFOW(fd, 0) = 0x8c0;
  14193. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  14194. WFIFOL(fd, 4) = tab;
  14195. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  14196. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  14197. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  14198. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  14199. }
  14200. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  14201. #endif
  14202. }
  14203. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14204. void clif_cashshop_list( struct map_session_data* sd ){
  14205. nullpo_retv( sd );
  14206. int fd = sd->fd;
  14207. if( !session_isActive( fd ) ){
  14208. return;
  14209. }
  14210. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  14211. // Skip empty tabs, the client only expects filled ones
  14212. if( cash_shop_items[tab].count == 0 ){
  14213. continue;
  14214. }
  14215. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  14216. WFIFOHEAD( fd, len );
  14217. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  14218. p->packetType = 0x8ca;
  14219. p->packetLength = len;
  14220. p->count = cash_shop_items[tab].count;
  14221. p->tabNum = tab;
  14222. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  14223. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  14224. p->items[i].price = cash_shop_items[tab].item[i]->price;
  14225. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14226. struct item_data* id = itemdb_search( cash_shop_items[tab].item[i]->nameid );
  14227. if( id == nullptr ){
  14228. p->items[i].location = 0;
  14229. p->items[i].viewSprite = 0;
  14230. }else{
  14231. p->items[i].location = pc_equippoint_sub( sd, id );
  14232. p->items[i].viewSprite = id->look;
  14233. }
  14234. #endif
  14235. }
  14236. WFIFOSET( fd, len );
  14237. }
  14238. }
  14239. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  14240. if( !sd->status.cashshop_sent ) {
  14241. clif_cashshop_list( sd );
  14242. #if PACKETVER_SUPPORTS_SALES
  14243. sale_notify_login(sd);
  14244. #endif
  14245. sd->status.cashshop_sent = true;
  14246. }
  14247. }
  14248. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14249. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14250. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14251. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14252. nullpo_retv( sd );
  14253. nullpo_retv( nd );
  14254. int fd = sd->fd;
  14255. if( !session_isActive( fd ) ){
  14256. return;
  14257. }
  14258. sd->npc_shopid = nd->bl.id;
  14259. int cost[2] = { 0, 0 };
  14260. npc_shop_currency_type( sd, nd, cost, true );
  14261. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14262. WFIFOHEAD( fd, len );
  14263. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14264. p->packetType = 0x287;
  14265. p->packetLength = len;
  14266. p->cashPoints = cost[0];
  14267. #if PACKETVER >= 20070711
  14268. p->kafraPoints = cost[1];
  14269. #endif
  14270. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14271. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14272. p->items[i].price = nd->u.shop.shop_item[i].value;
  14273. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14274. p->items[i].itemType = itemtype( id->nameid );
  14275. p->items[i].itemId = client_nameid( id->nameid );
  14276. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14277. p->items[i].location = pc_equippoint_sub( sd, id );
  14278. p->items[i].viewSprite = id->look;
  14279. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14280. #endif
  14281. }
  14282. WFIFOSET( fd, len );
  14283. }
  14284. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14285. /// 0289 <cash point>.L <error>.W
  14286. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14287. /// error:
  14288. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14289. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14290. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14291. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14292. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14293. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14294. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14295. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14296. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14297. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14298. {
  14299. int fd, cost[2] = { 0, 0 };
  14300. struct npc_data *nd;
  14301. nullpo_retv(sd);
  14302. fd = sd->fd;
  14303. nd = map_id2nd(sd->npc_shopid);
  14304. npc_shop_currency_type(sd, nd, cost, false);
  14305. WFIFOHEAD(fd, packet_len(0x289));
  14306. WFIFOW(fd,0) = 0x289;
  14307. WFIFOL(fd,2) = cost[0];
  14308. #if PACKETVER < 20070711
  14309. WFIFOW(fd,6) = TOW(error);
  14310. #else
  14311. WFIFOL(fd,6) = cost[1];
  14312. WFIFOW(fd,10) = TOW(error);
  14313. #endif
  14314. WFIFOSET(fd, packet_len(0x289));
  14315. }
  14316. void clif_cashshop_result( struct map_session_data *sd, t_itemid item_id, uint16 result ){
  14317. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14318. nullpo_retv( sd );
  14319. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14320. packet.packetType = 0x849;
  14321. if( item_id != 0 ){
  14322. packet.itemId = client_nameid( item_id );
  14323. }else{
  14324. packet.itemId = 0;
  14325. }
  14326. packet.result = result;
  14327. packet.cashPoints = sd->cashPoints;
  14328. packet.kafraPoints = sd->kafraPoints;
  14329. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14330. #endif
  14331. }
  14332. /// Request to buy item(s) from cash shop.
  14333. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14334. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14335. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14336. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14337. nullpo_retv( sd );
  14338. if( sd->state.trading || !sd->npc_shopid ){
  14339. clif_cashshop_ack( sd, 1 );
  14340. return;
  14341. }
  14342. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14343. #if PACKETVER < 20070711
  14344. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14345. #elif PACKETVER < 20101116
  14346. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14347. #else
  14348. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14349. 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 ){
  14350. 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 );
  14351. return;
  14352. }
  14353. std::vector<s_npc_buy_list> item_list = {};
  14354. item_list.reserve( p->count );
  14355. for( int i = 0; i < p->count; i++ ){
  14356. s_npc_buy_list item = {};
  14357. item.nameid = p->items[i].itemId;
  14358. item.qty = p->items[i].amount;
  14359. item_list.push_back( item );
  14360. }
  14361. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14362. #endif
  14363. }
  14364. /// Request to buy item(s) from cash shop.
  14365. /// 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)
  14366. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14367. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14368. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14369. 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 ){
  14370. 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 );
  14371. return;
  14372. }
  14373. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14374. }
  14375. /// Adoption System
  14376. ///
  14377. /// Adoption message (ZC_BABYMSG).
  14378. /// 0216 <msg>.L
  14379. /// msg:
  14380. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14381. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14382. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14383. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14384. {
  14385. int fd = sd->fd;
  14386. WFIFOHEAD(fd,6);
  14387. WFIFOW(fd,0) = 0x216;
  14388. WFIFOL(fd,2) = type;
  14389. WFIFOSET(fd,6);
  14390. }
  14391. /// Adoption confirmation (ZC_REQ_BABY).
  14392. /// 01f6 <account id>.L <char id>.L <name>.B
  14393. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14394. {
  14395. int fd = sd->fd;
  14396. WFIFOHEAD(fd,34);
  14397. WFIFOW(fd,0) = 0x1f6;
  14398. WFIFOL(fd,2) = src->status.account_id;
  14399. WFIFOL(fd,6) = p_id;
  14400. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14401. WFIFOSET(fd,34);
  14402. }
  14403. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14404. /// 01f9 <account id>.L
  14405. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14406. {
  14407. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14408. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14409. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14410. {
  14411. tsd->adopt_invite = sd->status.account_id;
  14412. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14413. }
  14414. }
  14415. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14416. /// 01f7 <account id>.L <char id>.L <answer>.L
  14417. /// answer:
  14418. /// 0 = rejected
  14419. /// 1 = accepted
  14420. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14421. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14422. int p1_id = RFIFOL(fd,info->pos[0]);
  14423. int p2_id = RFIFOL(fd,info->pos[1]);
  14424. int result = RFIFOL(fd,info->pos[2]);
  14425. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14426. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14427. int pid = sd->adopt_invite;
  14428. sd->adopt_invite = 0;
  14429. if( p1_sd == NULL || p2_sd == NULL )
  14430. return; // Both players need to be online
  14431. if( pid != p1_sd->status.account_id )
  14432. return; // Incorrect values
  14433. if( result == 0 )
  14434. return; // Rejected
  14435. pc_adoption(p1_sd, p2_sd, sd);
  14436. }
  14437. /// Convex Mirror (ZC_BOSS_INFO).
  14438. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14439. /// infoType:
  14440. /// BOSS_INFO_NOT = No boss on this map.
  14441. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14442. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14443. /// BOSS_INFO_DEAD = Boss is dead.
  14444. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14445. {
  14446. int fd = sd->fd;
  14447. WFIFOHEAD(fd,70);
  14448. memset(WFIFOP(fd,0),0,70);
  14449. WFIFOW(fd,0) = 0x293;
  14450. switch (flag) {
  14451. case BOSS_INFO_NOT:
  14452. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14453. // No data required
  14454. break;
  14455. case BOSS_INFO_ALIVE:
  14456. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14457. // Update X/Y
  14458. WFIFOL(fd,3) = md->bl.x;
  14459. WFIFOL(fd,7) = md->bl.y;
  14460. break;
  14461. case BOSS_INFO_ALIVE_WITHMSG:
  14462. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14463. // Current X/Y
  14464. WFIFOL(fd,3) = md->bl.x;
  14465. WFIFOL(fd,7) = md->bl.y;
  14466. break;
  14467. case BOSS_INFO_DEAD:
  14468. {
  14469. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14470. unsigned int seconds;
  14471. int hours, minutes;
  14472. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14473. hours = seconds / (60 * 60);
  14474. seconds = seconds - (60 * 60 * hours);
  14475. minutes = seconds / 60;
  14476. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14477. // Add respawn info
  14478. WFIFOW(fd,11) = hours; // Hours
  14479. WFIFOW(fd,13) = minutes; // Minutes
  14480. }
  14481. break;
  14482. }
  14483. if (md != NULL)
  14484. safestrncpy(WFIFOCP(fd,19), md->db->jname.c_str(), NAME_LENGTH);
  14485. WFIFOSET(fd,70);
  14486. }
  14487. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14488. /// 02d6 <account id>.L
  14489. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14490. {
  14491. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14492. struct map_session_data* tsd = map_id2sd(aid);
  14493. if (!tsd)
  14494. return;
  14495. if (sd->bl.m != tsd->bl.m)
  14496. return;
  14497. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14498. clif_viewequip_ack(sd, tsd);
  14499. else
  14500. clif_msg(sd, VIEW_EQUIP_FAIL);
  14501. }
  14502. /// Request to a configuration.
  14503. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14504. /// type: see enum e_config_type
  14505. /// flag:
  14506. /// false = disabled
  14507. /// true = enabled
  14508. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14509. int cmd = RFIFOW(fd,0);
  14510. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14511. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14512. switch( type ){
  14513. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14514. sd->status.show_equip = flag;
  14515. break;
  14516. case CONFIG_CALL:
  14517. sd->status.disable_call = flag;
  14518. break;
  14519. case CONFIG_PET_AUTOFEED:
  14520. // Player can not click this if he does not have a pet
  14521. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14522. return;
  14523. }
  14524. sd->pd->pet.autofeed = flag;
  14525. break;
  14526. case CONFIG_HOMUNCULUS_AUTOFEED:
  14527. // Player can not click this if he does not have a homunculus or it is vaporized
  14528. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14529. return;
  14530. }
  14531. sd->hd->homunculus.autofeed = flag;
  14532. break;
  14533. default:
  14534. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14535. return;
  14536. }
  14537. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14538. }
  14539. /// Request to change party invitation tick.
  14540. /// value:
  14541. /// 0 = disabled
  14542. /// 1 = enabled
  14543. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14544. {
  14545. bool flag = RFIFOB(fd,6) ? true : false;
  14546. sd->status.allow_party = flag;
  14547. clif_partytickack(sd, flag);
  14548. }
  14549. /// Questlog System [Kevin] [Inkfish]
  14550. ///
  14551. /**
  14552. * Safe check to init packet len & quest num for player.
  14553. * @param def_len
  14554. * @param info_len Length of each quest info.
  14555. * @param avail_quests Avail quests that player has.
  14556. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14557. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14558. **/
  14559. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14560. (*limit_out) = (0xFFFF - def_len) / info_len;
  14561. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14562. (*len_out) = ((*limit_out) * info_len) + def_len;
  14563. }
  14564. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14565. std::string race_name;
  14566. switch( objective->race ){
  14567. case RC_FORMLESS: race_name = "Formless"; break;
  14568. case RC_UNDEAD: race_name = "Undead"; break;
  14569. case RC_BRUTE: race_name = "Brute"; break;
  14570. case RC_PLANT: race_name = "Plant"; break;
  14571. case RC_INSECT: race_name = "Insect"; break;
  14572. case RC_FISH: race_name = "Fish"; break;
  14573. case RC_DEMON: race_name = "Demon"; break;
  14574. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14575. case RC_ANGEL: race_name = "Angel"; break;
  14576. case RC_DRAGON: race_name = "Dragon"; break;
  14577. default:
  14578. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14579. // Fallthrough
  14580. case RC_ALL: race_name = ""; break;
  14581. }
  14582. std::string size_name;
  14583. switch( objective->size ){
  14584. case SZ_SMALL: size_name = "Small"; break;
  14585. case SZ_MEDIUM: size_name = "Medium"; break;
  14586. case SZ_BIG: size_name = "Large"; break;
  14587. default:
  14588. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14589. // Fallthrough
  14590. case SZ_ALL: size_name = ""; break;
  14591. }
  14592. std::string ele_name;
  14593. switch( objective->element ){
  14594. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14595. case ELE_WATER: ele_name = "Water Element"; break;
  14596. case ELE_EARTH: ele_name = "Earth Element"; break;
  14597. case ELE_FIRE: ele_name = "Fire Element"; break;
  14598. case ELE_WIND: ele_name = "Wind Element"; break;
  14599. case ELE_POISON: ele_name = "Poison Element"; break;
  14600. case ELE_HOLY: ele_name = "Holy Element"; break;
  14601. case ELE_DARK: ele_name = "Shadow Element"; break;
  14602. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14603. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14604. default:
  14605. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14606. // Fallthrough
  14607. case ELE_ALL: ele_name = ""; break;
  14608. }
  14609. std::string str;
  14610. if( !objective->map_name.empty() ){
  14611. str += objective->map_name;
  14612. }
  14613. if( !race_name.empty() ){
  14614. if( !str.empty() ){
  14615. str += ", ";
  14616. }
  14617. str += race_name;
  14618. }
  14619. if( !size_name.empty() ){
  14620. if( !str.empty() ){
  14621. str += ", ";
  14622. }
  14623. str += size_name;
  14624. }
  14625. if( !ele_name.empty() ){
  14626. if( !str.empty() ){
  14627. str += ", ";
  14628. }
  14629. str += ele_name;
  14630. }
  14631. return str;
  14632. }
  14633. /// Sends list of all quest states
  14634. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14635. /// 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)
  14636. /// 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)
  14637. void clif_quest_send_list(struct map_session_data *sd)
  14638. {
  14639. nullpo_retv(sd);
  14640. int fd = sd->fd;
  14641. int i;
  14642. int offset = 8;
  14643. int limit = 0;
  14644. #if PACKETVER >= 20141022
  14645. #if PACKETVER >= 20150513
  14646. int size = 22 + NAME_LENGTH;
  14647. #else
  14648. int size = 10 + NAME_LENGTH;
  14649. #endif
  14650. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14651. WFIFOHEAD(fd,i);
  14652. #if PACKETVER >= 20150513
  14653. WFIFOW(fd, 0) = 0x9f8;
  14654. #else
  14655. WFIFOW(fd, 0) = 0x97a;
  14656. #endif
  14657. WFIFOL(fd, 4) = limit;
  14658. for (i = 0; i < limit; i++) {
  14659. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14660. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14661. offset += 4;
  14662. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14663. offset++;
  14664. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14665. offset += 4;
  14666. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14667. offset += 4;
  14668. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14669. offset += 2;
  14670. if (!qi->objectives.empty()) {
  14671. std::shared_ptr<s_mob_db> mob;
  14672. for (int j = 0; j < qi->objectives.size(); j++) {
  14673. mob = mob_db.find(qi->objectives[j]->mob_id);
  14674. e_race race = qi->objectives[j]->race;
  14675. e_size size = qi->objectives[j]->size;
  14676. e_element element = qi->objectives[j]->element;
  14677. #if PACKETVER >= 20150513
  14678. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14679. offset += 4;
  14680. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14681. offset += 4;
  14682. #endif
  14683. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14684. offset += 4;
  14685. #if PACKETVER >= 20150513
  14686. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14687. offset += 2;
  14688. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14689. offset += 2;
  14690. #endif
  14691. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14692. offset += 2;
  14693. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14694. offset += 2;
  14695. if (mob && qi->objectives[j]->mob_id > 0)
  14696. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14697. else
  14698. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14699. offset += NAME_LENGTH;
  14700. }
  14701. }
  14702. }
  14703. WFIFOW(fd, 2) = offset;
  14704. WFIFOSET(fd, offset);
  14705. #else
  14706. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14707. WFIFOHEAD(fd,i);
  14708. WFIFOW(fd, 0) = 0x2b1;
  14709. WFIFOL(fd, 4) = limit;
  14710. for (i = 0; i < limit; i++) {
  14711. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14712. offset += 4;
  14713. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14714. offset += 1;
  14715. }
  14716. WFIFOW(fd, 2) = offset;
  14717. WFIFOSET(fd, offset);
  14718. #endif
  14719. }
  14720. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14721. /// 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
  14722. void clif_quest_send_mission(struct map_session_data *sd)
  14723. {
  14724. nullpo_retv(sd);
  14725. int fd = sd->fd;
  14726. int limit = 0;
  14727. int len = sd->avail_quests*104+8;
  14728. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14729. WFIFOHEAD(fd, len);
  14730. WFIFOW(fd, 0) = 0x2b2;
  14731. WFIFOW(fd, 2) = len;
  14732. WFIFOL(fd, 4) = limit;
  14733. for (int i = 0; i < limit; i++) {
  14734. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14735. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14736. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14737. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14738. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14739. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14740. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14741. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14742. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14743. if (mob && qi->objectives[j]->mob_id > 0)
  14744. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14745. else
  14746. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14747. }
  14748. }
  14749. WFIFOSET(fd, len);
  14750. }
  14751. /// Notification about a new quest
  14752. /// 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)
  14753. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14754. /// 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)
  14755. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14756. {
  14757. nullpo_retv(sd);
  14758. nullpo_retv(qd);
  14759. int fd = sd->fd;
  14760. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14761. if (!qi)
  14762. return;
  14763. #if PACKETVER >= 20150513
  14764. int cmd = 0x9f9;
  14765. #else
  14766. int cmd = 0x2b3;
  14767. #endif
  14768. WFIFOHEAD(fd, packet_len(cmd));
  14769. WFIFOW(fd, 0) = cmd;
  14770. WFIFOL(fd, 2) = qd->quest_id;
  14771. WFIFOB(fd, 6) = qd->state;
  14772. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14773. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14774. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14775. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14776. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14777. e_race race = qi->objectives[i]->race;
  14778. e_size size = qi->objectives[i]->size;
  14779. e_element element = qi->objectives[i]->element;
  14780. #if PACKETVER >= 20150513
  14781. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14782. offset += 4;
  14783. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14784. offset += 4;
  14785. #endif
  14786. 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
  14787. offset += 4;
  14788. #if PACKETVER >= 20150513
  14789. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14790. offset += 2;
  14791. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14792. offset += 2;
  14793. #endif
  14794. WFIFOW(fd, offset) = qd->count[i];
  14795. offset += 2;
  14796. if (mob && qi->objectives[i]->mob_id > 0)
  14797. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14798. else
  14799. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14800. offset += NAME_LENGTH;
  14801. }
  14802. WFIFOSET(fd, packet_len(cmd));
  14803. #if PACKETVER >= 20150513
  14804. int len = 4 + qi->objectives.size() * 12;
  14805. WFIFOHEAD(fd, len);
  14806. WFIFOW(fd, 0) = 0x8fe;
  14807. WFIFOW(fd, 2) = len;
  14808. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14809. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14810. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14811. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14812. WFIFOW(fd, offset + 10) = qd->count[i];
  14813. }
  14814. WFIFOSET(fd, len);
  14815. #endif
  14816. }
  14817. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14818. /// 02b4 <quest id>.L
  14819. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14820. {
  14821. int fd = sd->fd;
  14822. WFIFOHEAD(fd, packet_len(0x2b4));
  14823. WFIFOW(fd, 0) = 0x2b4;
  14824. WFIFOL(fd, 2) = quest_id;
  14825. WFIFOSET(fd, packet_len(0x2b4));
  14826. }
  14827. /// Notification of an update to the hunting mission counter
  14828. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14829. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14830. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14831. {
  14832. int fd = sd->fd;
  14833. int offset = 6;
  14834. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14835. int len = qi->objectives.size() * 12 + 6;
  14836. #if PACKETVER >= 20150513
  14837. int cmd = 0x9fa;
  14838. #else
  14839. int cmd = 0x2b5;
  14840. #endif
  14841. WFIFOHEAD(fd, len);
  14842. WFIFOW(fd, 0) = cmd;
  14843. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14844. for (int i = 0; i < qi->objectives.size(); i++) {
  14845. WFIFOL(fd, offset) = qd->quest_id;
  14846. offset += 4;
  14847. #if PACKETVER >= 20150513
  14848. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14849. offset += 4;
  14850. #else
  14851. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14852. offset += 4;
  14853. #endif
  14854. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14855. offset += 2;
  14856. WFIFOW(fd, offset) = qd->count[i];
  14857. offset += 2;
  14858. }
  14859. WFIFOW(fd, 2) = offset;
  14860. WFIFOSET(fd, offset);
  14861. }
  14862. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14863. /// 02b6 <quest id>.L <active>.B
  14864. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14865. {
  14866. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14867. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14868. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14869. }
  14870. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14871. /// 02b7 <quest id>.L <active>.B
  14872. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14873. {
  14874. int fd = sd->fd;
  14875. WFIFOHEAD(fd, packet_len(0x2b7));
  14876. WFIFOW(fd, 0) = 0x2b7;
  14877. WFIFOL(fd, 2) = quest_id;
  14878. WFIFOB(fd, 6) = active;
  14879. WFIFOSET(fd, packet_len(0x2b7));
  14880. }
  14881. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14882. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14883. /// effect:
  14884. /// 0 = none
  14885. /// 1 = exclamation mark icon
  14886. /// 2 = question mark icon
  14887. /// color:
  14888. /// 0 = yellow
  14889. /// 1 = orange
  14890. /// 2 = green
  14891. /// 3 = purple
  14892. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14893. {
  14894. #if PACKETVER >= 20090218
  14895. nullpo_retv(sd);
  14896. nullpo_retv(bl);
  14897. int fd = sd->fd;
  14898. WFIFOHEAD(fd, packet_len(0x446));
  14899. WFIFOW(fd, 0) = 0x446;
  14900. WFIFOL(fd, 2) = bl->id;
  14901. WFIFOW(fd, 6) = bl->x;
  14902. WFIFOW(fd, 8) = bl->y;
  14903. WFIFOW(fd, 10) = effect;
  14904. WFIFOW(fd, 12) = color;
  14905. WFIFOSET(fd, packet_len(0x446));
  14906. #endif
  14907. }
  14908. /// Mercenary System
  14909. ///
  14910. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14911. /// 02a2 <var id>.W <value>.L
  14912. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14913. {
  14914. s_mercenary_data *md;
  14915. struct status_data *status;
  14916. int fd;
  14917. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14918. return;
  14919. fd = sd->fd;
  14920. status = &md->battle_status;
  14921. WFIFOHEAD(fd,packet_len(0x2a2));
  14922. WFIFOW(fd,0) = 0x2a2;
  14923. WFIFOW(fd,2) = type;
  14924. switch( type ) {
  14925. case SP_ATK1:
  14926. {
  14927. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14928. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14929. }
  14930. break;
  14931. case SP_MATK1:
  14932. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14933. break;
  14934. case SP_HIT:
  14935. WFIFOL(fd,4) = status->hit;
  14936. break;
  14937. case SP_CRITICAL:
  14938. WFIFOL(fd,4) = status->cri/10;
  14939. break;
  14940. case SP_DEF1:
  14941. WFIFOL(fd,4) = status->def;
  14942. break;
  14943. case SP_MDEF1:
  14944. WFIFOL(fd,4) = status->mdef;
  14945. break;
  14946. case SP_MERCFLEE:
  14947. WFIFOL(fd,4) = status->flee;
  14948. break;
  14949. case SP_ASPD:
  14950. WFIFOL(fd,4) = status->amotion;
  14951. break;
  14952. case SP_HP:
  14953. WFIFOL(fd,4) = status->hp;
  14954. break;
  14955. case SP_MAXHP:
  14956. WFIFOL(fd,4) = status->max_hp;
  14957. break;
  14958. case SP_SP:
  14959. WFIFOL(fd,4) = status->sp;
  14960. break;
  14961. case SP_MAXSP:
  14962. WFIFOL(fd,4) = status->max_sp;
  14963. break;
  14964. case SP_MERCKILLS:
  14965. WFIFOL(fd,4) = md->mercenary.kill_count;
  14966. break;
  14967. case SP_MERCFAITH:
  14968. WFIFOL(fd,4) = mercenary_get_faith(md);
  14969. break;
  14970. }
  14971. WFIFOSET(fd,packet_len(0x2a2));
  14972. }
  14973. /// Mercenary base status data (ZC_MER_INIT).
  14974. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14975. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14976. /// <calls>.L <kills>.L <atk range>.W
  14977. void clif_mercenary_info(struct map_session_data *sd)
  14978. {
  14979. int fd;
  14980. s_mercenary_data *md;
  14981. struct status_data *status;
  14982. int atk;
  14983. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14984. return;
  14985. fd = sd->fd;
  14986. status = &md->battle_status;
  14987. WFIFOHEAD(fd,packet_len(0x29b));
  14988. WFIFOW(fd,0) = 0x29b;
  14989. WFIFOL(fd,2) = md->bl.id;
  14990. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14991. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14992. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14993. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14994. WFIFOW(fd,10) = status->hit;
  14995. WFIFOW(fd,12) = status->cri/10;
  14996. WFIFOW(fd,14) = status->def;
  14997. WFIFOW(fd,16) = status->mdef;
  14998. WFIFOW(fd,18) = status->flee;
  14999. WFIFOW(fd,20) = status->amotion;
  15000. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15001. WFIFOW(fd,46) = md->db->lv;
  15002. WFIFOL(fd,48) = status->hp;
  15003. WFIFOL(fd,52) = status->max_hp;
  15004. WFIFOL(fd,56) = status->sp;
  15005. WFIFOL(fd,60) = status->max_sp;
  15006. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15007. WFIFOW(fd,68) = mercenary_get_faith(md);
  15008. WFIFOL(fd,70) = mercenary_get_calls(md);
  15009. WFIFOL(fd,74) = md->mercenary.kill_count;
  15010. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15011. WFIFOSET(fd,packet_len(0x29b));
  15012. }
  15013. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15014. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15015. void clif_mercenary_skillblock(struct map_session_data *sd)
  15016. {
  15017. s_mercenary_data *md;
  15018. int fd, len = 4;
  15019. if( sd == NULL || (md = sd->md) == NULL )
  15020. return;
  15021. fd = sd->fd;
  15022. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15023. WFIFOW(fd,0) = 0x29d;
  15024. for (const auto &it : md->db->skill) {
  15025. uint16 id = it.first;
  15026. if (!SKILL_CHK_MERC(id))
  15027. continue;
  15028. uint16 lv = it.second;
  15029. WFIFOW(fd,len) = id;
  15030. WFIFOL(fd,len+2) = skill_get_inf(id);
  15031. WFIFOW(fd,len+6) = lv;
  15032. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15033. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15034. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15035. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15036. len += 37;
  15037. }
  15038. WFIFOW(fd,2) = len;
  15039. WFIFOSET(fd,len);
  15040. }
  15041. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15042. /// 029f <command>.B
  15043. /// 1 = mercenary information
  15044. /// 2 = delete
  15045. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  15046. {
  15047. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15048. if( sd->md == NULL )
  15049. return;
  15050. if( option == 2 ) mercenary_delete(sd->md, 2);
  15051. }
  15052. /// Mercenary Message
  15053. /// message:
  15054. /// 0 = Mercenary soldier's duty hour is over.
  15055. /// 1 = Your mercenary soldier has been killed.
  15056. /// 2 = Your mercenary soldier has been fired.
  15057. /// 3 = Your mercenary soldier has ran away.
  15058. void clif_mercenary_message(struct map_session_data* sd, int message){
  15059. clif_msg(sd, MERC_MSG_BASE + message);
  15060. }
  15061. /// Notification about the remaining time of a rental item.
  15062. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15063. void clif_rental_time( struct map_session_data* sd, t_itemid nameid, int seconds ){
  15064. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15065. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15066. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15067. p.itemId = client_nameid( nameid );
  15068. p.seconds = seconds;
  15069. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15070. }
  15071. /// Deletes a rental item from client's inventory.
  15072. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15073. void clif_rental_expired( struct map_session_data* sd, int index, t_itemid nameid ){
  15074. // '<ItemName>' item has been deleted from the Inventory
  15075. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15076. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15077. p.index = client_index( index );
  15078. p.itemId = client_nameid( nameid );
  15079. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15080. }
  15081. /// Book Reading (ZC_READ_BOOK).
  15082. /// 0294 <book id>.L <page>.L
  15083. void clif_readbook(int fd, int book_id, int page)
  15084. {
  15085. WFIFOHEAD(fd,packet_len(0x294));
  15086. WFIFOW(fd,0) = 0x294;
  15087. WFIFOL(fd,2) = book_id;
  15088. WFIFOL(fd,6) = page;
  15089. WFIFOSET(fd,packet_len(0x294));
  15090. }
  15091. /// Battlegrounds
  15092. ///
  15093. /// Updates HP bar of a camp member.
  15094. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15095. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15096. void clif_bg_hp(struct map_session_data *sd) {
  15097. #if PACKETVER < 20140613
  15098. unsigned char buf[34];
  15099. const int cmd = 0x2e0;
  15100. #else
  15101. unsigned char buf[14];
  15102. const int cmd = 0xa0e;
  15103. #endif
  15104. nullpo_retv(sd);
  15105. WBUFW(buf,0) = cmd;
  15106. WBUFL(buf,2) = sd->status.account_id;
  15107. #if PACKETVER < 20140613
  15108. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15109. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15110. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15111. WBUFW(buf,32) = 100;
  15112. } else {
  15113. WBUFW(buf,30) = sd->battle_status.hp;
  15114. WBUFW(buf,32) = sd->battle_status.max_hp;
  15115. }
  15116. #else
  15117. if( sd->battle_status.max_hp > INT32_MAX ) {
  15118. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15119. WBUFL(buf,10) = 100;
  15120. } else {
  15121. WBUFL(buf,6) = sd->battle_status.hp;
  15122. WBUFL(buf,10) = sd->battle_status.max_hp;
  15123. }
  15124. #endif
  15125. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15126. }
  15127. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15128. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15129. void clif_bg_xy(struct map_session_data *sd)
  15130. {
  15131. unsigned char buf[36];
  15132. nullpo_retv(sd);
  15133. WBUFW(buf,0)=0x2df;
  15134. WBUFL(buf,2)=sd->status.account_id;
  15135. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15136. WBUFW(buf,30)=sd->status.class_;
  15137. WBUFW(buf,32)=sd->bl.x;
  15138. WBUFW(buf,34)=sd->bl.y;
  15139. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15140. }
  15141. void clif_bg_xy_remove(struct map_session_data *sd)
  15142. {
  15143. unsigned char buf[36];
  15144. nullpo_retv(sd);
  15145. WBUFW(buf,0)=0x2df;
  15146. WBUFL(buf,2)=sd->status.account_id;
  15147. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15148. WBUFW(buf,30)=0;
  15149. WBUFW(buf,32)=-1;
  15150. WBUFW(buf,34)=-1;
  15151. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15152. }
  15153. /// Notifies clients of a battleground message.
  15154. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15155. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15156. struct map_session_data *sd = bg_getavailablesd( bg );
  15157. if( sd == nullptr ){
  15158. return;
  15159. }
  15160. // limit length
  15161. len = min( len + 1, CHAT_SIZE_MAX );
  15162. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15163. WBUFW(buf,0) = 0x2dc;
  15164. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15165. WBUFL(buf,4) = src_id;
  15166. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15167. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15168. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15169. }
  15170. /// Validates and processes battlechat messages.
  15171. /// All messages that are sent after enabling battleground chat with /battlechat.
  15172. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15173. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  15174. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15175. if( !clif_process_message( sd, false, name, message, output ) )
  15176. return;
  15177. bg_send_message(sd, output, strlen(output) );
  15178. }
  15179. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15180. /// 02de <camp A points>.W <camp B points>.W
  15181. void clif_bg_updatescore(int16 m)
  15182. {
  15183. struct block_list bl;
  15184. unsigned char buf[6];
  15185. struct map_data *mapdata = map_getmapdata(m);
  15186. bl.id = 0;
  15187. bl.type = BL_NUL;
  15188. bl.m = m;
  15189. WBUFW(buf,0) = 0x2de;
  15190. WBUFW(buf,2) = mapdata->bgscore_lion;
  15191. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15192. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15193. }
  15194. void clif_bg_updatescore_single(struct map_session_data *sd)
  15195. {
  15196. int fd;
  15197. nullpo_retv(sd);
  15198. fd = sd->fd;
  15199. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15200. WFIFOHEAD(fd,packet_len(0x2de));
  15201. WFIFOW(fd,0) = 0x2de;
  15202. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15203. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15204. WFIFOSET(fd,packet_len(0x2de));
  15205. }
  15206. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15207. /// 02dd <account id>.L <name>.24B <camp>.W
  15208. void clif_sendbgemblem_area(struct map_session_data *sd)
  15209. {
  15210. unsigned char buf[33];
  15211. nullpo_retv(sd);
  15212. WBUFW(buf, 0) = 0x2dd;
  15213. WBUFL(buf,2) = sd->bl.id;
  15214. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15215. WBUFW(buf,30) = sd->bg_id;
  15216. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15217. }
  15218. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  15219. {
  15220. nullpo_retv(sd);
  15221. WFIFOHEAD(fd,32);
  15222. WFIFOW(fd,0) = 0x2dd;
  15223. WFIFOL(fd,2) = sd->bl.id;
  15224. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15225. WFIFOW(fd,30) = sd->bg_id;
  15226. WFIFOSET(fd,packet_len(0x2dd));
  15227. }
  15228. /// Battlegrounds queue incoming apply request from client.
  15229. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15230. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15231. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  15232. {
  15233. if (!battle_config.feature_bgqueue)
  15234. return;
  15235. nullpo_retv(sd);
  15236. short type = RFIFOW(fd,2);
  15237. char name[NAME_LENGTH];
  15238. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15239. if (sd->bg_queue_id > 0) {
  15240. //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);
  15241. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15242. return;
  15243. } else if (type == 1) // Solo
  15244. bg_queue_join_solo(name, sd);
  15245. else if (type == 2) // Party
  15246. bg_queue_join_party(name, sd);
  15247. else if (type == 4) // Guild
  15248. bg_queue_join_guild(name, sd);
  15249. else {
  15250. 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);
  15251. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15252. return;
  15253. }
  15254. }
  15255. /// Outgoing battlegrounds queue apply result.
  15256. /// Result types: @see e_bg_queue_apply_ack
  15257. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15258. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  15259. {
  15260. nullpo_retv(sd);
  15261. int fd = sd->fd;
  15262. WFIFOHEAD(fd, packet_len(0x8d8));
  15263. WFIFOW(fd,0) = 0x8d8;
  15264. WFIFOB(fd,2) = result;
  15265. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15266. WFIFOSET(fd, packet_len(0x8d8));
  15267. }
  15268. /// Outgoing battlegrounds queue apply notification.
  15269. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15270. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15271. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  15272. {
  15273. nullpo_retv(sd);
  15274. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15275. if (queue == nullptr) {
  15276. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15277. return;
  15278. }
  15279. int fd = sd->fd;
  15280. WFIFOHEAD(fd, packet_len(0x8d9));
  15281. WFIFOW(fd,0) = 0x8d9;
  15282. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15283. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15284. WFIFOSET(fd, packet_len(0x8d9));
  15285. }
  15286. /// Battlegrounds queue outgoing cancel result.
  15287. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15288. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  15289. {
  15290. nullpo_retv(sd);
  15291. int fd = sd->fd;
  15292. WFIFOHEAD(fd, packet_len(0x8d8));
  15293. WFIFOW(fd,0) = 0x8db;
  15294. WFIFOB(fd,2) = success;
  15295. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15296. WFIFOSET(fd, packet_len(0x8d8));
  15297. }
  15298. /// Battlegrounds queue incoming cancel request from client.
  15299. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15300. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15301. {
  15302. if (!battle_config.feature_bgqueue)
  15303. return;
  15304. nullpo_retv(sd);
  15305. bool success;
  15306. if (sd->bg_queue_id > 0) {
  15307. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15308. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15309. 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.
  15310. else
  15311. success = bg_queue_leave(sd);
  15312. } else {
  15313. 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);
  15314. success = false;
  15315. }
  15316. char name[NAME_LENGTH];
  15317. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15318. clif_bg_queue_cancel_result(success, name, sd);
  15319. }
  15320. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15321. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15322. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15323. {
  15324. nullpo_retv(sd);
  15325. int fd = sd->fd;
  15326. WFIFOHEAD(fd, packet_len(0x8df));
  15327. WFIFOW(fd,0) = 0x8df;
  15328. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15329. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15330. WFIFOSET(fd, packet_len(0x8df));
  15331. }
  15332. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15333. /// Result types: 1(Accept), 2(Decline).
  15334. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15335. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15336. {
  15337. nullpo_retv(sd);
  15338. if(sd->bg_queue_id > 0) {
  15339. uint8 result = RFIFOB(fd, 2);
  15340. if(result == 1) { // Accept
  15341. bg_queue_on_accept_invite(sd);
  15342. } else if(result == 2) { // Decline
  15343. bg_queue_leave(sd);
  15344. clif_bg_queue_entry_init(sd);
  15345. }
  15346. }
  15347. }
  15348. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15349. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15350. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15351. {
  15352. nullpo_retv(sd);
  15353. int fd = sd->fd;
  15354. WFIFOHEAD(fd, packet_len(0x8e1));
  15355. WFIFOW(fd,0) = 0x8e1;
  15356. WFIFOB(fd,2) = result;
  15357. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15358. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15359. WFIFOSET(fd, packet_len(0x8e1));
  15360. }
  15361. /// Battlegrounds queue incoming queue number request from client.
  15362. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15363. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15364. {
  15365. nullpo_retv(sd);
  15366. char name[NAME_LENGTH];
  15367. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15368. clif_bg_queue_apply_notify(name, sd);
  15369. }
  15370. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15371. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15372. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15373. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15374. {
  15375. nullpo_retv(sd);
  15376. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15377. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15378. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15379. }
  15380. /// Custom Fonts (ZC_NOTIFY_FONT).
  15381. /// 02ef <account_id>.L <font id>.W
  15382. void clif_font(struct map_session_data *sd)
  15383. {
  15384. #if PACKETVER >= 20080102
  15385. unsigned char buf[8];
  15386. nullpo_retv(sd);
  15387. WBUFW(buf,0) = 0x2ef;
  15388. WBUFL(buf,2) = sd->bl.id;
  15389. WBUFW(buf,6) = sd->status.font;
  15390. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15391. #endif
  15392. }
  15393. /// Required to start the instancing information window on Client
  15394. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15395. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15396. void clif_instance_create(int instance_id, int num)
  15397. {
  15398. #if PACKETVER >= 20071128
  15399. struct map_session_data *sd = NULL;
  15400. enum send_target target = PARTY;
  15401. unsigned char buf[65];
  15402. instance_getsd(instance_id, sd, &target);
  15403. if (!sd)
  15404. return;
  15405. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15406. if (!db)
  15407. return;
  15408. WBUFW(buf,0) = 0x2cb;
  15409. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15410. WBUFW(buf,63) = num;
  15411. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15412. #endif
  15413. return;
  15414. }
  15415. /// To announce Instancing queue creation if no maps available
  15416. /// S 0x2cc <Standby Position>.W
  15417. void clif_instance_changewait(int instance_id, int num)
  15418. {
  15419. #if PACKETVER >= 20071128
  15420. struct map_session_data *sd = NULL;
  15421. enum send_target target = PARTY;
  15422. unsigned char buf[4];
  15423. instance_getsd(instance_id, sd, &target);
  15424. if (!sd)
  15425. return;
  15426. WBUFW(buf,0) = 0x2cc;
  15427. WBUFW(buf,2) = num;
  15428. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15429. #endif
  15430. return;
  15431. }
  15432. /// Notify the current status to members
  15433. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15434. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15435. {
  15436. #if PACKETVER >= 20071128
  15437. struct map_session_data *sd = NULL;
  15438. enum send_target target = PARTY;
  15439. unsigned char buf[71];
  15440. instance_getsd(instance_id, sd, &target);
  15441. if (!sd)
  15442. return;
  15443. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15444. if (!db)
  15445. return;
  15446. WBUFW(buf,0) = 0x2cd;
  15447. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15448. WBUFL(buf,63) = limit1;
  15449. WBUFL(buf,67) = limit2;
  15450. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15451. #endif
  15452. return;
  15453. }
  15454. /// Notify a status change to members
  15455. /// S 0x2ce <Message ID>.L
  15456. /// 0 = Notification (EnterLimitDate update?)
  15457. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15458. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15459. /// 3 = The Memorial Dungeon has been removed.
  15460. /// 4 = Create failure (removes the instance window)
  15461. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15462. {
  15463. #if PACKETVER >= 20071128
  15464. struct map_session_data *sd = NULL;
  15465. enum send_target target = PARTY;
  15466. unsigned char buf[10];
  15467. instance_getsd(instance_id, sd, &target);
  15468. if (!sd)
  15469. return;
  15470. WBUFW(buf,0) = 0x2ce;
  15471. WBUFL(buf,2) = type;
  15472. WBUFL(buf,6) = limit;
  15473. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15474. #endif
  15475. return;
  15476. }
  15477. /// Destroy an instance from the status window
  15478. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15479. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15480. {
  15481. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15482. return;
  15483. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15484. switch (p->command) {
  15485. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15486. instance_destroy_command(sd);
  15487. break;
  15488. }
  15489. }
  15490. void clif_instance_info( struct map_session_data& sd ){
  15491. if( sd.instance_id > 0 ){
  15492. instance_reqinfo( &sd, sd.instance_id );
  15493. }
  15494. if( sd.status.party_id > 0 ){
  15495. struct party_data* p = party_search( sd.status.party_id );
  15496. if( p != nullptr && p->instance_id > 0 ){
  15497. instance_reqinfo( &sd, p->instance_id );
  15498. }
  15499. }
  15500. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15501. instance_reqinfo( &sd, sd.guild->instance_id );
  15502. }
  15503. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15504. instance_reqinfo( &sd, sd.clan->instance_id );
  15505. }
  15506. }
  15507. /// Notifies clients about item picked up by a party member.
  15508. /// 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)
  15509. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15510. #if PACKETVER >= 20071002
  15511. nullpo_retv( sd );
  15512. nullpo_retv( item_data );
  15513. struct item_data* id = itemdb_search( item_data->nameid );
  15514. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15515. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15516. p.AID = sd->status.account_id;
  15517. p.itemId = client_nameid( item_data->nameid );
  15518. p.identified = item_data->identify;
  15519. p.damaged = item_data->attribute;
  15520. p.refine = item_data->refine;
  15521. clif_addcards( &p.slot, item_data );
  15522. p.location = id->equip; // equip location
  15523. p.itemType = itemtype( id->nameid ); // item type
  15524. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15525. p.grade = item_data->enchantgrade;
  15526. #endif
  15527. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15528. #endif
  15529. }
  15530. /** Display gained exp.
  15531. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15532. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15533. * amount: INT32_MIN ~ INT32_MAX
  15534. * var id:
  15535. * SP_BASEEXP, SP_JOBEXP
  15536. * exp type:
  15537. * 0 = normal exp gained/lost
  15538. * 1 = quest exp gained/lost
  15539. * @param sd Player
  15540. * @param exp EXP value gained/loss
  15541. * @param type SP_BASEEXP, SP_JOBEXP
  15542. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15543. * @param lost True:if losing EXP
  15544. */
  15545. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15546. {
  15547. int fd;
  15548. int offset;
  15549. #if PACKETVER >= 20170830
  15550. int cmd = 0xacc;
  15551. #else
  15552. int cmd = 0x7f6;
  15553. #endif
  15554. nullpo_retv(sd);
  15555. fd = sd->fd;
  15556. WFIFOHEAD(fd, packet_len(cmd));
  15557. WFIFOW(fd,0) = cmd;
  15558. WFIFOL(fd,2) = sd->bl.id;
  15559. #if PACKETVER >= 20170830
  15560. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15561. offset = 4;
  15562. #else
  15563. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15564. offset = 0;
  15565. #endif
  15566. WFIFOW(fd,10+offset) = type;
  15567. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15568. WFIFOSET(fd,packet_len(cmd));
  15569. }
  15570. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15571. /// type:
  15572. /// 0 = Displays 'value' for 5 seconds.
  15573. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15574. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15575. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15576. /// value:
  15577. /// 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).
  15578. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15579. {
  15580. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15581. WFIFOW(sd->fd,0) = 0x1b1;
  15582. WFIFOB(sd->fd,2) = type;
  15583. WFIFOL(sd->fd,3) = value;
  15584. WFIFOSET(sd->fd, packet_len(0x1b1));
  15585. }
  15586. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15587. /// 021d <state>.L
  15588. /// state:
  15589. /// 0 = Full effects
  15590. /// 1 = Reduced effects
  15591. ///
  15592. /// NOTE: The state is used on Aegis for sending skill unit packet
  15593. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15594. /// whenever possible. Due to the way the decision check is
  15595. /// constructed, this state tracking was rendered useless,
  15596. /// as the only skill unit, that is sent with 0x1c9 is
  15597. /// Graffiti.
  15598. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15599. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15600. sd->state.lesseffect = ( isLess != 0 );
  15601. }
  15602. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15603. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15604. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15605. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15606. int type = RFIFOL(fd,info->pos[1]);
  15607. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15608. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15609. if( sd->state.trading || sd->npc_shopid )
  15610. return;
  15611. if( flag == 0 || n == 0) {
  15612. clif_menuskill_clear(sd);
  15613. return; // Canceled by player.
  15614. }
  15615. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15616. clif_menuskill_clear(sd);
  15617. return; // Prevent hacking.
  15618. }
  15619. switch( type ) {
  15620. case 0: // Change Material
  15621. skill_changematerial(sd,n,item_list);
  15622. break;
  15623. case 1: // Level 1: Pure to Rough
  15624. case 2: // Level 2: Rough to Pure
  15625. skill_elementalanalysis(sd,n,type,item_list);
  15626. break;
  15627. }
  15628. clif_menuskill_clear(sd);
  15629. return;
  15630. }
  15631. /*==========================================
  15632. * Elemental System
  15633. *==========================================*/
  15634. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15635. s_elemental_data *ed;
  15636. struct status_data *status;
  15637. int fd;
  15638. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15639. return;
  15640. fd = sd->fd;
  15641. status = &ed->battle_status;
  15642. WFIFOHEAD(fd,8);
  15643. WFIFOW(fd,0) = 0x81e;
  15644. WFIFOW(fd,2) = type;
  15645. switch( type ) {
  15646. case SP_HP:
  15647. WFIFOL(fd,4) = status->hp;
  15648. break;
  15649. case SP_MAXHP:
  15650. WFIFOL(fd,4) = status->max_hp;
  15651. break;
  15652. case SP_SP:
  15653. WFIFOL(fd,4) = status->sp;
  15654. break;
  15655. case SP_MAXSP:
  15656. WFIFOL(fd,4) = status->max_sp;
  15657. break;
  15658. }
  15659. WFIFOSET(fd,8);
  15660. }
  15661. void clif_elemental_info(struct map_session_data *sd) {
  15662. int fd;
  15663. s_elemental_data *ed;
  15664. struct status_data *status;
  15665. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15666. return;
  15667. fd = sd->fd;
  15668. status = &ed->battle_status;
  15669. WFIFOHEAD(fd,22);
  15670. WFIFOW(fd, 0) = 0x81d;
  15671. WFIFOL(fd, 2) = ed->bl.id;
  15672. WFIFOL(fd, 6) = status->hp;
  15673. WFIFOL(fd,10) = status->max_hp;
  15674. WFIFOL(fd,14) = status->sp;
  15675. WFIFOL(fd,18) = status->max_sp;
  15676. WFIFOSET(fd,22);
  15677. }
  15678. /// Buying Store System
  15679. ///
  15680. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15681. /// 0810 <slots>.B
  15682. void clif_buyingstore_open(struct map_session_data* sd)
  15683. {
  15684. int fd = sd->fd;
  15685. WFIFOHEAD(fd,packet_len(0x810));
  15686. WFIFOW(fd,0) = 0x810;
  15687. WFIFOB(fd,2) = sd->buyingstore.slots;
  15688. WFIFOSET(fd,packet_len(0x810));
  15689. }
  15690. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15691. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15692. /// result:
  15693. /// 0 = cancel
  15694. /// 1 = open
  15695. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15696. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15697. // TODO: Make this check global for all variable length packets.
  15698. // minimum packet length
  15699. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15700. 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 );
  15701. return;
  15702. }
  15703. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15704. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15705. return;
  15706. }
  15707. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15708. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15709. return;
  15710. }
  15711. char storename[MESSAGE_SIZE];
  15712. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15713. // so that buyingstore_create knows, how many elements it has access to
  15714. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15715. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15716. 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 ) );
  15717. return;
  15718. }
  15719. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15720. }
  15721. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15722. /// 0812 <result>.W <total weight>.L
  15723. /// result:
  15724. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15725. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15726. /// 8 = "No sale (purchase) information available." (0x705)
  15727. /// ? = nothing
  15728. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15729. {
  15730. int fd = sd->fd;
  15731. WFIFOHEAD(fd,packet_len(0x812));
  15732. WFIFOW(fd,0) = 0x812;
  15733. WFIFOW(fd,2) = result;
  15734. WFIFOL(fd,4) = weight;
  15735. WFIFOSET(fd,packet_len(0x812));
  15736. }
  15737. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15738. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15739. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15740. nullpo_retv( sd );
  15741. int fd = sd->fd;
  15742. if( !session_isActive( fd ) ){
  15743. return;
  15744. }
  15745. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15746. WFIFOHEAD( fd, length );
  15747. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15748. p->packetType = 0x813;
  15749. p->packetLength = length;
  15750. p->AID = sd->bl.id;
  15751. p->zenyLimit = sd->buyingstore.zenylimit;
  15752. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15753. p->items[i].price = sd->buyingstore.items[i].price;
  15754. p->items[i].amount = sd->buyingstore.items[i].amount;
  15755. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15756. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15757. }
  15758. WFIFOSET( fd, p->packetLength );
  15759. }
  15760. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15761. /// 0814 <account id>.L <store name>.80B
  15762. void clif_buyingstore_entry( struct map_session_data& sd, struct block_list* tbl ){
  15763. #if PACKETVER >= 20100420
  15764. enum send_target target;
  15765. if( tbl == nullptr ){
  15766. tbl = &sd.bl;
  15767. target = AREA_WOS;
  15768. }else{
  15769. target = SELF;
  15770. }
  15771. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15772. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15773. p.makerAID = sd.status.account_id;
  15774. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15775. clif_send( &p, sizeof( p ), tbl, target );
  15776. #endif
  15777. }
  15778. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15779. /// 0815
  15780. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15781. {
  15782. buyingstore_close(sd);
  15783. }
  15784. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15785. /// 0816 <account id>.L
  15786. void clif_buyingstore_disappear_entry( struct map_session_data& sd, struct block_list* tbl ){
  15787. #if PACKETVER >= 20100309
  15788. enum send_target target;
  15789. if( tbl == nullptr ){
  15790. tbl = &sd.bl;
  15791. target = AREA_WOS;
  15792. }else{
  15793. target = SELF;
  15794. }
  15795. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15796. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15797. p.makerAID = sd.status.account_id;
  15798. clif_send( &p, sizeof( p ), tbl, target );
  15799. #endif
  15800. }
  15801. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15802. /// 0817 <account id>.L
  15803. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15804. {
  15805. uint32 account_id;
  15806. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15807. buyingstore_open(sd, account_id);
  15808. }
  15809. /// Sends buying store item list.
  15810. /// 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)
  15811. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15812. nullpo_retv( sd );
  15813. nullpo_retv( pl_sd );
  15814. int fd = sd->fd;
  15815. if( !session_isActive( fd ) ){
  15816. return;
  15817. }
  15818. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15819. WFIFOHEAD( fd, length );
  15820. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15821. p->packetType = 0x818;
  15822. p->packetLength = length;
  15823. p->AID = pl_sd->bl.id;
  15824. p->storeId = pl_sd->buyer_id;
  15825. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15826. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15827. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15828. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15829. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15830. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15831. }
  15832. WFIFOSET( fd, p->packetLength );
  15833. }
  15834. /// Request to sell items to a buying store.
  15835. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15836. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15837. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15838. // minimum packet length
  15839. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15840. 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 );
  15841. return;
  15842. }
  15843. // so that buyingstore_trade knows, how many elements it has access to
  15844. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15845. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15846. 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 ) );
  15847. return;
  15848. }
  15849. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15850. }
  15851. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15852. /// 081a <result>.W
  15853. /// result:
  15854. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15855. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15856. /// ? = nothing
  15857. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15858. {
  15859. int fd = sd->fd;
  15860. WFIFOHEAD(fd,packet_len(0x81a));
  15861. WFIFOW(fd,0) = 0x81a;
  15862. WFIFOW(fd,2) = result;
  15863. WFIFOSET(fd,packet_len(0x81a));
  15864. }
  15865. /// Updates the zeny limit and an item in the buying store item list.
  15866. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15867. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15868. void clif_buyingstore_update_item( struct map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15869. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15870. p.packetType = buyingStoreUpdateItemType;
  15871. p.itemId = client_nameid( nameid );
  15872. p.amount = amount;
  15873. p.zenyLimit = sd->buyingstore.zenylimit;
  15874. #if PACKETVER >= 20141016
  15875. p.zeny = zeny;
  15876. p.charId = char_id; // GID
  15877. p.updateTime = (int)time(NULL);
  15878. #endif
  15879. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15880. }
  15881. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15882. /// 081c <index>.W <amount>.W <price>.L
  15883. /// message:
  15884. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15885. ///
  15886. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15887. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15888. {
  15889. int fd = sd->fd;
  15890. WFIFOHEAD(fd,packet_len(0x81c));
  15891. WFIFOW(fd,0) = 0x81c;
  15892. WFIFOW(fd,2) = client_index( index );
  15893. WFIFOW(fd,4) = amount;
  15894. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15895. WFIFOSET(fd,packet_len(0x81c));
  15896. }
  15897. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15898. /// 0824 <result>.W <name id>.W
  15899. /// result:
  15900. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15901. /// 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)
  15902. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15903. /// ? = nothing
  15904. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, t_itemid nameid ){
  15905. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15906. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15907. p.result = result;
  15908. p.itemId = client_nameid( nameid );
  15909. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15910. }
  15911. /// Search Store Info System
  15912. ///
  15913. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15914. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15915. /// type:
  15916. /// 0 = Vending
  15917. /// 1 = Buying Store
  15918. ///
  15919. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15920. /// amount of card slots. If the client does not know about the item it
  15921. /// cannot be searched.
  15922. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15923. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15924. // minimum packet length
  15925. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15926. 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 );
  15927. return;
  15928. }
  15929. // check, if there is enough data for the claimed count of items
  15930. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15931. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15932. 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 ) );
  15933. return;
  15934. }
  15935. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15936. if( count < p->itemsCount + p->cardsCount ){
  15937. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15938. return;
  15939. }
  15940. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15941. }
  15942. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15943. /// 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 }*
  15944. /// is first page:
  15945. /// 0 = appends to existing results
  15946. /// 1 = clears previous results before displaying this result set
  15947. /// is next page:
  15948. /// 0 = no "next" label
  15949. /// 1 = "next" label to retrieve more results
  15950. void clif_search_store_info_ack( struct map_session_data* sd ){
  15951. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  15952. nullpo_retv( sd );
  15953. int fd = sd->fd;
  15954. if( !session_isActive( fd ) ){
  15955. return;
  15956. }
  15957. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15958. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15959. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15960. WFIFOHEAD( fd, len );
  15961. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15962. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15963. p->packetLength = len;
  15964. p->firstPage = !sd->searchstore.pages;
  15965. p->nextPage = searchstore_querynext( sd );
  15966. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15967. for( int i = 0; i < end - start; i++ ) {
  15968. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  15969. p->items[i].storeId = ssitem->store_id;
  15970. p->items[i].AID = ssitem->account_id;
  15971. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15972. p->items[i].itemId = client_nameid( ssitem->nameid );
  15973. p->items[i].itemType = itemtype( ssitem->nameid );
  15974. p->items[i].price = ssitem->price;
  15975. p->items[i].amount = ssitem->amount;
  15976. p->items[i].refine = ssitem->refine;
  15977. // make-up an item for clif_addcards
  15978. struct item it = {};
  15979. for( int j = 0; j < MAX_SLOTS; j++ ){
  15980. it.card[j] = ssitem->card[j];
  15981. }
  15982. it.nameid = ssitem->nameid;
  15983. it.amount = ssitem->amount;
  15984. clif_addcards( &p->items[i].slot, &it );
  15985. #if PACKETVER >= 20150226
  15986. clif_add_random_options( p->items[i].option_data, &it );
  15987. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15988. p->items[i].grade = ssitem->enchantgrade;
  15989. #endif
  15990. #endif
  15991. }
  15992. WFIFOSET( fd, len );
  15993. #endif
  15994. }
  15995. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15996. /// 0837 <reason>.B
  15997. /// reason:
  15998. /// 0 = "No matching stores were found." (0x70b)
  15999. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16000. /// 2 = "You cannot search anymore." (0x706)
  16001. /// 3 = "You cannot search yet." (0x708)
  16002. /// 4 = "No sale (purchase) information available." (0x705)
  16003. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  16004. {
  16005. int fd = sd->fd;
  16006. WFIFOHEAD(fd,packet_len(0x837));
  16007. WFIFOW(fd,0) = 0x837;
  16008. WFIFOB(fd,2) = reason;
  16009. WFIFOSET(fd,packet_len(0x837));
  16010. }
  16011. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16012. /// 0838
  16013. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  16014. {
  16015. searchstore_next(sd);
  16016. }
  16017. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16018. /// 083a <type>.W <remaining uses>.B
  16019. /// type:
  16020. /// 0 = Search Stores
  16021. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16022. void clif_open_search_store_info(struct map_session_data* sd)
  16023. {
  16024. int fd = sd->fd;
  16025. WFIFOHEAD(fd,packet_len(0x83a));
  16026. WFIFOW(fd,0) = 0x83a;
  16027. WFIFOW(fd,2) = sd->searchstore.effect;
  16028. #if PACKETVER > 20100701
  16029. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16030. #endif
  16031. WFIFOSET(fd,packet_len(0x83a));
  16032. }
  16033. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16034. /// 083b
  16035. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  16036. {
  16037. searchstore_close(sd);
  16038. }
  16039. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16040. /// 083c <account id>.L <store id>.L <nameid>.W
  16041. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  16042. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16043. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16044. }
  16045. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16046. /// 083d <xPos>.W <yPos>.W
  16047. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  16048. {
  16049. int fd = sd->fd;
  16050. WFIFOHEAD(fd,packet_len(0x83d));
  16051. WFIFOW(fd,0) = 0x83d;
  16052. WFIFOW(fd,2) = x;
  16053. WFIFOW(fd,4) = y;
  16054. WFIFOSET(fd,packet_len(0x83d));
  16055. }
  16056. /// Parse function for packet debugging.
  16057. void clif_parse_debug(int fd,struct map_session_data *sd)
  16058. {
  16059. int cmd, packet_len;
  16060. // clif_parse ensures, that there is at least 2 bytes of data
  16061. cmd = RFIFOW(fd,0);
  16062. if( sd ) {
  16063. packet_len = packet_db[cmd].len;
  16064. if( packet_len == 0 )
  16065. {// unknown
  16066. packet_len = RFIFOREST(fd);
  16067. }
  16068. else if( packet_len == -1 )
  16069. {// variable length
  16070. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16071. }
  16072. 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);
  16073. }
  16074. else
  16075. {
  16076. packet_len = RFIFOREST(fd);
  16077. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16078. }
  16079. ShowDump(RFIFOP(fd,0), packet_len);
  16080. }
  16081. /*==========================================
  16082. * Server tells client to display a window similar to Magnifier (item) one
  16083. * Server populates the window with avilable elemental converter options according to player's inventory
  16084. *------------------------------------------*/
  16085. void clif_elementalconverter_list( struct map_session_data *sd ){
  16086. nullpo_retv( sd );
  16087. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16088. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16089. int count = 0;
  16090. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16091. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16092. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16093. count++;
  16094. }
  16095. }
  16096. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16097. clif_send( p, p->packetLength, &sd->bl, SELF );
  16098. if( count > 0 ){
  16099. sd->menuskill_id = SA_CREATECON;
  16100. sd->menuskill_val = count;
  16101. }
  16102. }
  16103. /**
  16104. * Rune Knight
  16105. **/
  16106. void clif_millenniumshield(struct block_list *bl, short shields) {
  16107. #if PACKETVER >= 20081217
  16108. unsigned char buf[10];
  16109. WBUFW(buf,0) = 0x440;
  16110. WBUFL(buf,2) = bl->id;
  16111. WBUFW(buf,6) = shields;
  16112. WBUFW(buf,8) = 0;
  16113. clif_send(buf,packet_len(0x440),bl,AREA);
  16114. #endif
  16115. }
  16116. /**
  16117. * Mechanic
  16118. **/
  16119. /*==========================================
  16120. * Magic Decoy Material List
  16121. *------------------------------------------*/
  16122. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  16123. nullpo_retv( sd );
  16124. int fd = sd->fd;
  16125. if( !session_isActive( fd ) ){
  16126. return;
  16127. }
  16128. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16129. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16130. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16131. int count = 0;
  16132. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16133. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16134. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16135. count++;
  16136. }
  16137. }
  16138. if( count > 0 ) {
  16139. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16140. WFIFOSET( fd, p->packetLength );
  16141. sd->menuskill_id = NC_MAGICDECOY;
  16142. sd->menuskill_val = skill_lv;
  16143. sd->sc.comet_x = x;
  16144. sd->sc.comet_y = y;
  16145. }else{
  16146. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16147. }
  16148. }
  16149. /*==========================================
  16150. * Guillotine Cross Poisons List
  16151. *------------------------------------------*/
  16152. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  16153. nullpo_retv( sd );
  16154. int fd = sd->fd;
  16155. if( !session_isActive( fd ) ){
  16156. return;
  16157. }
  16158. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16159. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16160. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16161. int count = 0;
  16162. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16163. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16164. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16165. count++;
  16166. }
  16167. }
  16168. if( count > 0 ){
  16169. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16170. WFIFOSET( fd, p->packetLength );
  16171. sd->menuskill_id = GC_POISONINGWEAPON;
  16172. sd->menuskill_val = skill_lv;
  16173. }else{
  16174. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16175. }
  16176. }
  16177. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16178. int clif_autoshadowspell_list(struct map_session_data *sd) {
  16179. int fd, i, c;
  16180. nullpo_ret(sd);
  16181. fd = sd->fd;
  16182. if( !session_isActive(fd) )
  16183. return 0;
  16184. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16185. return 0;
  16186. WFIFOHEAD(fd, 2 * 6 + 4);
  16187. WFIFOW(fd,0) = 0x442;
  16188. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16189. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16190. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16191. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16192. {
  16193. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16194. c++;
  16195. }
  16196. if( c > 0 ) {
  16197. WFIFOW(fd,2) = 8 + c * 2;
  16198. WFIFOL(fd,4) = c;
  16199. WFIFOSET(fd,WFIFOW(fd,2));
  16200. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16201. sd->menuskill_val = c;
  16202. } else {
  16203. status_change_end(&sd->bl,SC_STOP);
  16204. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16205. }
  16206. return 1;
  16207. }
  16208. /*===========================================
  16209. * Skill list for Four Elemental Analysis
  16210. * and Change Material skills.
  16211. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16212. *------------------------------------------*/
  16213. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16214. #if PACKETVER >= 20090922
  16215. int fd = sd->fd;
  16216. nullpo_ret(sd);
  16217. sd->menuskill_id = skill_id; // To prevent hacking.
  16218. sd->menuskill_val = skill_lv;
  16219. if( skill_id == GN_CHANGEMATERIAL )
  16220. skill_lv = 0; // Changematerial
  16221. WFIFOHEAD(fd, packet_len(0x7e3));
  16222. WFIFOW(fd,0) = 0x7e3;
  16223. WFIFOL(fd,2) = skill_lv;
  16224. WFIFOL(fd,4) = 0;
  16225. WFIFOSET(fd, packet_len(0x7e3));
  16226. #endif
  16227. return 1;
  16228. }
  16229. /*==========================================
  16230. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16231. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16232. * RFIFOL(fd,2) - type (currently not used)
  16233. *------------------------------------------*/
  16234. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  16235. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16236. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16237. if (sd->menuskill_id == SA_AUTOSPELL) {
  16238. sd->state.workinprogress = WIP_DISABLE_NONE;
  16239. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16240. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16241. if (pc_istrading(sd)) {
  16242. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16243. clif_menuskill_clear(sd);
  16244. return;
  16245. }
  16246. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16247. } else
  16248. return;
  16249. clif_menuskill_clear(sd);
  16250. }
  16251. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16252. /// 08cf <id>.L <type>.W <num>.W
  16253. void clif_spiritcharm(struct map_session_data *sd) {
  16254. unsigned char buf[10];
  16255. nullpo_retv(sd);
  16256. WBUFW(buf,0) = 0x08cf;
  16257. WBUFL(buf,2) = sd->bl.id;
  16258. WBUFW(buf,6) = sd->spiritcharm_type;
  16259. WBUFW(buf,8) = sd->spiritcharm;
  16260. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16261. }
  16262. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16263. /// 0907 <index>.W
  16264. ///
  16265. /// R 0908 <index>.w <type>.b
  16266. /// type:
  16267. /// 0 = move item to personal tab
  16268. /// 1 = move item to normal tab
  16269. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  16270. #if PACKETVER >= 20111122
  16271. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16272. int index = RFIFOW(fd,info->pos[0]) - 2;
  16273. int type = RFIFOB(fd, info->pos[1]);
  16274. /* can't move while dead. */
  16275. if(pc_isdead(sd)) {
  16276. return;
  16277. }
  16278. if (index < 0 || index >= MAX_INVENTORY)
  16279. return;
  16280. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16281. sd->inventory.u.items_inventory[index].favorite = 0;
  16282. else if( type == 0 )
  16283. sd->inventory.u.items_inventory[index].favorite = 1;
  16284. else
  16285. return;/* nothing to do. */
  16286. clif_favorite_item(sd, index);
  16287. #endif
  16288. }
  16289. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16290. /// 0900 <index>.W <favorite>.B
  16291. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16292. int fd = sd->fd;
  16293. WFIFOHEAD(fd,packet_len(0x908));
  16294. WFIFOW(fd,0) = 0x908;
  16295. WFIFOW(fd,2) = index+2;
  16296. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16297. WFIFOSET(fd,packet_len(0x908));
  16298. }
  16299. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16300. void clif_snap( struct block_list *bl, short x, short y ) {
  16301. unsigned char buf[10];
  16302. WBUFW(buf,0) = 0x8d2;
  16303. WBUFL(buf,2) = bl->id;
  16304. WBUFW(buf,6) = x;
  16305. WBUFW(buf,8) = y;
  16306. if( disguised(bl) )
  16307. {
  16308. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16309. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16310. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16311. } else
  16312. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16313. }
  16314. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16315. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16316. #if PACKETVER >= 20120404
  16317. WFIFOHEAD(fd,packet_len(0x977));
  16318. WFIFOW(fd,0) = 0x977;
  16319. WFIFOL(fd,2) = md->bl.id;
  16320. WFIFOL(fd,6) = md->status.hp;
  16321. WFIFOL(fd,10) = md->status.max_hp;
  16322. WFIFOSET(fd,packet_len(0x977));
  16323. #endif
  16324. }
  16325. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16326. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16327. return;
  16328. }
  16329. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16330. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16331. WFIFOW(sd->fd,0) = 0x2c9;
  16332. WFIFOB(sd->fd,2) = flag;
  16333. WFIFOSET(sd->fd, packet_len(0x2c9));
  16334. }
  16335. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16336. /// 0979 <world name>.24B <char name>.24B
  16337. void clif_ackworldinfo(struct map_session_data* sd) {
  16338. int fd;
  16339. nullpo_retv(sd);
  16340. fd = sd->fd;
  16341. WFIFOHEAD(fd,packet_len(0x979));
  16342. WFIFOW(fd,0)=0x979;
  16343. //AID -> world name ?
  16344. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16345. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16346. WFIFOSET(fd,packet_len(0x979));
  16347. }
  16348. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16349. /// 0978 <AID>.L
  16350. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16351. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16352. if(sd)
  16353. clif_ackworldinfo(sd);
  16354. }
  16355. static void clif_loadConfirm( struct map_session_data *sd ){
  16356. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16357. nullpo_retv( sd );
  16358. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16359. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16360. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16361. clif_instance_info( *sd );
  16362. #endif
  16363. }
  16364. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16365. /// 0447
  16366. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16367. clif_loadConfirm( sd );
  16368. }
  16369. /// req world info (CZ_CLIENT_VERSION)
  16370. /// 044A <version>.L
  16371. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16372. //if(sd)
  16373. ;
  16374. }
  16375. /// Ranking list
  16376. /// ranking pointlist { <name>.24B <point>.L }*10
  16377. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16378. struct fame_list* list;
  16379. int i, size = MAX_FAME_LIST;
  16380. switch(rankingtype) {
  16381. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16382. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16383. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16384. // PK currently unsupported
  16385. case RANK_KILLER: list = NULL; size = 0; break;
  16386. default:
  16387. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16388. return;
  16389. }
  16390. //Packet size limits this list to 10 elements. [Skotlex]
  16391. for (i = 0; i < min(10,size); i++) {
  16392. if (list[i].id > 0) {
  16393. const char* name;
  16394. if (strcmp(list[i].name, "-") == 0 &&
  16395. (name = map_charid2nick(list[i].id)) != NULL)
  16396. {
  16397. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16398. } else {
  16399. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16400. }
  16401. } else {
  16402. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16403. }
  16404. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16405. }
  16406. for(;i < 10; i++) { //In case the MAX is less than 10.
  16407. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16408. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16409. }
  16410. }
  16411. /// Request for the blacksmith ranklist.
  16412. /// /blacksmith command sends this packet to the server.
  16413. /// 0217 (CZ_BLACKSMITH_RANK)
  16414. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16415. clif_ranklist(sd,RANK_BLACKSMITH);
  16416. }
  16417. /// Request for the alchemist ranklist.
  16418. /// /alchemist command sends this packet to the server.
  16419. /// 0218 (CZ_ALCHEMIST_RANK)
  16420. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16421. clif_ranklist(sd,RANK_ALCHEMIST);
  16422. }
  16423. /// Request for the taekwon ranklist.
  16424. /// /taekwon command sends this packet to the server.
  16425. /// 0225 (CZ_TAEKWON_RANK)
  16426. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16427. clif_ranklist(sd,RANK_TAEKWON);
  16428. }
  16429. /// Request for the killer ranklist.
  16430. /// /pk command sends this packet to the server.
  16431. /// 0237 (CZ_KILLER_RANK)
  16432. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16433. clif_ranklist(sd,RANK_KILLER);
  16434. }
  16435. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16436. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16437. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16438. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16439. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16440. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16441. enum e_rank rank;
  16442. #if PACKETVER < 20130710
  16443. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16444. short cmd;
  16445. switch( rankingType ){
  16446. case RANK_BLACKSMITH: cmd = 0x219; break;
  16447. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16448. case RANK_TAEKWON: cmd = 0x226; break;
  16449. case RANK_KILLER: cmd = 0x238; break;
  16450. default:
  16451. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16452. return;
  16453. }
  16454. // Can be safely casted here, since we validated it before
  16455. rank = (enum e_rank)rankingType;
  16456. WBUFW(buf,0) = cmd;
  16457. clif_sub_ranklist(buf,2,sd,rank);
  16458. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16459. #else
  16460. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16461. int mypoint = 0;
  16462. switch( rankingType ){
  16463. case RANK_BLACKSMITH:
  16464. case RANK_ALCHEMIST:
  16465. case RANK_TAEKWON:
  16466. case RANK_KILLER:
  16467. break;
  16468. default:
  16469. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16470. return;
  16471. }
  16472. // Can be safely casted here, since we validated it before
  16473. rank = (enum e_rank)rankingType;
  16474. WBUFW(buf,0) = 0x97d;
  16475. WBUFW(buf,2) = rank;
  16476. clif_sub_ranklist(buf,4,sd,rank);
  16477. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16478. case MAPID_BLACKSMITH:
  16479. case MAPID_ALCHEMIST:
  16480. case MAPID_TAEKWON:
  16481. mypoint = sd->status.fame;
  16482. }
  16483. WBUFL(buf,284) = mypoint; //mypoint
  16484. clif_send(buf, 288, &sd->bl, SELF);
  16485. #endif
  16486. }
  16487. /*
  16488. * 097c <type> (CZ_REQ_RANKING)
  16489. * type
  16490. * 0: /blacksmith
  16491. * 1: /alchemist
  16492. * 2: /taekwon
  16493. * 3: /pk
  16494. * */
  16495. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16496. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16497. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16498. clif_ranklist(sd,rankingtype);
  16499. }
  16500. /// Updates the fame rank points for the given ranking.
  16501. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16502. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16503. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16504. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16505. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16506. int fd = sd.fd;
  16507. #if PACKETVER < 20130710
  16508. short cmd;
  16509. switch(rankingtype){
  16510. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16511. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16512. case RANK_TAEKWON: cmd = 0x224; break;
  16513. default:
  16514. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16515. return;
  16516. }
  16517. WFIFOHEAD(fd,packet_len(cmd));
  16518. WFIFOW(fd,0) = cmd;
  16519. WFIFOL(fd,2) = point;
  16520. WFIFOL(fd,6) = sd.status.fame;
  16521. WFIFOSET(fd, packet_len(cmd));
  16522. #else
  16523. WFIFOHEAD(fd,packet_len(0x97e));
  16524. WFIFOW(fd,0) = 0x97e;
  16525. WFIFOW(fd,2) = rankingtype;
  16526. WFIFOL(fd,4) = point;
  16527. WFIFOL(fd,8) = sd.status.fame;
  16528. WFIFOSET(fd,packet_len(0x97e));
  16529. #endif
  16530. }
  16531. /**
  16532. * Transmit personal information to player. (rates)
  16533. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16534. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16535. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16536. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16537. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16538. * FIXME!
  16539. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16540. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16541. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16542. */
  16543. #ifdef VIP_ENABLE
  16544. void clif_display_pinfo( struct map_session_data& sd ){
  16545. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16546. // TODO: Whoever wants to take the blame, fix this crappy logic below - and yes I know indentation is wrong, but CANT TOUCH THIS! *sings* [Lemongrass]
  16547. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16548. /**
  16549. * EXP
  16550. */
  16551. //0:PCRoom
  16552. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16553. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16554. details_bexp[PINFO_BASIC] = 0;
  16555. else {
  16556. if (details_bexp[PINFO_BASIC] < 100) {
  16557. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16558. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16559. } else
  16560. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16561. }
  16562. //1:Premium
  16563. if( pc_isvip( &sd ) ){
  16564. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16565. if (details_bexp[PINFO_PREMIUM] < 0)
  16566. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16567. } else
  16568. details_bexp[PINFO_PREMIUM] = 0;
  16569. //2:Server
  16570. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16571. if (details_bexp[PINFO_SERVER] == 100)
  16572. details_bexp[PINFO_SERVER] = 0;
  16573. else {
  16574. if (details_bexp[PINFO_SERVER] < 100) {
  16575. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16576. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16577. } else
  16578. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16579. }
  16580. //3:TPLUS
  16581. details_bexp[PINFO_CAFE] = 0;
  16582. /**
  16583. * Drop rate
  16584. */
  16585. //0:PCRoom
  16586. details_drop[PINFO_BASIC] = 0;
  16587. //1:Premium
  16588. if( pc_isvip( &sd ) ){
  16589. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16590. if (details_drop[PINFO_PREMIUM] < 0)
  16591. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16592. } else
  16593. details_drop[PINFO_PREMIUM] = 0;
  16594. //2:Server
  16595. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16596. if (details_drop[PINFO_SERVER] == 100)
  16597. details_drop[PINFO_SERVER] = 0;
  16598. else {
  16599. if (details_drop[PINFO_SERVER] < 100) {
  16600. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16601. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16602. } else
  16603. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16604. }
  16605. //3:TPLUS
  16606. details_drop[PINFO_CAFE] = 0;
  16607. /**
  16608. * Penalty rate
  16609. */
  16610. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16611. //0:PCRoom
  16612. details_penalty[PINFO_BASIC] = 0;
  16613. //1:Premium
  16614. if( pc_isvip( &sd ) ){
  16615. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16616. if (details_penalty[PINFO_PREMIUM] == 100)
  16617. details_penalty[PINFO_PREMIUM] = 0;
  16618. else {
  16619. if (details_penalty[PINFO_PREMIUM] < 100) {
  16620. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16621. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16622. } else
  16623. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16624. }
  16625. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16626. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16627. } else
  16628. details_penalty[PINFO_PREMIUM] = 0;
  16629. //2:Server
  16630. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16631. if (details_penalty[PINFO_SERVER] == 100)
  16632. details_penalty[PINFO_SERVER] = 0;
  16633. else {
  16634. if (details_penalty[PINFO_SERVER] < 100) {
  16635. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16636. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16637. } else
  16638. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16639. }
  16640. //3:TPLUS
  16641. details_penalty[PINFO_CAFE] = 0;
  16642. struct PACKET_ZC_PERSONAL_INFOMATION* p = (struct PACKET_ZC_PERSONAL_INFOMATION*)packet_buffer;
  16643. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16644. p->length = sizeof( *p ) + PINFO_MAX * sizeof( p->details[0] );
  16645. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16646. p->total_exp = 100 * 1000;
  16647. p->total_death = 100 * 1000;
  16648. p->total_drop = 100 * 1000;
  16649. #else
  16650. p->total_exp = 100;
  16651. p->total_death = 100;
  16652. p->total_drop = 100;
  16653. #endif
  16654. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16655. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16656. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16657. p->details[i].exp = details_bexp[i] * 1000;
  16658. p->details[i].death = details_penalty[i] * 1000;
  16659. p->details[i].drop = details_drop[i] * 1000;
  16660. #else
  16661. p->details[i].exp = details_bexp[i];
  16662. p->details[i].death = details_penalty[i];
  16663. p->details[i].drop = details_drop[i];
  16664. #endif
  16665. p->total_exp += p->details[i].exp;
  16666. p->total_death += p->details[i].death;
  16667. p->total_drop += p->details[i].drop;
  16668. }
  16669. clif_send( p, p->length, &sd.bl, SELF );
  16670. #endif
  16671. }
  16672. #endif
  16673. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16674. char cmd[30];
  16675. int t_aid = RFIFOL(fd,2);
  16676. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16677. is_atcommand(fd, sd, cmd, 1);
  16678. }
  16679. /**
  16680. * Marks Crimson Marker target on mini-map to the caster
  16681. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16682. * @param fd
  16683. * @param bl Crimson Marker target
  16684. **/
  16685. void clif_crimson_marker( struct map_session_data& sd, struct block_list& bl, bool remove ){
  16686. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16687. struct PACKET_ZC_C_MARKERINFO p = {};
  16688. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16689. p.AID = bl.id;
  16690. if( remove ){
  16691. p.xPos = -1;
  16692. p.yPos = -1;
  16693. }else{
  16694. p.xPos = bl.x;
  16695. p.yPos = bl.y;
  16696. }
  16697. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16698. #endif
  16699. }
  16700. /**
  16701. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16702. **/
  16703. void clif_notify_bindOnEquip( struct map_session_data& sd, int16 index ){
  16704. #if PACKETVER >= 20070227
  16705. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16706. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16707. p.index = client_index( index );
  16708. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16709. #endif
  16710. }
  16711. /**
  16712. * [Ind/Hercules]
  16713. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16714. **/
  16715. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16716. char buf[256];
  16717. size_t len;
  16718. nullpo_retv(bl);
  16719. if(!message)
  16720. return;
  16721. len = strlen(message)+1;
  16722. if( len > sizeof(buf)-8 ) {
  16723. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16724. len = sizeof(buf)-8;
  16725. }
  16726. WBUFW(buf,0) = 0x8b3;
  16727. WBUFW(buf,2) = (uint16)(len+8);
  16728. WBUFL(buf,4) = bl->id;
  16729. safestrncpy(WBUFCP(buf,8), message, len);
  16730. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16731. }
  16732. /**
  16733. * [Ind/Hercules]
  16734. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16735. **/
  16736. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16737. unsigned char buf[10];
  16738. nullpo_retv(sd);
  16739. WBUFW(buf,0) = 0x7fc;
  16740. WBUFL(buf,2) = prev_leader_aid;
  16741. WBUFL(buf,6) = new_leader_aid;
  16742. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16743. }
  16744. /**
  16745. * Sends a clan message to a player
  16746. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16747. **/
  16748. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16749. #if PACKETVER >= 20131223
  16750. struct map_session_data *sd;
  16751. uint8 buf[256];
  16752. if( len == 0 ){
  16753. return;
  16754. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16755. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16756. len = sizeof(buf)-5-NAME_LENGTH;
  16757. }
  16758. WBUFW(buf, 0) = 0x98e;
  16759. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16760. // 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
  16761. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16762. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16763. if((sd = clan_getavailablesd(clan)) != NULL)
  16764. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16765. #endif
  16766. }
  16767. /**
  16768. * Parses a clan message from a player.
  16769. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16770. **/
  16771. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16772. #if PACKETVER >= 20131223
  16773. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16774. // validate packet and retrieve name and message
  16775. if( !clif_process_message(sd, false, name, message, output ) )
  16776. return;
  16777. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16778. #endif
  16779. }
  16780. /**
  16781. * Sends the basic clan informations to the client.
  16782. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16783. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16784. **/
  16785. void clif_clan_basicinfo( struct map_session_data *sd ){
  16786. #if PACKETVER >= 20131223
  16787. int fd, offset, length, i, flag;
  16788. struct clan* clan;
  16789. char mapname[MAP_NAME_LENGTH_EXT];
  16790. nullpo_retv( sd );
  16791. nullpo_retv( clan = sd->clan );
  16792. // Check if the player has a valid session and is not autotrading
  16793. if( !clif_session_isValid( sd ) ){
  16794. return;
  16795. }
  16796. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16797. fd = sd->fd;
  16798. WFIFOHEAD(fd,length);
  16799. memset( WFIFOP(fd, 0), 0, length );
  16800. WFIFOW( fd, 0 ) = 0x98a;
  16801. WFIFOL( fd, 4 ) = clan->id;
  16802. offset = 8;
  16803. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16804. offset += NAME_LENGTH;
  16805. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16806. offset += NAME_LENGTH;
  16807. mapindex_getmapname_ext( clan->map, mapname );
  16808. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16809. offset += MAP_NAME_LENGTH_EXT;
  16810. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16811. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16812. for( flag = 0; flag < 2; flag++ ){
  16813. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16814. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16815. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16816. offset += NAME_LENGTH;
  16817. }
  16818. }
  16819. }
  16820. WFIFOW( fd, 2 ) = offset;
  16821. WFIFOSET(fd,offset);
  16822. #endif
  16823. }
  16824. /**
  16825. * Updates the online and maximum player count of a clan.
  16826. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16827. **/
  16828. void clif_clan_onlinecount( struct clan* clan ){
  16829. #if PACKETVER >= 20131223
  16830. uint8 buf[6];
  16831. struct map_session_data *sd;
  16832. WBUFW(buf,0) = 0x988;
  16833. WBUFW(buf,2) = clan->connect_member;
  16834. WBUFW(buf,4) = clan->max_member;
  16835. if((sd = clan_getavailablesd(clan)) != NULL)
  16836. clif_send(buf, 6, &sd->bl, CLAN);
  16837. #endif
  16838. }
  16839. /**
  16840. * Notifies the client that the player has left his clan.
  16841. * 0989 (ZC_ACK_CLAN_LEAVE)
  16842. **/
  16843. void clif_clan_leave( struct map_session_data* sd ){
  16844. #if PACKETVER >= 20131223
  16845. int fd;
  16846. nullpo_retv( sd );
  16847. if( !clif_session_isValid( sd ) ){
  16848. return;
  16849. }
  16850. fd = sd->fd;
  16851. WFIFOHEAD(fd,2);
  16852. WFIFOW(fd,0) = 0x989;
  16853. WFIFOSET(fd,2);
  16854. #endif
  16855. }
  16856. /**
  16857. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16858. * 0A2F <result>.B <title_id>.L
  16859. */
  16860. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16861. {
  16862. #if PACKETVER >= 20150513
  16863. int fd;
  16864. nullpo_retv(sd);
  16865. if (!clif_session_isValid(sd))
  16866. return;
  16867. fd = sd->fd;
  16868. WFIFOHEAD(fd, packet_len(0xa2f));
  16869. WFIFOW(fd, 0) = 0xa2f;
  16870. WFIFOB(fd, 2) = result;
  16871. WFIFOL(fd, 3) = title_id;
  16872. WFIFOSET(fd, packet_len(0xa2f));
  16873. #endif
  16874. }
  16875. /**
  16876. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16877. * 0A2E <title_id>.L
  16878. */
  16879. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16880. {
  16881. int title_id;
  16882. nullpo_retv(sd);
  16883. title_id = RFIFOL(fd, 2);
  16884. if( title_id == sd->status.title_id ){
  16885. // It is exactly the same as the old one
  16886. return;
  16887. }else if( title_id <= 0 ){
  16888. sd->status.title_id = 0;
  16889. }else{
  16890. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16891. clif_change_title_ack(sd, 1, title_id);
  16892. return;
  16893. }
  16894. sd->status.title_id = title_id;
  16895. }
  16896. clif_name_area(&sd->bl);
  16897. clif_change_title_ack(sd, 0, title_id);
  16898. }
  16899. #ifdef DUMP_UNKNOWN_PACKET
  16900. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16901. {
  16902. const char* packet_txt = "save/packet.txt";
  16903. FILE* fp;
  16904. time_t time_server;
  16905. struct tm *datetime;
  16906. char datestr[512];
  16907. time(&time_server); // get time in seconds since 1/1/1970
  16908. datetime = localtime(&time_server); // convert seconds in structure
  16909. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16910. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16911. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16912. if( sd ) {
  16913. 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);
  16914. } else {
  16915. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16916. }
  16917. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16918. fprintf(fp, "\n");
  16919. fclose(fp);
  16920. } else {
  16921. ShowError("Failed to write '%s'.\n", packet_txt);
  16922. // Dump on console instead
  16923. if( sd ) {
  16924. 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);
  16925. } else {
  16926. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16927. }
  16928. ShowDump(RFIFOP(fd,0), packet_len);
  16929. }
  16930. }
  16931. #endif
  16932. /// Roulette System
  16933. /// Author: Yommy
  16934. /// Opens the roulette window
  16935. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16936. void clif_roulette_open( struct map_session_data* sd ){
  16937. nullpo_retv( sd );
  16938. struct packet_roulette_open_ack p;
  16939. p.PacketType = 0xa1a;
  16940. p.Result = 0; // result
  16941. p.Serial = 0; // serial
  16942. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16943. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16944. p.AdditionItemID = -1; //! TODO: Display bonus item
  16945. p.GoldPoint = sd->roulette_point.gold;
  16946. p.SilverPoint = sd->roulette_point.silver;
  16947. p.BronzePoint = sd->roulette_point.bronze;
  16948. sd->state.roulette_open = true;
  16949. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16950. }
  16951. /// Request to open the roulette window
  16952. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16953. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16954. nullpo_retv(sd);
  16955. if (!battle_config.feature_roulette) {
  16956. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16957. return;
  16958. }
  16959. clif_roulette_open(sd);
  16960. }
  16961. /// Sends the info about the available roulette rewards to the client
  16962. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16963. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16964. void clif_roulette_info( struct map_session_data* sd ){
  16965. nullpo_retv(sd);
  16966. struct packet_roulette_info_ack p;
  16967. p.PacketType = rouletteinfoackType;
  16968. p.PacketLength = sizeof(p);
  16969. p.RouletteSerial = 1;
  16970. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16971. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16972. p.ItemInfo[count].Row = i;
  16973. p.ItemInfo[count].Position = j;
  16974. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  16975. p.ItemInfo[count].Count = rd.qty[i][j];
  16976. #if PACKETVER >= 20180511
  16977. p.ItemInfo[count].unused = 0;
  16978. #endif
  16979. count++;
  16980. }
  16981. }
  16982. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16983. }
  16984. /// Request the roulette reward data
  16985. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16986. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16987. nullpo_retv(sd);
  16988. if (!battle_config.feature_roulette) {
  16989. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16990. return;
  16991. }
  16992. clif_roulette_info(sd);
  16993. }
  16994. /// Notification of the client that the roulette window was closed
  16995. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16996. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16997. nullpo_retv(sd);
  16998. if (!battle_config.feature_roulette) {
  16999. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17000. return;
  17001. }
  17002. sd->state.roulette_open = false;
  17003. }
  17004. /// Response to a item reward request
  17005. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17006. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17007. #if PACKETVER >= 20141016
  17008. nullpo_retv(sd);
  17009. struct packet_roulette_itemrecv_ack p;
  17010. p.PacketType = roulettercvitemackType;
  17011. p.Result = type;
  17012. p.AdditionItemID = 0; //! TODO: Additional item
  17013. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17014. #endif
  17015. }
  17016. /**
  17017. * Claim roulette reward
  17018. * @param sd Player
  17019. * @return 0:Success
  17020. **/
  17021. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  17022. struct item it;
  17023. uint8 res = 1;
  17024. nullpo_retr(1, sd);
  17025. if (sd->roulette.prizeIdx < 0)
  17026. return RECV_ITEM_FAILED;
  17027. memset(&it, 0, sizeof(it));
  17028. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17029. it.identify = 1;
  17030. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  17031. ; // onSuccess
  17032. }
  17033. sd->roulette.claimPrize = false;
  17034. sd->roulette.prizeStage = 0;
  17035. sd->roulette.prizeIdx = -1;
  17036. sd->roulette.stage = 0;
  17037. return res;
  17038. }
  17039. /// Update Roulette window with current stats
  17040. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17041. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17042. nullpo_retv( sd );
  17043. struct packet_roulette_generate_ack p;
  17044. p.PacketType = roulettgenerateackType;
  17045. p.Result = result;
  17046. p.Step = stage;
  17047. p.Idx = prizeIdx;
  17048. p.AdditionItemID = bonusItemID;
  17049. p.RemainGold = sd->roulette_point.gold;
  17050. p.RemainSilver = sd->roulette_point.silver;
  17051. p.RemainBronze = sd->roulette_point.bronze;
  17052. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17053. }
  17054. /// Request to start the roulette
  17055. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17056. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  17057. enum GENERATE_ROULETTE_ACK result;
  17058. nullpo_retv(sd);
  17059. if (!battle_config.feature_roulette) {
  17060. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17061. return;
  17062. }
  17063. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17064. return;
  17065. }
  17066. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17067. sd->roulette.stage = 0;
  17068. sd->roulette.claimPrize = false;
  17069. sd->roulette.prizeStage = 0;
  17070. sd->roulette.prizeIdx = -1;
  17071. }
  17072. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17073. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17074. }else{
  17075. if (!sd->roulette.stage) {
  17076. if (sd->roulette_point.bronze > 0) {
  17077. sd->roulette_point.bronze -= 1;
  17078. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17079. } else if (sd->roulette_point.silver > 9) {
  17080. sd->roulette_point.silver -= 10;
  17081. sd->roulette.stage = 2;
  17082. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17083. } else if (sd->roulette_point.gold > 9) {
  17084. sd->roulette_point.gold -= 10;
  17085. sd->roulette.stage = 4;
  17086. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17087. }
  17088. }
  17089. sd->roulette.prizeStage = sd->roulette.stage;
  17090. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17091. sd->roulette.claimPrize = true;
  17092. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17093. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17094. result = GENERATE_ROULETTE_LOSING;
  17095. sd->roulette.stage = 0;
  17096. }else{
  17097. result = GENERATE_ROULETTE_SUCCESS;
  17098. sd->roulette.stage++;
  17099. }
  17100. }
  17101. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  17102. }
  17103. /// Request to claim a prize
  17104. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17105. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  17106. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17107. nullpo_retv(sd);
  17108. if (!battle_config.feature_roulette) {
  17109. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17110. return;
  17111. }
  17112. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17113. return;
  17114. }
  17115. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17116. switch (clif_roulette_getitem(sd)) {
  17117. case ADDITEM_SUCCESS:
  17118. type = RECV_ITEM_SUCCESS;
  17119. break;
  17120. case ADDITEM_INVALID:
  17121. case ADDITEM_OVERITEM:
  17122. case ADDITEM_OVERAMOUNT:
  17123. type = RECV_ITEM_OVERCOUNT;
  17124. break;
  17125. case ADDITEM_OVERWEIGHT:
  17126. type = RECV_ITEM_OVERWEIGHT;
  17127. break;
  17128. case ADDITEM_STACKLIMIT:
  17129. default:
  17130. type = RECV_ITEM_FAILED;
  17131. break;
  17132. }
  17133. }
  17134. clif_roulette_recvitem_ack(sd,type);
  17135. }
  17136. /// MERGE ITEM
  17137. /**
  17138. * Acknowledge the client about item merger result
  17139. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17140. * @param fd
  17141. * @param sd
  17142. **/
  17143. void clif_merge_item_ack( struct map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17144. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17145. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17146. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17147. if( type == MERGE_ITEM_SUCCESS ){
  17148. p.index = client_index( index );
  17149. }else{
  17150. p.index = index;
  17151. }
  17152. p.amount = count;
  17153. p.reason = type;
  17154. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17155. #endif
  17156. }
  17157. /**
  17158. * Check if item has the pair to be merged
  17159. * @param sd
  17160. * @param it Item
  17161. * @return True if has pair, False if not
  17162. **/
  17163. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  17164. struct item *it_;
  17165. unsigned short i;
  17166. nullpo_retr(false, sd);
  17167. 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);
  17168. if (i < MAX_INVENTORY)
  17169. return true;
  17170. return false;
  17171. }
  17172. /**
  17173. * Check if item can be merged
  17174. * @param id Item Data
  17175. * @param it Item
  17176. * @return True if can be merged, False if not
  17177. **/
  17178. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17179. if (!id || !it)
  17180. return false;
  17181. if (id->type == IT_CASH)
  17182. return false;
  17183. if (!itemdb_isstackable2(id))
  17184. return false;
  17185. if (itemdb_isspecial(it->card[0]))
  17186. return false;
  17187. if (!it->unique_id)
  17188. return false;
  17189. return true;
  17190. }
  17191. /**
  17192. * Open available item to be merged.
  17193. * Only show 1 item in 1 process.
  17194. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17195. * @param sd
  17196. **/
  17197. void clif_merge_item_open( struct map_session_data& sd ){
  17198. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17199. struct PACKET_ZC_MERGE_ITEM_OPEN* p = (struct PACKET_ZC_MERGE_ITEM_OPEN*)packet_buffer;
  17200. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17201. p->packetLen = sizeof( *p );
  17202. int n = 0;
  17203. // Get entries
  17204. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17205. struct item* it = &sd.inventory.u.items_inventory[i];
  17206. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17207. continue;
  17208. }
  17209. if( clif_merge_item_has_pair( &sd, it ) ){
  17210. p->items[n++].index = client_index( i );
  17211. p->packetLen += sizeof( p->items[0] );
  17212. }
  17213. }
  17214. // No item need to be merged
  17215. if( n < 2 ){
  17216. clif_msg( &sd, MERGE_ITEM_NOT_AVAILABLE );
  17217. return;
  17218. }
  17219. clif_send( p, p->packetLen, &sd.bl, SELF );
  17220. #endif
  17221. }
  17222. /**
  17223. * Process item merger
  17224. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17225. * @param fd
  17226. * @param sd
  17227. **/
  17228. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  17229. struct s_packet_db *info = NULL;
  17230. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  17231. unsigned int count = 0;
  17232. struct item_data *id = NULL;
  17233. nullpo_retv(sd);
  17234. if (!clif_session_isValid(sd))
  17235. return;
  17236. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  17237. return;
  17238. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  17239. if (n < 2) { // No item need to be merged
  17240. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17241. return;
  17242. }
  17243. for (i = 0, j = 0; i < n; i++) {
  17244. uint16 idx = server_index( RFIFOW( fd, info->pos[1] + i * 2 ) );
  17245. if( idx >= MAX_INVENTORY ){
  17246. return;
  17247. }
  17248. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17249. continue;
  17250. indexes[j] = idx;
  17251. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17252. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_NOT_MERGE );
  17253. return;
  17254. }
  17255. count += sd->inventory.u.items_inventory[idx].amount;
  17256. j++;
  17257. }
  17258. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17259. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17260. return;
  17261. }
  17262. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17263. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17264. return;
  17265. }
  17266. // Merrrrge!!!!
  17267. for (i = 1; i < n; i++) {
  17268. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17269. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17270. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17271. sd->inventory_data[idx] = NULL;
  17272. clif_delitem(sd, idx, amt, 0);
  17273. }
  17274. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17275. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, indexes[0], count );
  17276. }
  17277. /**
  17278. * Cancel item merge
  17279. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17280. * @param fd
  17281. * @param sd
  17282. **/
  17283. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17284. return; // Nothing todo yet
  17285. }
  17286. static std::string clif_hide_name(const char* original_name)
  17287. {
  17288. std::string censored(original_name);
  17289. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17290. censored.replace(censored.length() - hide, hide, hide, '*');
  17291. return censored;
  17292. }
  17293. /**
  17294. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17295. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17296. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17297. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17298. **/
  17299. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17300. char name[NAME_LENGTH];
  17301. if( battle_config.broadcast_hide_name ){
  17302. std::string dispname = clif_hide_name(char_name);
  17303. safestrncpy(name, dispname.c_str(), sizeof(name));
  17304. }else{
  17305. safestrncpy( name, char_name, sizeof( name ) );
  17306. }
  17307. switch( type ){
  17308. case ITEMOBTAIN_TYPE_BOXITEM:
  17309. #if PACKETVER >= 20091201
  17310. {
  17311. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17312. p.PacketType = package_item_announceType;
  17313. p.PacketLength = sizeof( p );
  17314. p.type = type;
  17315. p.ItemID = client_nameid( nameid );
  17316. p.len = NAME_LENGTH;
  17317. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17318. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17319. p.BoxItemID = client_nameid( container );
  17320. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17321. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17322. p.refineLevel = 0; // TODO: implement
  17323. #endif
  17324. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17325. }
  17326. #endif
  17327. break;
  17328. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17329. case ITEMOBTAIN_TYPE_NPC:
  17330. {
  17331. struct packet_item_drop_announce p;
  17332. p.PacketType = item_drop_announceType;
  17333. p.type = type;
  17334. p.ItemID = client_nameid( nameid );
  17335. p.len = NAME_LENGTH;
  17336. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17337. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17338. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17339. p.monsterNameLen = NAME_LENGTH;
  17340. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17341. }else{
  17342. p.monsterNameLen = 0;
  17343. p.monsterName[0] = '\0';
  17344. }
  17345. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17346. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17347. #else
  17348. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17349. #endif
  17350. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17351. }
  17352. break;
  17353. }
  17354. }
  17355. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17356. /// 0A02 <view>.W
  17357. /// Value <flag> has the following effects:
  17358. /// 1: Open a Dress Room window.
  17359. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17360. #if PACKETVER >= 20150513
  17361. int fd = sd->fd;
  17362. nullpo_retv(sd);
  17363. WFIFOHEAD(fd, packet_len(0xa02));
  17364. WFIFOW(fd,0) = 0xa02;
  17365. WFIFOW(fd,2) = flag;
  17366. WFIFOSET(fd, packet_len(0xa02));
  17367. #endif
  17368. }
  17369. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17370. /// 0A35 <result>.W
  17371. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17372. #if PACKETVER >= 20150513
  17373. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17374. // Ignore the request
  17375. // - Invalid item index
  17376. // - Invalid item ID or item doesn't exist
  17377. // - Item is already identified
  17378. if (idx < 0 || idx >= MAX_INVENTORY ||
  17379. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17380. sd->inventory.u.items_inventory[idx].identify)
  17381. return;
  17382. // Ignore the request - No magnifiers in inventory
  17383. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17384. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17385. return;
  17386. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17387. return;
  17388. skill_identify(sd, idx);
  17389. #endif
  17390. }
  17391. /// Starts navigation to the given target on client side
  17392. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17393. #if PACKETVER >= 20111010
  17394. int fd = sd->fd;
  17395. WFIFOHEAD(fd,27);
  17396. WFIFOW(fd,0) = 0x08e2;
  17397. // How detailed will our navigation be?
  17398. if( mob_id > 0 ){
  17399. x = 0;
  17400. y = 0;
  17401. WFIFOB(fd,2) = 3; // monster with destination field
  17402. }else if( x > 0 && y > 0 ){
  17403. WFIFOB(fd,2) = 0; // with coordinates
  17404. }else{
  17405. x = 0;
  17406. y = 0;
  17407. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17408. }
  17409. // Which services can be used for transportation?
  17410. WFIFOB(fd,3) = flag;
  17411. // If this flag is set, the navigation window will not be opened up
  17412. WFIFOB(fd,4) = hideWindow;
  17413. // Target map
  17414. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17415. // Target x
  17416. WFIFOW(fd,21) = x;
  17417. // Target y
  17418. WFIFOW(fd,23) = y;
  17419. // Target monster ID
  17420. WFIFOW(fd,25) = mob_id;
  17421. WFIFOSET(fd,27);
  17422. #endif
  17423. }
  17424. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17425. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17426. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17427. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17428. struct map_session_data *tsd;
  17429. struct block_list* tbl;
  17430. if( target == SELF ){
  17431. tsd = BL_CAST(BL_PC,bl);
  17432. tbl = &sd->bl;
  17433. }else{
  17434. tsd = sd;
  17435. tbl = bl;
  17436. }
  17437. nullpo_retv( tsd );
  17438. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->flag[MF_NOCOSTUME] ){
  17439. return;
  17440. }
  17441. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17442. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17443. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17444. p->aid = tsd->bl.id;
  17445. p->status = 1;
  17446. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17447. p->effects[i] = tsd->hatEffects[i];
  17448. }
  17449. clif_send( p, p->packetLength, tbl, target );
  17450. #endif
  17451. }
  17452. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17453. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17454. nullpo_retv( sd );
  17455. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17456. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17457. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17458. p->aid = sd->bl.id;
  17459. p->status = enable;
  17460. p->effects[0] = effectId;
  17461. clif_send( p, p->packetLength, &sd->bl, AREA );
  17462. #endif
  17463. }
  17464. /// Notify the client that a sale has started
  17465. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17466. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17467. #if PACKETVER_SUPPORTS_SALES
  17468. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17469. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17470. p.itemId = client_nameid( sale_item->nameid );
  17471. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17472. clif_send( &p, sizeof( p ), bl, target );
  17473. #endif
  17474. }
  17475. /// Notify the client that a sale has ended
  17476. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17477. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17478. #if PACKETVER_SUPPORTS_SALES
  17479. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17480. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17481. p.itemId = client_nameid( sale_item->nameid );
  17482. clif_send( &p, sizeof( p ), bl, target );
  17483. #endif
  17484. }
  17485. /// Update the remaining amount of a sale item.
  17486. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17487. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17488. #if PACKETVER_SUPPORTS_SALES
  17489. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17490. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17491. p.itemId = client_nameid( sale_item->nameid );
  17492. p.amount = sale_item->amount;
  17493. clif_send( &p, sizeof( p ), bl, target );
  17494. #endif
  17495. }
  17496. /// The client requested a refresh of the current remaining count of a sale item
  17497. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17498. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17499. #if PACKETVER_SUPPORTS_SALES
  17500. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17501. struct sale_item_data* sale;
  17502. if( p->AID != sd->status.account_id ){
  17503. return;
  17504. }
  17505. sale = sale_find_item( p->itemId, true );
  17506. if( sale == NULL ){
  17507. return;
  17508. }
  17509. clif_sale_amount(sale, &sd->bl, SELF);
  17510. #endif
  17511. }
  17512. /// Opens the sale administration window on the client
  17513. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17514. void clif_sale_open( struct map_session_data* sd ){
  17515. #if PACKETVER_SUPPORTS_SALES
  17516. nullpo_retv(sd);
  17517. if( sd->state.sale_open ){
  17518. return;
  17519. }
  17520. sd->state.sale_open = true;
  17521. int fd = sd->fd;
  17522. WFIFOHEAD(fd, 2);
  17523. WFIFOW(fd, 0) = 0x9b5;
  17524. WFIFOSET(fd, 2);
  17525. #endif
  17526. }
  17527. /// Client request to open the sale administration window.
  17528. /// This is sent by /limitedsale
  17529. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17530. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17531. #if PACKETVER_SUPPORTS_SALES
  17532. nullpo_retv(sd);
  17533. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17534. return;
  17535. }
  17536. char command[CHAT_SIZE_MAX];
  17537. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17538. is_atcommand(fd, sd, command, 1);
  17539. #endif
  17540. }
  17541. /// Closes the sale administration window on the client.
  17542. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17543. void clif_sale_close(struct map_session_data* sd) {
  17544. #if PACKETVER_SUPPORTS_SALES
  17545. nullpo_retv(sd);
  17546. if( !sd->state.sale_open ){
  17547. return;
  17548. }
  17549. sd->state.sale_open = false;
  17550. int fd = sd->fd;
  17551. WFIFOHEAD(fd, 2);
  17552. WFIFOW(fd, 0) = 0x9bd;
  17553. WFIFOSET(fd, 2);
  17554. #endif
  17555. }
  17556. /// Client request to close the sale administration window.
  17557. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17558. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17559. #if PACKETVER_SUPPORTS_SALES
  17560. nullpo_retv(sd);
  17561. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17562. return;
  17563. }
  17564. clif_sale_close(sd);
  17565. #endif
  17566. }
  17567. /// Reply to a item search request for item sale administration.
  17568. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17569. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17570. #if PACKETVER_SUPPORTS_SALES
  17571. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17572. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17573. if( item != NULL ){
  17574. p.result = 0;
  17575. p.itemId = client_nameid( item->nameid );
  17576. p.price = item->price;
  17577. }else{
  17578. p.result = 1;
  17579. p.itemId = 0;
  17580. p.price = 0;
  17581. }
  17582. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17583. #endif
  17584. }
  17585. /// Search request for an item sale administration.
  17586. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17587. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17588. #if PACKETVER_SUPPORTS_SALES
  17589. char item_name[ITEM_NAME_LENGTH];
  17590. nullpo_retv(sd);
  17591. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17592. return;
  17593. }
  17594. if( !sd->state.sale_open ){
  17595. return;
  17596. }
  17597. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17598. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17599. if( id ){
  17600. int i;
  17601. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17602. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17603. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17604. return;
  17605. }
  17606. }
  17607. }
  17608. // not found
  17609. clif_sale_search_reply( sd, NULL );
  17610. #endif
  17611. }
  17612. /// Reply if an item was successfully put on sale or not.
  17613. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17614. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17615. #if PACKETVER_SUPPORTS_SALES
  17616. int fd = sd->fd;
  17617. WFIFOHEAD(fd, 4);
  17618. WFIFOW(fd, 0) = 0x9af;
  17619. WFIFOW(fd, 2) = (uint16)result;
  17620. WFIFOSET(fd, 4);
  17621. #endif
  17622. }
  17623. /// A client request to put an item on sale.
  17624. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17625. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17626. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17627. #if PACKETVER_SUPPORTS_SALES
  17628. nullpo_retv( sd );
  17629. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17630. if( p->AID != sd->status.account_id ){
  17631. return;
  17632. }
  17633. if( !sd->state.sale_open ){
  17634. return;
  17635. }
  17636. time_t endTime = p->startTime + p->hours * 60 * 60;
  17637. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17638. #endif
  17639. }
  17640. /// Reply to an item removal from sale.
  17641. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17642. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17643. #if PACKETVER_SUPPORTS_SALES
  17644. int fd = sd->fd;
  17645. WFIFOHEAD(fd, 4);
  17646. WFIFOW(fd, 0) = 0x9b1;
  17647. WFIFOW(fd, 2) = failed;
  17648. WFIFOSET(fd, 4);
  17649. #endif
  17650. }
  17651. /// Request to remove an item from sale.
  17652. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17653. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17654. #if PACKETVER_SUPPORTS_SALES
  17655. nullpo_retv( sd );
  17656. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17657. if( p->AID != sd->status.account_id ){
  17658. return;
  17659. }
  17660. if( !sd->state.sale_open ){
  17661. return;
  17662. }
  17663. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17664. #endif
  17665. }
  17666. /// Achievement System
  17667. /// Author: Luxuri, Aleos
  17668. /**
  17669. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17670. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17671. */
  17672. void clif_achievement_list_all(struct map_session_data *sd)
  17673. {
  17674. nullpo_retv(sd);
  17675. if (!battle_config.feature_achievement) {
  17676. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17677. return;
  17678. }
  17679. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17680. if (count == 0)
  17681. return;
  17682. int len = (50 * count) + 22;
  17683. int fd = sd->fd;
  17684. int *info = achievement_level(sd, true);
  17685. WFIFOHEAD(fd,len);
  17686. WFIFOW(fd, 0) = 0xa23;
  17687. WFIFOW(fd, 2) = len;
  17688. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17689. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17690. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17691. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17692. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17693. for (int i = 0; i < count; i++) {
  17694. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17695. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17696. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17697. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17698. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17699. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17700. }
  17701. WFIFOSET(fd, len);
  17702. }
  17703. /**
  17704. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17705. * 0a24 <ACHPoint>.L
  17706. */
  17707. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17708. {
  17709. nullpo_retv(sd);
  17710. if (!battle_config.feature_achievement) {
  17711. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17712. return;
  17713. }
  17714. int fd = sd->fd;
  17715. int *info = achievement_level(sd, true);
  17716. WFIFOHEAD(fd, packet_len(0xa24));
  17717. WFIFOW(fd, 0) = 0xa24;
  17718. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17719. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17720. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17721. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17722. if (ach) {
  17723. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17724. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17725. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17726. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17727. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17728. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17729. } else
  17730. memset(WFIFOP(fd, 16), 0, 40);
  17731. WFIFOSET(fd, packet_len(0xa24));
  17732. }
  17733. /**
  17734. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17735. * 0a25 <achievementID>.L
  17736. */
  17737. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17738. {
  17739. nullpo_retv(sd);
  17740. if( sd->achievement_data.save )
  17741. intif_achievement_save(sd);
  17742. achievement_check_reward(sd, RFIFOL(fd,2));
  17743. }
  17744. /**
  17745. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17746. * 0a26 <result>.W <achievementID>.L
  17747. */
  17748. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17749. {
  17750. WFIFOHEAD(fd, packet_len(0xa26));
  17751. WFIFOW(fd, 0) = 0xa26;
  17752. WFIFOB(fd, 2) = result;
  17753. WFIFOL(fd, 3) = achievement_id;
  17754. WFIFOSET(fd, packet_len(0xa26));
  17755. }
  17756. /// Process the pet evolution request
  17757. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17758. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17759. #if PACKETVER >= 20141008
  17760. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17761. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17762. if (!pet) {
  17763. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17764. return;
  17765. }
  17766. pet_evolution(sd, pet->class_);
  17767. #endif
  17768. }
  17769. /// Sends the result of the evolution to the client.
  17770. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17771. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17772. #if PACKETVER >= 20141008
  17773. int fd = sd->fd;
  17774. WFIFOHEAD(fd, packet_len(0x9fc));
  17775. WFIFOW(fd, 0) = 0x9fc;
  17776. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17777. WFIFOSET(fd, packet_len(0x9fc));
  17778. #endif
  17779. }
  17780. /*
  17781. * This packet is sent by /changedress or /nocosplay
  17782. *
  17783. * 0ae8
  17784. */
  17785. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17786. #if PACKETVER >= 20180103
  17787. char command[CHAT_SIZE_MAX];
  17788. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17789. is_atcommand( fd, sd, command, 1 );
  17790. #endif
  17791. }
  17792. /// Opens an UI window of the given type and initializes it with the given data
  17793. /// 0AE2 <type>.B <data>.L
  17794. void clif_ui_open( struct map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17795. #if PACKETVER >= 20151202
  17796. // If the UI requires state tracking
  17797. switch( ui_type ){
  17798. case OUT_UI_STYLIST:
  17799. sd.state.stylist_open = true;
  17800. break;
  17801. case OUT_UI_ENCHANTGRADE:
  17802. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17803. sd.state.enchantgrade_open = true;
  17804. break;
  17805. #else
  17806. return;
  17807. #endif
  17808. }
  17809. struct PACKET_ZC_UI_OPEN p = {};
  17810. p.PacketType = HEADER_ZC_UI_OPEN;
  17811. p.UIType = ui_type;
  17812. #if PACKETVER >= 20171122
  17813. p.data = data;
  17814. #endif
  17815. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17816. #endif
  17817. }
  17818. /// Request to open an UI window of the given type
  17819. /// 0A68 <type>.B
  17820. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17821. switch( RFIFOB(fd,2) ){
  17822. case IN_UI_ATTENDANCE:
  17823. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17824. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17825. }else if( pc_attendance_enabled() ){
  17826. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17827. }else{
  17828. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17829. }
  17830. break;
  17831. #if PACKETVER >= 20160316
  17832. case IN_UI_MACRO_REGISTER:
  17833. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  17834. break;
  17835. case IN_UI_MACRO_DETECTOR:
  17836. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  17837. break;
  17838. #endif
  17839. }
  17840. }
  17841. /// Response for attedance request
  17842. /// 0AF0 <unknown>.L <data>.L
  17843. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17844. nullpo_retv(sd);
  17845. int fd = sd->fd;
  17846. WFIFOHEAD(fd,packet_len(0xAF0));
  17847. WFIFOW(fd,0) = 0xAF0;
  17848. WFIFOL(fd,2) = 0;
  17849. WFIFOL(fd,6) = data;
  17850. WFIFOSET(fd,packet_len(0xAF0));
  17851. }
  17852. /// Request from the client to retrieve today's attendance reward
  17853. /// 0AEF
  17854. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17855. pc_attendance_claim_reward(sd);
  17856. }
  17857. /// Send out the percentage of weight that causes it to be displayed in red.
  17858. /// 0ADE <percentage>.L
  17859. void clif_weight_limit( struct map_session_data* sd ){
  17860. #if PACKETVER >= 20171025
  17861. nullpo_retv(sd);
  17862. int fd = sd->fd;
  17863. WFIFOHEAD(fd, packet_len(0xADE));
  17864. WFIFOW(fd, 0) = 0xADE;
  17865. #ifdef RENEWAL
  17866. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17867. #else
  17868. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17869. #endif
  17870. WFIFOSET(fd, packet_len(0xADE));
  17871. #endif
  17872. }
  17873. enum e_private_airship_response : uint32{
  17874. PRIVATEAIRSHIP_OK,
  17875. PRIVATEAIRSHIP_RETRY,
  17876. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17877. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17878. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17879. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17880. };
  17881. /// Send out the response to a private airship request
  17882. /// 0A4A <response>.L
  17883. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17884. #if PACKETVER >= 20180321
  17885. nullpo_retv( sd );
  17886. int fd = sd->fd;
  17887. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17888. WFIFOW( fd, 0 ) = 0xA4A;
  17889. WFIFOL( fd, 2 ) = response;
  17890. WFIFOSET( fd, packet_len( 0xA4A ) );
  17891. #endif
  17892. }
  17893. /// Parses a request for a private airship
  17894. /// 0A49 <mapname>.16B <itemid>.W
  17895. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17896. #if PACKETVER >= 20180321
  17897. // Check if the feature is enabled
  17898. if( !battle_config.feature_privateairship ){
  17899. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17900. return;
  17901. }
  17902. // Check if the player is allowed to warp from the source map
  17903. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17904. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17905. return;
  17906. }
  17907. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17908. char mapname[MAP_NAME_LENGTH_EXT];
  17909. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17910. int16 mapindex = mapindex_name2id( mapname );
  17911. // Check if we know the mapname
  17912. if( mapindex < 0 ){
  17913. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17914. return;
  17915. }
  17916. int16 mapid = map_mapindex2mapid( mapindex );
  17917. // Check if the map is available on this server
  17918. if( mapid < 0 ){
  17919. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17920. return;
  17921. }
  17922. // Check if the player tried to warp to the map he is on
  17923. if( sd->bl.m == mapid ){
  17924. // This is blocked by the client, but just to be sure
  17925. return;
  17926. }
  17927. // This can only be a hack, so we prevent it
  17928. if( map_getmapdata( mapid )->instance_id ){
  17929. // Ignore requests to warp directly into a running instance
  17930. return;
  17931. }
  17932. // Check if the player is allowed to warp to the target map
  17933. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17934. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17935. return;
  17936. }
  17937. t_itemid item_id = p->ItemID;
  17938. // Check if the item sent by the client is known to us
  17939. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17940. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17941. return;
  17942. }
  17943. int idx = pc_search_inventory( sd, item_id );
  17944. // Check if the player has the item at all
  17945. if( idx < 0 ){
  17946. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17947. return;
  17948. }
  17949. // Delete the chosen item
  17950. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17951. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17952. return;
  17953. }
  17954. // Warp the player to a random spot on the destination map
  17955. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17956. #endif
  17957. }
  17958. /// Sends out the usage history of the guild storage
  17959. /// 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
  17960. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17961. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17962. #if PACKETVER >= 20140205
  17963. nullpo_retv( sd );
  17964. int fd = sd->fd;
  17965. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17966. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17967. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17968. }else{
  17969. log.clear();
  17970. }
  17971. WFIFOHEAD( fd, size );
  17972. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17973. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17974. p->PacketLength = size;
  17975. p->result = result;
  17976. p->amount = (uint16)log.size();
  17977. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17978. for( int i = 0; i < log.size(); i++ ){
  17979. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  17980. struct guild_log_entry& entry = log[i];
  17981. item->id = entry.id;
  17982. item->itemId = client_nameid( entry.item.nameid );
  17983. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17984. item->action = entry.amount > 0; // action = true(put), false(get)
  17985. item->refine = entry.item.refine;
  17986. item->uniqueId = entry.item.unique_id;
  17987. item->IsIdentified = entry.item.identify;
  17988. item->itemType = itemtype( entry.item.nameid );
  17989. clif_addcards( &item->slot, &entry.item );
  17990. safestrncpy( item->name, entry.name, NAME_LENGTH );
  17991. safestrncpy( item->time, entry.time, NAME_LENGTH );
  17992. item->attribute = entry.item.attribute;
  17993. }
  17994. }
  17995. WFIFOSET( fd, p->PacketLength );
  17996. #endif
  17997. }
  17998. /// Activates the client camera info or updates the client camera with the given values.
  17999. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18000. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18001. #if PACKETVER >= 20160525
  18002. int fd = sd->fd;
  18003. WFIFOHEAD(fd, packet_len(0xa78));
  18004. WFIFOW(fd, 0) = 0xa78;
  18005. WFIFOB(fd, 2) = show;
  18006. WFIFOF(fd, 3) = range;
  18007. WFIFOF(fd, 7) = rotation;
  18008. WFIFOF(fd, 11) = latitude;
  18009. WFIFOSET(fd, packet_len(0xa78));
  18010. #endif
  18011. }
  18012. /// Activates or deactives the client camera info or updates the camera settings.
  18013. /// This packet is triggered by /viewpointvalue or /setcamera
  18014. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18015. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  18016. char command[CHAT_SIZE_MAX];
  18017. // /viewpointvalue
  18018. if( RFIFOB( fd, 2 ) == 1 ){
  18019. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18020. // /setcamera
  18021. }else{
  18022. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18023. }
  18024. is_atcommand( fd, sd, command, 1 );
  18025. }
  18026. /// Send the full list of items in the equip switch window
  18027. /// 0a9b <length>.W { <index>.W <position>.L }*
  18028. void clif_equipswitch_list( struct map_session_data* sd ){
  18029. #if PACKETVER >= 20170208
  18030. int fd = sd->fd;
  18031. int offset, i, position;
  18032. WFIFOW(fd, 0) = 0xa9b;
  18033. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18034. short index = sd->equip_switch_index[i];
  18035. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18036. WFIFOW(fd, offset) = index + 2;
  18037. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18038. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18039. offset += 6;
  18040. }
  18041. }
  18042. WFIFOW(fd, 2) = offset;
  18043. WFIFOSET(fd, offset);
  18044. #endif
  18045. }
  18046. /// Acknowledgement for removing an equip to the equip switch window
  18047. /// 0a9a <index>.W <position.>.L <failure>.W
  18048. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18049. #if PACKETVER >= 20170208
  18050. int fd = sd->fd;
  18051. WFIFOHEAD(fd, packet_len(0xa9a));
  18052. WFIFOW(fd, 0) = 0xa9a;
  18053. WFIFOW(fd, 2) = index + 2;
  18054. WFIFOL(fd, 4) = pos;
  18055. WFIFOW(fd, 8) = failed;
  18056. WFIFOSET(fd, packet_len(0xa9a));
  18057. #endif
  18058. }
  18059. /// Request to remove an equip from the equip switch window
  18060. /// 0a99 <index>.W <position>.L <= 20170502
  18061. /// 0a99 <index>.W
  18062. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  18063. #if PACKETVER >= 20170208
  18064. uint16 index = RFIFOW(fd, 2) - 2;
  18065. bool removed = false;
  18066. if( !battle_config.feature_equipswitch ){
  18067. return;
  18068. }
  18069. // Check if the index is valid
  18070. if( index >= MAX_INVENTORY ){
  18071. return;
  18072. }
  18073. pc_equipswitch_remove( sd, index );
  18074. #endif
  18075. }
  18076. /// Acknowledgement for adding an equip to the equip switch window
  18077. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18078. /// 0a98 <index>.W <position.>.L <flag>.W
  18079. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18080. #if PACKETVER >= 20170208
  18081. int fd = sd->fd;
  18082. WFIFOHEAD(fd, packet_len(0xa98));
  18083. WFIFOW(fd, 0) = 0xa98;
  18084. WFIFOW(fd, 2) = index + 2;
  18085. WFIFOL(fd, 4) = pos;
  18086. #if PACKETVER <= 20170502
  18087. WFIFOL(fd, 8) = flag;
  18088. #else
  18089. WFIFOW(fd, 8) = flag;
  18090. #endif
  18091. WFIFOSET(fd,packet_len(0xa98));
  18092. #endif
  18093. }
  18094. /// Request to add an equip to the equip switch window
  18095. /// 0a97 <index>.W <position>.L
  18096. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  18097. #if PACKETVER >= 20170208
  18098. uint16 index = RFIFOW(fd, 2) - 2;
  18099. uint32 position = RFIFOL(fd, 4);
  18100. if( !battle_config.feature_equipswitch ){
  18101. return;
  18102. }
  18103. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18104. return;
  18105. }
  18106. if( sd->state.trading || sd->npc_shopid ){
  18107. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18108. return;
  18109. }
  18110. if( sd->inventory_data[index]->type == IT_AMMO ){
  18111. position = EQP_AMMO;
  18112. }
  18113. pc_equipitem( sd, index, position, true );
  18114. #endif
  18115. }
  18116. /// Acknowledgement packet for the full equip switch
  18117. /// 0a9d <failed>.W
  18118. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  18119. #if PACKETVER >= 20170208
  18120. int fd = sd->fd;
  18121. WFIFOHEAD(fd, packet_len(0xa9d));
  18122. WFIFOW(fd, 0) = 0xa9d;
  18123. WFIFOW(fd, 2) = failed;
  18124. WFIFOSET(fd, packet_len(0xa9d));
  18125. #endif
  18126. }
  18127. /// Request to do a full equip switch
  18128. /// 0a9c
  18129. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  18130. #if PACKETVER >= 20170208
  18131. int i;
  18132. t_tick tick = gettick();
  18133. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18134. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18135. // Client will not let you send a request
  18136. return;
  18137. }
  18138. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18139. if( !battle_config.feature_equipswitch ){
  18140. return;
  18141. }
  18142. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18143. if( i == EQI_MAX ){
  18144. // client will show: "There is no item to replace." and should not even come here
  18145. clif_equipswitch_reply( sd, false );
  18146. return;
  18147. }
  18148. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18149. return;
  18150. }
  18151. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18152. #endif
  18153. }
  18154. /// Request to do a single equip switch
  18155. /// 0ace <index>.W
  18156. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  18157. #if PACKETVER >= 20170502
  18158. uint16 index = RFIFOW(fd, 2) - 2;
  18159. if( !battle_config.feature_equipswitch ){
  18160. return;
  18161. }
  18162. // Check if the index is valid
  18163. if( index >= MAX_INVENTORY ){
  18164. return;
  18165. }
  18166. // Check if the item exists
  18167. if (sd->inventory_data[index] == nullptr)
  18168. return;
  18169. // Check if the item was already added to equip switch
  18170. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18171. if( sd->npc_id ){
  18172. #ifdef RENEWAL
  18173. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18174. clif_msg( sd, WORK_IN_PROGRESS );
  18175. return;
  18176. }
  18177. #endif
  18178. if( !sd->npc_item_flag ){
  18179. return;
  18180. }
  18181. }
  18182. pc_equipswitch( sd, index );
  18183. return;
  18184. }
  18185. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18186. #endif
  18187. }
  18188. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  18189. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18190. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18191. // Only rolling cutter is supported for now
  18192. if( p->skillId != GC_ROLLINGCUTTER ){
  18193. return;
  18194. }
  18195. // Already running - cant happen on officials, since only one skill is supported
  18196. if( sd->skill_keep_using.skill_id != 0 ){
  18197. return;
  18198. }
  18199. sd->skill_keep_using.tid = INVALID_TIMER;
  18200. sd->skill_keep_using.skill_id = p->skillId;
  18201. sd->skill_keep_using.level = p->skillLv;
  18202. sd->skill_keep_using.target = p->targetId;
  18203. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18204. #endif
  18205. }
  18206. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  18207. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18208. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18209. // Not running
  18210. if( sd->skill_keep_using.skill_id == 0 ){
  18211. return;
  18212. }
  18213. #if 0
  18214. // Hack
  18215. if( p->skillId != sd->skill_keep_using.skill_id ){
  18216. return;
  18217. }
  18218. #endif
  18219. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18220. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18221. sd->skill_keep_using.tid = INVALID_TIMER;
  18222. }
  18223. sd->skill_keep_using.skill_id = 0;
  18224. sd->skill_keep_using.level = 0;
  18225. sd->skill_keep_using.target = 0;
  18226. #endif
  18227. }
  18228. void clif_ping( struct map_session_data* sd ){
  18229. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18230. nullpo_retv( sd );
  18231. int fd = sd->fd;
  18232. if( !session_isActive( fd ) ){
  18233. return;
  18234. }
  18235. struct PACKET_ZC_PING_LIVE p = {};
  18236. p.packetType = HEADER_ZC_PING_LIVE;
  18237. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18238. #endif
  18239. }
  18240. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  18241. nullpo_ret( sd );
  18242. int fd = sd->fd;
  18243. if( !session_isActive( fd ) ){
  18244. return 0;
  18245. }
  18246. t_tick tick = va_arg( ap, t_tick );
  18247. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18248. clif_ping( sd );
  18249. }
  18250. return 0;
  18251. }
  18252. TIMER_FUNC( clif_ping_timer ){
  18253. map_foreachpc( clif_ping_timer_sub, gettick() );
  18254. return 0;
  18255. }
  18256. /**
  18257. * Opens the refine UI on the designated client.
  18258. * 0aa0
  18259. */
  18260. void clif_refineui_open( struct map_session_data* sd ){
  18261. #if PACKETVER >= 20161012
  18262. nullpo_retv( sd );
  18263. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18264. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18265. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18266. sd->state.refineui_open = true;
  18267. #endif
  18268. }
  18269. /**
  18270. * Parses cancel/close of the refine UI on client side.
  18271. * 0aa4
  18272. */
  18273. void clif_parse_refineui_close( int fd, struct map_session_data* sd ){
  18274. #if PACKETVER >= 20161012
  18275. sd->state.refineui_open = false;
  18276. #endif
  18277. }
  18278. /**
  18279. * Adds the selected item into the refine UI and sends the possible materials
  18280. * to the client.
  18281. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18282. */
  18283. void clif_refineui_info( struct map_session_data* sd, uint16 index ){
  18284. #if PACKETVER >= 20161012
  18285. int fd = sd->fd;
  18286. // Get the item db reference
  18287. struct item_data* id = sd->inventory_data[index];
  18288. // No item data was found
  18289. if( id == NULL ){
  18290. return;
  18291. }
  18292. // Check the inventory
  18293. struct item* item = &sd->inventory.u.items_inventory[index];
  18294. // No item was found at the given index
  18295. if( item == NULL ){
  18296. return;
  18297. }
  18298. // Check if the item is identified
  18299. if( !item->identify ){
  18300. return;
  18301. }
  18302. // Check if the item is broken
  18303. if( item->attribute ){
  18304. return;
  18305. }
  18306. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18307. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18308. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18309. p->itemIndex = client_index( index );
  18310. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18311. // No possibilities were found
  18312. if( info == nullptr ){
  18313. p->blacksmithBlessing = 0;
  18314. }else{
  18315. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18316. uint16 count = 0;
  18317. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18318. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18319. if( cost != nullptr ){
  18320. p->req[count].itemId = client_nameid( cost->nameid );
  18321. p->req[count].chance = (uint8)( cost->chance / 100 );
  18322. p->req[count].zeny = cost->zeny;
  18323. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18324. count++;
  18325. }
  18326. }
  18327. }
  18328. clif_send( p, p->packetLength, &sd->bl, SELF );
  18329. #endif
  18330. }
  18331. /**
  18332. * Client request to add an item to the refine UI.
  18333. * 0aa1 <index>.W
  18334. */
  18335. void clif_parse_refineui_add( int fd, struct map_session_data* sd ){
  18336. #if PACKETVER >= 20161012
  18337. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18338. uint16 index = server_index( p->index );
  18339. // Check if the refine UI is open
  18340. if( !sd->state.refineui_open ){
  18341. return;
  18342. }
  18343. // Check if the index is valid
  18344. if( index >= MAX_INVENTORY ){
  18345. return;
  18346. }
  18347. // Send out the requirements for the refine process
  18348. clif_refineui_info( sd, index );
  18349. #endif
  18350. }
  18351. /**
  18352. * Client requests to try to refine an item.
  18353. * 0aa3 <index>.W <material>.W <catalyst>.B
  18354. */
  18355. void clif_parse_refineui_refine( int fd, struct map_session_data* sd ){
  18356. #if PACKETVER >= 20161012
  18357. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18358. uint16 index = server_index( p->index );
  18359. t_itemid material = p->itemId;
  18360. int16 j;
  18361. // Check if the refine UI is open
  18362. if( !sd->state.refineui_open ){
  18363. return;
  18364. }
  18365. // Check if the index is valid
  18366. if( index >= MAX_INVENTORY ){
  18367. return;
  18368. }
  18369. // Get the item db reference
  18370. struct item_data* id = sd->inventory_data[index];
  18371. // No item data was found
  18372. if( id == NULL ){
  18373. return;
  18374. }
  18375. // Check the inventory
  18376. struct item* item = &sd->inventory.u.items_inventory[index];
  18377. // No item was found at the given index
  18378. if( item == NULL ){
  18379. return;
  18380. }
  18381. // Check if the item is identified
  18382. if( !item->identify ){
  18383. return;
  18384. }
  18385. // Check if the item is broken
  18386. if( item->attribute ){
  18387. return;
  18388. }
  18389. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18390. // No refine possible
  18391. if( info == nullptr ){
  18392. return;
  18393. }
  18394. // No possibilities were found
  18395. if( info->costs.empty() ){
  18396. return;
  18397. }
  18398. // Check if the player has the selected material
  18399. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18400. return;
  18401. }
  18402. int16 blacksmith_index = -1;
  18403. uint16 blacksmith_amount = 0;
  18404. // Check if the player has enough blacksmith blessings
  18405. if( p->blacksmithBlessing != 0 ){
  18406. blacksmith_amount = info->blessing_amount;
  18407. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18408. if( blacksmith_amount == 0 ){
  18409. return;
  18410. }
  18411. // Check if the player has blacksmith blessings
  18412. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18413. return;
  18414. }
  18415. // Check if the player has enough blacksmith blessings
  18416. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18417. return;
  18418. }
  18419. }
  18420. std::shared_ptr<s_refine_cost> cost = nullptr;
  18421. for( const auto& pair : info->costs ){
  18422. if( pair.second->nameid == material ){
  18423. cost = pair.second;
  18424. break;
  18425. }
  18426. }
  18427. // The material was not in the list of possible materials
  18428. if( cost == nullptr ){
  18429. return;
  18430. }
  18431. // Try to pay for the refine
  18432. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME, NULL ) ){
  18433. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18434. return;
  18435. }
  18436. // Delete the required material
  18437. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18438. return;
  18439. }
  18440. // Delete the required blacksmith blessings
  18441. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18442. return;
  18443. }
  18444. // Try to refine the item
  18445. if( cost->chance >= ( rnd() % 10000 ) ){
  18446. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18447. // Success
  18448. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18449. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18450. clif_misceffect( &sd->bl, 3 );
  18451. clif_refine( fd, 0, index, item->refine );
  18452. if (info->broadcast_success) {
  18453. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18454. }
  18455. if( id->type == IT_WEAPON ){
  18456. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18457. }
  18458. clif_refineui_info( sd, index );
  18459. }else{
  18460. // Failure
  18461. if (info->broadcast_failure) {
  18462. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18463. }
  18464. // Blacksmith blessings were used to prevent breaking and downgrading
  18465. if( blacksmith_amount > 0 ){
  18466. clif_refine( fd, 3, index, item->refine );
  18467. clif_refineui_info( sd, index );
  18468. // Delete the item if it is breakable
  18469. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18470. clif_refine( fd, 1, index, item->refine );
  18471. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18472. // Downgrade the item if necessary
  18473. }else if( cost->downgrade_amount > 0 ){
  18474. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18475. clif_refine( fd, 2, index, item->refine );
  18476. clif_refineui_info(sd, index);
  18477. // Only show failure, but dont do anything
  18478. }else{
  18479. clif_refine( fd, 3, index, item->refine );
  18480. clif_refineui_info( sd, index );
  18481. }
  18482. clif_misceffect( &sd->bl, 2 );
  18483. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18484. }
  18485. #endif
  18486. }
  18487. void clif_unequipall_reply( struct map_session_data* sd, bool failed ){
  18488. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18489. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18490. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18491. p.result = failed;
  18492. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18493. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18494. }
  18495. void clif_parse_unequipall( int fd, struct map_session_data* sd ){
  18496. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18497. if( pc_cant_act( sd ) ){
  18498. clif_unequipall_reply( sd, true );
  18499. return;
  18500. }
  18501. for( int i = 0; i < EQI_COSTUME_HEAD_TOP; i++ ){
  18502. if( sd->equip_index[i] >= 0 ){
  18503. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18504. }
  18505. }
  18506. clif_unequipall_reply( sd, false );
  18507. #endif
  18508. }
  18509. void clif_stylist_response( struct map_session_data* sd, bool failed ){
  18510. #if PACKETVER >= 20151104
  18511. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18512. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18513. p.flag = failed;
  18514. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18515. if( !failed ){
  18516. sd->state.stylist_open = false;
  18517. }
  18518. #endif
  18519. }
  18520. bool clif_parse_stylist_buy_sub( struct map_session_data* sd, _look look, int16 index ){
  18521. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18522. if( list == nullptr ){
  18523. return false;
  18524. }
  18525. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18526. if( entry == nullptr ){
  18527. return false;
  18528. }
  18529. std::shared_ptr<s_stylist_costs> costs;
  18530. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18531. costs = entry->doram;
  18532. }else{
  18533. costs = entry->human;
  18534. }
  18535. if( costs == nullptr ){
  18536. return false;
  18537. }
  18538. if( sd->status.zeny < costs->price ){
  18539. return false;
  18540. }
  18541. int16 inventoryIndex = -1;
  18542. if( costs->requiredItem != 0 ){
  18543. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18544. if( inventoryIndex < 0 ){
  18545. // No other option
  18546. if( costs->requiredItemBox == 0 ){
  18547. return false;
  18548. }
  18549. // Check if the box that contains the item is in the inventory
  18550. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18551. // The box containing the item also does not exist
  18552. if( inventoryIndex < 0 ){
  18553. return false;
  18554. }
  18555. }
  18556. }else if( costs->requiredItemBox != 0 ){
  18557. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18558. if( inventoryIndex < 0 ){
  18559. return false;
  18560. }
  18561. }
  18562. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18563. return false;
  18564. }
  18565. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER, nullptr ) != 0 ){
  18566. return false;
  18567. }
  18568. switch( look ){
  18569. case LOOK_HAIR:
  18570. case LOOK_HAIR_COLOR:
  18571. case LOOK_CLOTHES_COLOR:
  18572. case LOOK_BODY2:
  18573. pc_changelook( sd, look, entry->value );
  18574. break;
  18575. case LOOK_HEAD_BOTTOM:
  18576. case LOOK_HEAD_MID:
  18577. case LOOK_HEAD_TOP: {
  18578. struct mail_message msg = {};
  18579. msg.dest_id = sd->status.char_id;
  18580. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18581. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18582. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18583. msg.item[0].nameid = entry->value;
  18584. msg.item[0].identify = 1;
  18585. msg.item[0].amount = 1;
  18586. msg.status = MAIL_NEW;
  18587. msg.type = MAIL_INBOX_NORMAL;
  18588. msg.timestamp = time( nullptr );
  18589. intif_Mail_send( 0, &msg );
  18590. } break;
  18591. }
  18592. return true;
  18593. }
  18594. void clif_parse_stylist_buy( int fd, struct map_session_data* sd ){
  18595. #if PACKETVER >= 20151104
  18596. #if PACKETVER >= 20180516
  18597. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18598. #else
  18599. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18600. #endif
  18601. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18602. clif_stylist_response( sd, true );
  18603. return;
  18604. }
  18605. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18606. clif_stylist_response( sd, true );
  18607. return;
  18608. }
  18609. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18610. clif_stylist_response( sd, true );
  18611. return;
  18612. }
  18613. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18614. clif_stylist_response( sd, true );
  18615. return;
  18616. }
  18617. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18618. clif_stylist_response( sd, true );
  18619. return;
  18620. }
  18621. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18622. clif_stylist_response( sd, true );
  18623. return;
  18624. }
  18625. #if PACKETVER >= 20180516
  18626. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18627. clif_stylist_response( sd, true );
  18628. return;
  18629. }
  18630. #endif
  18631. clif_stylist_response( sd, false );
  18632. #endif
  18633. }
  18634. void clif_parse_stylist_close( int fd, struct map_session_data* sd ){
  18635. #if PACKETVER >= 20151104
  18636. sd->state.stylist_open = false;
  18637. #endif
  18638. }
  18639. void clif_inventory_expansion_info( struct map_session_data* sd ){
  18640. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18641. nullpo_retv( sd );
  18642. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18643. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18644. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18645. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18646. #endif
  18647. }
  18648. enum class e_inventory_expansion_response : uint8{
  18649. ASK_CONFIRMATION = 0,
  18650. FAILED,
  18651. BUSY,
  18652. MISSING_ITEM,
  18653. MAXIMUM_REACHED
  18654. };
  18655. void clif_inventory_expansion_response( struct map_session_data* sd, e_inventory_expansion_response response ){
  18656. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18657. nullpo_retv( sd );
  18658. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18659. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18660. p.result = (uint8)response;
  18661. p.itemId = sd->state.inventory_expansion_confirmation;
  18662. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18663. #endif
  18664. }
  18665. void clif_parse_inventory_expansion_request( int fd, struct map_session_data* sd ){
  18666. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18667. // Check if player is dead or busy with other stuff
  18668. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18669. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18670. return;
  18671. }
  18672. // Check if the player already reached the maximum
  18673. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18674. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18675. return;
  18676. }
  18677. static std::map<t_itemid, uint16> items = {
  18678. // The order of entries in this list defines which will be used first
  18679. // This order and the usable items are hardcoded into the client
  18680. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18681. { ITEMID_INVENTORY_EX_EVT, 10 },
  18682. { ITEMID_INVENTORY_EX_DIS, 10 },
  18683. { ITEMID_INVENTORY_EX, 10 },
  18684. };
  18685. int16 index = -1;
  18686. bool found_over_limit = false;
  18687. for( const auto& entry : items ){
  18688. // Check if the player has the required item
  18689. index = pc_search_inventory( sd, entry.first );
  18690. // Found an item
  18691. if( index >= 0 ){
  18692. // Check if the player would exceed the maximum
  18693. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18694. found_over_limit = true;
  18695. }else{
  18696. found_over_limit = false;
  18697. sd->state.inventory_expansion_confirmation = entry.first;
  18698. sd->state.inventory_expansion_amount = entry.second;
  18699. break;
  18700. }
  18701. }
  18702. }
  18703. // Check if an item was found
  18704. if( sd->state.inventory_expansion_confirmation == 0 ){
  18705. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18706. return;
  18707. }
  18708. // Check if an item would have been found, but the player would exceed the maximum
  18709. if( found_over_limit ){
  18710. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18711. return;
  18712. }
  18713. // The player met all requirements => ask him for confirmation
  18714. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18715. #endif
  18716. }
  18717. enum class e_inventory_expansion_result : uint8{
  18718. SUCCESS = 0,
  18719. FAILED,
  18720. BUSY,
  18721. MISSING_ITEM,
  18722. MAXIMUM_REACHED
  18723. };
  18724. void clif_inventory_expansion_result( struct map_session_data* sd, e_inventory_expansion_result result ){
  18725. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18726. nullpo_retv( sd );
  18727. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18728. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18729. p.result = (uint8)result;
  18730. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18731. // Reset the state tracking
  18732. sd->state.inventory_expansion_confirmation = 0;
  18733. sd->state.inventory_expansion_amount = 0;
  18734. #endif
  18735. }
  18736. void clif_parse_inventory_expansion_confirm( int fd, struct map_session_data* sd ){
  18737. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18738. if( sd->state.inventory_expansion_confirmation == 0 ){
  18739. return;
  18740. }
  18741. // Check if player is dead
  18742. if( pc_isdead( sd ) ){
  18743. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18744. return;
  18745. }
  18746. // Check if the player already reached the maximum
  18747. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18748. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18749. return;
  18750. }
  18751. // Check if the player has the required item
  18752. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18753. // The player did not have the item anymore
  18754. if( index < 0 ){
  18755. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18756. return;
  18757. }
  18758. // Check if the player would exceed the maximum
  18759. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18760. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18761. return;
  18762. }
  18763. // Delete the required item
  18764. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18765. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18766. return;
  18767. }
  18768. // Increase the slots
  18769. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18770. // Save player data (slots) and inventory data (removed item)
  18771. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18772. // Inform the player of success
  18773. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18774. clif_inventory_expansion_info( sd );
  18775. #endif
  18776. }
  18777. void clif_parse_inventory_expansion_reject( int fd, struct map_session_data* sd ){
  18778. #if PACKETVER_MAIN_NUM >= 20181031 || PACKETVER_RE_NUM >= 20181031 || PACKETVER_ZERO_NUM >= 20181114
  18779. sd->state.inventory_expansion_confirmation = 0;
  18780. sd->state.inventory_expansion_amount = 0;
  18781. #endif
  18782. }
  18783. void clif_barter_open( struct map_session_data& sd, struct npc_data& nd ){
  18784. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18785. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18786. return;
  18787. }
  18788. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18789. if( barter == nullptr ){
  18790. return;
  18791. }
  18792. sd.state.barter_open = true;
  18793. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18794. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18795. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  18796. int16 count = 0;
  18797. for( const auto& itemPair : barter->items ){
  18798. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  18799. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18800. item->nameid = client_nameid( id->nameid );
  18801. item->type = itemtype( id->nameid );
  18802. if( itemPair.second->stockLimited ){
  18803. item->amount = itemPair.second->stock;
  18804. }else{
  18805. item->amount = -1;
  18806. }
  18807. item->weight = id->weight;
  18808. item->index = itemPair.second->index;
  18809. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18810. item->viewSprite = id->look;
  18811. item->location = pc_equippoint_sub( &sd, id.get() );
  18812. #endif
  18813. // Use a loop if someone did not start with index 0
  18814. for( const auto& requirementPair : itemPair.second->requirements ){
  18815. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18816. item->currencyNameid = client_nameid( requirement->nameid );
  18817. item->currencyAmount = requirement->amount;
  18818. // It is a normal barter, cancel after first entry
  18819. break;
  18820. }
  18821. p->packetLength += (int16)( sizeof( *item ) );
  18822. count++;
  18823. }
  18824. clif_send( p, p->packetLength, &sd.bl, SELF );
  18825. #endif
  18826. }
  18827. void clif_parse_barter_close( int fd, struct map_session_data* sd ){
  18828. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18829. if( sd->state.barter_open ){
  18830. sd->npc_shopid = 0;
  18831. sd->state.barter_open = false;
  18832. }
  18833. #endif
  18834. }
  18835. void clif_parse_barter_buy( int fd, struct map_session_data* sd ){
  18836. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18837. // No shop open
  18838. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18839. return;
  18840. }
  18841. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18842. // Unknown shop
  18843. if( nd == nullptr ){
  18844. return;
  18845. }
  18846. // Not a barter
  18847. if( nd->subtype != NPCTYPE_BARTER ){
  18848. return;
  18849. }
  18850. // It is an extended barter
  18851. if( nd->u.barter.extended ){
  18852. return;
  18853. }
  18854. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18855. if( barter == nullptr ){
  18856. return;
  18857. }
  18858. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18859. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  18860. // Empty purchase list
  18861. if( entries == 0 ){
  18862. return;
  18863. }
  18864. std::vector<s_barter_purchase> purchases;
  18865. purchases.reserve( entries );
  18866. // Make sure each shop index and target item id is only used once
  18867. for( int i = 0; i < entries; i++ ){
  18868. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18869. // Invalid shop index
  18870. if( item == nullptr ){
  18871. return;
  18872. }
  18873. for( int j = i + 1; j < entries; j++ ){
  18874. // Same shop index
  18875. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18876. return;
  18877. }
  18878. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  18879. // Invalid shop index
  18880. if( item2 == nullptr ){
  18881. return;
  18882. }
  18883. // Same target item id
  18884. if( item->nameid == item2->nameid ){
  18885. return;
  18886. }
  18887. }
  18888. s_barter_purchase purchase = {};
  18889. purchase.item = item;
  18890. purchase.amount = p->list[i].amount;
  18891. purchases.push_back( purchase );
  18892. }
  18893. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  18894. #endif
  18895. }
  18896. void clif_barter_extended_open( struct map_session_data& sd, struct npc_data& nd ){
  18897. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18898. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  18899. return;
  18900. }
  18901. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18902. if( barter == nullptr ){
  18903. return;
  18904. }
  18905. sd.state.barter_extended_open = true;
  18906. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  18907. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  18908. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  18909. p->items_count = 0;
  18910. for( const auto& itemPair : barter->items ){
  18911. // Needs dynamic calculation, because of variable currencies
  18912. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  18913. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18914. item->nameid = client_nameid( id->nameid );
  18915. item->type = itemtype( id->nameid );
  18916. if( itemPair.second->stockLimited ){
  18917. item->amount = itemPair.second->stock;
  18918. }else{
  18919. item->amount = -1;
  18920. }
  18921. item->weight = id->weight;
  18922. item->index = itemPair.second->index;
  18923. item->zeny = itemPair.second->price;
  18924. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18925. item->viewSprite = id->look;
  18926. item->location = pc_equippoint_sub( &sd, id.get() );
  18927. #endif
  18928. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  18929. p->items_count++;
  18930. item->currency_count = 0;
  18931. for( const auto& requirementPair : itemPair.second->requirements ){
  18932. // Needs dynamic calculation, because of variable currencies
  18933. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  18934. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18935. req->nameid = requirement->nameid;
  18936. if( requirement->refine >= 0 ){
  18937. req->refine_level = requirement->refine;
  18938. }else{
  18939. req->refine_level = 0;
  18940. }
  18941. req->amount = requirement->amount;
  18942. req->type = itemtype( requirement->nameid );
  18943. p->packetLength += (int16)( sizeof( *req ) );
  18944. item->currency_count++;
  18945. }
  18946. }
  18947. clif_send( p, p->packetLength, &sd.bl, SELF );
  18948. #endif
  18949. }
  18950. void clif_parse_barter_extended_close( int fd, struct map_session_data* sd ){
  18951. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18952. if( sd->state.barter_extended_open ){
  18953. sd->npc_shopid = 0;
  18954. sd->state.barter_extended_open = false;
  18955. }
  18956. #endif
  18957. }
  18958. void clif_parse_barter_extended_buy( int fd, struct map_session_data* sd ){
  18959. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18960. // No shop open
  18961. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  18962. return;
  18963. }
  18964. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18965. // Unknown shop
  18966. if( nd == nullptr ){
  18967. return;
  18968. }
  18969. // Not a barter
  18970. if( nd->subtype != NPCTYPE_BARTER ){
  18971. return;
  18972. }
  18973. // Not an extended barter
  18974. if( !nd->u.barter.extended ){
  18975. return;
  18976. }
  18977. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18978. if( barter == nullptr ){
  18979. return;
  18980. }
  18981. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18982. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  18983. // Empty purchase list
  18984. if( entries == 0 ){
  18985. return;
  18986. }
  18987. std::vector<s_barter_purchase> purchases;
  18988. purchases.reserve( entries );
  18989. // Make sure each shop index and target item id is only used once
  18990. for( int i = 0; i < entries; i++ ){
  18991. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18992. // Invalid shop index
  18993. if( item == nullptr ){
  18994. return;
  18995. }
  18996. for( int j = i + 1; j < entries; j++ ){
  18997. // Same shop index
  18998. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18999. return;
  19000. }
  19001. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19002. // Invalid shop index
  19003. if( item2 == nullptr ){
  19004. return;
  19005. }
  19006. // Same target item id
  19007. if( item->nameid == item2->nameid ){
  19008. return;
  19009. }
  19010. }
  19011. s_barter_purchase purchase = {};
  19012. purchase.item = item;
  19013. purchase.amount = p->list[i].amount;
  19014. purchases.push_back( purchase );
  19015. }
  19016. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19017. #endif
  19018. }
  19019. void clif_summon_init(struct mob_data& md) {
  19020. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19021. struct block_list* master_bl = battle_get_master(&md.bl);
  19022. if( master_bl == nullptr ){
  19023. return;
  19024. }
  19025. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19026. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19027. p.summonAID = md.bl.id;
  19028. p.CurrentHP = md.status.hp;
  19029. p.MaxHP = md.status.max_hp;
  19030. clif_send( &p, sizeof( p ), master_bl, SELF );
  19031. #endif
  19032. }
  19033. void clif_summon_hp_bar(struct mob_data& md) {
  19034. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19035. struct block_list* master_bl = battle_get_master(&md.bl);
  19036. if( master_bl == nullptr ){
  19037. return;
  19038. }
  19039. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19040. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19041. p.summonAID = md.bl.id;
  19042. p.VarId = SP_HP; // HP parameter
  19043. p.Value = md.status.hp;
  19044. clif_send( &p, sizeof( p ), master_bl, SELF );
  19045. #endif
  19046. }
  19047. void clif_laphine_synthesis_open( struct map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19048. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19049. nullpo_retv( sd );
  19050. sd->state.laphine_synthesis = synthesis->item_id;
  19051. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19052. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19053. p.itemId = client_nameid( synthesis->item_id );
  19054. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19055. #endif
  19056. }
  19057. void clif_parse_laphine_synthesis_close( int fd, struct map_session_data* sd ){
  19058. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19059. sd->state.laphine_synthesis = 0;
  19060. #endif
  19061. }
  19062. enum e_laphine_synthesis_result : int16{
  19063. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19064. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19065. LAPHINE_SYNTHESIS_ITEM = 7
  19066. };
  19067. void clif_laphine_synthesis_result( struct map_session_data* sd, enum e_laphine_synthesis_result result ){
  19068. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19069. nullpo_retv( sd );
  19070. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19071. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19072. p.result = result;
  19073. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19074. #endif
  19075. }
  19076. void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){
  19077. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19078. if( sd->state.laphine_synthesis == 0 ){
  19079. return;
  19080. }
  19081. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19082. if( sd->state.laphine_synthesis != p->itemId ){
  19083. return;
  19084. }
  19085. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19086. if( synthesis == nullptr ){
  19087. return;
  19088. }
  19089. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19090. // Player sent more or less than actually required
  19091. if( count != synthesis->requiredRequirements ){
  19092. return;
  19093. }
  19094. // Check for duplicates
  19095. for( size_t i = 0; i < count; i++ ){
  19096. for( size_t j = i + 1; j < count; j++ ){
  19097. if( p->items[i].index == p->items[j].index ){
  19098. return;
  19099. }
  19100. }
  19101. }
  19102. for( size_t i = 0; i < count; i++ ){
  19103. int16 index = server_index( p->items[i].index );
  19104. if( index >= MAX_INVENTORY ){
  19105. return;
  19106. }
  19107. if( sd->inventory_data[i] == nullptr ){
  19108. return;
  19109. }
  19110. struct item* item = &sd->inventory.u.items_inventory[index];
  19111. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19112. if( requirement == nullptr ){
  19113. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19114. return;
  19115. }
  19116. if( p->items[i].count != requirement->amount ){
  19117. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19118. return;
  19119. }
  19120. if( item->amount < requirement->amount ){
  19121. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19122. return;
  19123. }
  19124. if( item->refine < synthesis->minimumRefine ){
  19125. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19126. return;
  19127. }
  19128. if( item->refine > synthesis->maximumRefine ){
  19129. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19130. return;
  19131. }
  19132. if( item->equip != 0 ){
  19133. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19134. return;
  19135. }
  19136. if( item->equipSwitch != 0 ){
  19137. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19138. return;
  19139. }
  19140. }
  19141. // If triggered from item
  19142. if( sd->itemid == sd->state.laphine_synthesis ){
  19143. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19144. if( index < 0 ){
  19145. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19146. return;
  19147. }
  19148. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19149. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19150. return;
  19151. }
  19152. }
  19153. }
  19154. for( size_t i = 0; i < count; i++ ){
  19155. int16 index = server_index( p->items[i].index );
  19156. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19157. return;
  19158. }
  19159. }
  19160. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19161. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19162. #endif
  19163. }
  19164. void clif_laphine_upgrade_open( struct map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19165. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19166. nullpo_retv( sd );
  19167. sd->state.laphine_upgrade = upgrade->item_id;
  19168. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19169. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19170. p.itemId = client_nameid( upgrade->item_id );
  19171. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19172. #endif
  19173. }
  19174. void clif_parse_laphine_upgrade_close( int fd, struct map_session_data* sd ){
  19175. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19176. sd->state.laphine_upgrade = 0;
  19177. #endif
  19178. }
  19179. void clif_laphine_upgrade_result( struct map_session_data *sd, bool failed ){
  19180. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19181. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19182. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19183. p.result = failed;
  19184. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19185. #endif
  19186. }
  19187. static void clif_item_preview( struct map_session_data *sd, int16 index ){
  19188. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19189. nullpo_retv( sd );
  19190. struct item* item = &sd->inventory.u.items_inventory[index];
  19191. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19192. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19193. p.index = client_index( index );
  19194. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19195. p.isDamaged = item->attribute != 0;
  19196. #endif
  19197. p.refiningLevel = item->refine;
  19198. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19199. p.grade = item->enchantgrade;
  19200. #endif
  19201. clif_addcards( &p.slot, item );
  19202. clif_add_random_options( p.option_data, item );
  19203. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19204. #endif
  19205. }
  19206. void clif_parse_laphine_upgrade( int fd, struct map_session_data* sd ){
  19207. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19208. if( sd->state.laphine_upgrade == 0 ){
  19209. return;
  19210. }
  19211. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19212. if( sd->state.laphine_upgrade != p->itemId ){
  19213. return;
  19214. }
  19215. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19216. if( upgrade == nullptr ){
  19217. return;
  19218. }
  19219. uint16 index = server_index( p->index );
  19220. if( index >= MAX_INVENTORY ){
  19221. return;
  19222. }
  19223. if( sd->inventory_data[index] == nullptr ){
  19224. return;
  19225. }
  19226. struct item* item = &sd->inventory.u.items_inventory[index];
  19227. // Not a valid target item
  19228. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19229. clif_laphine_upgrade_result( sd, true );
  19230. return;
  19231. }
  19232. // If target item is not identified
  19233. if( item->identify == 0 ){
  19234. clif_laphine_upgrade_result( sd, true );
  19235. return;
  19236. }
  19237. // If target item is equipped
  19238. if( item->equip != 0 ){
  19239. clif_laphine_upgrade_result( sd, true );
  19240. return;
  19241. }
  19242. // If target item is in equipswitch
  19243. if( item->equipSwitch != 0 ){
  19244. clif_laphine_upgrade_result( sd, true );
  19245. return;
  19246. }
  19247. // Check minimum refine requirement
  19248. if( item->refine < upgrade->minimumRefine ){
  19249. clif_laphine_upgrade_result( sd, true );
  19250. return;
  19251. }
  19252. // Check maximum refine requirement
  19253. if( item->refine > upgrade->maximumRefine ){
  19254. clif_laphine_upgrade_result( sd, true );
  19255. return;
  19256. }
  19257. // If no cards are allowed
  19258. if( !upgrade->cardsAllowed ){
  19259. for( int i = 0; i < MAX_SLOTS; i++ ){
  19260. if( item->card[i] != 0 ){
  19261. clif_laphine_upgrade_result( sd, true );
  19262. return;
  19263. }
  19264. }
  19265. }
  19266. // If random options are required
  19267. if( upgrade->requiredRandomOptions > 0 ){
  19268. int i;
  19269. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19270. if( item->option[i].id != 0 ){
  19271. break;
  19272. }
  19273. }
  19274. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19275. clif_laphine_upgrade_result( sd, true );
  19276. return;
  19277. }
  19278. }
  19279. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19280. if( index2 < 0 ){
  19281. clif_laphine_upgrade_result( sd, true );
  19282. return;
  19283. }
  19284. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19285. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19286. return;
  19287. }
  19288. }
  19289. // Log removal of item
  19290. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19291. // Visually remove it from the client
  19292. clif_delitem( sd, index, 1, 0 );
  19293. // Apply the random options
  19294. if( upgrade->randomOptionGroup != nullptr ){
  19295. upgrade->randomOptionGroup->apply( *item );
  19296. }
  19297. // Change the refine rate if needed
  19298. if( upgrade->resultRefine > 0 ){
  19299. // Absolute refine level change
  19300. item->refine = max( item->refine, upgrade->resultRefine );
  19301. }else if( upgrade->resultRefineMaximum > 0 ){
  19302. // If a minimum is specified it can also downgrade
  19303. if( upgrade->resultRefineMinimum ){
  19304. item->refine = rnd_value( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum );
  19305. }else{
  19306. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19307. item->refine = rnd_value( item->refine, upgrade->resultRefineMaximum );
  19308. }
  19309. }else if( upgrade->resultRefineMinimum > 0 ){
  19310. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19311. item->refine = rnd_value( upgrade->resultRefineMinimum, MAX_REFINE );
  19312. }
  19313. // Log retrieving the item again -> with the new options
  19314. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19315. // Make it visible for the client again
  19316. clif_additem( sd, index, 1, 0 );
  19317. // Open a preview of the item
  19318. clif_item_preview( sd, index );
  19319. // Tell the client we are done
  19320. clif_laphine_upgrade_result( sd, false );
  19321. #endif
  19322. }
  19323. void clif_enchantgrade_add( struct map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19324. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19325. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19326. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19327. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19328. if( index < UINT16_MAX ){
  19329. p->index = client_index( index );
  19330. if( sd.inventory.u.items_inventory[index].refine >= gradeLevel->refine ){
  19331. p->success_chance = gradeLevel->chance / 100;
  19332. }else{
  19333. p->success_chance = 0;
  19334. }
  19335. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19336. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19337. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19338. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19339. // Not displayed by client
  19340. p->protect_itemid = 0;
  19341. p->protect_amount = 0;
  19342. int i = 0;
  19343. for( const auto& pair : gradeLevel->options ){
  19344. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19345. p->material_info[i].nameid = client_nameid( option->item );
  19346. p->material_info[i].amount = option->amount;
  19347. p->material_info[i].price = option->zeny;
  19348. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19349. p->material_info[i].breakable = option->breaking_rate > 0;
  19350. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19351. i++;
  19352. }
  19353. }else{
  19354. p->index = -1;
  19355. p->success_chance = 0;
  19356. p->blessing_info.id = 0;
  19357. p->blessing_info.amount = 0;
  19358. p->blessing_info.max_blessing = 0;
  19359. p->blessing_info.bonus = 0;
  19360. p->protect_itemid = 0;
  19361. p->protect_amount = 0;
  19362. }
  19363. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19364. #endif
  19365. }
  19366. void clif_parse_enchantgrade_add( int fd, struct map_session_data* sd ){
  19367. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19368. nullpo_retv( sd );
  19369. if( !sd->state.enchantgrade_open ){
  19370. return;
  19371. }
  19372. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19373. uint16 index = server_index( p->index );
  19374. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19375. return;
  19376. }
  19377. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19378. // Unsupported item type - no answer, because client should have actually prevented this request
  19379. if( enchantgrade == nullptr ){
  19380. return;
  19381. }
  19382. // Item can't be enhanced
  19383. if( !sd->inventory_data[index]->flag.gradable ){
  19384. return;
  19385. }
  19386. uint16 level = 0;
  19387. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19388. level = sd->inventory_data[index]->weapon_level;
  19389. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19390. level = sd->inventory_data[index]->armor_level;
  19391. }
  19392. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19393. // Cannot upgrade this weapon or armor level
  19394. if( enchantgradelevels == enchantgrade->levels.end() ){
  19395. clif_enchantgrade_add( *sd );
  19396. return;
  19397. }
  19398. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19399. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19400. if( enchantgradelevel == nullptr ){
  19401. return;
  19402. }
  19403. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19404. #endif
  19405. }
  19406. /// <summary>
  19407. /// Sends the result for trying to enchant an item
  19408. /// </summary>
  19409. /// <param name="sd">The player session</param>
  19410. /// <param name="index">The target item</param>
  19411. /// <param name="result">
  19412. /// 0= The grade has been successfully upgraded.
  19413. /// 1= Refinement failed.
  19414. /// 2= The refine level has decreased.
  19415. /// 3= Equipment destroyed.
  19416. /// 4= The equipment is protected.
  19417. /// </param>
  19418. void clif_enchantgrade_result( struct map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19419. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19420. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19421. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19422. p.index = client_index( index );
  19423. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19424. p.result = result;
  19425. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19426. #endif
  19427. }
  19428. void clif_enchantgrade_announce( struct map_session_data& sd, struct item& item, bool success ){
  19429. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19430. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19431. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19432. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19433. p.itemId = client_nameid( item.nameid );
  19434. p.grade = item.enchantgrade;
  19435. p.status = success;
  19436. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19437. #endif
  19438. }
  19439. void clif_parse_enchantgrade_start( int fd, struct map_session_data* sd ){
  19440. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19441. nullpo_retv( sd );
  19442. if( !sd->state.enchantgrade_open ){
  19443. return;
  19444. }
  19445. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19446. uint16 index = server_index( p->index );
  19447. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19448. return;
  19449. }
  19450. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19451. // Unsupported item type - no answer
  19452. if( enchantgrade == nullptr ){
  19453. return;
  19454. }
  19455. uint16 level = 0;
  19456. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19457. level = sd->inventory_data[index]->weapon_level;
  19458. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19459. level = sd->inventory_data[index]->armor_level;
  19460. }
  19461. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19462. // Cannot upgrade this weapon or armor level - no answer
  19463. if( enchantgradelevels == enchantgrade->levels.end() ){
  19464. return;
  19465. }
  19466. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19467. // Cannot increase enchantgrade any further - no answer
  19468. if( enchantgradelevel == nullptr ){
  19469. return;
  19470. }
  19471. // Not refined enough
  19472. if( sd->inventory.u.items_inventory[index].refine < enchantgradelevel->refine ){
  19473. return;
  19474. }
  19475. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19476. // Unknown option id - no answer
  19477. if( option == nullptr ){
  19478. return;
  19479. }
  19480. // Not enough zeny
  19481. if( sd->status.zeny < option->zeny ){
  19482. return;
  19483. }
  19484. uint16 totalChance = enchantgradelevel->chance;
  19485. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19486. std::unordered_map<uint16, uint16> requiredItems;
  19487. if( p->blessing_flag ){
  19488. // If the catalysator item is the same as the option item build the sum of amounts
  19489. if( enchantgradelevel->catalyst.item == option->item ){
  19490. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19491. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19492. if( index < 0 ){
  19493. return;
  19494. }
  19495. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19496. return;
  19497. }
  19498. requiredItems[index] = amount;
  19499. }else{
  19500. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19501. // Check catalysator item
  19502. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19503. if( index < 0 ){
  19504. return;
  19505. }
  19506. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19507. return;
  19508. }
  19509. requiredItems[index] = amount;
  19510. // Check option item
  19511. index = pc_search_inventory( sd, option->item );
  19512. if( index < 0 ){
  19513. return;
  19514. }
  19515. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19516. return;
  19517. }
  19518. requiredItems[index] = option->amount;
  19519. }
  19520. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19521. }else{
  19522. // Check option item
  19523. int16 index = pc_search_inventory( sd, option->item );
  19524. if( index < 0 ){
  19525. return;
  19526. }
  19527. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19528. return;
  19529. }
  19530. requiredItems[index] = option->amount;
  19531. }
  19532. // All items should be there, start deleting
  19533. for( const auto& pair : requiredItems ){
  19534. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19535. return;
  19536. }
  19537. }
  19538. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE, nullptr ) > 0 ){
  19539. return;
  19540. }
  19541. if( rnd()%10000 < totalChance ){
  19542. // Log removal of item
  19543. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19544. // Increase enchantgrade
  19545. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19546. // On successful enchantgrade increase the refine is reset
  19547. sd->inventory.u.items_inventory[index].refine = 0;
  19548. // Log retrieving the item again -> with the new refine and enchantgrade
  19549. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19550. // Show success
  19551. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19552. // Check if it has to be announced
  19553. if( enchantgradelevel->announceSuccess ){
  19554. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19555. }
  19556. }else{
  19557. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19558. if( enchantgradelevel->announceFail ){
  19559. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19560. }
  19561. // Delete the item if it is breakable
  19562. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19563. // Delete the item
  19564. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19565. // Show failure
  19566. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19567. // Downgrade the item if necessary
  19568. }else if( option->downgrade_amount > 0 ){
  19569. // Log removal of item
  19570. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19571. // Decrease refine level
  19572. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19573. // Log retrieving the item again -> with the new refine
  19574. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19575. // Show downgrade
  19576. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19577. // Only show failure, but dont do anything
  19578. }else{
  19579. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19580. }
  19581. }
  19582. #endif
  19583. }
  19584. void clif_parse_enchantgrade_close( int fd, struct map_session_data* sd ){
  19585. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19586. nullpo_retv( sd );
  19587. sd->state.enchantgrade_open = false;
  19588. #endif
  19589. }
  19590. void clif_reputation_type( struct map_session_data& sd, int64 type, int64 points ){
  19591. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19592. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19593. p->packetType = HEADER_ZC_REPUTE_INFO;
  19594. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19595. p->success = true;
  19596. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19597. entry->type = type;
  19598. entry->points = points;
  19599. clif_send( p, p->packetLength, &sd.bl, SELF );
  19600. #endif
  19601. }
  19602. void clif_reputation_list( struct map_session_data& sd ){
  19603. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19604. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19605. p->packetType = HEADER_ZC_REPUTE_INFO;
  19606. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19607. p->success = true;
  19608. size_t index = 0;
  19609. for( const auto& entry : reputation_db ){
  19610. std::shared_ptr<s_reputation> reputation = entry.second;
  19611. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19612. list_entry->type = reputation->id;
  19613. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19614. p->packetLength += sizeof( *list_entry );
  19615. index++;
  19616. }
  19617. clif_send( p, p->packetLength, &sd.bl, SELF );
  19618. #endif
  19619. }
  19620. void clif_item_reform_open( struct map_session_data& sd, t_itemid item ){
  19621. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19622. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19623. p.packetType = HEADER_ZC_OPEN_REFORM_UI;
  19624. p.itemId = item;
  19625. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19626. sd.state.item_reform = item;
  19627. #endif
  19628. }
  19629. void clif_parse_item_reform_close( int fd, struct map_session_data* sd ){
  19630. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19631. sd->state.item_reform = 0;
  19632. #endif
  19633. }
  19634. void clif_item_reform_result( struct map_session_data& sd, uint16 index, uint8 result ){
  19635. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19636. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19637. p.packetType = HEADER_ZC_ITEM_REFORM_ACK;
  19638. p.index = client_index( index );
  19639. p.result = result;
  19640. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19641. if( result == 0 ){
  19642. // Client closes the window on success
  19643. sd.state.item_reform = 0;
  19644. }
  19645. #endif
  19646. }
  19647. void clif_parse_item_reform_start( int fd, struct map_session_data* sd ){
  19648. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19649. // Not opened
  19650. if( sd->state.item_reform == 0 ){
  19651. return;
  19652. }
  19653. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19654. // Item mismatch
  19655. if( p->itemId != sd->state.item_reform ){
  19656. return;
  19657. }
  19658. uint16 index = server_index( p->index );
  19659. if( index >= MAX_INVENTORY ){
  19660. return;
  19661. }
  19662. if( sd->inventory_data[index] == nullptr ){
  19663. return;
  19664. }
  19665. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19666. if( reform == nullptr ){
  19667. return;
  19668. }
  19669. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19670. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19671. if( base == nullptr ){
  19672. return;
  19673. }
  19674. // If target item is not identified
  19675. if( selected_item.identify == 0 ){
  19676. return;
  19677. }
  19678. // If target item is equipped
  19679. if( selected_item.equip != 0 ){
  19680. return;
  19681. }
  19682. // Check minimum refine requirement
  19683. if( selected_item.refine < base->minimumRefine ){
  19684. return;
  19685. }
  19686. // Check maximum refine requirement
  19687. if( selected_item.refine > base->maximumRefine ){
  19688. return;
  19689. }
  19690. // If no cards are allowed
  19691. if( !base->cardsAllowed ){
  19692. for( int i = 0; i < MAX_SLOTS; i++ ){
  19693. if( selected_item.card[i] != 0 ){
  19694. return;
  19695. }
  19696. }
  19697. }
  19698. // If random options are required
  19699. if( base->requiredRandomOptions > 0 ){
  19700. int i;
  19701. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19702. if( selected_item.option[i].id != 0 ){
  19703. break;
  19704. }
  19705. }
  19706. if( ( i + 1 ) < base->requiredRandomOptions ){
  19707. return;
  19708. }
  19709. }
  19710. std::unordered_map<uint16, uint16> materials;
  19711. // Check if all materials exist
  19712. for( const auto& material : base->materials ){
  19713. int16 material_index = pc_search_inventory( sd, material.first );
  19714. if( material_index < 0 ){
  19715. return;
  19716. }
  19717. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19718. return;
  19719. }
  19720. materials[material_index] = material.second;
  19721. }
  19722. // Remove the material
  19723. for( const auto& material : materials ){
  19724. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19725. return;
  19726. }
  19727. }
  19728. // If triggered from item
  19729. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19730. return;
  19731. }
  19732. // Log removal of item
  19733. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19734. // Visually remove it from the client
  19735. clif_delitem( sd, index, 1, 0 );
  19736. // Apply the random options
  19737. if( base->randomOptionGroup != nullptr ){
  19738. base->randomOptionGroup->apply( selected_item );
  19739. }
  19740. // Change the refine rate if needed
  19741. if( base->refineChange != 0 ){
  19742. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19743. }
  19744. // Remove all cards and socket enchants
  19745. if( base->clearSlots ){
  19746. for( int i = 0; i < MAX_SLOTS; i++ ){
  19747. selected_item.card[i] = 0;
  19748. }
  19749. }
  19750. // Remove the current enchantgrade
  19751. if( base->removeEnchantgrade ){
  19752. selected_item.enchantgrade = 0;
  19753. }
  19754. // Finally change the item id
  19755. selected_item.nameid = base->resultItemId;
  19756. // Link inventory data cache to the new item
  19757. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19758. // Log retrieving the item again -> with the new options
  19759. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19760. // Make it visible for the client again
  19761. clif_additem( sd, index, 1, 0 );
  19762. clif_item_reform_result( *sd, index, 0 );
  19763. #endif
  19764. }
  19765. void clif_enchantwindow_open( struct map_session_data& sd, uint64 clientLuaIndex ){
  19766. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19767. // Hardcoded clientside check
  19768. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19769. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  19770. sd.state.item_enchant_index = 0;
  19771. return;
  19772. }
  19773. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19774. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19775. p.type = OUT_UI_ENCHANT;
  19776. p.data = clientLuaIndex;
  19777. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19778. sd.state.item_enchant_index = clientLuaIndex;
  19779. #endif
  19780. }
  19781. void clif_enchantwindow_result( struct map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19782. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19783. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  19784. p.packetType = HEADER_ZC_RESPONSE_ENCHANT;
  19785. if( success ){
  19786. p.messageId = C_ENCHANT_SUCCESS;
  19787. }else{
  19788. p.messageId = C_ENCHANT_FAILURE;
  19789. }
  19790. p.enchantItemId = enchant;
  19791. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19792. sd.state.item_enchant_index = 0;
  19793. #endif
  19794. }
  19795. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19796. if( selected_item.equip != 0 ){
  19797. return false;
  19798. }
  19799. if( selected_item.equipSwitch != 0 ){
  19800. return false;
  19801. }
  19802. if( selected_item.attribute != 0 ){
  19803. return false;
  19804. }
  19805. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19806. return false;
  19807. }
  19808. if( selected_item.refine < enchant->minimumRefine ){
  19809. return false;
  19810. }
  19811. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19812. return false;
  19813. }
  19814. if( !enchant->allowRandomOptions ){
  19815. for( const s_item_randomoption& option : selected_item.option ){
  19816. if( option.id != 0 ){
  19817. return false;
  19818. }
  19819. }
  19820. }
  19821. return true;
  19822. }
  19823. void clif_parse_enchantwindow_general( int fd, struct map_session_data* sd ){
  19824. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19825. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  19826. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19827. return;
  19828. }
  19829. uint16 index = server_index( p->index );
  19830. if( index >= MAX_INVENTORY ){
  19831. return;
  19832. }
  19833. if( sd->inventory_data[index] == nullptr ){
  19834. return;
  19835. }
  19836. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19837. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19838. if( enchant == nullptr ){
  19839. return;
  19840. }
  19841. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19842. return;
  19843. }
  19844. uint16 slot = MAX_SLOTS;
  19845. for( uint16 nextSlot : enchant->order ){
  19846. if( selected_item.card[nextSlot] == 0 ){
  19847. slot = nextSlot;
  19848. break;
  19849. }
  19850. }
  19851. if( slot == MAX_SLOTS ){
  19852. return;
  19853. }
  19854. if( slot < sd->inventory_data[index]->slots ){
  19855. return;
  19856. }
  19857. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19858. if( enchant_slot == nullptr ){
  19859. return;
  19860. }
  19861. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  19862. if( enchants_for_enchantgrade == nullptr ){
  19863. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  19864. clif_enchantwindow_result( *sd, false );
  19865. return;
  19866. }
  19867. if( sd->status.zeny < enchant_slot->normal.zeny ){
  19868. return;
  19869. }
  19870. std::unordered_map<uint16, uint16> materials;
  19871. for( const auto& entry : enchant_slot->normal.materials ){
  19872. int16 idx = pc_search_inventory( sd, entry.first );
  19873. if( idx < 0 ){
  19874. return;
  19875. }
  19876. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19877. return;
  19878. }
  19879. materials[idx] = entry.second;
  19880. }
  19881. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  19882. return;
  19883. }
  19884. for( const auto& entry : materials ){
  19885. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19886. return;
  19887. }
  19888. }
  19889. uint32 chance = enchant_slot->normal.chance;
  19890. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  19891. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  19892. }
  19893. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  19894. clif_enchantwindow_result( *sd, false );
  19895. return;
  19896. }
  19897. // Log removal of item
  19898. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  19899. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  19900. bool enchanted = false;
  19901. for( int i = 0; i < maximum; i++ ){
  19902. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19903. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  19904. selected_item.card[slot] = normal_enchant->item_id;
  19905. enchanted = true;
  19906. break;
  19907. }
  19908. }
  19909. if( !enchanted ){
  19910. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19911. selected_item.card[slot] = normal_enchant->item_id;
  19912. }
  19913. // Log retrieving the item again -> with the new enchant
  19914. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  19915. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  19916. #endif
  19917. }
  19918. void clif_parse_enchantwindow_perfect( int fd, struct map_session_data* sd ){
  19919. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19920. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  19921. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19922. return;
  19923. }
  19924. uint16 index = server_index( p->index );
  19925. if( index >= MAX_INVENTORY ){
  19926. return;
  19927. }
  19928. if( sd->inventory_data[index] == nullptr ){
  19929. return;
  19930. }
  19931. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19932. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  19933. if( enchant == nullptr ){
  19934. return;
  19935. }
  19936. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19937. return;
  19938. }
  19939. uint16 slot = MAX_SLOTS;
  19940. for( uint16 nextSlot : enchant->order ){
  19941. if( selected_item.card[nextSlot] == 0 ){
  19942. slot = nextSlot;
  19943. break;
  19944. }
  19945. }
  19946. if( slot == MAX_SLOTS ){
  19947. return;
  19948. }
  19949. if( slot < sd->inventory_data[index]->slots ){
  19950. return;
  19951. }
  19952. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19953. if( enchant_slot == nullptr ){
  19954. return;
  19955. }
  19956. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->itemId );
  19957. if( perfect_enchant == nullptr ){
  19958. return;
  19959. }
  19960. if( sd->status.zeny < perfect_enchant->zeny ){
  19961. return;
  19962. }
  19963. std::unordered_map<uint16, uint16> materials;
  19964. for( const auto& entry : perfect_enchant->materials ){
  19965. int16 idx = pc_search_inventory( sd, entry.first );
  19966. if( idx < 0 ){
  19967. return;
  19968. }
  19969. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19970. return;
  19971. }
  19972. materials[idx] = entry.second;
  19973. }
  19974. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  19975. return;
  19976. }
  19977. for( const auto& entry : materials ){
  19978. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19979. return;
  19980. }
  19981. }
  19982. // Log removal of item
  19983. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  19984. selected_item.card[slot] = perfect_enchant->item_id;
  19985. // Log retrieving the item again -> with the new enchant
  19986. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  19987. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  19988. #endif
  19989. }
  19990. void clif_parse_enchantwindow_upgrade( int fd, struct map_session_data* sd ){
  19991. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19992. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  19993. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  19994. return;
  19995. }
  19996. uint16 index = server_index( p->index );
  19997. if( index >= MAX_INVENTORY ){
  19998. return;
  19999. }
  20000. if( sd->inventory_data[index] == nullptr ){
  20001. return;
  20002. }
  20003. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20004. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20005. if( enchant == nullptr ){
  20006. return;
  20007. }
  20008. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20009. return;
  20010. }
  20011. uint16 slot = p->slot;
  20012. if( slot >= MAX_SLOTS ){
  20013. return;
  20014. }
  20015. if( slot < sd->inventory_data[index]->slots ){
  20016. return;
  20017. }
  20018. if( selected_item.card[slot] == 0 ){
  20019. return;
  20020. }
  20021. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20022. if( enchant_slot == nullptr ){
  20023. return;
  20024. }
  20025. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20026. if( upgrade == nullptr ){
  20027. return;
  20028. }
  20029. if( sd->status.zeny < upgrade->zeny ){
  20030. return;
  20031. }
  20032. std::unordered_map<uint16, uint16> materials;
  20033. for( const auto& entry : upgrade->materials ){
  20034. int16 idx = pc_search_inventory( sd, entry.first );
  20035. if( idx < 0 ){
  20036. return;
  20037. }
  20038. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20039. return;
  20040. }
  20041. materials[idx] = entry.second;
  20042. }
  20043. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20044. return;
  20045. }
  20046. for( const auto& entry : materials ){
  20047. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20048. return;
  20049. }
  20050. }
  20051. // Log removal of item
  20052. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20053. selected_item.card[slot] = upgrade->upgrade_item_id;
  20054. // Log retrieving the item again -> with the new enchant
  20055. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20056. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20057. #endif
  20058. }
  20059. void clif_parse_enchantwindow_reset( int fd, struct map_session_data* sd ){
  20060. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20061. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20062. if( sd->state.item_enchant_index != p->clientLuaIndex ){
  20063. return;
  20064. }
  20065. uint16 index = server_index( p->index );
  20066. if( index >= MAX_INVENTORY ){
  20067. return;
  20068. }
  20069. if( sd->inventory_data[index] == nullptr ){
  20070. return;
  20071. }
  20072. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20073. if( selected_item.equip != 0 ){
  20074. return;
  20075. }
  20076. if( selected_item.equipSwitch != 0 ){
  20077. return;
  20078. }
  20079. if( selected_item.attribute != 0 ){
  20080. return;
  20081. }
  20082. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->clientLuaIndex );
  20083. if( enchant == nullptr ){
  20084. return;
  20085. }
  20086. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20087. return;
  20088. }
  20089. if( selected_item.refine < enchant->minimumRefine ){
  20090. return;
  20091. }
  20092. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20093. return;
  20094. }
  20095. bool is_enchanted = false;
  20096. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20097. if( selected_item.card[i] != 0 ){
  20098. is_enchanted = true;
  20099. break;
  20100. }
  20101. }
  20102. if( !is_enchanted ){
  20103. return;
  20104. }
  20105. if( sd->status.zeny < enchant->reset.zeny ){
  20106. return;
  20107. }
  20108. std::unordered_map<uint16, uint16> materials;
  20109. for( const auto& entry : enchant->reset.materials ){
  20110. int16 idx = pc_search_inventory( sd, entry.first );
  20111. if( idx < 0 ){
  20112. return;
  20113. }
  20114. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20115. return;
  20116. }
  20117. materials[idx] = entry.second;
  20118. }
  20119. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT, nullptr ) != 0 ){
  20120. return;
  20121. }
  20122. for( const auto& entry : materials ){
  20123. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20124. return;
  20125. }
  20126. }
  20127. uint32 chance = enchant->reset.chance;
  20128. if( chance == 0 ){
  20129. return;
  20130. }
  20131. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20132. clif_enchantwindow_result( *sd, false );
  20133. return;
  20134. }
  20135. // Log removal of item
  20136. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20137. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20138. selected_item.card[i] = 0;
  20139. }
  20140. // Log retrieving the item again -> with the new enchant
  20141. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20142. clif_enchantwindow_result( *sd, true );
  20143. #endif
  20144. }
  20145. void clif_parse_enchantwindow_close( int fd, struct map_session_data* sd ){
  20146. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20147. sd->state.item_enchant_index = 0;
  20148. #endif
  20149. }
  20150. void clif_parse_itempackage_select( int fd, struct map_session_data* sd ){
  20151. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20152. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20153. if( p->AID != sd->status.account_id ){
  20154. return;
  20155. }
  20156. uint16 index = server_index( p->index );
  20157. if( index >= MAX_INVENTORY ){
  20158. return;
  20159. }
  20160. if( sd->inventory_data[index] == nullptr ){
  20161. return;
  20162. }
  20163. if( sd->inventory_data[index]->nameid != p->itemID ){
  20164. return;
  20165. }
  20166. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20167. return;
  20168. }
  20169. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20170. if( package == nullptr ){
  20171. return;
  20172. }
  20173. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20174. if( group == nullptr ){
  20175. return;
  20176. }
  20177. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20178. return;
  20179. }
  20180. for( const auto& entry : group->items ){
  20181. struct item item = {};
  20182. item.nameid = entry.second->item_id;
  20183. item.identify = 1;
  20184. item.refine = (char)entry.second->refine;
  20185. if( entry.second->rentalhours ){
  20186. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20187. }
  20188. // Check if it is a pet egg
  20189. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20190. if( pet != nullptr ){
  20191. for( int i = 0; i < entry.second->amount; i++ ){
  20192. pet_create_egg( sd, item.nameid );
  20193. }
  20194. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20195. for( int i = 0; i < entry.second->amount; i++ ){
  20196. // New random options on each iteration
  20197. if( entry.second->randomOptionGroup != nullptr ){
  20198. entry.second->randomOptionGroup->apply( item );
  20199. }
  20200. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20201. }
  20202. }else{
  20203. if( entry.second->randomOptionGroup != nullptr ){
  20204. entry.second->randomOptionGroup->apply( item );
  20205. }
  20206. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20207. }
  20208. }
  20209. #endif
  20210. }
  20211. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20212. {
  20213. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20214. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20215. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20216. p.itemId = itemId;
  20217. p.refine_level = level;
  20218. p.status = (int8)success;
  20219. if (battle_config.broadcast_hide_name) {
  20220. std::string dispname = clif_hide_name(sd.status.name);
  20221. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20222. }
  20223. else {
  20224. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20225. }
  20226. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20227. #endif
  20228. }
  20229. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20230. #if PACKETVER >= 20160316
  20231. nullpo_retv(sd);
  20232. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20233. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20234. return;
  20235. }
  20236. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20237. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20238. #endif
  20239. }
  20240. void clif_captcha_upload_request(map_session_data &sd) {
  20241. #if PACKETVER >= 20160330
  20242. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20243. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20244. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20245. if (sd.captcha_upload.cd != nullptr) {
  20246. p.captchaFlag = 0;
  20247. } else {
  20248. p.captchaFlag = 1;
  20249. }
  20250. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20251. #endif
  20252. }
  20253. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20254. #if PACKETVER >= 20160316
  20255. nullpo_retv(sd);
  20256. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20257. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20258. return;
  20259. }
  20260. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20261. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20262. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20263. return;
  20264. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20265. return;
  20266. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20267. #endif
  20268. }
  20269. void clif_captcha_upload_end(map_session_data &sd) {
  20270. #if PACKETVER >= 20160330
  20271. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20272. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20273. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20274. #endif
  20275. }
  20276. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20277. #if PACKETVER >= 20160323
  20278. nullpo_retv(sd);
  20279. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20280. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20281. return;
  20282. }
  20283. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20284. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20285. #endif
  20286. }
  20287. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20288. #if PACKETVER >= 20160330
  20289. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20290. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20291. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20292. if (cd == nullptr) {
  20293. p.captchaFlag = 1;
  20294. p.imageSize = 0;
  20295. } else {
  20296. p.captchaFlag = 0;
  20297. p.imageSize = cd->image_size;
  20298. }
  20299. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20300. if (cd != nullptr) {
  20301. for (uint16 offset = 0; offset < cd->image_size;) {
  20302. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20303. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20304. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20305. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20306. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20307. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20308. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20309. offset += chunk_size;
  20310. }
  20311. }
  20312. #endif
  20313. }
  20314. void clif_macro_detector_request(map_session_data &sd) {
  20315. #if PACKETVER >= 20160330
  20316. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20317. if (cd == nullptr) {
  20318. return;
  20319. }
  20320. // Send preview initialization request to the client.
  20321. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20322. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20323. p.imageSize = cd->image_size;
  20324. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20325. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20326. for (uint16 offset = 0; offset < cd->image_size;) {
  20327. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20328. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20329. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20330. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20331. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20332. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20333. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20334. offset += chunk_size;
  20335. }
  20336. #endif
  20337. }
  20338. void clif_macro_detector_request_show(map_session_data &sd) {
  20339. #if PACKETVER >= 20160330
  20340. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20341. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20342. p.retryCount = sd.macro_detect.retry;
  20343. p.timeout = battle_config.macro_detection_timeout;
  20344. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20345. #endif
  20346. }
  20347. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20348. #if PACKETVER >= 20160316
  20349. nullpo_retv(sd);
  20350. if (sd->macro_detect.retry != 0) {
  20351. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20352. clif_macro_detector_request_show(*sd);
  20353. }
  20354. #endif
  20355. }
  20356. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20357. #if PACKETVER >= 20160316
  20358. nullpo_retv(sd);
  20359. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20360. pc_macro_detector_process_answer(*sd, p->answer);
  20361. #endif
  20362. }
  20363. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20364. #if PACKETVER >= 20160330
  20365. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20366. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20367. p.status = stype;
  20368. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20369. #endif
  20370. }
  20371. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20372. #if PACKETVER >= 20160330
  20373. nullpo_retv(sd);
  20374. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20375. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20376. return;
  20377. }
  20378. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20379. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20380. #endif
  20381. }
  20382. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20383. #if PACKETVER >= 20160330
  20384. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20385. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20386. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20387. for (size_t i = 0; i < aid_list.size(); i++)
  20388. p->AID[i] = aid_list[static_cast<int32>(i)];
  20389. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20390. #endif
  20391. }
  20392. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20393. #if PACKETVER >= 20160316
  20394. nullpo_retv(sd);
  20395. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20396. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20397. return;
  20398. }
  20399. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20400. map_session_data *tsd = map_id2sd(p->AID);
  20401. if (tsd == nullptr) {
  20402. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20403. return;
  20404. }
  20405. if (tsd->macro_detect.retry != 0) {
  20406. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20407. return;
  20408. }
  20409. if (captcha_db.empty()) {
  20410. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20411. return;
  20412. }
  20413. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20414. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20415. #endif
  20416. }
  20417. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20418. #if PACKETVER >= 20160330
  20419. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20420. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20421. p.status = stype;
  20422. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20423. #endif
  20424. }
  20425. /*==========================================
  20426. * Main client packet processing function
  20427. *------------------------------------------*/
  20428. static int clif_parse(int fd)
  20429. {
  20430. int cmd, packet_len;
  20431. TBL_PC* sd;
  20432. int pnum;
  20433. #ifdef PACKET_OBFUSCATION
  20434. int cmd2;
  20435. #endif
  20436. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20437. // Note: "click masters" can do 80+ clicks in 10 seconds
  20438. 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]
  20439. { // begin main client packet processing loop
  20440. sd = (TBL_PC *)session[fd]->session_data;
  20441. if (session[fd]->flag.eof) {
  20442. if (sd) {
  20443. if (sd->state.autotrade) {
  20444. //Disassociate character from the socket connection.
  20445. session[fd]->session_data = NULL;
  20446. sd->fd = 0;
  20447. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20448. } else
  20449. if (sd->state.active) {
  20450. // Player logout display [Valaris]
  20451. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20452. clif_quitsave(fd, sd);
  20453. } else {
  20454. //Unusual logout (during log on/off/map-changer procedure)
  20455. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20456. map_quit(sd);
  20457. }
  20458. } else {
  20459. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20460. }
  20461. do_close(fd);
  20462. return 0;
  20463. }
  20464. if (RFIFOREST(fd) < 2)
  20465. return 0;
  20466. cmd = RFIFOW(fd, 0);
  20467. #ifdef PACKET_OBFUSCATION
  20468. // Check if it is a player that tries to connect to the map server.
  20469. if( sd ){
  20470. // Decrypt the current packet ID with the last key stored in the session.
  20471. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20472. }else{
  20473. // Store the original value for checking
  20474. cmd2 = cmd;
  20475. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20476. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20477. }
  20478. #endif
  20479. // filter out invalid / unsupported packets
  20480. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20481. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20482. #ifdef DUMP_INVALID_PACKET
  20483. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20484. #endif
  20485. #ifdef PACKET_OBFUSCATION_WARN
  20486. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20487. if( !sd ){
  20488. #ifdef PACKET_OBFUSCATION
  20489. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20490. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20491. }
  20492. #else
  20493. // Try to use the initial keys for the decryption of the packet ID.
  20494. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20495. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20496. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20497. }
  20498. #endif
  20499. }
  20500. #endif
  20501. set_eof(fd);
  20502. return 0;
  20503. }
  20504. // determine real packet length
  20505. packet_len = packet_db[cmd].len;
  20506. if (packet_len == -1) { // variable-length packet
  20507. if (RFIFOREST(fd) < 4)
  20508. return 0;
  20509. packet_len = RFIFOW(fd,2);
  20510. if (packet_len < 4 || packet_len > 32768) {
  20511. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20512. #ifdef DUMP_INVALID_PACKET
  20513. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20514. #endif
  20515. set_eof(fd);
  20516. return 0;
  20517. }
  20518. }
  20519. if ((int)RFIFOREST(fd) < packet_len){
  20520. 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 );
  20521. #ifdef DUMP_INVALID_PACKET
  20522. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20523. #endif
  20524. set_eof( fd );
  20525. return 0; // not enough data received to form the packet
  20526. }
  20527. #ifdef PACKET_OBFUSCATION
  20528. RFIFOW(fd, 0) = cmd;
  20529. if (sd)
  20530. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20531. #endif
  20532. if( packet_db[cmd].func == clif_parse_debug )
  20533. packet_db[cmd].func(fd, sd);
  20534. else if( packet_db[cmd].func != NULL ) {
  20535. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20536. ; //Only valid packet when there is no session
  20537. else
  20538. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20539. ; //Only valid packet when player is not on a map
  20540. else
  20541. packet_db[cmd].func(fd, sd);
  20542. }
  20543. #ifdef DUMP_UNKNOWN_PACKET
  20544. else DumpUnknown(fd,sd,cmd,packet_len);
  20545. #endif
  20546. RFIFOSKIP(fd, packet_len);
  20547. }; // main loop end
  20548. return 0;
  20549. }
  20550. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  20551. va_list argp;
  20552. int i;
  20553. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20554. return;
  20555. packet_db[cmd].len = length;
  20556. packet_db[cmd].func = func;
  20557. va_start(argp, func);
  20558. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20559. int offset = va_arg(argp, int);
  20560. if( offset == 0 ){
  20561. break;
  20562. }
  20563. packet_db[cmd].pos[i] = offset;
  20564. }
  20565. if( i == MAX_PACKET_POS ){
  20566. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20567. }
  20568. va_end(argp);
  20569. }
  20570. /*==========================================
  20571. * Reads packets and setups its array reference
  20572. *------------------------------------------*/
  20573. void packetdb_readdb(){
  20574. memset(packet_db,0,sizeof(packet_db));
  20575. #include "clif_packetdb.hpp"
  20576. #include "clif_shuffle.hpp"
  20577. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20578. #ifdef PACKET_OBFUSCATION
  20579. 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]);
  20580. #else
  20581. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20582. #endif
  20583. }
  20584. /*==========================================
  20585. *
  20586. *------------------------------------------*/
  20587. void do_init_clif(void) {
  20588. const int colors[COLOR_MAX] = {
  20589. 0x00FF00, // COLOR_DEFAULT
  20590. 0xFF0000, // COLOR_RED
  20591. 0xFFFFFF, // COLOR_WHITE
  20592. 0xFFFF00, // COLOR_YELLOW
  20593. 0x00FFFF, // COLOR_CYAN
  20594. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20595. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20596. };
  20597. /**
  20598. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20599. **/
  20600. for( int i = 0; i < COLOR_MAX; i++ ){
  20601. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20602. }
  20603. packetdb_readdb();
  20604. set_defaultparse(clif_parse);
  20605. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20606. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20607. exit(EXIT_FAILURE);
  20608. }
  20609. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20610. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20611. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20612. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20613. if( battle_config.ping_timer_interval > 0 ){
  20614. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20615. }
  20616. #endif
  20617. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20618. }
  20619. void do_final_clif(void) {
  20620. ers_destroy(delay_clearunit_ers);
  20621. }