clif.cpp 625 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700
  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. /* for clif_clearunit_delayed */
  62. static struct eri *delay_clearunit_ers;
  63. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  64. int packet_db_ack[MAX_ACK_FUNC + 1];
  65. unsigned long color_table[COLOR_MAX];
  66. #include "clif_obfuscation.hpp"
  67. static bool clif_session_isValid(struct map_session_data *sd);
  68. static void clif_loadConfirm( struct map_session_data *sd );
  69. #if PACKETVER >= 20150513
  70. enum mail_type {
  71. MAIL_TYPE_TEXT = 0x0,
  72. MAIL_TYPE_ZENY = 0x2,
  73. MAIL_TYPE_ITEM = 0x4,
  74. MAIL_TYPE_NPC = 0x8
  75. };
  76. #endif
  77. enum e_inventory_type{
  78. INVTYPE_INVENTORY = 0,
  79. INVTYPE_CART = 1,
  80. INVTYPE_STORAGE = 2,
  81. INVTYPE_GUILD_STORAGE = 3,
  82. };
  83. /** Converts item type to display it on client if necessary.
  84. * @param nameid: Item ID
  85. * @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
  86. */
  87. static inline int itemtype(unsigned short nameid) {
  88. 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
  89. int type = id->type;
  90. if( type == IT_SHADOWGEAR ) {
  91. if( id->equip&EQP_SHADOW_WEAPON )
  92. return IT_WEAPON;
  93. else
  94. return IT_ARMOR;
  95. }
  96. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  97. }
  98. // TODO: doc
  99. static inline uint16 client_index( uint16 server_index ){
  100. return server_index + 2;
  101. }
  102. static inline uint16 server_index( uint16 client_index ){
  103. return client_index - 2;
  104. }
  105. static inline uint16 client_storage_index( uint16 server_index ){
  106. return server_index + 1;
  107. }
  108. static inline uint16 server_storage_index( uint16 client_index ){
  109. return client_index - 1;
  110. }
  111. static inline uint32 disguised_bl_id( uint32 bl_id ){
  112. // Casting to prevent a compiler warning
  113. return -((int32)bl_id);
  114. }
  115. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  116. static inline uint32 client_nameid( uint32 server_nameid ){
  117. uint32 view = itemdb_viewid( server_nameid );
  118. if( view > 0 ){
  119. return view;
  120. }else{
  121. return server_nameid;
  122. }
  123. }
  124. #else
  125. static inline uint16 client_nameid( uint32 server_nameid ){
  126. uint32 view = itemdb_viewid( server_nameid );
  127. if( view > 0 ){
  128. return (uint16)view;
  129. }else{
  130. return (uint16)server_nameid;
  131. }
  132. }
  133. #endif
  134. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  135. p += pos;
  136. p[0] = (uint8)(x>>2);
  137. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  138. p[2] = (uint8)((y<<4) | (dir&0xf));
  139. }
  140. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  141. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  142. p += pos;
  143. p[0] = (uint8)(x0>>2);
  144. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  145. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  146. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  147. p[4] = (uint8)y1;
  148. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  149. }
  150. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  151. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  152. }
  153. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  154. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  155. }
  156. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  157. p += pos;
  158. if( x ) {
  159. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  160. }
  161. if( y ) {
  162. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  163. }
  164. if( dir ) {
  165. dir[0] = ( p[2] & 0x0f );
  166. }
  167. }
  168. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  169. p += pos;
  170. if( x0 ) {
  171. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  172. }
  173. if( y0 ) {
  174. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  175. }
  176. if( x1 ) {
  177. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  178. }
  179. if( y1 ) {
  180. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  181. }
  182. if( sx0 ) {
  183. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  184. }
  185. if( sy0 ) {
  186. sy0[0] = ( p[5] & 0x0f ) >> 0;
  187. }
  188. }
  189. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  190. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  191. }
  192. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  193. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  194. }
  195. //To idenfity disguised characters.
  196. static inline bool disguised(struct block_list* bl) {
  197. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  198. }
  199. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  200. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  201. if( len > max )
  202. len = max;
  203. mes[len-1] = '\0';
  204. return len;
  205. }
  206. static char map_ip_str[128];
  207. static uint32 map_ip;
  208. static uint32 bind_ip = INADDR_ANY;
  209. static uint16 map_port = 5121;
  210. static bool clif_ally_only = false;
  211. int map_fd;
  212. static int clif_parse (int fd);
  213. /*==========================================
  214. * Ip setting of map-server
  215. *------------------------------------------*/
  216. int clif_setip(const char* ip) {
  217. char ip_str[16];
  218. map_ip = host2ip(ip);
  219. if (!map_ip) {
  220. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  221. return 0;
  222. }
  223. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  224. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  225. return 1;
  226. }
  227. void clif_setbindip(const char* ip)
  228. {
  229. bind_ip = host2ip(ip);
  230. if (bind_ip) {
  231. char ip_str[16];
  232. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  233. } else {
  234. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  235. }
  236. }
  237. /*==========================================
  238. * Sets map port to 'port'
  239. * is run from map.cpp upon loading map server configuration
  240. *------------------------------------------*/
  241. void clif_setport(uint16 port)
  242. {
  243. map_port = port;
  244. }
  245. /*==========================================
  246. * Returns map server IP
  247. *------------------------------------------*/
  248. uint32 clif_getip(void)
  249. {
  250. return map_ip;
  251. }
  252. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  253. uint32 clif_refresh_ip(void)
  254. {
  255. uint32 new_ip;
  256. new_ip = host2ip(map_ip_str);
  257. if (new_ip && new_ip != map_ip) {
  258. map_ip = new_ip;
  259. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  260. return map_ip;
  261. }
  262. return 0;
  263. }
  264. /*==========================================
  265. * Returns map port which is set by clif_setport()
  266. *------------------------------------------*/
  267. uint16 clif_getport(void)
  268. {
  269. return map_port;
  270. }
  271. #if PACKETVER >= 20071106
  272. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  273. switch (bl->type) {
  274. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  275. case BL_ITEM: return 0x2; //ITEM_TYPE
  276. case BL_SKILL: return 0x3; //SKILL_TYPE
  277. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  278. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  279. case BL_NPC:
  280. // From 2017-07-26 on NPC type units can also use player sprites.
  281. // There is one exception and this is if they are walking.
  282. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  283. #if PACKETVER >= 20170726
  284. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0x6; //NPC_EVT_TYPE
  285. #else
  286. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  287. #endif
  288. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  289. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  290. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  291. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  292. default: return 0x1; //NPC_TYPE
  293. }
  294. }
  295. #endif
  296. static bool clif_session_isValid(struct map_session_data *sd) {
  297. return ( sd != NULL && session_isActive(sd->fd) );
  298. }
  299. /*==========================================
  300. * sub process of clif_send
  301. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  302. * In order to send area-wise packets, such as:
  303. * - AREA : everyone nearby your area
  304. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  305. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  306. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  307. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  308. *------------------------------------------*/
  309. static int clif_send_sub(struct block_list *bl, va_list ap)
  310. {
  311. struct block_list *src_bl;
  312. struct map_session_data *sd;
  313. unsigned char *buf;
  314. int len, type, fd;
  315. nullpo_ret(bl);
  316. nullpo_ret(sd = (struct map_session_data *)bl);
  317. // Don't send to disconnected clients.
  318. if( !session_isActive( fd = sd->fd ) ){
  319. return 0;
  320. }
  321. buf = va_arg(ap,unsigned char*);
  322. len = va_arg(ap,int);
  323. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  324. type = va_arg(ap,int);
  325. switch(type) {
  326. case AREA_WOS:
  327. if (bl == src_bl)
  328. return 0;
  329. break;
  330. case AREA_WOC:
  331. if (sd->chatID || bl == src_bl)
  332. return 0;
  333. break;
  334. case AREA_WOSC:
  335. {
  336. if(src_bl->type == BL_PC) {
  337. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  338. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  339. return 0;
  340. }
  341. else if(src_bl->type == BL_NPC) {
  342. struct npc_data *nd = (struct npc_data *)src_bl;
  343. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  344. return 0;
  345. }
  346. }
  347. break;
  348. }
  349. /* unless visible, hold it here */
  350. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  351. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  352. return 0;
  353. WFIFOHEAD(fd, len);
  354. if (WFIFOP(fd,0) == buf) {
  355. ShowError("WARNING: Invalid use of clif_send function\n");
  356. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  357. ShowError(" Please correct your code.\n");
  358. // don't send to not move the pointer of the packet for next sessions in the loop
  359. //WFIFOSET(fd,0);//## TODO is this ok?
  360. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  361. return 0;
  362. }
  363. memcpy(WFIFOP(fd,0), buf, len);
  364. WFIFOSET(fd,len);
  365. return 0;
  366. }
  367. /*==========================================
  368. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  369. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  370. *------------------------------------------*/
  371. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  372. {
  373. int i;
  374. struct map_session_data *sd, *tsd;
  375. struct party_data *p = NULL;
  376. struct guild *g = NULL;
  377. std::shared_ptr<s_battleground_data> bg;
  378. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  379. struct s_mapiterator* iter;
  380. if( type != ALL_CLIENT )
  381. nullpo_ret(bl);
  382. sd = BL_CAST(BL_PC, bl);
  383. switch(type) {
  384. case ALL_CLIENT: //All player clients.
  385. iter = mapit_getallusers();
  386. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  387. if( session_isActive( fd = tsd->fd ) ){
  388. WFIFOHEAD( fd, len );
  389. memcpy( WFIFOP( fd, 0 ), buf, len );
  390. WFIFOSET( fd, len );
  391. }
  392. }
  393. mapit_free(iter);
  394. break;
  395. case ALL_SAMEMAP: //All players on the same map
  396. iter = mapit_getallusers();
  397. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  398. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  399. WFIFOHEAD( fd, len );
  400. memcpy( WFIFOP( fd, 0 ), buf, len );
  401. WFIFOSET( fd, len );
  402. }
  403. }
  404. mapit_free(iter);
  405. break;
  406. case AREA:
  407. case AREA_WOSC:
  408. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  409. clif_send (buf, len, bl, SELF);
  410. case AREA_WOC:
  411. case AREA_WOS:
  412. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  413. BL_PC, buf, len, bl, type);
  414. break;
  415. case AREA_CHAT_WOC:
  416. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  417. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  418. break;
  419. case CHAT:
  420. case CHAT_WOS:
  421. {
  422. struct chat_data *cd;
  423. if (sd) {
  424. cd = (struct chat_data*)map_id2bl(sd->chatID);
  425. } else if (bl->type == BL_CHAT) {
  426. cd = (struct chat_data*)bl;
  427. } else break;
  428. if (cd == NULL)
  429. break;
  430. for(i = 0; i < cd->users; i++) {
  431. if (type == CHAT_WOS && cd->usersd[i] == sd)
  432. continue;
  433. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  434. WFIFOHEAD(fd,len);
  435. memcpy(WFIFOP(fd,0), buf, len);
  436. WFIFOSET(fd,len);
  437. }
  438. }
  439. }
  440. break;
  441. case PARTY_AREA:
  442. case PARTY_AREA_WOS:
  443. x0 = bl->x - AREA_SIZE;
  444. y0 = bl->y - AREA_SIZE;
  445. x1 = bl->x + AREA_SIZE;
  446. y1 = bl->y + AREA_SIZE;
  447. case PARTY:
  448. case PARTY_WOS:
  449. case PARTY_SAMEMAP:
  450. case PARTY_SAMEMAP_WOS:
  451. if (sd && sd->status.party_id)
  452. p = party_search(sd->status.party_id);
  453. if (p) {
  454. for(i=0;i<MAX_PARTY;i++){
  455. if( (sd = p->data[i].sd) == NULL )
  456. continue;
  457. if( !session_isActive( fd = sd->fd ) )
  458. continue;
  459. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  460. continue;
  461. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  462. continue;
  463. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  464. continue;
  465. WFIFOHEAD(fd, len);
  466. memcpy(WFIFOP(fd, 0), buf, len);
  467. WFIFOSET(fd, len);
  468. }
  469. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  470. break;
  471. iter = mapit_getallusers();
  472. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  473. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  474. WFIFOHEAD( fd, len );
  475. memcpy( WFIFOP( fd, 0 ), buf, len );
  476. WFIFOSET( tsd->fd, len );
  477. }
  478. }
  479. mapit_free(iter);
  480. }
  481. break;
  482. case DUEL:
  483. case DUEL_WOS:
  484. if (!sd || !sd->duel_group) break; //Invalid usage.
  485. iter = mapit_getallusers();
  486. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  487. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  488. continue;
  489. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  490. WFIFOHEAD( fd, len );
  491. memcpy( WFIFOP( fd, 0 ), buf, len );
  492. WFIFOSET( fd, len );
  493. }
  494. }
  495. mapit_free(iter);
  496. break;
  497. case SELF:
  498. if( sd && session_isActive( fd=sd->fd ) ){
  499. WFIFOHEAD(fd,len);
  500. memcpy(WFIFOP(fd,0), buf, len);
  501. WFIFOSET(fd,len);
  502. }
  503. break;
  504. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  505. case GUILD_AREA:
  506. case GUILD_AREA_WOS:
  507. x0 = bl->x - AREA_SIZE;
  508. y0 = bl->y - AREA_SIZE;
  509. x1 = bl->x + AREA_SIZE;
  510. y1 = bl->y + AREA_SIZE;
  511. case GUILD_SAMEMAP:
  512. case GUILD_SAMEMAP_WOS:
  513. case GUILD:
  514. case GUILD_WOS:
  515. case GUILD_NOBG:
  516. if (sd && sd->status.guild_id)
  517. g = sd->guild;
  518. if (g) {
  519. for(i = 0; i < g->max_member; i++) {
  520. if( (sd = g->member[i].sd) != nullptr ){
  521. if( !session_isActive( fd = sd->fd ) )
  522. continue;
  523. if( type == GUILD_NOBG && sd->bg_id )
  524. continue;
  525. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  526. continue;
  527. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  528. continue;
  529. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  530. continue;
  531. WFIFOHEAD(fd,len);
  532. memcpy(WFIFOP(fd,0), buf, len);
  533. WFIFOSET(fd,len);
  534. }
  535. }
  536. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  537. break;
  538. iter = mapit_getallusers();
  539. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  540. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  541. WFIFOHEAD( fd, len );
  542. memcpy( WFIFOP( fd, 0 ), buf, len );
  543. WFIFOSET( fd, len );
  544. }
  545. }
  546. mapit_free(iter);
  547. }
  548. break;
  549. case BG_AREA:
  550. case BG_AREA_WOS:
  551. x0 = bl->x - AREA_SIZE;
  552. y0 = bl->y - AREA_SIZE;
  553. x1 = bl->x + AREA_SIZE;
  554. y1 = bl->y + AREA_SIZE;
  555. case BG_SAMEMAP:
  556. case BG_SAMEMAP_WOS:
  557. case BG:
  558. case BG_WOS:
  559. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  560. {
  561. for (const auto &member : bg->members) {
  562. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  563. continue;
  564. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  565. continue;
  566. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  567. continue;
  568. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  569. continue;
  570. WFIFOHEAD(fd,len);
  571. memcpy(WFIFOP(fd,0), buf, len);
  572. WFIFOSET(fd,len);
  573. }
  574. }
  575. break;
  576. case CLAN:
  577. if( sd && sd->clan ){
  578. struct clan* clan = sd->clan;
  579. for( i = 0; i < clan->max_member; i++ ){
  580. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  581. continue;
  582. }
  583. WFIFOHEAD(fd,len);
  584. memcpy(WFIFOP(fd,0), buf, len);
  585. WFIFOSET(fd,len);
  586. }
  587. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  588. break;
  589. iter = mapit_getallusers();
  590. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  591. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  592. WFIFOHEAD(fd, len);
  593. memcpy(WFIFOP(fd, 0), buf, len);
  594. WFIFOSET(fd, len);
  595. }
  596. }
  597. mapit_free(iter);
  598. }
  599. break;
  600. default:
  601. ShowError("clif_send: Unrecognized type %d\n",type);
  602. return -1;
  603. }
  604. return 0;
  605. }
  606. /// Notifies the client, that it's connection attempt was accepted.
  607. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  608. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  609. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  610. void clif_authok(struct map_session_data *sd)
  611. {
  612. #if PACKETVER < 20080102
  613. const int cmd = 0x73;
  614. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  615. const int cmd = 0x2eb;
  616. #else
  617. const int cmd = 0xa18;
  618. #endif
  619. int fd = sd->fd;
  620. WFIFOHEAD(fd,packet_len(cmd));
  621. WFIFOW(fd, 0) = cmd;
  622. WFIFOL(fd, 2) = client_tick(gettick());
  623. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  624. WFIFOB(fd, 9) = 5; // ignored
  625. WFIFOB(fd,10) = 5; // ignored
  626. #if PACKETVER >= 20080102
  627. WFIFOW(fd,11) = sd->status.font;
  628. #endif
  629. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  630. WFIFOB(fd,13) = sd->status.sex;
  631. #endif
  632. WFIFOSET(fd,packet_len(cmd));
  633. }
  634. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  635. /// 0074 <error code>.B
  636. /// error code:
  637. /// 0 = client type mismatch
  638. /// 1 = ID mismatch
  639. /// 2 = mobile - out of available time
  640. /// 3 = mobile - already logged in
  641. /// 4 = mobile - waiting state
  642. void clif_authrefuse(int fd, uint8 error_code)
  643. {
  644. WFIFOHEAD(fd,packet_len(0x74));
  645. WFIFOW(fd,0) = 0x74;
  646. WFIFOB(fd,2) = error_code;
  647. WFIFOSET(fd,packet_len(0x74));
  648. }
  649. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  650. /// 0081 <error code>.B
  651. /// error code:
  652. /// 0 = BAN_UNFAIR
  653. /// 1 = server closed -> MsgStringTable[4]
  654. /// 2 = ID already logged in -> MsgStringTable[5]
  655. /// 3 = timeout/too much lag -> MsgStringTable[241]
  656. /// 4 = server full -> MsgStringTable[264]
  657. /// 5 = underaged -> MsgStringTable[305]
  658. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  659. /// 9 = too many connections from this ip -> MsgStringTable[529]
  660. /// 10 = out of available time paid for -> MsgStringTable[530]
  661. /// 11 = BAN_PAY_SUSPEND
  662. /// 12 = BAN_PAY_CHANGE
  663. /// 13 = BAN_PAY_WRONGIP
  664. /// 14 = BAN_PAY_PNGAMEROOM
  665. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  666. /// 16 = BAN_JAPAN_REFUSE1
  667. /// 17 = BAN_JAPAN_REFUSE2
  668. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  669. /// 100 = BAN_PC_IP_UNFAIR
  670. /// 101 = BAN_PC_IP_COUNT_ALL
  671. /// 102 = BAN_PC_IP_COUNT
  672. /// 103 = BAN_GRAVITY_MEM_AGREE
  673. /// 104 = BAN_GAME_MEM_AGREE
  674. /// 105 = BAN_HAN_VALID
  675. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  676. /// 107 = BAN_OVER_CHARACTER_LIST
  677. /// 108 = BAN_IP_BLOCK
  678. /// 109 = BAN_INVALID_PWD_CNT
  679. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  680. /// ? = disconnected -> MsgStringTable[3]
  681. void clif_authfail_fd(int fd, int type)
  682. {
  683. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  684. return;
  685. WFIFOHEAD(fd, packet_len(0x81));
  686. WFIFOW(fd,0) = 0x81;
  687. WFIFOB(fd,2) = type;
  688. WFIFOSET(fd,packet_len(0x81));
  689. set_eof(fd);
  690. }
  691. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  692. /// 00b3 <type>.B
  693. /// type:
  694. /// 1 = disconnect, char-select
  695. /// ? = nothing
  696. void clif_charselectok(int id, uint8 ok)
  697. {
  698. struct map_session_data* sd;
  699. int fd;
  700. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  701. return;
  702. fd = sd->fd;
  703. WFIFOHEAD(fd,packet_len(0xb3));
  704. WFIFOW(fd,0) = 0xb3;
  705. WFIFOB(fd,2) = ok;
  706. WFIFOSET(fd,packet_len(0xb3));
  707. }
  708. /// Makes an item appear on the ground.
  709. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  710. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  711. /// 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)
  712. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  713. nullpo_retv(fitem);
  714. if( fitem->item.nameid <= 0 ){
  715. return;
  716. }
  717. int view = itemdb_viewid( fitem->item.nameid );
  718. struct packet_dropflooritem p;
  719. p.PacketType = dropflooritemType;
  720. p.ITAID = fitem->bl.id;
  721. p.ITID = ( view > 0 ) ? view : fitem->item.nameid;
  722. #if PACKETVER >= 20130000 /* not sure date */
  723. p.type = itemtype( fitem->item.nameid );
  724. #endif
  725. p.IsIdentified = fitem->item.identify ? 1 : 0;
  726. p.xPos = fitem->bl.x;
  727. p.yPos = fitem->bl.y;
  728. p.subX = fitem->subx;
  729. p.subY = fitem->suby;
  730. p.count = fitem->item.amount;
  731. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  732. if( canShowEffect ){
  733. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  734. if( dropEffect > 0 ){
  735. p.showdropeffect = 1;
  736. p.dropeffectmode = dropEffect - 1;
  737. }else{
  738. p.showdropeffect = 0;
  739. p.dropeffectmode = 0;
  740. }
  741. }else{
  742. p.showdropeffect = 0;
  743. p.dropeffectmode = 0;
  744. }
  745. #endif
  746. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  747. }
  748. /// Makes an item disappear from the ground.
  749. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  750. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  751. {
  752. unsigned char buf[16];
  753. nullpo_retv(fitem);
  754. WBUFW(buf,0) = 0xa1;
  755. WBUFL(buf,2) = fitem->bl.id;
  756. if (fd == 0) {
  757. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  758. } else {
  759. WFIFOHEAD(fd,packet_len(0xa1));
  760. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  761. WFIFOSET(fd,packet_len(0xa1));
  762. }
  763. }
  764. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  765. /// 0080 <id>.L <type>.B
  766. /// type:
  767. /// 0 = out of sight
  768. /// 1 = died
  769. /// 2 = logged out
  770. /// 3 = teleport
  771. /// 4 = trickdead
  772. void clif_clearunit_single(int id, clr_type type, int fd)
  773. {
  774. WFIFOHEAD(fd, packet_len(0x80));
  775. WFIFOW(fd,0) = 0x80;
  776. WFIFOL(fd,2) = id;
  777. WFIFOB(fd,6) = type;
  778. WFIFOSET(fd, packet_len(0x80));
  779. }
  780. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  781. /// 0080 <id>.L <type>.B
  782. /// type:
  783. /// 0 = out of sight
  784. /// 1 = died
  785. /// 2 = logged out
  786. /// 3 = teleport
  787. /// 4 = trickdead
  788. void clif_clearunit_area(struct block_list* bl, clr_type type)
  789. {
  790. unsigned char buf[8];
  791. nullpo_retv(bl);
  792. WBUFW(buf,0) = 0x80;
  793. WBUFL(buf,2) = bl->id;
  794. WBUFB(buf,6) = type;
  795. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  796. if(disguised(bl)) {
  797. WBUFL(buf,2) = disguised_bl_id( bl->id );
  798. clif_send(buf, packet_len(0x80), bl, SELF);
  799. }
  800. }
  801. /// Used to make monsters with player-sprites disappear after dying
  802. /// like normal monsters, because the client does not remove those
  803. /// automatically.
  804. static TIMER_FUNC(clif_clearunit_delayed_sub){
  805. struct block_list *bl = (struct block_list *)data;
  806. clif_clearunit_area(bl, (clr_type) id);
  807. ers_free(delay_clearunit_ers,bl);
  808. return 0;
  809. }
  810. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  811. {
  812. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  813. memcpy (tbl, bl, sizeof (struct block_list));
  814. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  815. }
  816. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  817. {
  818. if(sd->sc.option&OPTION_COSTUME)
  819. {
  820. *rhand = *lhand = 0;
  821. return;
  822. }
  823. #if PACKETVER < 4
  824. *rhand = sd->status.weapon;
  825. *lhand = sd->status.shield;
  826. #else
  827. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  828. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  829. {
  830. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  831. if (id->view_id > 0)
  832. *rhand = id->view_id;
  833. else
  834. *rhand = id->nameid;
  835. } else
  836. *rhand = 0;
  837. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  838. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  839. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  840. {
  841. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  842. if (id->view_id > 0)
  843. *lhand = id->view_id;
  844. else
  845. *lhand = id->nameid;
  846. } else
  847. *lhand = 0;
  848. #endif
  849. }
  850. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  851. static int clif_setlevel_sub(int lv) {
  852. if( lv < battle_config.max_lv ) {
  853. ;
  854. } else if( lv < battle_config.aura_lv ) {
  855. lv = battle_config.max_lv - 1;
  856. } else {
  857. lv = battle_config.max_lv;
  858. }
  859. return lv;
  860. }
  861. static int clif_setlevel(struct block_list* bl) {
  862. int lv = status_get_lv(bl);
  863. if( battle_config.client_limit_unit_lv&bl->type )
  864. return clif_setlevel_sub(lv);
  865. switch( bl->type ) {
  866. case BL_NPC:
  867. case BL_PET:
  868. // npcs and pets do not have level
  869. return 0;
  870. }
  871. return lv;
  872. }
  873. /*==========================================
  874. * Prepares 'unit standing/spawning' packet
  875. *------------------------------------------*/
  876. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  877. nullpo_retv( bl );
  878. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  879. struct status_change* sc = status_get_sc( bl );
  880. struct view_data* vd = status_get_viewdata( bl );
  881. int g_id = status_get_guild_id( bl );
  882. #if PACKETVER < 20091103
  883. if( !pcdb_checkid( vd->class_ ) ){
  884. struct packet_idle_unit2 p;
  885. p.PacketType = idle_unit2Type;
  886. #if PACKETVER >= 20071106
  887. p.objecttype = clif_bl_type( bl, walking );
  888. #endif
  889. p.GID = bl->id;
  890. p.speed = status_get_speed( bl );
  891. p.bodyState = ( sc ) ? sc->opt1 : 0;
  892. p.healthState = ( sc ) ? sc->opt2 : 0;
  893. p.effectState = ( sc ) ? sc->option : 0;
  894. p.job = vd->class_;
  895. p.head = vd->hair_style;
  896. p.weapon = vd->weapon;
  897. p.accessory = vd->head_bottom;
  898. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  899. // The hell, why flags work like this?
  900. p.shield = status_get_emblem_id( bl );
  901. p.accessory2 = GetWord( g_id, 1 );
  902. p.accessory3 = GetWord( g_id, 0 );
  903. }else{
  904. p.shield = vd->shield;
  905. p.accessory2 = vd->head_top;
  906. p.accessory3 = vd->head_mid;
  907. }
  908. p.headpalette = vd->hair_color;
  909. p.bodypalette = vd->cloth_color;
  910. p.headDir = ( sd )? sd->head_dir : 0;
  911. p.GUID = g_id;
  912. p.GEmblemVer = status_get_emblem_id( bl );
  913. p.honor = ( sd ) ? sd->status.manner : 0;
  914. p.virtue = ( sc ) ? sc->opt3 : 0;
  915. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  916. p.sex = vd->sex;
  917. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  918. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  919. p.state = vd->dead_sit;
  920. p.clevel = clif_setlevel( bl );
  921. clif_send( &p, sizeof( p ), tbl, target );
  922. return;
  923. }
  924. #endif
  925. struct packet_idle_unit p;
  926. p.PacketType = idle_unitType;
  927. #if PACKETVER >= 20091103
  928. p.PacketLength = sizeof(p);
  929. p.objecttype = clif_bl_type( bl, walking );
  930. #endif
  931. #if PACKETVER >= 20131223
  932. p.AID = bl->id;
  933. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  934. #else
  935. p.GID = bl->id;
  936. #endif
  937. p.speed = status_get_speed(bl);
  938. p.bodyState = (sc) ? sc->opt1 : 0;
  939. p.healthState = (sc) ? sc->opt2 : 0;
  940. // npc option changed?
  941. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  942. struct map_session_data* sd = (struct map_session_data*)tbl;
  943. struct npc_data* nd = (struct npc_data*)bl;
  944. int option = (sc) ? sc->option : 0;
  945. if( !nd->vd.dead_sit ){
  946. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  947. option ^= OPTION_CLOAK;
  948. }
  949. }
  950. p.effectState = option;
  951. }else{
  952. p.effectState = (sc) ? sc->option : 0;
  953. }
  954. p.job = vd->class_;
  955. p.head = vd->hair_style;
  956. p.weapon = vd->weapon;
  957. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  958. p.shield = vd->shield;
  959. #endif
  960. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  961. // The hell, why flags work like this?
  962. p.accessory = status_get_emblem_id( bl );
  963. p.accessory2 = GetWord( g_id, 1 );
  964. p.accessory3 = GetWord( g_id, 0 );
  965. }else{
  966. p.accessory = vd->head_bottom;
  967. p.accessory2 = vd->head_top;
  968. p.accessory3 = vd->head_mid;
  969. }
  970. p.headpalette = vd->hair_color;
  971. p.bodypalette = vd->cloth_color;
  972. p.headDir = (sd)? sd->head_dir : 0;
  973. #if PACKETVER >= 20101124
  974. p.robe = vd->robe;
  975. #endif
  976. p.GUID = g_id;
  977. p.GEmblemVer = status_get_emblem_id( bl );
  978. p.honor = (sd) ? sd->status.manner : 0;
  979. p.virtue = (sc) ? sc->opt3 : 0;
  980. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  981. p.sex = vd->sex;
  982. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  983. p.xSize = p.ySize = (sd) ? 5 : 0;
  984. p.state = vd->dead_sit;
  985. p.clevel = clif_setlevel( bl );
  986. #if PACKETVER >= 20080102
  987. p.font = (sd) ? sd->status.font : 0;
  988. #endif
  989. #if PACKETVER >= 20120221
  990. 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 ) ) ){
  991. p.maxHP = status_get_max_hp(bl);
  992. p.HP = status_get_hp(bl);
  993. }else{
  994. p.maxHP = -1;
  995. p.HP = -1;
  996. }
  997. p.isBoss = ( bl->type == BL_MOB && ( ( ( TBL_MOB *)bl )->db->mexp > 0 ) ) ? 1 : 0;
  998. #endif
  999. #if PACKETVER >= 20150513
  1000. p.body = vd->body_style;
  1001. #endif
  1002. /* Might be earlier, this is when the named item bug began */
  1003. #if PACKETVER >= 20131223
  1004. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1005. #endif
  1006. if( disguised( bl ) ){
  1007. #if PACKETVER >= 20091103
  1008. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1009. #if PACKETVER >= 20131223
  1010. p.AID = disguised_bl_id( bl->id );
  1011. #else
  1012. p.GID = disguised_bl_id( bl->id );
  1013. #endif
  1014. #else
  1015. p.GID = disguised_bl_id( bl->id );
  1016. #endif
  1017. }
  1018. clif_send( &p, sizeof( p ), tbl, target );
  1019. }
  1020. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1021. nullpo_retv( bl );
  1022. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1023. struct status_change* sc = status_get_sc( bl );
  1024. struct view_data* vd = status_get_viewdata( bl );
  1025. int g_id = status_get_guild_id( bl );
  1026. #if PACKETVER < 20091103
  1027. if( !pcdb_checkid( vd->class_ ) ){
  1028. struct packet_spawn_unit2 p;
  1029. p.PacketType = spawn_unit2Type;
  1030. #if PACKETVER >= 20071106
  1031. p.objecttype = clif_bl_type( bl, false );
  1032. #endif
  1033. p.GID = bl->id;
  1034. p.speed = status_get_speed( bl );
  1035. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1036. p.healthState = ( sc ) ? sc->opt2 : 0;
  1037. p.effectState = ( sc ) ? sc->option : 0;
  1038. p.head = vd->hair_style;
  1039. p.weapon = vd->weapon;
  1040. p.accessory = vd->head_bottom;
  1041. p.job = vd->class_;
  1042. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1043. // The hell, why flags work like this?
  1044. p.shield = status_get_emblem_id( bl );
  1045. p.accessory2 = GetWord( g_id, 1 );
  1046. p.accessory3 = GetWord( g_id, 0 );
  1047. }else{
  1048. p.shield = vd->shield;
  1049. p.accessory2 = vd->head_top;
  1050. p.accessory3 = vd->head_mid;
  1051. }
  1052. p.headpalette = vd->hair_color;
  1053. p.bodypalette = vd->cloth_color;
  1054. p.headDir = ( sd ) ? sd->head_dir : 0;
  1055. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1056. p.sex = vd->sex;
  1057. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1058. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1059. clif_send( &p, sizeof( p ), bl, target );
  1060. return;
  1061. }
  1062. #endif
  1063. struct packet_spawn_unit p;
  1064. p.PacketType = spawn_unitType;
  1065. #if PACKETVER >= 20091103
  1066. p.PacketLength = sizeof(p);
  1067. p.objecttype = clif_bl_type( bl, false );
  1068. #endif
  1069. #if PACKETVER >= 20131223
  1070. p.AID = bl->id;
  1071. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1072. #else
  1073. p.GID = bl->id;
  1074. #endif
  1075. p.speed = status_get_speed( bl );
  1076. p.bodyState = (sc) ? sc->opt1 : 0;
  1077. p.healthState = (sc) ? sc->opt2 : 0;
  1078. p.effectState = (sc) ? sc->option : 0;
  1079. p.job = vd->class_;
  1080. p.head = vd->hair_style;
  1081. p.weapon = vd->weapon;
  1082. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1083. p.shield = vd->shield;
  1084. #endif
  1085. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1086. // The hell, why flags work like this?
  1087. p.accessory = status_get_emblem_id( bl );
  1088. p.accessory2 = GetWord( g_id, 1 );
  1089. p.accessory3 = GetWord( g_id, 0 );
  1090. }else{
  1091. p.accessory = vd->head_bottom;
  1092. p.accessory2 = vd->head_top;
  1093. p.accessory3 = vd->head_mid;
  1094. }
  1095. p.headpalette = vd->hair_color;
  1096. p.bodypalette = vd->cloth_color;
  1097. p.headDir = (sd)? sd->head_dir : 0;
  1098. #if PACKETVER >= 20101124
  1099. p.robe = vd->robe;
  1100. #endif
  1101. p.GUID = g_id;
  1102. p.GEmblemVer = status_get_emblem_id( bl );
  1103. p.honor = (sd) ? sd->status.manner : 0;
  1104. p.virtue = (sc) ? sc->opt3 : 0;
  1105. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1106. p.sex = vd->sex;
  1107. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1108. p.xSize = p.ySize = (sd) ? 5 : 0;
  1109. p.clevel = clif_setlevel( bl );
  1110. #if PACKETVER >= 20080102
  1111. p.font = (sd) ? sd->status.font : 0;
  1112. #endif
  1113. #if PACKETVER >= 20120221
  1114. 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 ) ) ){
  1115. p.maxHP = status_get_max_hp( bl );
  1116. p.HP = status_get_hp( bl );
  1117. }else{
  1118. p.maxHP = -1;
  1119. p.HP = -1;
  1120. }
  1121. p.isBoss = ( bl->type == BL_MOB && ( ( ( TBL_MOB *)bl)->db->mexp > 0 ) ) ? 1 : 0;
  1122. #endif
  1123. #if PACKETVER >= 20150513
  1124. p.body = vd->body_style;
  1125. #endif
  1126. /* Might be earlier, this is when the named item bug began */
  1127. #if PACKETVER >= 20131223
  1128. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1129. #endif
  1130. if( disguised( bl ) ){
  1131. nullpo_retv( sd );
  1132. if( sd->status.class_ != sd->disguise ){
  1133. clif_send( &p, sizeof( p ), bl, target );
  1134. }
  1135. #if PACKETVER >= 20091103
  1136. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1137. #if PACKETVER >= 20131223
  1138. p.AID = disguised_bl_id( bl->id );
  1139. #else
  1140. p.GID = disguised_bl_id( bl->id );
  1141. #endif
  1142. #else
  1143. p.GID = disguised_bl_id( bl->id );
  1144. #endif
  1145. clif_send( &p, sizeof( p ), bl, SELF );
  1146. }else{
  1147. clif_send( &p, sizeof( p ), bl, target );
  1148. }
  1149. }
  1150. /*==========================================
  1151. * Prepares 'unit walking' packet
  1152. *------------------------------------------*/
  1153. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1154. nullpo_retv( bl );
  1155. nullpo_retv( ud );
  1156. struct map_session_data* sd;
  1157. struct status_change* sc = status_get_sc( bl );
  1158. struct view_data* vd = status_get_viewdata( bl );
  1159. struct packet_unit_walking p;
  1160. int g_id = status_get_guild_id(bl);
  1161. sd = BL_CAST(BL_PC, bl);
  1162. p.PacketType = unit_walkingType;
  1163. #if PACKETVER >= 20091103
  1164. p.PacketLength = sizeof(p);
  1165. #endif
  1166. #if PACKETVER >= 20071106
  1167. p.objecttype = clif_bl_type( bl, true );
  1168. #endif
  1169. #if PACKETVER >= 20131223
  1170. p.AID = bl->id;
  1171. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1172. #else
  1173. p.GID = bl->id;
  1174. #endif
  1175. p.speed = status_get_speed(bl);
  1176. p.bodyState = (sc) ? sc->opt1 : 0;
  1177. p.healthState = (sc) ? sc->opt2 : 0;
  1178. p.effectState = (sc) ? sc->option : 0;
  1179. p.job = vd->class_;
  1180. p.head = vd->hair_style;
  1181. p.weapon = vd->weapon;
  1182. p.accessory = vd->head_bottom;
  1183. p.moveStartTime = client_tick(gettick());
  1184. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1185. p.shield = vd->shield;
  1186. #endif
  1187. p.accessory2 = vd->head_top;
  1188. p.accessory3 = vd->head_mid;
  1189. p.headpalette = vd->hair_color;
  1190. p.bodypalette = vd->cloth_color;
  1191. p.headDir = (sd) ? sd->head_dir : 0;
  1192. #if PACKETVER >= 20101124
  1193. p.robe = vd->robe;
  1194. #endif
  1195. p.GUID = g_id;
  1196. p.GEmblemVer = status_get_emblem_id(bl);
  1197. p.honor = (sd) ? sd->status.manner : 0;
  1198. p.virtue = (sc) ? sc->opt3 : 0;
  1199. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1200. p.sex = vd->sex;
  1201. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1202. p.xSize = p.ySize = (sd) ? 5 : 0;
  1203. p.clevel = clif_setlevel(bl);
  1204. #if PACKETVER >= 20080102
  1205. p.font = (sd) ? sd->status.font : 0;
  1206. #endif
  1207. #if PACKETVER >= 20120221
  1208. 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 ) ) ){
  1209. p.maxHP = status_get_max_hp(bl);
  1210. p.HP = status_get_hp(bl);
  1211. } else {
  1212. p.maxHP = -1;
  1213. p.HP = -1;
  1214. }
  1215. p.isBoss = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0;
  1216. #endif
  1217. #if PACKETVER >= 20150513
  1218. p.body = vd->body_style;
  1219. #endif
  1220. /* Might be earlier, this is when the named item bug began */
  1221. #if PACKETVER >= 20131223
  1222. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1223. #endif
  1224. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1225. if( disguised( bl ) ){
  1226. #if PACKETVER >= 20091103
  1227. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1228. #if PACKETVER >= 20131223
  1229. p.AID = disguised_bl_id( bl->id );
  1230. #else
  1231. p.GID = disguised_bl_id( bl->id );
  1232. #endif
  1233. #else
  1234. p.GID = disguised_bl_id( bl->id );
  1235. #endif
  1236. clif_send(&p,sizeof(p),bl,SELF);
  1237. }
  1238. }
  1239. //Modifies the buffer for disguise characters and sends it to self.
  1240. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1241. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1242. {
  1243. #if PACKETVER >= 20091103
  1244. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1245. WBUFL(buf,5)=-bl->id;
  1246. #elif PACKETVER >= 20071106
  1247. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1248. WBUFL(buf,3)=-bl->id;
  1249. #else
  1250. WBUFL(buf,2)=-bl->id;
  1251. #endif
  1252. clif_send(buf, len, bl, SELF);
  1253. }
  1254. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1255. /// 01b0 <id>.L <type>.B <value>.L
  1256. /// type:
  1257. /// unused
  1258. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1259. {
  1260. nullpo_retv(bl);
  1261. if(!pcdb_checkid(class_))
  1262. {// player classes yield missing sprites
  1263. unsigned char buf[16];
  1264. WBUFW(buf,0)=0x1b0;
  1265. WBUFL(buf,2)=bl->id;
  1266. WBUFB(buf,6)=type;
  1267. WBUFL(buf,7)=class_;
  1268. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1269. }
  1270. }
  1271. /// Notifies the client of an object's spirits.
  1272. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1273. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1274. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1275. {
  1276. WFIFOHEAD(fd, packet_len(0x1e1));
  1277. WFIFOW(fd,0)=0x1e1;
  1278. WFIFOL(fd,2)=sd->bl.id;
  1279. WFIFOW(fd,6)=sd->spiritball;
  1280. WFIFOSET(fd, packet_len(0x1e1));
  1281. }
  1282. /*==========================================
  1283. * Kagerou/Oboro amulet spirit
  1284. *------------------------------------------*/
  1285. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1286. {
  1287. WFIFOHEAD(fd, packet_len(0x08cf));
  1288. WFIFOW(fd,0)=0x08cf;
  1289. WFIFOL(fd,2)=sd->bl.id;
  1290. WFIFOW(fd,6)=sd->spiritcharm_type;
  1291. WFIFOW(fd,8)=sd->spiritcharm;
  1292. WFIFOSET(fd, packet_len(0x08cf));
  1293. }
  1294. /// Notifies the client of an object's souls.
  1295. /// Note: Spirit spheres and Soul spheres work on
  1296. /// seprate systems officially, but both send out
  1297. /// the same packet which leads to confusion on how
  1298. /// much soul energy a Soul Reaper acturally has
  1299. /// should the player also have spirit spheres.
  1300. /// They will likely create a new packet for this soon
  1301. /// to seprate the animations for spirit and soul spheres.
  1302. /// For now well use this and replace it later when possible. [Rytech]
  1303. ///
  1304. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1305. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1306. static void clif_soulball_single(int fd, struct map_session_data *sd)
  1307. {
  1308. WFIFOHEAD(fd, packet_len(0x1d0));
  1309. WFIFOW(fd,0)=0x1d0;
  1310. WFIFOL(fd,2)=sd->bl.id;
  1311. WFIFOW(fd,6)=sd->soulball;
  1312. WFIFOSET(fd, packet_len(0x1d0));
  1313. }
  1314. /*==========================================
  1315. * Run when player changes map / refreshes
  1316. * Tells its client to display all weather settings being used by this map
  1317. *------------------------------------------*/
  1318. static void clif_weather_check(struct map_session_data *sd)
  1319. {
  1320. int16 m = sd->bl.m;
  1321. int fd = sd->fd;
  1322. if (map_getmapflag(m, MF_SNOW)
  1323. || map_getmapflag(m, MF_CLOUDS)
  1324. || map_getmapflag(m, MF_FOG)
  1325. || map_getmapflag(m, MF_FIREWORKS)
  1326. || map_getmapflag(m, MF_SAKURA)
  1327. || map_getmapflag(m, MF_LEAVES)
  1328. || map_getmapflag(m, MF_CLOUDS2))
  1329. {
  1330. if (map_getmapflag(m, MF_SNOW))
  1331. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1332. if (map_getmapflag(m, MF_CLOUDS))
  1333. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1334. if (map_getmapflag(m, MF_CLOUDS2))
  1335. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1336. if (map_getmapflag(m, MF_FOG))
  1337. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1338. if (map_getmapflag(m, MF_FIREWORKS)) {
  1339. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1340. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1341. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1342. }
  1343. if (map_getmapflag(m, MF_SAKURA))
  1344. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1345. if (map_getmapflag(m, MF_LEAVES))
  1346. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1347. }
  1348. }
  1349. /**
  1350. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1351. **/
  1352. void clif_weather(int16 m)
  1353. {
  1354. struct s_mapiterator* iter;
  1355. struct map_session_data *sd=NULL;
  1356. iter = mapit_getallusers();
  1357. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1358. {
  1359. if( sd->bl.m == m )
  1360. clif_weather_check(sd);
  1361. }
  1362. mapit_free(iter);
  1363. }
  1364. /**
  1365. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1366. **/
  1367. int clif_spawn( struct block_list *bl, bool walking ){
  1368. struct view_data *vd;
  1369. vd = status_get_viewdata(bl);
  1370. if( !vd || vd->class_ == JT_INVISIBLE )
  1371. return 0;
  1372. /**
  1373. * Hide NPC from maya purple card.
  1374. **/
  1375. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1376. return 0;
  1377. if( bl->type == BL_NPC && !vd->dead_sit ){
  1378. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1379. }else{
  1380. clif_spawn_unit( bl, AREA_WOS );
  1381. }
  1382. if (vd->cloth_color)
  1383. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1384. if (vd->body_style)
  1385. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1386. switch (bl->type)
  1387. {
  1388. case BL_PC:
  1389. {
  1390. TBL_PC *sd = ((TBL_PC*)bl);
  1391. if (sd->spiritball > 0)
  1392. clif_spiritball(&sd->bl);
  1393. if (sd->soulball > 0)
  1394. clif_soulball(sd);
  1395. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1396. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1397. else if(sd->state.size==SZ_MEDIUM)
  1398. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1399. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1400. clif_sendbgemblem_area(sd);
  1401. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1402. clif_spiritcharm(sd);
  1403. if (sd->status.robe)
  1404. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1405. clif_efst_status_change_sub(bl, bl, AREA);
  1406. clif_hat_effects(sd,bl,AREA);
  1407. }
  1408. break;
  1409. case BL_MOB:
  1410. {
  1411. TBL_MOB *md = ((TBL_MOB*)bl);
  1412. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1413. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1414. else if(md->special_state.size==SZ_MEDIUM)
  1415. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1416. }
  1417. break;
  1418. case BL_NPC:
  1419. {
  1420. TBL_NPC *nd = ((TBL_NPC*)bl);
  1421. if( nd->size == SZ_BIG )
  1422. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1423. else if( nd->size == SZ_MEDIUM )
  1424. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1425. clif_efst_status_change_sub(bl, bl, AREA);
  1426. clif_progressbar_npc_area(nd);
  1427. }
  1428. break;
  1429. case BL_PET:
  1430. if (vd->head_bottom)
  1431. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1432. break;
  1433. }
  1434. return 0;
  1435. }
  1436. /// Sends information about owned homunculus to the client . [orn]
  1437. /// 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)
  1438. /// 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)
  1439. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1440. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1441. nullpo_retv( sd );
  1442. nullpo_retv( hd );
  1443. struct status_data *status = &hd->battle_status;
  1444. struct PACKET_ZC_PROPERTY_HOMUN p;
  1445. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1446. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1447. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1448. 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 );
  1449. p.level = hd->homunculus.level;
  1450. p.hunger = hd->homunculus.hunger;
  1451. p.intimacy = hd->homunculus.intimacy / 100;
  1452. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1453. p.itemId = 0; // equip id
  1454. #endif
  1455. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1456. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1457. p.hit = status->hit;
  1458. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1459. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1460. }else{
  1461. p.crit = status->cri / 10;
  1462. }
  1463. #ifdef RENEWAL
  1464. p.def = status->def + status->def2;
  1465. p.mdef = status->mdef + status->mdef2;
  1466. #else
  1467. p.def = status->def + status->vit;
  1468. p.mdef = status->mdef;
  1469. #endif
  1470. p.flee = status->flee;
  1471. p.amotion = (flag) ? 0 : status->amotion;
  1472. #if PACKETVER >= 20141016
  1473. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1474. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1475. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1476. p.hp = status->hp / ( status->max_hp / 100 );
  1477. p.maxHp = 100;
  1478. }else{
  1479. p.hp = status->hp;
  1480. p.maxHp = status->max_hp;
  1481. }
  1482. #else
  1483. if( status->max_hp > INT16_MAX ){
  1484. p.hp = status->hp / ( status->max_hp / 100 );
  1485. p.maxHp = 100;
  1486. }else{
  1487. p.hp = status->hp;
  1488. p.maxHp = status->max_hp;
  1489. }
  1490. #endif
  1491. if( status->max_sp > INT16_MAX ){
  1492. p.sp = status->sp / ( status->max_sp / 100 );
  1493. p.maxSp = 100;
  1494. }else{
  1495. p.sp = status->sp;
  1496. p.maxSp = status->max_sp;
  1497. }
  1498. p.exp = hd->homunculus.exp;
  1499. p.expNext = hd->exp_next;
  1500. switch( hom_class2type( hd->homunculus.class_ ) ){
  1501. case HT_REG:
  1502. case HT_EVO:
  1503. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1504. p.expNext = 0;
  1505. }
  1506. break;
  1507. case HT_S:
  1508. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1509. p.expNext = 0;
  1510. }
  1511. break;
  1512. }
  1513. p.skillPoints = hd->homunculus.skillpts;
  1514. p.range = status_get_range( &hd->bl );
  1515. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1516. #endif
  1517. }
  1518. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1519. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1520. /// type:
  1521. /// unused
  1522. /// state:
  1523. /// 0 = pre-init
  1524. /// 1 = intimacy
  1525. /// 2 = hunger
  1526. /// 3 = accessory?
  1527. /// ? = ignored
  1528. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1529. { //[orn]
  1530. int fd = sd->fd;
  1531. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1532. hom_calc_skilltree(sd->hd, 0);
  1533. WFIFOHEAD(fd, packet_len(0x230));
  1534. WFIFOW(fd,0)=0x230;
  1535. WFIFOB(fd,2)=0;
  1536. WFIFOB(fd,3)=state;
  1537. WFIFOL(fd,4)=sd->hd->bl.id;
  1538. WFIFOL(fd,8)=param;
  1539. WFIFOSET(fd,packet_len(0x230));
  1540. }
  1541. int clif_homskillinfoblock(struct map_session_data *sd)
  1542. { //[orn]
  1543. struct homun_data *hd;
  1544. int fd = sd->fd;
  1545. int i, len=4;
  1546. nullpo_ret(sd);
  1547. hd = sd->hd;
  1548. if ( !hd )
  1549. return 0 ;
  1550. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1551. WFIFOW(fd,0)=0x235;
  1552. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1553. int id = hd->homunculus.hskill[i].id;
  1554. if( id != 0 ){
  1555. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1556. short idx = hom_skill_get_index(id);
  1557. if (idx == -1)
  1558. continue;
  1559. WFIFOW(fd,len ) = id;
  1560. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1561. WFIFOW(fd,len+4) = 0;
  1562. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1563. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1564. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1565. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1566. 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;
  1567. len+=37;
  1568. }
  1569. }
  1570. WFIFOW(fd,2)=len;
  1571. WFIFOSET(fd,len);
  1572. return 0;
  1573. }
  1574. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1575. { //[orn]
  1576. struct homun_data *hd;
  1577. int fd;
  1578. short idx = -1;
  1579. nullpo_retv(sd);
  1580. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1581. return;
  1582. fd = sd->fd;
  1583. hd = sd->hd;
  1584. WFIFOHEAD(fd, packet_len(0x239));
  1585. WFIFOW(fd,0) = 0x239;
  1586. WFIFOW(fd,2) = skill_id;
  1587. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1588. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1589. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1590. 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;
  1591. WFIFOSET(fd,packet_len(0x239));
  1592. }
  1593. /// Result of request to feed a homun/merc.
  1594. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1595. /// result:
  1596. /// 0 = failure
  1597. /// 1 = success
  1598. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1599. nullpo_retv( sd );
  1600. struct PACKET_ZC_FEED_MER p;
  1601. p.packetType = 0x22f;
  1602. p.result = fail;
  1603. p.itemId = client_nameid( foodid );
  1604. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1605. }
  1606. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1607. /// 0087 <walk start time>.L <walk data>.6B
  1608. void clif_walkok(struct map_session_data *sd)
  1609. {
  1610. int fd=sd->fd;
  1611. WFIFOHEAD(fd, packet_len(0x87));
  1612. WFIFOW(fd,0)=0x87;
  1613. WFIFOL(fd,2)=client_tick(gettick());
  1614. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1615. WFIFOSET(fd,packet_len(0x87));
  1616. }
  1617. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1618. struct status_change *sc = NULL;
  1619. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1620. clif_ally_only = true;
  1621. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1622. if(vd->cloth_color)
  1623. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1624. if(vd->body_style)
  1625. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1626. switch(bl->type) {
  1627. case BL_PC:
  1628. {
  1629. TBL_PC *sd = ((TBL_PC*)bl);
  1630. // clif_movepc(sd);
  1631. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1632. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1633. else if(sd->state.size==SZ_MEDIUM)
  1634. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1635. if (sd->status.robe)
  1636. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1637. }
  1638. break;
  1639. case BL_MOB:
  1640. {
  1641. TBL_MOB *md = ((TBL_MOB*)bl);
  1642. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1643. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1644. else if(md->special_state.size==SZ_MEDIUM)
  1645. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1646. }
  1647. break;
  1648. case BL_PET:
  1649. if(vd->head_bottom) // needed to display pet equip properly
  1650. clif_pet_equip_area((TBL_PET*)bl);
  1651. break;
  1652. }
  1653. clif_ally_only = false;
  1654. }
  1655. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1656. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1657. /// Note: unit must not be self
  1658. void clif_move(struct unit_data *ud)
  1659. {
  1660. unsigned char buf[16];
  1661. struct view_data* vd;
  1662. struct block_list* bl = ud->bl;
  1663. struct status_change *sc = NULL;
  1664. vd = status_get_viewdata(bl);
  1665. if (!vd )
  1666. return;
  1667. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1668. else if( vd->class_ == JT_INVISIBLE ){
  1669. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1670. if(disguised(bl)) {
  1671. WBUFW(buf,0)=0x86;
  1672. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1673. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1674. WBUFL(buf,12)=client_tick(gettick());
  1675. clif_send(buf, packet_len(0x86), bl, SELF);
  1676. }
  1677. return;
  1678. }
  1679. /**
  1680. * Hide NPC from maya purple card.
  1681. **/
  1682. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1683. return;
  1684. if (ud->state.speed_changed) {
  1685. // Since we don't know how to update the speed of other objects,
  1686. // use the old walk packet to update the data.
  1687. ud->state.speed_changed = 0;
  1688. clif_move2(bl, vd, ud);
  1689. return;
  1690. }
  1691. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1692. clif_ally_only = true;
  1693. WBUFW(buf,0)=0x86;
  1694. WBUFL(buf,2)=bl->id;
  1695. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1696. WBUFL(buf,12)=client_tick(gettick());
  1697. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1698. if (disguised(bl)) {
  1699. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1700. clif_send(buf, packet_len(0x86), bl, SELF);
  1701. }
  1702. clif_ally_only = false;
  1703. }
  1704. /*==========================================
  1705. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1706. *------------------------------------------*/
  1707. static TIMER_FUNC(clif_delayquit){
  1708. struct map_session_data *sd = NULL;
  1709. //Remove player from map server
  1710. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1711. map_quit(sd);
  1712. return 0;
  1713. }
  1714. /*==========================================
  1715. *
  1716. *------------------------------------------*/
  1717. void clif_quitsave(int fd,struct map_session_data *sd) {
  1718. if (!battle_config.prevent_logout ||
  1719. sd->canlog_tick == 0 ||
  1720. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1721. map_quit(sd);
  1722. else if (sd->fd) {
  1723. //Disassociate session from player (session is deleted after this function was called)
  1724. //And set a timer to make him quit later.
  1725. session[sd->fd]->session_data = NULL;
  1726. sd->fd = 0;
  1727. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1728. }
  1729. }
  1730. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1731. /// 0091 <map name>.16B <x>.W <y>.W
  1732. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1733. {
  1734. int fd;
  1735. nullpo_retv(sd);
  1736. fd = sd->fd;
  1737. WFIFOHEAD(fd,packet_len(0x91));
  1738. WFIFOW(fd,0) = 0x91;
  1739. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1740. WFIFOW(fd,18) = x;
  1741. WFIFOW(fd,20) = y;
  1742. WFIFOSET(fd,packet_len(0x91));
  1743. }
  1744. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1745. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1746. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1747. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1748. {
  1749. int fd;
  1750. #if PACKETVER >= 20170315
  1751. int cmd = 0xac7;
  1752. #else
  1753. int cmd = 0x92;
  1754. #endif
  1755. nullpo_retv(sd);
  1756. fd = sd->fd;
  1757. WFIFOHEAD(fd,packet_len(cmd));
  1758. WFIFOW(fd,0) = cmd;
  1759. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1760. WFIFOW(fd,18) = x;
  1761. WFIFOW(fd,20) = y;
  1762. WFIFOL(fd,22) = htonl(ip);
  1763. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1764. #if PACKETVER >= 20170315
  1765. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1766. #endif
  1767. WFIFOSET(fd,packet_len(cmd));
  1768. }
  1769. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1770. /// This function combines both calls and allows to simplify the calling code
  1771. void clif_blown(struct block_list *bl)
  1772. {
  1773. clif_slide(bl, bl->x, bl->y);
  1774. clif_fixpos(bl);
  1775. }
  1776. /// Visually moves(slides) a character to x,y. If the target cell
  1777. /// isn't walkable, the char doesn't move at all. If the char is
  1778. /// sitting it will stand up (ZC_STOPMOVE).
  1779. /// 0088 <id>.L <x>.W <y>.W
  1780. void clif_fixpos(struct block_list *bl)
  1781. {
  1782. unsigned char buf[10];
  1783. nullpo_retv(bl);
  1784. WBUFW(buf,0) = 0x88;
  1785. WBUFL(buf,2) = bl->id;
  1786. WBUFW(buf,6) = bl->x;
  1787. WBUFW(buf,8) = bl->y;
  1788. clif_send(buf, packet_len(0x88), bl, AREA);
  1789. if( disguised(bl) ) {
  1790. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1791. clif_send(buf, packet_len(0x88), bl, SELF);
  1792. }
  1793. }
  1794. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1795. /// 00c4 <shop id>.L
  1796. void clif_npcbuysell(struct map_session_data* sd, int id)
  1797. {
  1798. int fd;
  1799. nullpo_retv(sd);
  1800. fd=sd->fd;
  1801. WFIFOHEAD(fd, packet_len(0xc4));
  1802. WFIFOW(fd,0)=0xc4;
  1803. WFIFOL(fd,2)=id;
  1804. WFIFOSET(fd,packet_len(0xc4));
  1805. }
  1806. /// Presents list of items, that can be bought in an NPC shop.
  1807. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1808. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1809. nullpo_retv( sd );
  1810. nullpo_retv( nd );
  1811. int fd = sd->fd;
  1812. if( !session_isActive( fd ) ){
  1813. return;
  1814. }
  1815. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1816. WFIFOHEAD( fd, len );
  1817. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1818. p->packetType = 0xc6;
  1819. int count = 0;
  1820. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1821. int val = nd->u.shop.shop_item[i].value;
  1822. p->items[count].price = val;
  1823. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1824. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1825. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1826. count++;
  1827. }
  1828. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1829. WFIFOSET( fd, p->packetLength );
  1830. }
  1831. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1832. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1833. void clif_selllist(struct map_session_data *sd)
  1834. {
  1835. int fd,i,c=0,val;
  1836. struct npc_data *nd;
  1837. nullpo_retv(sd);
  1838. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1839. return;
  1840. fd=sd->fd;
  1841. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1842. WFIFOW(fd,0)=0xc7;
  1843. for( i = 0; i < MAX_INVENTORY; i++ )
  1844. {
  1845. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1846. {
  1847. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1848. continue;
  1849. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1850. val = 0;
  1851. else {
  1852. val = sd->inventory_data[i]->value_sell;
  1853. if( val < 0 )
  1854. continue;
  1855. }
  1856. WFIFOW(fd,4+c*10)=i+2;
  1857. WFIFOL(fd,6+c*10)=val;
  1858. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1859. c++;
  1860. }
  1861. }
  1862. WFIFOW(fd,2)=c*10+4;
  1863. WFIFOSET(fd,WFIFOW(fd,2));
  1864. }
  1865. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1866. /// 09d4
  1867. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1868. // TODO: State tracking?
  1869. sd->npc_shopid = 0;
  1870. }
  1871. /**
  1872. * Presents list of items, that can be sold to a Market shop.
  1873. * @author: Ind and Yommy
  1874. **/
  1875. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1876. #if PACKETVER >= 20131223
  1877. nullpo_retv( sd );
  1878. nullpo_retv( nd );
  1879. if( sd->state.trading ){
  1880. return;
  1881. }
  1882. int fd = sd->fd;
  1883. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1884. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1885. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1886. int count = 0;
  1887. for( int i = 0; i < nd->u.shop.count; i++ ){
  1888. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1889. if( !item->nameid ){
  1890. continue;
  1891. }
  1892. struct item_data *id = itemdb_exists( item->nameid );
  1893. if( !id ){
  1894. continue;
  1895. }
  1896. p->list[count].nameid = client_nameid( item->nameid );
  1897. p->list[count].type = itemtype( item->nameid );
  1898. p->list[count].price = item->value;
  1899. p->list[count].qty = item->qty;
  1900. p->list[count].weight = id->weight;
  1901. count++;
  1902. }
  1903. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  1904. WFIFOSET( fd, p->packetLength );
  1905. sd->state.trading = 1;
  1906. #endif
  1907. }
  1908. /// Closes the Market shop window.
  1909. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1910. nullpo_retv(sd);
  1911. sd->npc_shopid = 0;
  1912. sd->state.trading = 0;
  1913. }
  1914. /// Purchase item from Market shop.
  1915. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1916. #if PACKETVER >= 20131223
  1917. nullpo_retv( sd );
  1918. nullpo_retv( list );
  1919. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  1920. nullpo_retv( nd );
  1921. int fd = sd->fd;
  1922. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + n * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub ) );
  1923. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)WFIFOP( fd, 0 );
  1924. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  1925. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  1926. p->result = ( res == 0 ? 0 : -1 );
  1927. #else
  1928. p->result = ( res == 0 ? 1 : 0 );
  1929. #endif
  1930. int count = 0;
  1931. if( p->result ){
  1932. for( int i = 0, j; i < n; i++ ){
  1933. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  1934. // Not found
  1935. if( j == nd->u.shop.count ){
  1936. continue;
  1937. }
  1938. p->list[count].ITID = client_nameid( list[i].nameid );
  1939. p->list[count].qty = list[i].qty;
  1940. p->list[count].price = nd->u.shop.shop_item[j].value;
  1941. count++;
  1942. }
  1943. }
  1944. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  1945. WFIFOSET( fd, p->PacketLength );
  1946. #endif
  1947. }
  1948. /// Purchase item from Market shop.
  1949. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1950. #if PACKETVER >= 20131223
  1951. nullpo_retv( sd );
  1952. if( !sd->npc_shopid ){
  1953. return;
  1954. }
  1955. const struct packet_npc_market_purchase *p = (struct packet_npc_market_purchase *)RFIFOP( fd, 0 );
  1956. int count = ( p->PacketLength - sizeof( struct packet_npc_market_purchase ) ) / sizeof( struct packet_npc_market_purchase_sub );
  1957. struct s_npc_buy_list *list;
  1958. CREATE( list, struct s_npc_buy_list, count );
  1959. // Sadly order is reverse
  1960. for( int i = 0; i < count; i++ ){
  1961. list[i].nameid = p->list[i].ITID;
  1962. list[i].qty = p->list[i].qty;
  1963. }
  1964. uint8 res = npc_buylist( sd, count, list );
  1965. clif_npc_market_purchase_ack( sd, res, count, list );
  1966. aFree( list );
  1967. #endif
  1968. }
  1969. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1970. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1971. /// Client behavior (dialog window):
  1972. /// - disable mouse targeting
  1973. /// - open the dialog window
  1974. /// - set npcid of dialog window (0 by default)
  1975. /// - if set to clear on next mes, clear contents
  1976. /// - append this text
  1977. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1978. {
  1979. int fd = sd->fd;
  1980. int slen = strlen(mes) + 9;
  1981. WFIFOHEAD(fd, slen);
  1982. WFIFOW(fd,0)=0xb4;
  1983. WFIFOW(fd,2)=slen;
  1984. WFIFOL(fd,4)=npcid;
  1985. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1986. WFIFOSET(fd,WFIFOW(fd,2));
  1987. }
  1988. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1989. /// 00b5 <npc id>.L
  1990. /// Client behavior (dialog window):
  1991. /// - disable mouse targeting
  1992. /// - open the dialog window
  1993. /// - add 'next' button
  1994. /// When 'next' is pressed:
  1995. /// - 00B9 <npcid of dialog window>.L
  1996. /// - set to clear on next mes
  1997. /// - remove 'next' button
  1998. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1999. {
  2000. int fd;
  2001. nullpo_retv(sd);
  2002. fd=sd->fd;
  2003. WFIFOHEAD(fd, packet_len(0xb5));
  2004. WFIFOW(fd,0)=0xb5;
  2005. WFIFOL(fd,2)=npcid;
  2006. WFIFOSET(fd,packet_len(0xb5));
  2007. }
  2008. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2009. /// 00b6 <npc id>.L
  2010. /// Client behavior:
  2011. /// - if dialog window is open:
  2012. /// - remove 'next' button
  2013. /// - add 'close' button
  2014. /// - else:
  2015. /// - enable mouse targeting
  2016. /// - close the dialog window
  2017. /// - close the menu window
  2018. /// When 'close' is pressed:
  2019. /// - enable mouse targeting
  2020. /// - close the dialog window
  2021. /// - close the menu window
  2022. /// - 0146 <npcid of dialog window>.L
  2023. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2024. {
  2025. int fd;
  2026. nullpo_retv(sd);
  2027. fd=sd->fd;
  2028. WFIFOHEAD(fd, packet_len(0xb6));
  2029. WFIFOW(fd,0)=0xb6;
  2030. WFIFOL(fd,2)=npcid;
  2031. WFIFOSET(fd,packet_len(0xb6));
  2032. }
  2033. /**
  2034. * Close script when player is idle
  2035. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2036. * @author [Ind/Hercules]
  2037. * @param sd : player pointer
  2038. * @param npcid : npc gid to close
  2039. */
  2040. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2041. {
  2042. struct s_packet_db* info;
  2043. int16 len;
  2044. int cmd = 0;
  2045. int fd;
  2046. nullpo_retv(sd);
  2047. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2048. if(!cmd) cmd = 0x8d6; //default
  2049. info = &packet_db[cmd];
  2050. len = info->len;
  2051. fd = sd->fd;
  2052. WFIFOHEAD(fd, len);
  2053. WFIFOW(fd,0)=0x8d6;
  2054. WFIFOL(fd,info->pos[0])=npcid;
  2055. WFIFOSET(fd,len);
  2056. }
  2057. /*==========================================
  2058. *
  2059. *------------------------------------------*/
  2060. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2061. unsigned char *buf;
  2062. int fd = sd->fd;
  2063. sd->state.using_fake_npc = 1;
  2064. WFIFOHEAD(fd, packet_len(0x78));
  2065. buf = WFIFOP(fd,0);
  2066. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2067. WBUFW(buf,0)=0x78;
  2068. #if PACKETVER >= 20071106
  2069. WBUFB(buf,2) = 0; // object type
  2070. buf = WFIFOP(fd,1);
  2071. #endif
  2072. WBUFL(buf,2)=npcid;
  2073. WBUFW(buf,14)=111;
  2074. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2075. WBUFB(buf,49)=5;
  2076. WBUFB(buf,50)=5;
  2077. WFIFOSET(fd, packet_len(0x78));
  2078. }
  2079. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2080. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2081. /// Client behavior:
  2082. /// - disable mouse targeting
  2083. /// - close the menu window
  2084. /// - open the menu window
  2085. /// - add options to the menu (separated in the text by ":")
  2086. /// - set npcid of menu window
  2087. /// - if dialog window is open:
  2088. /// - remove 'next' button
  2089. /// When 'ok' is pressed:
  2090. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2091. /// - close the menu window
  2092. /// When 'cancel' is pressed:
  2093. /// - 00B8 <npcid of menu window>.L <-1>.B
  2094. /// - enable mouse targeting
  2095. /// - close a bunch of windows...
  2096. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2097. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2098. /// TODO investigate behavior of other windows [FlavioJS]
  2099. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2100. {
  2101. int fd = sd->fd;
  2102. int slen = strlen(mes) + 9;
  2103. struct block_list *bl = NULL;
  2104. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2105. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2106. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2107. clif_sendfakenpc(sd, npcid);
  2108. WFIFOHEAD(fd, slen);
  2109. WFIFOW(fd,0)=0xb7;
  2110. WFIFOW(fd,2)=slen;
  2111. WFIFOL(fd,4)=npcid;
  2112. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2113. WFIFOSET(fd,WFIFOW(fd,2));
  2114. }
  2115. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2116. /// 0142 <npc id>.L
  2117. /// Client behavior (inputnum window):
  2118. /// - if npcid exists in the client:
  2119. /// - open the inputnum window
  2120. /// - set npcid of inputnum window
  2121. /// When 'ok' is pressed:
  2122. /// - if inputnum window has text:
  2123. /// - if npcid exists in the client:
  2124. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2125. /// - close inputnum window
  2126. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2127. {
  2128. int fd;
  2129. struct block_list *bl = NULL;
  2130. nullpo_retv(sd);
  2131. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2132. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2133. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2134. clif_sendfakenpc(sd, npcid);
  2135. fd=sd->fd;
  2136. WFIFOHEAD(fd, packet_len(0x142));
  2137. WFIFOW(fd,0)=0x142;
  2138. WFIFOL(fd,2)=npcid;
  2139. WFIFOSET(fd,packet_len(0x142));
  2140. }
  2141. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2142. /// 01d4 <npc id>.L
  2143. /// Client behavior (inputstr window):
  2144. /// - if npcid is 0 or npcid exists in the client:
  2145. /// - open the inputstr window
  2146. /// - set npcid of inputstr window
  2147. /// When 'ok' is pressed:
  2148. /// - if inputstr window has text and isn't an insult(manner.txt):
  2149. /// - if npcid is 0 or npcid exists in the client:
  2150. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2151. /// - close inputstr window
  2152. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2153. {
  2154. int fd;
  2155. struct block_list *bl = NULL;
  2156. nullpo_retv(sd);
  2157. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2158. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2159. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2160. clif_sendfakenpc(sd, npcid);
  2161. fd=sd->fd;
  2162. WFIFOHEAD(fd, packet_len(0x1d4));
  2163. WFIFOW(fd,0)=0x1d4;
  2164. WFIFOL(fd,2)=npcid;
  2165. WFIFOSET(fd,packet_len(0x1d4));
  2166. }
  2167. /// Marks a position on client's minimap (ZC_COMPASS).
  2168. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2169. /// npc id:
  2170. /// is ignored in the client
  2171. /// type:
  2172. /// 0 = display mark for 15 seconds
  2173. /// 1 = display mark until dead or teleported
  2174. /// 2 = remove mark
  2175. /// color:
  2176. /// 0x00RRGGBB
  2177. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2178. {
  2179. int fd;
  2180. nullpo_retv(sd);
  2181. fd=sd->fd;
  2182. WFIFOHEAD(fd, packet_len(0x144));
  2183. WFIFOW(fd,0)=0x144;
  2184. WFIFOL(fd,2)=npc_id;
  2185. WFIFOL(fd,6)=type;
  2186. WFIFOL(fd,10)=x;
  2187. WFIFOL(fd,14)=y;
  2188. WFIFOB(fd,18)=id;
  2189. WFIFOL(fd,19)=color;
  2190. WFIFOSET(fd,packet_len(0x144));
  2191. }
  2192. /// Displays an illustration image.
  2193. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2194. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2195. /// type:
  2196. /// 0 = bottom left corner
  2197. /// 1 = bottom middle
  2198. /// 2 = bottom right corner
  2199. /// 3 = middle of screen, inside a movable window
  2200. /// 4 = middle of screen, movable with a close button, chrome-less
  2201. /// 255 = clear all displayed cutins
  2202. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2203. {
  2204. int fd;
  2205. nullpo_retv(sd);
  2206. fd=sd->fd;
  2207. WFIFOHEAD(fd, packet_len(0x1b3));
  2208. WFIFOW(fd,0)=0x1b3;
  2209. strncpy(WFIFOCP(fd,2),image,64);
  2210. WFIFOB(fd,66)=type;
  2211. WFIFOSET(fd,packet_len(0x1b3));
  2212. }
  2213. /*==========================================
  2214. * Fills in card data from the given item and into the buffer. [Skotlex]
  2215. *------------------------------------------*/
  2216. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2217. nullpo_retv( buf );
  2218. // Blank data
  2219. if( item == nullptr ){
  2220. buf->card[0] = 0;
  2221. buf->card[1] = 0;
  2222. buf->card[2] = 0;
  2223. buf->card[3] = 0;
  2224. return;
  2225. }
  2226. // Pet eggs
  2227. if( item->card[0] == CARD0_PET ){
  2228. buf->card[0] = 0;
  2229. buf->card[1] = 0;
  2230. // Pet intimacy
  2231. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2232. buf->card[2] = item->card[3] >> 1;
  2233. // Pet renamed flag
  2234. buf->card[3] = item->card[3] & 1;
  2235. return;
  2236. }
  2237. // Forged/created items
  2238. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2239. buf->card[0] = item->card[0];
  2240. buf->card[1] = item->card[1];
  2241. buf->card[2] = item->card[2];
  2242. buf->card[3] = item->card[3];
  2243. return;
  2244. }
  2245. int i = 0, j;
  2246. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2247. if( MAX_SLOTS > 4 && ( j = itemdb_slot( item->nameid ) ) > 4 ){
  2248. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2249. }
  2250. // Normal items.
  2251. if( item->card[i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2252. buf->card[0] = j;
  2253. }else{
  2254. buf->card[0] = item->card[i];
  2255. }
  2256. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2257. buf->card[1] = j;
  2258. }else{
  2259. buf->card[1] = item->card[i];
  2260. }
  2261. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2262. buf->card[2] = j;
  2263. }else{
  2264. buf->card[2] = item->card[i];
  2265. }
  2266. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2267. buf->card[3] = j;
  2268. }else{
  2269. buf->card[3] = item->card[i];
  2270. }
  2271. }
  2272. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2273. /// A maximum of 5 random options can be supported.
  2274. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2275. nullpo_retr( 0, it );
  2276. uint8 count = 0;
  2277. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2278. if( it->option[i].id ){
  2279. buf[i].index = it->option[i].id; // OptIndex
  2280. buf[i].value = it->option[i].value; // Value
  2281. buf[i].param = it->option[i].param; // Param1
  2282. count++;
  2283. }else{
  2284. buf[i].index = 0;
  2285. buf[i].value = 0;
  2286. buf[i].param = 0;
  2287. }
  2288. }
  2289. #if MAX_ITEM_RDM_OPT < 5
  2290. for( ; i < 5; i++ ){
  2291. buf[i].index = 0; // OptIndex
  2292. buf[i].value = 0; // Value
  2293. buf[i].param = 0; // Param1
  2294. }
  2295. #endif
  2296. return count;
  2297. }
  2298. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2299. /// 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)
  2300. /// 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)
  2301. /// 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)
  2302. /// 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)
  2303. /// 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)
  2304. /// 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)
  2305. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2306. nullpo_retv( sd );
  2307. int fd = sd->fd;
  2308. if( !session_isActive( fd ) ){
  2309. return;
  2310. }
  2311. struct packet_additem p;
  2312. if( fail ){
  2313. p = {};
  2314. }else{
  2315. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <= 0 || sd->inventory_data[n] == nullptr ){
  2316. return;
  2317. }
  2318. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2319. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2320. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2321. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2322. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2323. p.location = pc_equippoint(sd,n);
  2324. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2325. #if PACKETVER >= 20061218
  2326. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2327. #endif
  2328. #if PACKETVER >= 20071002
  2329. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2330. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2331. */
  2332. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2333. #endif
  2334. #if PACKETVER >= 20150226
  2335. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2336. #endif
  2337. #if PACKETVER >= 20160921
  2338. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2339. p.look = sd->inventory_data[n]->look;
  2340. #endif
  2341. }
  2342. p.PacketType = additemType;
  2343. p.Index = client_index( n );
  2344. p.count = amount;
  2345. p.result = fail;
  2346. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2347. }
  2348. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2349. /// 00af <index>.W <amount>.W
  2350. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2351. {
  2352. int fd;
  2353. nullpo_retv(sd);
  2354. fd=sd->fd;
  2355. WFIFOHEAD(fd, packet_len(0xaf));
  2356. WFIFOW(fd,0)=0xaf;
  2357. WFIFOW(fd,2)=n+2;
  2358. WFIFOW(fd,4)=amount;
  2359. WFIFOSET(fd,packet_len(0xaf));
  2360. }
  2361. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2362. /// 07fa <delete type>.W <index>.W <amount>.W
  2363. /// delete type:
  2364. /// 0 = Normal
  2365. /// 1 = Item used for a skill
  2366. /// 2 = Refine failed
  2367. /// 3 = Material changed
  2368. /// 4 = Moved to storage
  2369. /// 5 = Moved to cart
  2370. /// 6 = Item sold
  2371. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2372. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2373. {
  2374. #if PACKETVER < 20091117
  2375. clif_dropitem(sd,n,amount);
  2376. #else
  2377. int fd;
  2378. nullpo_retv(sd);
  2379. fd=sd->fd;
  2380. WFIFOHEAD(fd, packet_len(0x7fa));
  2381. WFIFOW(fd,0)=0x7fa;
  2382. WFIFOW(fd,2)=reason;
  2383. WFIFOW(fd,4)=n+2;
  2384. WFIFOW(fd,6)=amount;
  2385. WFIFOSET(fd,packet_len(0x7fa));
  2386. #endif
  2387. }
  2388. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2389. nullpo_retv( p );
  2390. nullpo_retv( it );
  2391. nullpo_retv( id );
  2392. p->index = idx;
  2393. p->ITID = client_nameid( it->nameid );
  2394. p->type = itemtype( it->nameid );
  2395. #if PACKETVER < 20120925
  2396. p->IsIdentified = it->identify ? 1 : 0;
  2397. #endif
  2398. p->location = eqp_pos;
  2399. p->WearState = it->equip;
  2400. #if PACKETVER < 20120925
  2401. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2402. #endif
  2403. p->RefiningLevel = it->refine;
  2404. clif_addcards( &p->slot, it );
  2405. #if PACKETVER >= 20071002
  2406. p->HireExpireDate = it->expire_time;
  2407. #endif
  2408. #if PACKETVER >= 20080102
  2409. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2410. #endif
  2411. #if PACKETVER >= 20100629
  2412. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2413. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2414. #endif
  2415. #if PACKETVER >= 20120925
  2416. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2417. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2418. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2419. p->Flag.SpareBits = 0;
  2420. #endif
  2421. #if PACKETVER >= 20150226
  2422. p->option_count = clif_add_random_options( p->option_data, it );
  2423. #endif
  2424. }
  2425. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2426. nullpo_retv(p);
  2427. nullpo_retv(i);
  2428. nullpo_retv(id);
  2429. p->index = idx;
  2430. p->ITID = client_nameid( i->nameid );
  2431. p->type = itemtype( i->nameid );
  2432. #if PACKETVER < 20120925
  2433. p->IsIdentified = i->identify ? 1 : 0;
  2434. #endif
  2435. p->count = i->amount;
  2436. p->WearState = id->equip;
  2437. #if PACKETVER >= 5
  2438. clif_addcards( &p->slot, i );
  2439. #endif
  2440. #if PACKETVER >= 20080102
  2441. p->HireExpireDate = i->expire_time;
  2442. #endif
  2443. #if PACKETVER >= 20120925
  2444. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2445. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2446. p->Flag.SpareBits = 0;
  2447. #endif
  2448. }
  2449. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2450. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2451. nullpo_retv(sd);
  2452. nullpo_retv(name);
  2453. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2454. memset(buf, 0, sizeof(buf));
  2455. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2456. p->packetType = HEADER_ZC_INVENTORY_START;
  2457. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2458. p->invType = type;
  2459. #endif
  2460. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2461. int strLen = (int)safestrnlen(name, 24) + 1;
  2462. if (strLen > 24)
  2463. strLen = 24;
  2464. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2465. p->packetLength = len;
  2466. safestrncpy(p->name, name, strLen);
  2467. #else
  2468. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2469. safestrncpy(p->name, name, NAME_LENGTH);
  2470. #endif
  2471. clif_send( p, len, &sd->bl, SELF );
  2472. #endif
  2473. }
  2474. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2475. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2476. nullpo_retv(sd);
  2477. struct PACKET_ZC_INVENTORY_END p;
  2478. p.packetType = HEADER_ZC_INVENTORY_END;
  2479. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2480. p.invType = type;
  2481. #endif
  2482. p.flag = 0;
  2483. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2484. #endif
  2485. }
  2486. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2487. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2488. void clif_inventorylist( struct map_session_data *sd ){
  2489. nullpo_retv( sd );
  2490. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2491. e_inventory_type type = INVTYPE_INVENTORY;
  2492. clif_inventoryStart( sd, type, "" );
  2493. #endif
  2494. static struct packet_itemlist_normal itemlist_normal;
  2495. static struct packet_itemlist_equip itemlist_equip;
  2496. int equip = 0;
  2497. int normal = 0;
  2498. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2499. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == nullptr ){
  2500. continue;
  2501. }
  2502. // Non-stackable (Equippable)
  2503. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2504. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2505. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2506. itemlist_equip.PacketType = inventorylistequipType;
  2507. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2508. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2509. itemlist_equip.invType = type;
  2510. #endif
  2511. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2512. equip = 0;
  2513. }
  2514. // Stackable (Normal)
  2515. }else{
  2516. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2517. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2518. itemlist_normal.PacketType = inventorylistnormalType;
  2519. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2520. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2521. itemlist_normal.invType = type;
  2522. #endif
  2523. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2524. normal = 0;
  2525. }
  2526. }
  2527. }
  2528. if( normal ){
  2529. itemlist_normal.PacketType = inventorylistnormalType;
  2530. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2531. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2532. itemlist_normal.invType = type;
  2533. #endif
  2534. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2535. }
  2536. if( sd->equip_index[EQI_AMMO] >= 0 )
  2537. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2538. if( equip ) {
  2539. itemlist_equip.PacketType = inventorylistequipType;
  2540. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2541. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2542. itemlist_equip.invType = type;
  2543. #endif
  2544. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2545. }
  2546. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2547. clif_inventoryEnd( sd, type );
  2548. #endif
  2549. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2550. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2551. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2552. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2553. continue;
  2554. if ( sd->inventory.u.items_inventory[i].favorite )
  2555. clif_favorite_item(sd, i);
  2556. }
  2557. #endif
  2558. }
  2559. //Required when items break/get-repaired. Only sends equippable item list.
  2560. void clif_equiplist( struct map_session_data *sd ){
  2561. // TODO: implement again => only send equip part
  2562. clif_inventorylist( sd );
  2563. }
  2564. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2565. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2566. e_inventory_type type = INVTYPE_STORAGE;
  2567. clif_inventoryStart( sd, type, storename );
  2568. #endif
  2569. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2570. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2571. int equip = 0;
  2572. int normal = 0;
  2573. for( int i = 0; i < items_length; i++ ){
  2574. if( items[i].nameid <= 0 ){
  2575. continue;
  2576. }
  2577. struct item_data* id = itemdb_search( items[i].nameid );
  2578. // Non-stackable (Equippable)
  2579. if( !itemdb_isstackable2( id ) ){
  2580. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2581. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2582. storage_itemlist_equip.PacketType = storageListEquipType;
  2583. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2584. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2585. storage_itemlist_equip.invType = type;
  2586. #elif PACKETVER >= 20120925
  2587. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2588. #endif
  2589. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2590. equip = 0;
  2591. }
  2592. // Stackable (Normal)
  2593. }else{
  2594. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2595. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2596. storage_itemlist_normal.PacketType = storageListNormalType;
  2597. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2598. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2599. storage_itemlist_normal.invType = type;
  2600. #elif PACKETVER >= 20120925
  2601. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2602. #endif
  2603. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2604. normal = 0;
  2605. }
  2606. }
  2607. }
  2608. if( normal ){
  2609. storage_itemlist_normal.PacketType = storageListNormalType;
  2610. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2611. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2612. storage_itemlist_normal.invType = type;
  2613. #elif PACKETVER >= 20120925
  2614. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2615. #endif
  2616. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2617. }
  2618. if( equip ) {
  2619. storage_itemlist_equip.PacketType = storageListEquipType;
  2620. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2621. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2622. storage_itemlist_equip.invType = type;
  2623. #elif PACKETVER >= 20120925
  2624. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2625. #endif
  2626. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2627. }
  2628. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2629. clif_inventoryEnd( sd, type );
  2630. #endif
  2631. }
  2632. void clif_cartlist( struct map_session_data *sd ){
  2633. nullpo_retv( sd );
  2634. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2635. e_inventory_type type = INVTYPE_CART;
  2636. clif_inventoryStart( sd, type, "" );
  2637. #endif
  2638. static struct packet_itemlist_normal itemlist_normal;
  2639. static struct packet_itemlist_equip itemlist_equip;
  2640. int normal = 0;
  2641. int equip = 0;
  2642. for( int i = 0; i < MAX_CART; i++ ){
  2643. if( sd->cart.u.items_cart[i].nameid <= 0 ){
  2644. continue;
  2645. }
  2646. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2647. // Non-stackable (Equippable)
  2648. if( !itemdb_isstackable2(id) ){
  2649. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2650. // Stackable (Normal)
  2651. }else{
  2652. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2653. }
  2654. }
  2655. if( normal ){
  2656. itemlist_normal.PacketType = cartlistnormalType;
  2657. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2658. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2659. itemlist_normal.invType = type;
  2660. #endif
  2661. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2662. }
  2663. if( equip ){
  2664. itemlist_equip.PacketType = cartlistequipType;
  2665. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2666. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2667. itemlist_equip.invType = type;
  2668. #endif
  2669. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2670. }
  2671. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2672. clif_inventoryEnd( sd, type );
  2673. #endif
  2674. }
  2675. /// Removes cart (ZC_CARTOFF).
  2676. /// 012b
  2677. /// Client behaviour:
  2678. /// Closes the cart storage and removes all it's items from memory.
  2679. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2680. void clif_clearcart(int fd)
  2681. {
  2682. WFIFOHEAD(fd, packet_len(0x12b));
  2683. WFIFOW(fd,0) = 0x12b;
  2684. WFIFOSET(fd, packet_len(0x12b));
  2685. }
  2686. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2687. /// 01eb <account id>.L <x>.W <y>.W
  2688. void clif_guild_xy(struct map_session_data *sd)
  2689. {
  2690. unsigned char buf[10];
  2691. nullpo_retv(sd);
  2692. WBUFW(buf,0)=0x1eb;
  2693. WBUFL(buf,2)=sd->status.account_id;
  2694. WBUFW(buf,6)=sd->bl.x;
  2695. WBUFW(buf,8)=sd->bl.y;
  2696. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2697. }
  2698. /*==========================================
  2699. * Sends x/y dot to a single fd. [Skotlex]
  2700. *------------------------------------------*/
  2701. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2702. {
  2703. if( sd->bg_id )
  2704. return;
  2705. WFIFOHEAD(fd,packet_len(0x1eb));
  2706. WFIFOW(fd,0)=0x1eb;
  2707. WFIFOL(fd,2)=sd->status.account_id;
  2708. WFIFOW(fd,6)=sd->bl.x;
  2709. WFIFOW(fd,8)=sd->bl.y;
  2710. WFIFOSET(fd,packet_len(0x1eb));
  2711. }
  2712. // Guild XY locators [Valaris]
  2713. void clif_guild_xy_remove(struct map_session_data *sd)
  2714. {
  2715. unsigned char buf[10];
  2716. nullpo_retv(sd);
  2717. WBUFW(buf,0)=0x1eb;
  2718. WBUFL(buf,2)=sd->status.account_id;
  2719. WBUFW(buf,6)=-1;
  2720. WBUFW(buf,8)=-1;
  2721. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2722. }
  2723. /*==========================================
  2724. *
  2725. *------------------------------------------*/
  2726. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2727. {
  2728. struct map_session_data *sd, *tsd;
  2729. #if PACKETVER < 20100126
  2730. const int cmd = 0x106;
  2731. #else
  2732. const int cmd = 0x80e;
  2733. #endif
  2734. sd = va_arg(ap, struct map_session_data *);
  2735. tsd = (TBL_PC *)bl;
  2736. nullpo_ret(sd);
  2737. nullpo_ret(tsd);
  2738. if( !tsd->fd || tsd == sd )
  2739. return 0;
  2740. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2741. return 0;
  2742. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2743. WFIFOW(tsd->fd,0) = cmd;
  2744. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2745. #if PACKETVER < 20100126
  2746. if( sd->battle_status.max_hp > INT16_MAX )
  2747. { //To correctly display the %hp bar. [Skotlex]
  2748. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2749. WFIFOW(tsd->fd,8) = 100;
  2750. } else {
  2751. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2752. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2753. }
  2754. #else
  2755. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2756. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2757. #endif
  2758. WFIFOSET(tsd->fd,packet_len(cmd));
  2759. return 0;
  2760. }
  2761. /*==========================================
  2762. * Server tells all players that are allowed to view HP bars
  2763. * and are nearby 'sd' that 'sd' hp bar was updated.
  2764. *------------------------------------------*/
  2765. static int clif_hpmeter(struct map_session_data *sd)
  2766. {
  2767. nullpo_ret(sd);
  2768. 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);
  2769. return 0;
  2770. }
  2771. /// Notifies client of a character parameter change.
  2772. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2773. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2774. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2775. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2776. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2777. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2778. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2779. /// TODO: Extract individual packets.
  2780. /// FIXME: Packet lengths from packet_len(cmd)
  2781. void clif_updatestatus(struct map_session_data *sd,int type)
  2782. {
  2783. int fd,len=8;
  2784. nullpo_retv(sd);
  2785. fd=sd->fd;
  2786. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2787. return;
  2788. WFIFOHEAD(fd, 14);
  2789. WFIFOW(fd,0)=0xb0;
  2790. WFIFOW(fd,2)=type;
  2791. switch(type){
  2792. // 00b0
  2793. case SP_WEIGHT:
  2794. pc_updateweightstatus(sd);
  2795. WFIFOHEAD(fd,14);
  2796. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2797. WFIFOW(fd,2)=type;
  2798. WFIFOL(fd,4)=sd->weight;
  2799. break;
  2800. case SP_MAXWEIGHT:
  2801. WFIFOL(fd,4)=sd->max_weight;
  2802. break;
  2803. case SP_SPEED:
  2804. WFIFOL(fd,4)=sd->battle_status.speed;
  2805. break;
  2806. case SP_BASELEVEL:
  2807. WFIFOL(fd,4)=sd->status.base_level;
  2808. break;
  2809. case SP_JOBLEVEL:
  2810. WFIFOL(fd,4)=sd->status.job_level;
  2811. break;
  2812. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2813. WFIFOL(fd,4)=sd->status.karma;
  2814. break;
  2815. case SP_MANNER:
  2816. WFIFOL(fd,4)=sd->status.manner;
  2817. break;
  2818. case SP_STATUSPOINT:
  2819. WFIFOL(fd,4)=sd->status.status_point;
  2820. break;
  2821. case SP_SKILLPOINT:
  2822. WFIFOL(fd,4)=sd->status.skill_point;
  2823. break;
  2824. case SP_HIT:
  2825. WFIFOL(fd,4)=sd->battle_status.hit;
  2826. break;
  2827. case SP_FLEE1:
  2828. WFIFOL(fd,4)=sd->battle_status.flee;
  2829. break;
  2830. case SP_FLEE2:
  2831. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2832. break;
  2833. case SP_MAXHP:
  2834. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2835. break;
  2836. case SP_MAXSP:
  2837. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2838. break;
  2839. case SP_HP:
  2840. // On officials the HP never go below 1, even if you die [Lemongrass]
  2841. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2842. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2843. break;
  2844. case SP_SP:
  2845. WFIFOL(fd,4)=sd->battle_status.sp;
  2846. break;
  2847. case SP_ASPD:
  2848. WFIFOL(fd,4)=sd->battle_status.amotion;
  2849. break;
  2850. case SP_ATK1:
  2851. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2852. break;
  2853. case SP_DEF1:
  2854. WFIFOL(fd,4)=pc_leftside_def(sd);
  2855. break;
  2856. case SP_MDEF1:
  2857. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2858. break;
  2859. case SP_ATK2:
  2860. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2861. break;
  2862. case SP_DEF2:
  2863. WFIFOL(fd,4)=pc_rightside_def(sd);
  2864. break;
  2865. case SP_MDEF2: {
  2866. //negative check (in case you have something like Berserk active)
  2867. int mdef2 = pc_rightside_mdef(sd);
  2868. WFIFOL(fd,4)=
  2869. #ifndef RENEWAL
  2870. ( mdef2 < 0 ) ? 0 :
  2871. #endif
  2872. mdef2;
  2873. }
  2874. break;
  2875. case SP_CRITICAL:
  2876. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2877. break;
  2878. case SP_MATK1:
  2879. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2880. break;
  2881. case SP_MATK2:
  2882. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2883. break;
  2884. case SP_ZENY:
  2885. WFIFOW(fd,0)=0xb1;
  2886. WFIFOL(fd,4)=sd->status.zeny;
  2887. break;
  2888. #if PACKETVER >= 20170830
  2889. case SP_BASEEXP:
  2890. WFIFOW(fd,0)=0xacb;
  2891. WFIFOQ(fd,4)=sd->status.base_exp;
  2892. len = packet_len(0xacb);
  2893. break;
  2894. case SP_JOBEXP:
  2895. WFIFOW(fd,0)=0xacb;
  2896. WFIFOQ(fd,4)=sd->status.job_exp;
  2897. len = packet_len(0xacb);
  2898. break;
  2899. case SP_NEXTBASEEXP:
  2900. WFIFOW(fd,0)=0xacb;
  2901. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2902. len = packet_len(0xacb);
  2903. break;
  2904. case SP_NEXTJOBEXP:
  2905. WFIFOW(fd,0)=0xacb;
  2906. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2907. len = packet_len(0xacb);
  2908. break;
  2909. #else
  2910. case SP_BASEEXP:
  2911. WFIFOW(fd,0)=0xb1;
  2912. WFIFOL(fd,4)=sd->status.base_exp;
  2913. break;
  2914. case SP_JOBEXP:
  2915. WFIFOW(fd,0)=0xb1;
  2916. WFIFOL(fd,4)=sd->status.job_exp;
  2917. break;
  2918. case SP_NEXTBASEEXP:
  2919. WFIFOW(fd,0)=0xb1;
  2920. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2921. break;
  2922. case SP_NEXTJOBEXP:
  2923. WFIFOW(fd,0)=0xb1;
  2924. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2925. break;
  2926. #endif
  2927. /**
  2928. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2929. **/
  2930. case SP_USTR:
  2931. case SP_UAGI:
  2932. case SP_UVIT:
  2933. case SP_UINT:
  2934. case SP_UDEX:
  2935. case SP_ULUK:
  2936. WFIFOW(fd,0)=0xbe;
  2937. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2938. len=5;
  2939. break;
  2940. /**
  2941. * Tells the client how far it is allowed to attack (weapon range)
  2942. **/
  2943. case SP_ATTACKRANGE:
  2944. WFIFOW(fd,0)=0x13a;
  2945. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2946. len=4;
  2947. break;
  2948. case SP_STR:
  2949. WFIFOW(fd,0)=0x141;
  2950. WFIFOL(fd,2)=type;
  2951. WFIFOL(fd,6)=sd->status.str;
  2952. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2953. len=14;
  2954. break;
  2955. case SP_AGI:
  2956. WFIFOW(fd,0)=0x141;
  2957. WFIFOL(fd,2)=type;
  2958. WFIFOL(fd,6)=sd->status.agi;
  2959. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2960. len=14;
  2961. break;
  2962. case SP_VIT:
  2963. WFIFOW(fd,0)=0x141;
  2964. WFIFOL(fd,2)=type;
  2965. WFIFOL(fd,6)=sd->status.vit;
  2966. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2967. len=14;
  2968. break;
  2969. case SP_INT:
  2970. WFIFOW(fd,0)=0x141;
  2971. WFIFOL(fd,2)=type;
  2972. WFIFOL(fd,6)=sd->status.int_;
  2973. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2974. len=14;
  2975. break;
  2976. case SP_DEX:
  2977. WFIFOW(fd,0)=0x141;
  2978. WFIFOL(fd,2)=type;
  2979. WFIFOL(fd,6)=sd->status.dex;
  2980. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2981. len=14;
  2982. break;
  2983. case SP_LUK:
  2984. WFIFOW(fd,0)=0x141;
  2985. WFIFOL(fd,2)=type;
  2986. WFIFOL(fd,6)=sd->status.luk;
  2987. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2988. len=14;
  2989. break;
  2990. case SP_CARTINFO:
  2991. WFIFOW(fd,0)=0x121;
  2992. WFIFOW(fd,2)=sd->cart_num;
  2993. WFIFOW(fd,4)=MAX_CART;
  2994. WFIFOL(fd,6)=sd->cart_weight;
  2995. WFIFOL(fd,10)=sd->cart_weight_max;
  2996. len=14;
  2997. break;
  2998. default:
  2999. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3000. return;
  3001. }
  3002. WFIFOSET(fd,len);
  3003. // Additional update packets that should be sent right after
  3004. switch( type ){
  3005. case SP_BASELEVEL:
  3006. if( sd->status.party_id ){
  3007. struct party_data* p;
  3008. int i;
  3009. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3010. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3011. if( i < MAX_PARTY ){
  3012. p->party.member[i].lv = sd->status.base_level;
  3013. clif_party_job_and_level(sd);
  3014. }
  3015. }
  3016. }
  3017. break;
  3018. case SP_HP:
  3019. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3020. clif_hpmeter(sd);
  3021. }
  3022. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3023. clif_party_hp(sd);
  3024. }
  3025. if( sd->bg_id ){
  3026. clif_bg_hp(sd);
  3027. }
  3028. break;
  3029. }
  3030. }
  3031. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3032. /// 01ab <account id>.L <var id>.W <value>.L
  3033. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3034. {
  3035. unsigned char buf[12];
  3036. nullpo_retv(sd);
  3037. WBUFW(buf,0)=0x1ab;
  3038. WBUFL(buf,2)=sd->bl.id;
  3039. WBUFW(buf,6)=type;
  3040. switch(type)
  3041. {
  3042. case SP_MANNER:
  3043. WBUFL(buf,8)=val;
  3044. break;
  3045. default:
  3046. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3047. return;
  3048. }
  3049. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3050. }
  3051. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3052. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3053. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3054. struct PACKET_ZC_SPRITE_CHANGE p;
  3055. p.packetType = sendLookType;
  3056. p.AID = id;
  3057. p.type = type;
  3058. p.val = val;
  3059. #if PACKETVER >= 4
  3060. p.val2 = val2;
  3061. #endif
  3062. clif_send( &p, sizeof( p ), bl, target );
  3063. }
  3064. /// Updates sprite/style properties of an object.
  3065. void clif_changelook(struct block_list *bl, int type, int val) {
  3066. struct map_session_data* sd;
  3067. struct status_change* sc;
  3068. struct view_data* vd;
  3069. enum send_target target = AREA;
  3070. int val2 = 0;
  3071. nullpo_retv(bl);
  3072. sd = BL_CAST(BL_PC, bl);
  3073. sc = status_get_sc(bl);
  3074. vd = status_get_viewdata(bl);
  3075. if( vd ) //temp hack to let Warp Portal change appearance
  3076. switch(type) {
  3077. case LOOK_WEAPON:
  3078. if (sd) {
  3079. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3080. val = vd->weapon;
  3081. }
  3082. else
  3083. vd->weapon = val;
  3084. break;
  3085. case LOOK_SHIELD:
  3086. if (sd) {
  3087. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3088. val = vd->shield;
  3089. }
  3090. else
  3091. vd->shield = val;
  3092. break;
  3093. case LOOK_BASE:
  3094. if (!sd)
  3095. break;
  3096. if ( val == JT_INVISIBLE )
  3097. return;
  3098. if (sd->sc.option&OPTION_COSTUME)
  3099. vd->weapon = vd->shield = 0;
  3100. if (!vd->cloth_color)
  3101. break;
  3102. if (sd) {
  3103. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3104. vd->cloth_color = 0;
  3105. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3106. vd->cloth_color = 0;
  3107. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3108. vd->cloth_color = 0;
  3109. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3110. vd->cloth_color = 0;
  3111. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3112. vd->cloth_color = 0;
  3113. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3114. vd->body_style = 0;
  3115. }
  3116. break;
  3117. case LOOK_HAIR:
  3118. vd->hair_style = val;
  3119. break;
  3120. case LOOK_HEAD_BOTTOM:
  3121. vd->head_bottom = val;
  3122. break;
  3123. case LOOK_HEAD_TOP:
  3124. vd->head_top = val;
  3125. break;
  3126. case LOOK_HEAD_MID:
  3127. vd->head_mid = val;
  3128. break;
  3129. case LOOK_HAIR_COLOR:
  3130. vd->hair_color = val;
  3131. break;
  3132. case LOOK_CLOTHES_COLOR:
  3133. if (val && sd) {
  3134. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3135. val = 0;
  3136. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3137. val = 0;
  3138. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3139. val = 0;
  3140. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3141. val = 0;
  3142. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3143. val = 0;
  3144. }
  3145. vd->cloth_color = val;
  3146. break;
  3147. case LOOK_SHOES:
  3148. #if PACKETVER > 3
  3149. if (sd) {
  3150. int n;
  3151. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3152. if(sd->inventory_data[n]->view_id > 0)
  3153. val = sd->inventory_data[n]->view_id;
  3154. else
  3155. val = sd->inventory.u.items_inventory[n].nameid;
  3156. } else
  3157. val = 0;
  3158. }
  3159. #endif
  3160. //Shoes? No packet uses this....
  3161. break;
  3162. case LOOK_BODY:
  3163. // unknown purpose
  3164. break;
  3165. case LOOK_ROBE:
  3166. #if PACKETVER < 20110111
  3167. return;
  3168. #else
  3169. vd->robe = val;
  3170. #endif
  3171. break;
  3172. case LOOK_BODY2:
  3173. #if PACKETVER < 20150513
  3174. return;
  3175. #else
  3176. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3177. val = 0;
  3178. vd->body_style = val;
  3179. #endif
  3180. break;
  3181. }
  3182. // prevent leaking the presence of GM-hidden objects
  3183. if( sc && sc->option&OPTION_INVISIBLE )
  3184. target = SELF;
  3185. #if PACKETVER < 4
  3186. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3187. #else
  3188. if (bl->type != BL_NPC) {
  3189. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3190. type = LOOK_WEAPON;
  3191. val = (vd ? vd->weapon : 0);
  3192. val2 = (vd ? vd->shield : 0);
  3193. }
  3194. if (disguised(bl)) {
  3195. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3196. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3197. } else
  3198. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3199. } else
  3200. unit_refresh(bl);
  3201. #endif
  3202. }
  3203. //Sends a change-base-look packet required for traps as they are triggered.
  3204. void clif_changetraplook(struct block_list *bl,int val) {
  3205. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3206. }
  3207. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3208. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3209. clif_sprite_change(bl, id, type, val, 0, target);
  3210. }
  3211. /// Character status (ZC_STATUS).
  3212. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3213. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3214. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3215. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3216. void clif_initialstatus(struct map_session_data *sd) {
  3217. int fd, mdef2;
  3218. unsigned char *buf;
  3219. nullpo_retv(sd);
  3220. fd=sd->fd;
  3221. WFIFOHEAD(fd, packet_len(0xbd));
  3222. buf = WFIFOP(fd,0);
  3223. WBUFW(buf,0) = 0xbd;
  3224. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3225. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3226. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3227. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3228. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3229. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3230. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3231. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3232. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3233. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3234. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3235. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3236. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3237. WBUFW(buf,16) = pc_leftside_atk(sd);
  3238. WBUFW(buf,18) = pc_rightside_atk(sd);
  3239. WBUFW(buf,20) = pc_rightside_matk(sd);
  3240. WBUFW(buf,22) = pc_leftside_matk(sd);
  3241. WBUFW(buf,24) = pc_leftside_def(sd);
  3242. WBUFW(buf,26) = pc_rightside_def(sd);
  3243. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3244. mdef2 = pc_rightside_mdef(sd);
  3245. WBUFW(buf,30) =
  3246. #ifndef RENEWAL
  3247. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3248. #endif
  3249. mdef2;
  3250. WBUFW(buf,32) = sd->battle_status.hit;
  3251. WBUFW(buf,34) = sd->battle_status.flee;
  3252. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3253. WBUFW(buf,38) = sd->battle_status.cri/10;
  3254. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3255. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3256. WFIFOSET(fd, packet_len(0xbd));
  3257. clif_updatestatus(sd, SP_STR);
  3258. clif_updatestatus(sd, SP_AGI);
  3259. clif_updatestatus(sd, SP_VIT);
  3260. clif_updatestatus(sd, SP_INT);
  3261. clif_updatestatus(sd, SP_DEX);
  3262. clif_updatestatus(sd, SP_LUK);
  3263. clif_updatestatus(sd, SP_ATTACKRANGE);
  3264. clif_updatestatus(sd, SP_ASPD);
  3265. }
  3266. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3267. /// 013c <index>.W
  3268. void clif_arrowequip(struct map_session_data *sd,int val) {
  3269. int fd;
  3270. nullpo_retv(sd);
  3271. #if PACKETVER >= 20121128
  3272. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3273. #endif
  3274. fd=sd->fd;
  3275. WFIFOHEAD(fd, packet_len(0x013c));
  3276. WFIFOW(fd,0) = 0x013c;
  3277. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3278. WFIFOSET(fd, packet_len(0x013c));
  3279. }
  3280. /// Ammunition action message (ZC_ACTION_FAILURE).
  3281. /// 013b <type>.W
  3282. /// type:
  3283. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3284. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3285. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3286. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3287. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3288. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3289. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3290. int fd;
  3291. nullpo_retv(sd);
  3292. fd=sd->fd;
  3293. WFIFOHEAD(fd, packet_len(0x013b));
  3294. WFIFOW(fd,0) = 0x013b;
  3295. WFIFOW(fd,2) = type;
  3296. WFIFOSET(fd, packet_len(0x013b));
  3297. }
  3298. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3299. /// 01ad <packet len>.W { <name id>.W }*
  3300. void clif_arrow_create_list( struct map_session_data *sd ){
  3301. nullpo_retv( sd );
  3302. int fd = sd->fd;
  3303. if( !session_isActive( fd ) ){
  3304. return;
  3305. }
  3306. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  3307. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  3308. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3309. int count = 0;
  3310. for( int i = 0; i < MAX_SKILL_ARROW_DB; i++ ){
  3311. short nameid = skill_arrow_db[i].nameid;
  3312. if( !itemdb_exists( nameid ) ){
  3313. continue;
  3314. }
  3315. int index = pc_search_inventory( sd, nameid );
  3316. if( index < 0 ){
  3317. continue;
  3318. }
  3319. if( sd->inventory.u.items_inventory[index].equip ){
  3320. continue;
  3321. }
  3322. if( !sd->inventory.u.items_inventory[index].identify ){
  3323. continue;
  3324. }
  3325. p->items[count].itemId = client_nameid( nameid );
  3326. count++;
  3327. }
  3328. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3329. WFIFOSET( fd, p->packetLength );
  3330. if( count > 0 ){
  3331. sd->menuskill_id = AC_MAKINGARROW;
  3332. sd->menuskill_val = count;
  3333. }
  3334. }
  3335. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3336. /// 00bc <status id>.W <result>.B <value>.B
  3337. /// status id:
  3338. /// SP_STR ~ SP_LUK
  3339. /// result:
  3340. /// 0 = failure
  3341. /// 1 = success
  3342. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3343. int fd;
  3344. nullpo_retv(sd);
  3345. fd=sd->fd;
  3346. WFIFOHEAD(fd, packet_len(0xbc));
  3347. WFIFOW(fd,0) = 0xbc;
  3348. WFIFOW(fd,2) = type;
  3349. WFIFOB(fd,4) = ok;
  3350. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3351. WFIFOSET(fd, packet_len(0xbc));
  3352. }
  3353. /// Notifies the client about the result of a request to equip an item.
  3354. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3355. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3356. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3357. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3358. /// @ok: //inversed forv2 v5
  3359. /// 0 = failure
  3360. /// 1 = success
  3361. /// 2 = failure due to low level
  3362. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3363. {
  3364. int fd = 0, cmd = 0, look = 0;
  3365. struct s_packet_db *info = NULL;
  3366. nullpo_retv(sd);
  3367. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3368. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3369. return;
  3370. fd = sd->fd;
  3371. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3372. look = sd->inventory_data[n]->look;
  3373. WFIFOHEAD(fd, info->len);
  3374. WFIFOW(fd, 0) = cmd;
  3375. WFIFOW(fd, info->pos[0]) = n+2;
  3376. switch (cmd) {
  3377. case 0xaa:
  3378. WFIFOW(fd, info->pos[1]) = pos;
  3379. #if PACKETVER < 20100629
  3380. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3381. #else
  3382. WFIFOL(fd, info->pos[2]) = look;
  3383. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3384. #endif
  3385. break;
  3386. case 0x8d0:
  3387. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3388. flag = 1;
  3389. case 0x999:
  3390. if (cmd == 0x999)
  3391. WFIFOL(fd, info->pos[1]) = pos;
  3392. else
  3393. WFIFOW(fd, info->pos[1]) = pos;
  3394. WFIFOL(fd, info->pos[2]) = look;
  3395. WFIFOW(fd, info->pos[3]) = flag;
  3396. break;
  3397. }
  3398. WFIFOSET(fd, info->len);
  3399. }
  3400. /// Notifies the client about the result of a request to take off an item.
  3401. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3402. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3403. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3404. /// @ok : //inversed for v2 v5
  3405. /// 0 = failure
  3406. /// 1 = success
  3407. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3408. {
  3409. int fd, header, offs = 0;
  3410. #if PACKETVER >= 20130000
  3411. header = 0x99a;
  3412. ok = ok ? 0 : 1;
  3413. #elif PACKETVER >= 20110824
  3414. header = 0x8d1;
  3415. ok = ok ? 0 : 1;
  3416. #else
  3417. header = 0xac;
  3418. #endif
  3419. nullpo_retv(sd);
  3420. fd=sd->fd;
  3421. WFIFOHEAD(fd, packet_len(header));
  3422. WFIFOW(fd,offs+0) = header;
  3423. WFIFOW(fd,offs+2) = n+2;
  3424. #if PACKETVER >= 20130000
  3425. WFIFOL(fd,offs+4) = pos;
  3426. offs += 2;
  3427. #else
  3428. WFIFOW(fd,offs+4) = pos;
  3429. #endif
  3430. WFIFOB(fd,offs+6) = ok;
  3431. WFIFOSET(fd, packet_len(header));
  3432. }
  3433. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3434. /// 019b <id>.L <effect id>.L
  3435. /// effect id:
  3436. /// 0 = base level up
  3437. /// 1 = job level up
  3438. /// 2 = refine failure
  3439. /// 3 = refine success
  3440. /// 4 = game over
  3441. /// 5 = pharmacy success
  3442. /// 6 = pharmacy failure
  3443. /// 7 = base level up (super novice)
  3444. /// 8 = job level up (super novice)
  3445. /// 9 = base level up (taekwon)
  3446. void clif_misceffect(struct block_list* bl,int type)
  3447. {
  3448. unsigned char buf[32];
  3449. nullpo_retv(bl);
  3450. WBUFW(buf,0) = 0x19b;
  3451. WBUFL(buf,2) = bl->id;
  3452. WBUFL(buf,6) = type;
  3453. clif_send(buf,packet_len(0x19b),bl,AREA);
  3454. }
  3455. /// Notifies clients in the area of a state change.
  3456. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3457. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3458. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3459. nullpo_retv( bl );
  3460. struct status_change* sc = status_get_sc( bl );
  3461. //How can an option change if there's no sc?
  3462. if( sc == nullptr ){
  3463. return;
  3464. }
  3465. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3466. struct PACKET_ZC_STATE_CHANGE p;
  3467. p.packetType = HEADER_ZC_STATE_CHANGE;
  3468. p.AID = bl->id;
  3469. p.bodyState = sc->opt1;
  3470. p.healthState = sc->opt2;
  3471. p.effectState = sc->option;
  3472. p.isPKModeON = sd ? sd->status.karma : false;
  3473. if( target == nullptr ){
  3474. if( disguised( bl ) ){
  3475. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3476. p.AID = disguised_bl_id( p.AID );
  3477. clif_send( &p, sizeof( p ), bl, SELF );
  3478. p.AID = disguised_bl_id( p.AID );
  3479. p.effectState = OPTION_INVISIBLE;
  3480. clif_send( &p, sizeof( p ), bl, SELF );
  3481. }else{
  3482. clif_send( &p, sizeof( p ), bl, AREA );
  3483. }
  3484. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3485. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3486. if( sc->data[SC_PROVOKE] ){
  3487. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3488. clif_status_change( bl, StatusIconChangeTable[SC_PROVOKE], 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3489. }
  3490. }else{
  3491. if( disguised( bl ) ){
  3492. p.AID = disguised_bl_id( p.AID );
  3493. clif_send( &p, sizeof( p ), target, SELF );
  3494. p.AID = disguised_bl_id( p.AID );
  3495. p.effectState = OPTION_INVISIBLE;
  3496. clif_send( &p, sizeof( p ), target, SELF );
  3497. }else{
  3498. clif_send( &p, sizeof( p ), target, SELF );
  3499. }
  3500. }
  3501. }
  3502. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3503. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3504. void clif_changeoption2(struct block_list* bl)
  3505. {
  3506. unsigned char buf[20];
  3507. struct status_change *sc;
  3508. sc = status_get_sc(bl);
  3509. if (!sc) return; //How can an option change if there's no sc?
  3510. WBUFW(buf,0) = 0x28a;
  3511. WBUFL(buf,2) = bl->id;
  3512. WBUFL(buf,6) = sc->option;
  3513. WBUFL(buf,10) = clif_setlevel(bl);
  3514. WBUFL(buf,14) = sc->opt3;
  3515. if(disguised(bl)) {
  3516. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3517. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3518. clif_send(buf,packet_len(0x28a),bl,SELF);
  3519. WBUFL(buf,2) = bl->id;
  3520. WBUFL(buf,6) = OPTION_INVISIBLE;
  3521. clif_send(buf,packet_len(0x28a),bl,SELF);
  3522. } else
  3523. clif_send(buf,packet_len(0x28a),bl,AREA);
  3524. }
  3525. /// Notifies the client about the result of an item use request.
  3526. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3527. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3528. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3529. nullpo_retv( sd );
  3530. int fd = sd->fd;
  3531. if( !session_isActive( fd ) ){
  3532. return;
  3533. }
  3534. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid <= 0 || sd->inventory_data[index] == nullptr ){
  3535. return;
  3536. }
  3537. struct PACKET_ZC_USE_ITEM_ACK p;
  3538. p.packetType = useItemAckType;
  3539. p.index = index + 2;
  3540. #if PACKETVER > 3
  3541. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3542. p.AID = sd->bl.id;
  3543. #endif
  3544. p.amount = amount;
  3545. p.result = ok;
  3546. if( !ok ){
  3547. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3548. }else{
  3549. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3550. }
  3551. }
  3552. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3553. /// 00d6 <flag>.B
  3554. /// flag:
  3555. /// 0 = Room has been successfully created (opens chat room)
  3556. /// 1 = Room limit exceeded
  3557. /// 2 = Same room already exists
  3558. void clif_createchat(struct map_session_data* sd, int flag)
  3559. {
  3560. int fd;
  3561. nullpo_retv(sd);
  3562. fd = sd->fd;
  3563. WFIFOHEAD(fd,packet_len(0xd6));
  3564. WFIFOW(fd,0) = 0xd6;
  3565. WFIFOB(fd,2) = flag;
  3566. WFIFOSET(fd,packet_len(0xd6));
  3567. }
  3568. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3569. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3570. /// type:
  3571. /// 0 = private (password protected)
  3572. /// 1 = public
  3573. /// 2 = arena (npc waiting room)
  3574. /// 3 = PK zone (non-clickable)
  3575. void clif_dispchat(struct chat_data* cd, int fd)
  3576. {
  3577. unsigned char buf[128];
  3578. uint8 type;
  3579. if( cd == NULL || cd->owner == NULL )
  3580. return;
  3581. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3582. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3583. : 1;
  3584. WBUFW(buf, 0) = 0xd7;
  3585. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3586. WBUFL(buf, 4) = cd->owner->id;
  3587. WBUFL(buf, 8) = cd->bl.id;
  3588. WBUFW(buf,12) = cd->limit;
  3589. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3590. WBUFB(buf,16) = type;
  3591. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3592. if( fd ) {
  3593. WFIFOHEAD(fd,WBUFW(buf,2));
  3594. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3595. WFIFOSET(fd,WBUFW(buf,2));
  3596. } else {
  3597. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3598. }
  3599. }
  3600. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3601. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3602. /// type:
  3603. /// 0 = private (password protected)
  3604. /// 1 = public
  3605. /// 2 = arena (npc waiting room)
  3606. /// 3 = PK zone (non-clickable)
  3607. void clif_changechatstatus(struct chat_data* cd)
  3608. {
  3609. unsigned char buf[128];
  3610. uint8 type;
  3611. if( cd == NULL || cd->usersd[0] == NULL )
  3612. return;
  3613. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3614. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3615. : 1;
  3616. WBUFW(buf, 0) = 0xdf;
  3617. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3618. WBUFL(buf, 4) = cd->owner->id;
  3619. WBUFL(buf, 8) = cd->bl.id;
  3620. WBUFW(buf,12) = cd->limit;
  3621. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3622. WBUFB(buf,16) = type;
  3623. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3624. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3625. }
  3626. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3627. /// 00d8 <chat id>.L
  3628. void clif_clearchat(struct chat_data *cd,int fd)
  3629. {
  3630. unsigned char buf[32];
  3631. nullpo_retv(cd);
  3632. WBUFW(buf,0) = 0xd8;
  3633. WBUFL(buf,2) = cd->bl.id;
  3634. if( fd ) {
  3635. WFIFOHEAD(fd,packet_len(0xd8));
  3636. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3637. WFIFOSET(fd,packet_len(0xd8));
  3638. } else {
  3639. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3640. }
  3641. }
  3642. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3643. /// 00da <result>.B
  3644. /// result:
  3645. /// 0 = room full
  3646. /// 1 = wrong password
  3647. /// 2 = kicked
  3648. /// 3 = success (no message)
  3649. /// 4 = no enough zeny
  3650. /// 5 = too low level
  3651. /// 6 = too high level
  3652. /// 7 = unsuitable job class
  3653. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3654. {
  3655. int fd;
  3656. nullpo_retv(sd);
  3657. fd = sd->fd;
  3658. WFIFOHEAD(fd,packet_len(0xda));
  3659. WFIFOW(fd,0) = 0xda;
  3660. WFIFOB(fd,2) = flag;
  3661. WFIFOSET(fd,packet_len(0xda));
  3662. }
  3663. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3664. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3665. /// role:
  3666. /// 0 = owner (menu)
  3667. /// 1 = normal
  3668. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3669. {
  3670. int fd;
  3671. int i,t;
  3672. nullpo_retv(sd);
  3673. nullpo_retv(cd);
  3674. fd = sd->fd;
  3675. if (!session_isActive(fd))
  3676. return;
  3677. t = (int)(cd->owner->type == BL_NPC);
  3678. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3679. WFIFOW(fd, 0) = 0xdb;
  3680. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3681. WFIFOL(fd, 4) = cd->bl.id;
  3682. if(cd->owner->type == BL_NPC){
  3683. WFIFOL(fd, 30) = 1;
  3684. WFIFOL(fd, 8) = 0;
  3685. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3686. for (i = 0; i < cd->users; i++) {
  3687. WFIFOL(fd, 8+(i+1)*28) = 1;
  3688. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3689. }
  3690. }else{
  3691. for (i = 0; i < cd->users; i++) {
  3692. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3693. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3694. }
  3695. }
  3696. WFIFOSET(fd, WFIFOW(fd, 2));
  3697. }
  3698. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3699. /// 00dc <users>.W <name>.24B
  3700. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3701. {
  3702. unsigned char buf[29];
  3703. nullpo_retv(sd);
  3704. nullpo_retv(cd);
  3705. WBUFW(buf, 0) = 0xdc;
  3706. WBUFW(buf, 2) = cd->users;
  3707. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3708. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3709. }
  3710. /// Announce the new owner (ZC_ROLE_CHANGE).
  3711. /// 00e1 <role>.L <nick>.24B
  3712. /// role:
  3713. /// 0 = owner (menu)
  3714. /// 1 = normal
  3715. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3716. {
  3717. unsigned char buf[64];
  3718. nullpo_retv(sd);
  3719. nullpo_retv(cd);
  3720. WBUFW(buf, 0) = 0xe1;
  3721. WBUFL(buf, 2) = 1;
  3722. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3723. WBUFW(buf,30) = 0xe1;
  3724. WBUFL(buf,32) = 0;
  3725. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3726. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3727. }
  3728. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3729. /// 00dd <users>.W <nick>.24B <flag>.B
  3730. /// flag:
  3731. /// 0 = left
  3732. /// 1 = kicked
  3733. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3734. {
  3735. unsigned char buf[32];
  3736. nullpo_retv(sd);
  3737. nullpo_retv(cd);
  3738. WBUFW(buf, 0) = 0xdd;
  3739. WBUFW(buf, 2) = cd->users-1;
  3740. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3741. WBUFB(buf,28) = flag;
  3742. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3743. }
  3744. /// Opens a trade request window from char 'name'.
  3745. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3746. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3747. void clif_traderequest(struct map_session_data* sd, const char* name)
  3748. {
  3749. int fd = sd->fd;
  3750. #if PACKETVER < 6
  3751. WFIFOHEAD(fd,packet_len(0xe5));
  3752. WFIFOW(fd,0) = 0xe5;
  3753. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3754. WFIFOSET(fd,packet_len(0xe5));
  3755. #else
  3756. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3757. if( !tsd ) return;
  3758. WFIFOHEAD(fd,packet_len(0x1f4));
  3759. WFIFOW(fd,0) = 0x1f4;
  3760. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3761. WFIFOL(fd,26) = tsd->status.char_id;
  3762. WFIFOW(fd,30) = tsd->status.base_level;
  3763. WFIFOSET(fd,packet_len(0x1f4));
  3764. #endif
  3765. }
  3766. /// Reply to a trade-request.
  3767. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3768. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3769. /// result:
  3770. /// 0 = Char is too far
  3771. /// 1 = Character does not exist
  3772. /// 2 = Trade failed
  3773. /// 3 = Accept
  3774. /// 4 = Cancel
  3775. /// 5 = Busy
  3776. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3777. {
  3778. int fd = sd->fd;
  3779. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3780. if( PACKETVER < 6 || !tsd ) {
  3781. WFIFOHEAD(fd,packet_len(0xe7));
  3782. WFIFOW(fd,0) = 0xe7;
  3783. WFIFOB(fd,2) = type;
  3784. WFIFOSET(fd,packet_len(0xe7));
  3785. } else {
  3786. WFIFOHEAD(fd,packet_len(0x1f5));
  3787. WFIFOW(fd,0) = 0x1f5;
  3788. WFIFOB(fd,2) = type;
  3789. WFIFOL(fd,3) = tsd->status.char_id;
  3790. WFIFOW(fd,7) = tsd->status.base_level;
  3791. WFIFOSET(fd,packet_len(0x1f5));
  3792. }
  3793. }
  3794. /// Notifies the client about an item from other player in current trade.
  3795. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3796. /// 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)
  3797. /// 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)
  3798. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3799. nullpo_retv( sd );
  3800. nullpo_retv( tsd );
  3801. int fd = tsd->fd;
  3802. if( !session_isActive( fd ) ){
  3803. return;
  3804. }
  3805. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3806. if( index ){
  3807. index = server_index( index );
  3808. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid <= 0 || sd->inventory_data[index] == nullptr ){
  3809. return;
  3810. }
  3811. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3812. #if PACKETVER >= 20100223
  3813. p.itemType = sd->inventory_data[index]->type;
  3814. #endif
  3815. p.identified = sd->inventory.u.items_inventory[index].identify;
  3816. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3817. p.refine = sd->inventory.u.items_inventory[index].refine;
  3818. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3819. #if PACKETVER >= 20150226
  3820. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3821. #endif
  3822. }else{
  3823. p = {};
  3824. }
  3825. p.packetType = tradeaddType;
  3826. p.amount = amount;
  3827. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  3828. }
  3829. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3830. /// 00ea <index>.W <result>.B
  3831. /// result:
  3832. /// 0 = success
  3833. /// 1 = overweight
  3834. /// 2 = trade canceled
  3835. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3836. {
  3837. int fd;
  3838. nullpo_retv(sd);
  3839. fd = sd->fd;
  3840. WFIFOHEAD(fd,packet_len(0xea));
  3841. WFIFOW(fd,0) = 0xea;
  3842. WFIFOW(fd,2) = index;
  3843. WFIFOB(fd,4) = fail;
  3844. WFIFOSET(fd,packet_len(0xea));
  3845. }
  3846. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3847. /// 00ec <who>.B
  3848. /// who:
  3849. /// 0 = self
  3850. /// 1 = other player
  3851. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3852. {
  3853. int fd;
  3854. nullpo_retv(sd);
  3855. fd = sd->fd;
  3856. WFIFOHEAD(fd,packet_len(0xec));
  3857. WFIFOW(fd,0) = 0xec;
  3858. WFIFOB(fd,2) = fail;
  3859. WFIFOSET(fd,packet_len(0xec));
  3860. }
  3861. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3862. /// 00ee
  3863. void clif_tradecancelled(struct map_session_data* sd)
  3864. {
  3865. int fd;
  3866. nullpo_retv(sd);
  3867. fd = sd->fd;
  3868. WFIFOHEAD(fd,packet_len(0xee));
  3869. WFIFOW(fd,0) = 0xee;
  3870. WFIFOSET(fd,packet_len(0xee));
  3871. }
  3872. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3873. /// 00f0 <result>.B
  3874. /// result:
  3875. /// 0 = success
  3876. /// 1 = failure
  3877. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3878. {
  3879. int fd;
  3880. nullpo_retv(sd);
  3881. fd = sd->fd;
  3882. WFIFOHEAD(fd,packet_len(0xf0));
  3883. WFIFOW(fd,0) = 0xf0;
  3884. WFIFOB(fd,2) = fail;
  3885. WFIFOSET(fd,packet_len(0xf0));
  3886. }
  3887. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3888. /// 00f1
  3889. /// NOTE: Unknown purpose. Items are not removed until the window is
  3890. /// refreshed (ex. by putting another item in there).
  3891. void clif_tradeundo(struct map_session_data* sd)
  3892. {
  3893. int fd = sd->fd;
  3894. WFIFOHEAD(fd,packet_len(0xf1));
  3895. WFIFOW(fd,0) = 0xf1;
  3896. WFIFOSET(fd,packet_len(0xf1));
  3897. }
  3898. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3899. /// 00f2 <current count>.W <max count>.W
  3900. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3901. {
  3902. int fd;
  3903. nullpo_retv(sd);
  3904. fd=sd->fd;
  3905. WFIFOHEAD(fd,packet_len(0xf2));
  3906. WFIFOW(fd,0) = 0xf2;
  3907. WFIFOW(fd,2) = amount;
  3908. WFIFOW(fd,4) = max_amount;
  3909. WFIFOSET(fd,packet_len(0xf2));
  3910. }
  3911. /// Notifies the client of an item being added to the storage.
  3912. /// 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)
  3913. /// 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)
  3914. /// 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)
  3915. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  3916. nullpo_retv( sd );
  3917. nullpo_retv( i );
  3918. int fd = sd->fd;
  3919. if( !session_isActive( fd ) ){
  3920. return;
  3921. }
  3922. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  3923. p.packetType = storageaddType; // Storage item added
  3924. p.index = client_storage_index( index ); // index
  3925. p.amount = amount; // amount
  3926. p.itemId = client_nameid( i->nameid ); // id
  3927. #if PACKETVER >= 5
  3928. p.itemType = itemtype( i->nameid ); //type
  3929. #endif
  3930. p.identified = i->identify; //identify flag
  3931. p.damaged = i->attribute; // attribute
  3932. p.refine = i->refine; //refine
  3933. clif_addcards( &p.slot, i );
  3934. #if PACKETVER >= 20150226
  3935. clif_add_random_options( p.option_data, i );
  3936. #endif
  3937. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  3938. }
  3939. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3940. /// 00f6 <index>.W <amount>.L
  3941. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3942. {
  3943. int fd;
  3944. nullpo_retv(sd);
  3945. fd=sd->fd;
  3946. WFIFOHEAD(fd,packet_len(0xf6));
  3947. WFIFOW(fd,0)=0xf6; // Storage item removed
  3948. WFIFOW(fd,2)=client_storage_index(index);
  3949. WFIFOL(fd,4)=amount;
  3950. WFIFOSET(fd,packet_len(0xf6));
  3951. }
  3952. /// Closes storage (ZC_CLOSE_STORE).
  3953. /// 00f8
  3954. void clif_storageclose(struct map_session_data* sd)
  3955. {
  3956. int fd;
  3957. nullpo_retv(sd);
  3958. fd=sd->fd;
  3959. WFIFOHEAD(fd,packet_len(0xf8));
  3960. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3961. WFIFOSET(fd,packet_len(0xf8));
  3962. }
  3963. /// Notifies clients in an area of an object's souls.
  3964. /// Note: Spirit spheres and Soul spheres work on
  3965. /// seprate systems officially, but both send out
  3966. /// the same packet which leads to confusion on how
  3967. /// much soul energy a Soul Reaper actually has
  3968. /// should the player also have spirit spheres.
  3969. /// They will likely create a new packet for this soon
  3970. /// to seprate the animations for spirit and soul spheres.
  3971. /// For now we'll use this and replace it later when possible. [Rytech]
  3972. ///
  3973. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  3974. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  3975. void clif_soulball(struct map_session_data *sd)
  3976. {
  3977. unsigned char buf[8];
  3978. nullpo_retv(sd);
  3979. WBUFW(buf,0)=0x1d0;
  3980. WBUFL(buf,2)=sd->bl.id;
  3981. WBUFW(buf,6)=sd->soulball;
  3982. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  3983. return;
  3984. }
  3985. /*==========================================
  3986. * Server tells 'sd' player client the abouts of 'dstsd' player
  3987. *------------------------------------------*/
  3988. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3989. {
  3990. struct block_list *d_bl;
  3991. int i;
  3992. if( dstsd->chatID ) {
  3993. struct chat_data *cd = NULL;
  3994. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3995. clif_dispchat(cd,sd->fd);
  3996. } else if( dstsd->state.vending )
  3997. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3998. else if( dstsd->state.buyingstore )
  3999. clif_buyingstore_entry_single(sd, dstsd);
  4000. if(dstsd->spiritball > 0)
  4001. clif_spiritball_single(sd->fd, dstsd);
  4002. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4003. clif_spiritcharm_single(sd->fd, dstsd);
  4004. if (dstsd->soulball > 0)
  4005. clif_soulball_single(sd->fd, dstsd);
  4006. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4007. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4008. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4009. )
  4010. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4011. // display link (sd - dstsd) to sd
  4012. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4013. if( i < MAX_DEVOTION )
  4014. clif_devotion(&sd->bl, sd);
  4015. // display links (dstsd - devotees) to sd
  4016. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4017. if( i < MAX_DEVOTION )
  4018. clif_devotion(&dstsd->bl, sd);
  4019. // display link (dstsd - crusader) to sd
  4020. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4021. clif_devotion(d_bl, sd);
  4022. }
  4023. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4024. struct unit_data *ud;
  4025. struct view_data *vd;
  4026. bool option = false;
  4027. unsigned int option_val = 0;
  4028. vd = status_get_viewdata(bl);
  4029. if (!vd || vd->class_ == JT_INVISIBLE)
  4030. return;
  4031. /**
  4032. * Hide NPC from maya purple card.
  4033. **/
  4034. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4035. return;
  4036. ud = unit_bl2ud(bl);
  4037. if( ud && ud->walktimer != INVALID_TIMER ){
  4038. clif_set_unit_walking( bl, sd, ud, SELF );
  4039. }else{
  4040. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4041. }
  4042. if (vd->cloth_color)
  4043. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4044. if (vd->body_style)
  4045. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4046. switch (bl->type)
  4047. {
  4048. case BL_PC:
  4049. {
  4050. TBL_PC* tsd = (TBL_PC*)bl;
  4051. clif_getareachar_pc(sd, tsd);
  4052. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4053. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4054. else if(tsd->state.size==SZ_MEDIUM)
  4055. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4056. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4057. clif_sendbgemblem_single(sd->fd,tsd);
  4058. if ( tsd->status.robe )
  4059. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4060. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4061. clif_hat_effects(sd,bl,SELF);
  4062. }
  4063. break;
  4064. case BL_MER: // Devotion Effects
  4065. if( ((TBL_MER*)bl)->devotion_flag )
  4066. clif_devotion(bl, sd);
  4067. break;
  4068. case BL_NPC:
  4069. {
  4070. TBL_NPC* nd = (TBL_NPC*)bl;
  4071. if( nd->chat_id )
  4072. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4073. if( nd->size == SZ_BIG )
  4074. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4075. else if( nd->size == SZ_MEDIUM )
  4076. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4077. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4078. clif_progressbar_npc(nd, sd);
  4079. }
  4080. break;
  4081. case BL_MOB:
  4082. {
  4083. TBL_MOB* md = (TBL_MOB*)bl;
  4084. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4085. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4086. else if(md->special_state.size==SZ_MEDIUM)
  4087. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4088. #if PACKETVER >= 20120404
  4089. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4090. int i;
  4091. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4092. if( md->dmglog[i].id == sd->status.char_id )
  4093. clif_monster_hp_bar(md, sd->fd);
  4094. }
  4095. #endif
  4096. }
  4097. break;
  4098. case BL_PET:
  4099. if (vd->head_bottom)
  4100. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4101. break;
  4102. }
  4103. }
  4104. //Modifies the type of damage according to status changes [Skotlex]
  4105. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4106. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4107. {
  4108. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4109. }
  4110. /*==========================================
  4111. * Estimates walk delay based on the damage criteria. [Skotlex]
  4112. *------------------------------------------*/
  4113. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4114. {
  4115. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4116. return 0;
  4117. if (bl->type == BL_PC) {
  4118. if (battle_config.pc_walk_delay_rate != 100)
  4119. delay = delay*battle_config.pc_walk_delay_rate/100;
  4120. } else
  4121. if (battle_config.walk_delay_rate != 100)
  4122. delay = delay*battle_config.walk_delay_rate/100;
  4123. if (div_ > 1) //Multi-hit skills mean higher delays.
  4124. delay += battle_config.multihit_delay*(div_-1);
  4125. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4126. }
  4127. /*========================================== [Playtester]
  4128. * Returns hallucination damage the client displays
  4129. *------------------------------------------*/
  4130. static int clif_hallucination_damage()
  4131. {
  4132. int digit = rnd() % 5 + 1;
  4133. switch (digit)
  4134. {
  4135. case 1:
  4136. return (rnd() % 10);
  4137. case 2:
  4138. return (rnd() % 100);
  4139. case 3:
  4140. return (rnd() % 1000);
  4141. case 4:
  4142. return (rnd() % 10000);
  4143. }
  4144. return (rnd() % 32767);
  4145. }
  4146. /// Sends a 'damage' packet (src performs action on dst)
  4147. /// 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)
  4148. /// 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)
  4149. /// 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)
  4150. /// type:
  4151. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4152. /// 1 = pick up item
  4153. /// 2 = sit down
  4154. /// 3 = stand up
  4155. /// 4 = damage (endure)
  4156. /// 5 = (splash?)
  4157. /// 6 = (skill?)
  4158. /// 7 = (repeat damage?)
  4159. /// 8 = multi-hit damage
  4160. /// 9 = multi-hit damage (endure)
  4161. /// 10 = critical hit
  4162. /// 11 = lucky dodge
  4163. /// 12 = (touch skill?)
  4164. /// 13 = multi-hit critical
  4165. 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)
  4166. {
  4167. unsigned char buf[34];
  4168. struct status_change *sc;
  4169. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4170. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4171. #if PACKETVER < 20071113
  4172. const int cmd = 0x8a;
  4173. int offset = 0;
  4174. #elif PACKETVER < 20131223
  4175. const int cmd = 0x2e1;
  4176. int offset = 2;
  4177. #else
  4178. const int cmd = 0x8c8;
  4179. int offset = 3;
  4180. #endif
  4181. nullpo_ret(src);
  4182. nullpo_ret(dst);
  4183. if (type != DMG_MULTI_HIT_CRITICAL)
  4184. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4185. sc = status_get_sc(dst);
  4186. if(sc && sc->count) {
  4187. if(sc->data[SC_HALLUCINATION]) {
  4188. if(damage) damage = clif_hallucination_damage();
  4189. if(damage2) damage2 = clif_hallucination_damage();
  4190. }
  4191. }
  4192. WBUFW(buf,0) = cmd;
  4193. WBUFL(buf,2) = src->id;
  4194. WBUFL(buf,6) = dst->id;
  4195. WBUFL(buf,10) = client_tick(tick);
  4196. WBUFL(buf,14) = sdelay;
  4197. WBUFL(buf,18) = ddelay;
  4198. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4199. #if PACKETVER < 20071113
  4200. WBUFW(buf,22) = damage ? div : 0;
  4201. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4202. #else
  4203. WBUFL(buf, 22) = damage ? div : 0;
  4204. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4205. #endif
  4206. } else {
  4207. #if PACKETVER < 20071113
  4208. WBUFW(buf,22) = min(damage, INT16_MAX);
  4209. WBUFW(buf,27+offset) = damage2;
  4210. #else
  4211. WBUFL(buf,22) = damage;
  4212. WBUFL(buf,27+offset) = damage2;
  4213. #endif
  4214. }
  4215. #if PACKETVER >= 20131223
  4216. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4217. #endif
  4218. WBUFW(buf,24+offset) = div;
  4219. WBUFB(buf,26+offset) = type;
  4220. if(disguised(dst)) {
  4221. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4222. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4223. clif_send(buf, packet_len(cmd), dst, SELF);
  4224. } else
  4225. clif_send(buf, packet_len(cmd), dst, AREA);
  4226. if(disguised(src)) {
  4227. WBUFL(buf,2) = disguised_bl_id( src->id );
  4228. if (disguised(dst))
  4229. WBUFL(buf,6) = dst->id;
  4230. #if PACKETVER < 20071113
  4231. if(damage > 0) WBUFW(buf,22) = -1;
  4232. if(damage2 > 0) WBUFW(buf,27) = -1;
  4233. #else
  4234. if(damage > 0) WBUFL(buf,22) = -1;
  4235. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4236. #endif
  4237. clif_send(buf,packet_len(cmd),src,SELF);
  4238. }
  4239. if(src == dst) {
  4240. unit_setdir(src, unit_getdir(src));
  4241. }
  4242. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4243. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4244. //Return adjusted can't walk delay for further processing.
  4245. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4246. }
  4247. /*==========================================
  4248. * src picks up dst
  4249. *------------------------------------------*/
  4250. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4251. {
  4252. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4253. unsigned char buf[32];
  4254. nullpo_retv(src);
  4255. nullpo_retv(dst);
  4256. WBUFW(buf, 0) = 0x8a;
  4257. WBUFL(buf, 2) = src->id;
  4258. WBUFL(buf, 6) = dst->id;
  4259. WBUFB(buf,26) = 1;
  4260. clif_send(buf, packet_len(0x8a), src, AREA);
  4261. }
  4262. /*==========================================
  4263. * inform clients in area that `bl` is sitting
  4264. *------------------------------------------*/
  4265. void clif_sitting(struct block_list* bl)
  4266. {
  4267. unsigned char buf[32];
  4268. nullpo_retv(bl);
  4269. WBUFW(buf, 0) = 0x8a;
  4270. WBUFL(buf, 2) = bl->id;
  4271. WBUFB(buf,26) = 2;
  4272. clif_send(buf, packet_len(0x8a), bl, AREA);
  4273. if(disguised(bl)) {
  4274. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4275. clif_send(buf, packet_len(0x8a), bl, SELF);
  4276. }
  4277. }
  4278. /*==========================================
  4279. * inform clients in area that `bl` is standing
  4280. *------------------------------------------*/
  4281. void clif_standing(struct block_list* bl)
  4282. {
  4283. unsigned char buf[32];
  4284. nullpo_retv(bl);
  4285. WBUFW(buf, 0) = 0x8a;
  4286. WBUFL(buf, 2) = bl->id;
  4287. WBUFB(buf,26) = 3;
  4288. clif_send(buf, packet_len(0x8a), bl, AREA);
  4289. if(disguised(bl)) {
  4290. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4291. clif_send(buf, packet_len(0x8a), bl, SELF);
  4292. }
  4293. }
  4294. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4295. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4296. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4297. {
  4298. unsigned char buf[32];
  4299. WBUFW(buf,0) = 0x192;
  4300. WBUFW(buf,2) = x;
  4301. WBUFW(buf,4) = y;
  4302. WBUFW(buf,6) = type;
  4303. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4304. if( fd )
  4305. {
  4306. WFIFOHEAD(fd,packet_len(0x192));
  4307. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4308. WFIFOSET(fd,packet_len(0x192));
  4309. }
  4310. else
  4311. {
  4312. struct block_list dummy_bl;
  4313. dummy_bl.type = BL_NUL;
  4314. dummy_bl.x = x;
  4315. dummy_bl.y = y;
  4316. dummy_bl.m = m;
  4317. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4318. }
  4319. }
  4320. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4321. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4322. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4323. nullpo_retv( sd );
  4324. nullpo_retv( fitem );
  4325. struct PACKET_ZC_ITEM_ENTRY p;
  4326. int view = itemdb_viewid( fitem->item.nameid );
  4327. p.packetType = 0x9d;
  4328. p.AID = fitem->bl.id;
  4329. p.itemId = view > 0 ? view : fitem->item.nameid;
  4330. p.identify = fitem->item.identify;
  4331. p.x = fitem->bl.x;
  4332. p.y = fitem->bl.y;
  4333. p.amount = fitem->item.amount;
  4334. p.subX = fitem->subx;
  4335. p.subY = fitem->suby;
  4336. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4337. }
  4338. /// Notifes client about Graffiti
  4339. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4340. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4341. unsigned char buf[128];
  4342. nullpo_retv(bl);
  4343. nullpo_retv(unit);
  4344. WBUFW(buf, 0) = 0x1c9;
  4345. WBUFL(buf, 2) = unit->bl.id;
  4346. WBUFL(buf, 6) = unit->group->src_id;
  4347. WBUFW(buf,10) = unit->bl.x;
  4348. WBUFW(buf,12) = unit->bl.y;
  4349. WBUFB(buf,14) = unit->group->unit_id;
  4350. WBUFB(buf,15) = 1;
  4351. WBUFB(buf,16) = 1;
  4352. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4353. clif_send(buf,packet_len(0x1c9),bl,target);
  4354. }
  4355. /// Notifies the client of a skill unit.
  4356. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4357. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4358. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4359. /// 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)
  4360. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4361. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4362. unsigned char buf[128];
  4363. nullpo_retv(bl);
  4364. nullpo_retv(unit);
  4365. if (bl->type == BL_PC)
  4366. fd = ((TBL_PC*)bl)->fd;
  4367. if (unit->group->state.guildaura)
  4368. return;
  4369. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4370. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4371. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4372. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4373. else
  4374. unit_id = unit->group->unit_id;
  4375. if (!visible)
  4376. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4377. #if PACKETVER >= 3
  4378. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4379. clif_graffiti(bl, unit, target);
  4380. return;
  4381. }
  4382. #endif
  4383. #if PACKETVER <= 20120702
  4384. header = 0x011f;
  4385. //#if PACKETVER < 20110718
  4386. // header = 0x011f;
  4387. //#elif PACKETVER < 20121212
  4388. // header = 0x08c7;
  4389. #elif PACKETVER < 20130731
  4390. header = 0x099f;
  4391. #else
  4392. header = 0x09ca;
  4393. #endif
  4394. len = packet_len(header);
  4395. WBUFW(buf,pos) = header;
  4396. if (header != 0x011f) {
  4397. WBUFW(buf, pos+2) = len;
  4398. pos += 2;
  4399. }
  4400. WBUFL(buf,pos+2) = unit->bl.id;
  4401. WBUFL(buf,pos+6) = unit->group->src_id;
  4402. WBUFW(buf,pos+10) = unit->bl.x;
  4403. WBUFW(buf,pos+12) = unit->bl.y;
  4404. switch (header) {
  4405. case 0x011f:
  4406. WBUFB(buf,pos+14) = unit_id;
  4407. WBUFB(buf,pos+15) = visible;
  4408. break;
  4409. case 0x08c7:
  4410. WBUFB(buf,pos+14) = unit_id;
  4411. WBUFW(buf,pos+15) = unit->range;
  4412. WBUFB(buf,pos+17) = visible;
  4413. break;
  4414. case 0x099f:
  4415. WBUFL(buf,pos+14) = unit_id;
  4416. WBUFW(buf,pos+18) = unit->range;
  4417. WBUFB(buf,pos+20) = visible;
  4418. break;
  4419. case 0x09ca:
  4420. WBUFL(buf,pos+14) = unit_id;
  4421. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4422. WBUFB(buf,pos+19) = visible;
  4423. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4424. break;
  4425. }
  4426. clif_send(buf, len, bl, target);
  4427. if (unit->group->skill_id == WZ_ICEWALL)
  4428. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4429. }
  4430. /*==========================================
  4431. * Server tells client to remove unit of id 'unit->bl.id'
  4432. *------------------------------------------*/
  4433. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4434. {
  4435. nullpo_retv(unit);
  4436. WFIFOHEAD(fd,packet_len(0x120));
  4437. WFIFOW(fd, 0)=0x120;
  4438. WFIFOL(fd, 2)=unit->bl.id;
  4439. WFIFOSET(fd,packet_len(0x120));
  4440. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4441. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4442. }
  4443. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4444. /// 0120 <id>.L
  4445. void clif_skill_delunit(struct skill_unit *unit)
  4446. {
  4447. unsigned char buf[16];
  4448. nullpo_retv(unit);
  4449. WBUFW(buf, 0)=0x120;
  4450. WBUFL(buf, 2)=unit->bl.id;
  4451. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4452. }
  4453. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4454. /// 01ac <id>.L
  4455. /// Only affects units with class [139,153] client-side.
  4456. void clif_skillunit_update(struct block_list* bl)
  4457. {
  4458. unsigned char buf[6];
  4459. nullpo_retv(bl);
  4460. WBUFW(buf,0) = 0x1ac;
  4461. WBUFL(buf,2) = bl->id;
  4462. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4463. }
  4464. /*==========================================
  4465. *
  4466. *------------------------------------------*/
  4467. static int clif_getareachar(struct block_list* bl,va_list ap)
  4468. {
  4469. struct map_session_data *sd;
  4470. nullpo_ret(bl);
  4471. sd=va_arg(ap,struct map_session_data*);
  4472. if (sd == NULL || !sd->fd)
  4473. return 0;
  4474. switch(bl->type){
  4475. case BL_ITEM:
  4476. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4477. break;
  4478. case BL_SKILL:
  4479. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4480. break;
  4481. default:
  4482. if(&sd->bl == bl)
  4483. break;
  4484. clif_getareachar_unit(sd,bl);
  4485. break;
  4486. }
  4487. return 0;
  4488. }
  4489. /*==========================================
  4490. * tbl has gone out of view-size of bl
  4491. *------------------------------------------*/
  4492. int clif_outsight(struct block_list *bl,va_list ap)
  4493. {
  4494. struct block_list *tbl;
  4495. struct view_data *vd;
  4496. TBL_PC *sd, *tsd;
  4497. tbl=va_arg(ap,struct block_list*);
  4498. if(bl == tbl) return 0;
  4499. sd = BL_CAST(BL_PC, bl);
  4500. tsd = BL_CAST(BL_PC, tbl);
  4501. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4502. nullpo_ret(bl);
  4503. switch(bl->type){
  4504. case BL_PC:
  4505. if(sd->vd.class_ != JT_INVISIBLE)
  4506. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4507. if(sd->chatID){
  4508. struct chat_data *cd;
  4509. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4510. if(cd->usersd[0]==sd)
  4511. clif_dispchat(cd,tsd->fd);
  4512. }
  4513. if(sd->state.vending)
  4514. clif_closevendingboard(bl,tsd->fd);
  4515. if(sd->state.buyingstore)
  4516. clif_buyingstore_disappear_entry_single(tsd, sd);
  4517. break;
  4518. case BL_ITEM:
  4519. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4520. break;
  4521. case BL_SKILL:
  4522. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4523. break;
  4524. case BL_NPC:
  4525. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4526. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4527. break;
  4528. default:
  4529. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4530. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4531. break;
  4532. }
  4533. }
  4534. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4535. nullpo_ret(tbl);
  4536. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4537. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4538. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4539. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4540. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4541. }
  4542. return 0;
  4543. }
  4544. /*==========================================
  4545. * tbl has come into view of bl
  4546. *------------------------------------------*/
  4547. int clif_insight(struct block_list *bl,va_list ap)
  4548. {
  4549. struct block_list *tbl;
  4550. TBL_PC *sd, *tsd;
  4551. tbl=va_arg(ap,struct block_list*);
  4552. if (bl == tbl) return 0;
  4553. sd = BL_CAST(BL_PC, bl);
  4554. tsd = BL_CAST(BL_PC, tbl);
  4555. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4556. switch(bl->type){
  4557. case BL_ITEM:
  4558. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4559. break;
  4560. case BL_SKILL:
  4561. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4562. break;
  4563. default:
  4564. clif_getareachar_unit(tsd,bl);
  4565. break;
  4566. }
  4567. }
  4568. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4569. clif_getareachar_unit(sd,tbl);
  4570. }
  4571. return 0;
  4572. }
  4573. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4574. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4575. void clif_skillinfoblock(struct map_session_data *sd)
  4576. {
  4577. int fd;
  4578. int i,len,id;
  4579. nullpo_retv(sd);
  4580. fd = sd->fd;
  4581. if (!fd)
  4582. return;
  4583. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4584. WFIFOW(fd,0) = 0x10f;
  4585. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4586. {
  4587. if( (id = sd->status.skill[i].id) != 0 )
  4588. {
  4589. // workaround for bugreport:5348
  4590. if (len + 37 > 8192)
  4591. break;
  4592. WFIFOW(fd,len) = id;
  4593. WFIFOL(fd,len+2) = skill_get_inf(id);
  4594. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4595. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4596. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4597. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4598. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4599. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4600. else
  4601. WFIFOB(fd,len+36) = 0;
  4602. len += 37;
  4603. }
  4604. }
  4605. WFIFOW(fd,2)=len;
  4606. WFIFOSET(fd,len);
  4607. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4608. for ( ; i < MAX_SKILL; i++)
  4609. {
  4610. if( (id = sd->status.skill[i].id) != 0 )
  4611. {
  4612. clif_addskill(sd, id);
  4613. clif_skillinfo(sd, id, 0);
  4614. }
  4615. }
  4616. }
  4617. /**
  4618. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4619. **/
  4620. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4621. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4622. void clif_addskill(struct map_session_data *sd, int skill_id)
  4623. {
  4624. int fd;
  4625. uint16 idx = 0;
  4626. nullpo_retv(sd);
  4627. fd = sd->fd;
  4628. if (!fd || !(idx = skill_get_index(skill_id)))
  4629. return;
  4630. if( sd->status.skill[idx].id <= 0 )
  4631. return;
  4632. WFIFOHEAD(fd, packet_len(0x111));
  4633. WFIFOW(fd,0) = 0x111;
  4634. WFIFOW(fd,2) = skill_id;
  4635. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4636. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4637. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4638. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4639. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4640. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4641. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4642. else
  4643. WFIFOB(fd,38) = 0;
  4644. WFIFOSET(fd,packet_len(0x111));
  4645. }
  4646. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4647. /// 0441 <skill id>.W
  4648. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4649. {
  4650. #if PACKETVER >= 20081217
  4651. int fd;
  4652. uint16 idx = 0;
  4653. nullpo_retv(sd);
  4654. fd = sd->fd;
  4655. if (!fd || !(idx = skill_get_index(skill_id)))
  4656. return;
  4657. WFIFOHEAD(fd,packet_len(0x441));
  4658. WFIFOW(fd,0) = 0x441;
  4659. WFIFOW(fd,2) = skill_id;
  4660. WFIFOSET(fd,packet_len(0x441));
  4661. #endif
  4662. clif_skillinfoblock(sd);
  4663. }
  4664. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4665. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4666. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4667. int fd;
  4668. nullpo_retv(sd);
  4669. fd = sd->fd;
  4670. WFIFOHEAD(fd, packet_len(0x10e));
  4671. WFIFOW(fd, 0) = 0x10e;
  4672. WFIFOW(fd, 2) = skill_id;
  4673. WFIFOW(fd, 4) = lv;
  4674. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4675. WFIFOW(fd, 8) = range;
  4676. WFIFOB(fd, 10) = upgradable;
  4677. WFIFOSET(fd, packet_len(0x10e));
  4678. }
  4679. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4680. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4681. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4682. {
  4683. const int fd = sd->fd;
  4684. uint16 idx = skill_get_index(skill_id);
  4685. if (!idx)
  4686. return;
  4687. WFIFOHEAD(fd,packet_len(0x7e1));
  4688. WFIFOW(fd,0) = 0x7e1;
  4689. WFIFOW(fd,2) = skill_id;
  4690. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4691. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4692. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4693. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4694. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4695. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4696. else
  4697. WFIFOB(fd,14) = 0;
  4698. WFIFOSET(fd,packet_len(0x7e1));
  4699. }
  4700. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4701. #if PACKETVER >= 20151223
  4702. if( !battle_config.show_skill_scale ){
  4703. return;
  4704. }
  4705. struct PACKET_ZC_SKILL_SCALE p;
  4706. p.PacketType = skillscale;
  4707. p.AID = src_id;
  4708. p.skill_id = skill_id;
  4709. p.skill_lv = skill_lv;
  4710. p.x = x;
  4711. p.y = y;
  4712. p.casttime = casttime;
  4713. if( disguised( bl ) ){
  4714. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4715. p.AID = disguised_bl_id( bl->id );
  4716. clif_send( &p, sizeof( p ), bl, SELF );
  4717. }else{
  4718. clif_send( &p, sizeof( p ), bl, AREA );
  4719. }
  4720. #endif
  4721. }
  4722. /// Notifies clients in area, that an object is about to use a skill.
  4723. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4724. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4725. /// property:
  4726. /// 0 = Yellow cast aura
  4727. /// 1 = Water elemental cast aura
  4728. /// 2 = Earth elemental cast aura
  4729. /// 3 = Fire elemental cast aura
  4730. /// 4 = Wind elemental cast aura
  4731. /// 5 = Poison elemental cast aura
  4732. /// 6 = Holy elemental cast aura
  4733. /// ? = like 0
  4734. /// is disposable:
  4735. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4736. /// 1 = no text
  4737. 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)
  4738. {
  4739. #if PACKETVER < 20091124
  4740. const int cmd = 0x13e;
  4741. #else
  4742. const int cmd = 0x7fb;
  4743. #endif
  4744. unsigned char buf[32];
  4745. WBUFW(buf,0) = cmd;
  4746. WBUFL(buf,2) = src_id;
  4747. WBUFL(buf,6) = dst_id;
  4748. WBUFW(buf,10) = dst_x;
  4749. WBUFW(buf,12) = dst_y;
  4750. WBUFW(buf,14) = skill_id;
  4751. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4752. WBUFL(buf,20) = casttime;
  4753. #if PACKETVER >= 20091124
  4754. WBUFB(buf,24) = 0; // isDisposable
  4755. #endif
  4756. if (disguised(bl)) {
  4757. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4758. WBUFL(buf,2) = disguised_bl_id( src_id );
  4759. clif_send(buf,packet_len(cmd), bl, SELF);
  4760. } else
  4761. clif_send(buf,packet_len(cmd), bl, AREA);
  4762. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4763. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4764. }
  4765. }
  4766. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4767. /// 01b9 <id>.L
  4768. void clif_skillcastcancel(struct block_list* bl)
  4769. {
  4770. unsigned char buf[16];
  4771. nullpo_retv(bl);
  4772. WBUFW(buf,0) = 0x1b9;
  4773. WBUFL(buf,2) = bl->id;
  4774. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4775. }
  4776. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4777. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4778. /// num (only used when skill id = NV_BASIC and cause = 0):
  4779. /// 0 = "skill failed" MsgStringTable[159]
  4780. /// 1 = "no emotions" MsgStringTable[160]
  4781. /// 2 = "no sit" MsgStringTable[161]
  4782. /// 3 = "no chat" MsgStringTable[162]
  4783. /// 4 = "no party" MsgStringTable[163]
  4784. /// 5 = "no shout" MsgStringTable[164]
  4785. /// 6 = "no PKing" MsgStringTable[165]
  4786. /// 7 = "no alligning" MsgStringTable[383]
  4787. /// ? = ignored
  4788. /// cause:
  4789. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4790. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4791. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4792. /// "skill failed" MsgStringTable[204] (otherwise)
  4793. /// ... = @see enum useskill_fail_cause
  4794. /// ? = ignored
  4795. ///
  4796. /// if(result!=0) doesn't display any of the previous messages
  4797. /// Note: when this packet is received an unknown flag is always set to 0,
  4798. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4799. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, int itemId ){
  4800. nullpo_retv( sd );
  4801. int fd = sd->fd;
  4802. if( !session_isActive( fd ) ){
  4803. return;
  4804. }
  4805. if(battle_config.display_skill_fail&1)
  4806. return; //Disable all skill failed messages
  4807. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4808. return; //Disable delay failed messages
  4809. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4810. return;
  4811. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4812. return;
  4813. struct PACKET_ZC_ACK_TOUSESKILL p;
  4814. p.packetType = 0x110;
  4815. p.skillId = skill_id;
  4816. p.btype = btype;
  4817. p.itemId = itemId;
  4818. p.flag = 0; // 0 - failed
  4819. p.cause = cause;
  4820. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4821. }
  4822. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4823. /// 043d <skill ID>.W <tick>.L
  4824. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4825. {
  4826. #if PACKETVER>=20081112
  4827. int fd;
  4828. nullpo_retv(sd);
  4829. fd=sd->fd;
  4830. WFIFOHEAD(fd,packet_len(0x43d));
  4831. WFIFOW(fd,0) = 0x43d;
  4832. WFIFOW(fd,2) = skill_id;
  4833. WFIFOL(fd,4) = client_tick(tick);
  4834. WFIFOSET(fd,packet_len(0x43d));
  4835. #endif
  4836. }
  4837. /// Skill attack effect and damage.
  4838. /// 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)
  4839. /// 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)
  4840. 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)
  4841. {
  4842. unsigned char buf[64];
  4843. struct status_change *sc;
  4844. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4845. nullpo_ret(src);
  4846. nullpo_ret(dst);
  4847. type = clif_calc_delay(type,div,damage,ddelay);
  4848. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4849. if(sc->data[SC_HALLUCINATION] && damage)
  4850. damage = clif_hallucination_damage();
  4851. }
  4852. #if PACKETVER < 3
  4853. WBUFW(buf,0)=0x114;
  4854. WBUFW(buf,2)=skill_id;
  4855. WBUFL(buf,4)=src->id;
  4856. WBUFL(buf,8)=dst->id;
  4857. WBUFL(buf,12)=client_tick(tick);
  4858. WBUFL(buf,16)=sdelay;
  4859. WBUFL(buf,20)=ddelay;
  4860. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4861. WBUFW(buf,24)=damage?div:0;
  4862. } else {
  4863. WBUFW(buf,24)=damage;
  4864. }
  4865. WBUFW(buf,26)=skill_lv;
  4866. WBUFW(buf,28)=div;
  4867. WBUFB(buf,30)=type;
  4868. if (disguised(dst)) {
  4869. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4870. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4871. clif_send(buf,packet_len(0x114),dst,SELF);
  4872. } else
  4873. clif_send(buf,packet_len(0x114),dst,AREA);
  4874. if(disguised(src)) {
  4875. WBUFL(buf,4)=disguised_bl_id(src->id);
  4876. if (disguised(dst))
  4877. WBUFL(buf,8)=dst->id;
  4878. if(damage > 0)
  4879. WBUFW(buf,24)=-1;
  4880. clif_send(buf,packet_len(0x114),src,SELF);
  4881. }
  4882. #else
  4883. WBUFW(buf,0)=0x1de;
  4884. WBUFW(buf,2)=skill_id;
  4885. WBUFL(buf,4)=src->id;
  4886. WBUFL(buf,8)=dst->id;
  4887. WBUFL(buf,12)=client_tick(tick);
  4888. WBUFL(buf,16)=sdelay;
  4889. WBUFL(buf,20)=ddelay;
  4890. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4891. WBUFL(buf,24)=damage?div:0;
  4892. } else {
  4893. WBUFL(buf,24)=damage;
  4894. }
  4895. WBUFW(buf,28)=skill_lv;
  4896. WBUFW(buf,30)=div;
  4897. // For some reason, late 2013 and newer clients have
  4898. // a issue that causes players and monsters to endure
  4899. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4900. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4901. #if PACKETVER < 20131223
  4902. WBUFB(buf,32)=type;
  4903. #else
  4904. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  4905. #endif
  4906. if (disguised(dst)) {
  4907. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4908. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4909. clif_send(buf,packet_len(0x1de),dst,SELF);
  4910. } else
  4911. clif_send(buf,packet_len(0x1de),dst,AREA);
  4912. if(disguised(src)) {
  4913. WBUFL(buf,4)=disguised_bl_id(src->id);
  4914. if (disguised(dst))
  4915. WBUFL(buf,8)=dst->id;
  4916. if(damage > 0)
  4917. WBUFL(buf,24)=-1;
  4918. clif_send(buf,packet_len(0x1de),src,SELF);
  4919. }
  4920. #endif
  4921. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4922. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4923. }
  4924. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4925. /// 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
  4926. /*
  4927. 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)
  4928. {
  4929. unsigned char buf[64];
  4930. struct status_change *sc;
  4931. nullpo_ret(src);
  4932. nullpo_ret(dst);
  4933. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4934. type = clif_calc_delay(type,div,damage,ddelay);
  4935. sc = status_get_sc(dst);
  4936. if(sc && sc->count) {
  4937. if(sc->data[SC_HALLUCINATION] && damage)
  4938. damage = clif_hallucination_damage();
  4939. }
  4940. WBUFW(buf,0)=0x115;
  4941. WBUFW(buf,2)=skill_id;
  4942. WBUFL(buf,4)=src->id;
  4943. WBUFL(buf,8)=dst->id;
  4944. WBUFL(buf,12)=client_tick(tick);
  4945. WBUFL(buf,16)=sdelay;
  4946. WBUFL(buf,20)=ddelay;
  4947. WBUFW(buf,24)=dst->x;
  4948. WBUFW(buf,26)=dst->y;
  4949. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4950. WBUFW(buf,28)=damage?div:0;
  4951. } else {
  4952. WBUFW(buf,28)=damage;
  4953. }
  4954. WBUFW(buf,30)=skill_lv;
  4955. WBUFW(buf,32)=div;
  4956. WBUFB(buf,34)=type;
  4957. clif_send(buf,packet_len(0x115),src,AREA);
  4958. if(disguised(src)) {
  4959. WBUFL(buf,4)=disguised_bl_id(src->id);
  4960. if(damage > 0)
  4961. WBUFW(buf,28)=-1;
  4962. clif_send(buf,packet_len(0x115),src,SELF);
  4963. }
  4964. if (disguised(dst)) {
  4965. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4966. if (disguised(src))
  4967. WBUFL(buf,4)=src->id;
  4968. else if(damage > 0)
  4969. WBUFW(buf,28)=-1;
  4970. clif_send(buf,packet_len(0x115),dst,SELF);
  4971. }
  4972. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4973. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4974. }
  4975. */
  4976. /// Non-damaging skill effect
  4977. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4978. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4979. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  4980. {
  4981. unsigned char buf[17];
  4982. #if PACKETVER < 20130731
  4983. const int cmd = 0x11a;
  4984. #else
  4985. const int cmd = 0x9cb;
  4986. #endif
  4987. int offset = 0;
  4988. bool success = ( tick != 0 );
  4989. nullpo_ret(dst);
  4990. WBUFW(buf,0) = cmd;
  4991. WBUFW(buf,2) = skill_id;
  4992. #if PACKETVER < 20130731
  4993. WBUFW(buf,4) = min(heal, INT16_MAX);
  4994. #else
  4995. WBUFL(buf,4) = min(heal, INT32_MAX);
  4996. offset += 2;
  4997. #endif
  4998. WBUFL(buf,6+offset) = dst->id;
  4999. WBUFL(buf,10+offset) = src ? src->id : 0;
  5000. WBUFB(buf,14+offset) = success;
  5001. if (disguised(dst)) {
  5002. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5003. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5004. clif_send(buf, packet_len(cmd), dst, SELF);
  5005. } else
  5006. clif_send(buf, packet_len(cmd), dst, AREA);
  5007. if(src && disguised(src)) {
  5008. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5009. if (disguised(dst))
  5010. WBUFL(buf,6+offset) = dst->id;
  5011. clif_send(buf, packet_len(cmd), src, SELF);
  5012. }
  5013. return success;
  5014. }
  5015. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5016. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5017. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5018. {
  5019. unsigned char buf[32];
  5020. nullpo_retv(src);
  5021. WBUFW(buf,0)=0x117;
  5022. WBUFW(buf,2)=skill_id;
  5023. WBUFL(buf,4)=src->id;
  5024. WBUFW(buf,8)=val;
  5025. WBUFW(buf,10)=x;
  5026. WBUFW(buf,12)=y;
  5027. WBUFL(buf,14)=client_tick(tick);
  5028. if(disguised(src)) {
  5029. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5030. WBUFL(buf,4)=disguised_bl_id(src->id);
  5031. clif_send(buf,packet_len(0x117),src,SELF);
  5032. } else
  5033. clif_send(buf,packet_len(0x117),src,AREA);
  5034. }
  5035. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5036. /// 011c <skill id>.W { <map name>.16B }*4
  5037. 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)
  5038. {
  5039. int fd;
  5040. nullpo_retv(sd);
  5041. fd = sd->fd;
  5042. WFIFOHEAD(fd,packet_len(0x11c));
  5043. WFIFOW(fd,0) = 0x11c;
  5044. WFIFOW(fd,2) = skill_id;
  5045. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5046. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5047. else // normal map name
  5048. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5049. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5050. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5051. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5052. WFIFOSET(fd,packet_len(0x11c));
  5053. sd->menuskill_id = skill_id;
  5054. if (skill_id == AL_WARP) {
  5055. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5056. sd->state.workinprogress = WIP_DISABLE_ALL;
  5057. } else
  5058. sd->menuskill_val = skill_lv;
  5059. }
  5060. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5061. /// 011e <type>.B
  5062. /// type:
  5063. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5064. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5065. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5066. ///
  5067. /// @param sd Who receives the message
  5068. /// @param type What message
  5069. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5070. {
  5071. int fd;
  5072. nullpo_retv(sd);
  5073. fd=sd->fd;
  5074. WFIFOHEAD(fd,packet_len(0x11e));
  5075. WFIFOW(fd,0)=0x11e;
  5076. WFIFOB(fd,2)=type;
  5077. WFIFOSET(fd,packet_len(0x11e));
  5078. }
  5079. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5080. /// 0189 <type>.W
  5081. /// type:
  5082. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5083. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5084. ///
  5085. /// @param sd Who receives the message
  5086. /// @param type What message
  5087. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5088. {
  5089. int fd;
  5090. nullpo_retv(sd);
  5091. fd=sd->fd;
  5092. WFIFOHEAD(fd,packet_len(0x189));
  5093. WFIFOW(fd,0)=0x189;
  5094. WFIFOW(fd,2)=type;
  5095. WFIFOSET(fd,packet_len(0x189));
  5096. }
  5097. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5098. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5099. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5100. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5101. {
  5102. struct status_data *status;
  5103. unsigned char buf[64];
  5104. int i, fix;
  5105. nullpo_retv(sd);
  5106. nullpo_retv(dst);
  5107. if( dst->type != BL_MOB )
  5108. return;
  5109. status = status_get_status_data(dst);
  5110. WBUFW(buf, 0)=0x18c;
  5111. WBUFW(buf, 2)=status_get_class(dst);
  5112. WBUFW(buf, 4)=status_get_lv(dst);
  5113. WBUFW(buf, 6)=status->size;
  5114. WBUFL(buf, 8)=status->hp;
  5115. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5116. +(battle_config.estimation_type&2?status->def2:0);
  5117. WBUFW(buf,14)=status->race;
  5118. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5119. +(battle_config.estimation_type&2?status->mdef2:0);
  5120. WBUFW(buf,18)= status->def_ele;
  5121. for(i=0;i<9;i++)
  5122. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5123. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5124. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5125. }
  5126. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5127. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5128. /// material id:
  5129. /// unused by the client
  5130. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5131. nullpo_retv(sd);
  5132. int fd = sd->fd;
  5133. if( !session_isActive( fd ) ){
  5134. return;
  5135. }
  5136. if (sd->menuskill_id == skill_id)
  5137. return; //Avoid resending the menu twice or more times...
  5138. if (skill_id == GC_CREATENEWPOISON)
  5139. skill_id = GC_RESEARCHNEWPOISON;
  5140. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5141. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5142. p->packetType = 0x18d;
  5143. int count = 0;
  5144. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5145. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5146. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5147. )
  5148. {
  5149. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5150. p->items[count].material[0] = 0;
  5151. p->items[count].material[1] = 0;
  5152. p->items[count].material[2] = 0;
  5153. count++;
  5154. }
  5155. }
  5156. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5157. WFIFOSET( fd, p->packetLength );
  5158. if( count > 0 ){
  5159. sd->menuskill_id = skill_id;
  5160. sd->menuskill_val = trigger;
  5161. return;
  5162. }
  5163. }
  5164. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5165. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5166. /// mk type:
  5167. /// 1 = cooking
  5168. /// 2 = arrow
  5169. /// 3 = elemental
  5170. /// 4 = GN_MIX_COOKING
  5171. /// 5 = GN_MAKEBOMB
  5172. /// 6 = GN_S_PHARMACY
  5173. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5174. nullpo_retv( sd );
  5175. // Avoid resending the menu twice or more times...
  5176. if( sd->menuskill_id == skill_id ){
  5177. return;
  5178. }
  5179. int fd = sd->fd;
  5180. if( !session_isActive( fd ) ){
  5181. return;
  5182. }
  5183. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5184. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5185. p->packetType = 0x25a;
  5186. p->makeItem = list_type; // list type
  5187. int count = 0;
  5188. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5189. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5190. continue;
  5191. }
  5192. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5193. count++;
  5194. }
  5195. if( count > 0 || skill_id == AM_PHARMACY ){
  5196. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5197. WFIFOSET( fd, p->packetLength );
  5198. sd->menuskill_id = skill_id;
  5199. sd->menuskill_val = trigger;
  5200. sd->menuskill_val2 = qty; // amount.
  5201. }else{
  5202. clif_menuskill_clear(sd);
  5203. #if PACKETVER >= 20090922
  5204. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5205. #else
  5206. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5207. WFIFOSET( fd, p->packetLength );
  5208. #endif
  5209. }
  5210. }
  5211. /// Notifies clients of a status change.
  5212. /// 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)]
  5213. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5214. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5215. /// @param bl Sends packet to clients around this object
  5216. /// @param id ID of object that has this effect
  5217. /// @param type Status icon see enum efst_types
  5218. /// @param flag 1:Active, 0:Deactive
  5219. /// @param tick Duration in ms
  5220. /// @param val1
  5221. /// @param val2
  5222. /// @param val3
  5223. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, t_tick tick, int val1, int val2, int val3, enum send_target target_type)
  5224. {
  5225. unsigned char buf[32];
  5226. if (type == EFST_BLANK) //It shows nothing on the client...
  5227. return;
  5228. if (type == EFST_POSTDELAY && tick == 0)
  5229. return;
  5230. nullpo_retv(bl);
  5231. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5232. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5233. tick = 200;
  5234. #if PACKETVER >= 20120618
  5235. if (flag && battle_config.display_status_timers)
  5236. WBUFW(buf,0) = 0x983;
  5237. else
  5238. #elif PACKETVER >= 20090121
  5239. if (flag && battle_config.display_status_timers)
  5240. WBUFW(buf,0) = 0x43f;
  5241. else
  5242. #endif
  5243. WBUFW(buf,0) = 0x196;
  5244. WBUFW(buf,2) = type;
  5245. WBUFL(buf,4) = id;
  5246. WBUFB(buf,8) = flag;
  5247. #if PACKETVER >= 20120618
  5248. if (flag && battle_config.display_status_timers) {
  5249. if (tick <= 0)
  5250. tick = 9999; // this is indeed what official servers do
  5251. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5252. WBUFL(buf,13) = client_tick(tick);
  5253. WBUFL(buf,17) = val1;
  5254. WBUFL(buf,21) = val2;
  5255. WBUFL(buf,25) = val3;
  5256. }
  5257. #elif PACKETVER >= 20090121
  5258. if (flag && battle_config.display_status_timers) {
  5259. if (tick <= 0)
  5260. tick = 9999; // this is indeed what official servers do
  5261. WBUFL(buf,9) = client_tick(tick);
  5262. WBUFL(buf,13) = val1;
  5263. WBUFL(buf,17) = val2;
  5264. WBUFL(buf,21) = val3;
  5265. }
  5266. #endif
  5267. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5268. }
  5269. /* Sends status effect to clients around the bl
  5270. * @param bl Object that has the effect
  5271. * @param type Status icon see enum efst_types
  5272. * @param flag 1:Active, 0:Deactive
  5273. * @param tick Duration in ms
  5274. * @param val1
  5275. * @param val2
  5276. * @param val3
  5277. */
  5278. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5279. struct map_session_data *sd = NULL;
  5280. if (type == EFST_BLANK) //It shows nothing on the client...
  5281. return;
  5282. if (type == EFST_POSTDELAY && tick == 0)
  5283. return;
  5284. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5285. return;
  5286. nullpo_retv(bl);
  5287. sd = BL_CAST(BL_PC, bl);
  5288. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5289. return;
  5290. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5291. }
  5292. /**
  5293. * Send any active EFST to those around.
  5294. * @param tbl: Unit to send the packet to
  5295. * @param bl: Objects walking into view
  5296. * @param target: Client send type
  5297. */
  5298. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5299. unsigned char i;
  5300. struct sc_display_entry **sc_display;
  5301. unsigned char sc_display_count;
  5302. bool spheres_sent;
  5303. nullpo_retv(bl);
  5304. switch( bl->type ){
  5305. case BL_PC: {
  5306. struct map_session_data* sd = (struct map_session_data*)bl;
  5307. sc_display = sd->sc_display;
  5308. sc_display_count = sd->sc_display_count;
  5309. spheres_sent = !sd->state.connect_new;
  5310. }
  5311. break;
  5312. case BL_NPC: {
  5313. struct npc_data* nd = (struct npc_data*)bl;
  5314. sc_display = nd->sc_display;
  5315. sc_display_count = nd->sc_display_count;
  5316. spheres_sent = true;
  5317. }
  5318. break;
  5319. default:
  5320. return;
  5321. }
  5322. for (i = 0; i < sc_display_count; i++) {
  5323. enum sc_type type = sc_display[i]->type;
  5324. struct status_change *sc = status_get_sc(bl);
  5325. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5326. t_tick tick = 0;
  5327. if (td)
  5328. tick = DIFF_TICK(td->tick, gettick());
  5329. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5330. #if PACKETVER > 20120418
  5331. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5332. #else
  5333. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, AREA_WOS);
  5334. #endif
  5335. }else{
  5336. #if PACKETVER > 20120418
  5337. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5338. #else
  5339. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5340. #endif
  5341. }
  5342. }
  5343. }
  5344. /// Notifies the client when a player enters the screen with an active EFST.
  5345. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5346. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5347. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, t_tick tick, int val1, int val2, int val3) {
  5348. #if PACKETVER >= 20111108
  5349. unsigned char buf[32];
  5350. #if PACKETVER >= 20120618
  5351. const int cmd = 0x984;
  5352. #elif PACKETVER >= 20111108
  5353. const int cmd = 0x8ff;
  5354. #endif
  5355. int offset = 0;
  5356. if (type == EFST_BLANK)
  5357. return;
  5358. nullpo_retv(bl);
  5359. if (tick <= 0)
  5360. tick = 9999;
  5361. WBUFW(buf,offset + 0) = cmd;
  5362. WBUFL(buf,offset + 2) = tid;
  5363. WBUFW(buf,offset + 6) = type;
  5364. #if PACKETVER >= 20111108
  5365. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5366. #if PACKETVER >= 20120618
  5367. WBUFL(buf,offset + 12) = client_tick(tick);
  5368. offset += 4;
  5369. #endif
  5370. WBUFL(buf,offset + 12) = val1;
  5371. WBUFL(buf,offset + 16) = val2;
  5372. WBUFL(buf,offset + 20) = val3;
  5373. #endif
  5374. clif_send(buf,packet_len(cmd),bl,target);
  5375. #endif
  5376. }
  5377. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5378. /// 008e <packet len>.W <message>.?B
  5379. void clif_displaymessage(const int fd, const char* mes)
  5380. {
  5381. nullpo_retv(mes);
  5382. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5383. if (fd == 0)
  5384. ;
  5385. else {
  5386. char *message, *line;
  5387. message = aStrdup(mes);
  5388. line = strtok(message, "\n");
  5389. while(line != NULL) {
  5390. #if PACKETVER == 20141022
  5391. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5392. /** so we redirect to ZC_NPC_CHAT **/
  5393. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5394. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5395. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5396. if (len > 0) {
  5397. WFIFOHEAD(fd, 13 + len);
  5398. WFIFOW(fd, 0) = 0x2C1;
  5399. WFIFOW(fd, 2) = 13 + len;
  5400. WFIFOL(fd, 4) = 0;
  5401. WFIFOL(fd, 8) = color;
  5402. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5403. WFIFOSET(fd, WFIFOW(fd, 2));
  5404. }
  5405. #else
  5406. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5407. int len = strnlen(line, CHAT_SIZE_MAX);
  5408. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5409. WFIFOHEAD(fd, 5 + len);
  5410. WFIFOW(fd,0) = 0x8e;
  5411. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5412. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5413. WFIFOSET(fd, 5 + len);
  5414. }
  5415. #endif
  5416. line = strtok(NULL, "\n");
  5417. }
  5418. aFree(message);
  5419. }
  5420. }
  5421. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5422. /// 009a <packet len>.W <message>.?B
  5423. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5424. {
  5425. nullpo_retv(mes);
  5426. if (len < 2)
  5427. return;
  5428. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5429. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5430. WBUFW(buf.get(),0) = 0x9a;
  5431. WBUFW(buf.get(),2) = 4 + lp + len;
  5432. if (type&BC_BLUE)
  5433. WBUFL(buf.get(),4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5434. else if (type&BC_WOE)
  5435. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5436. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5437. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5438. }
  5439. /*==========================================
  5440. * Displays a message on a 'bl' to all it's nearby clients
  5441. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5442. *------------------------------------------*/
  5443. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5444. size_t len;
  5445. nullpo_retv(bl);
  5446. if(!message)
  5447. return;
  5448. len = strlen(message)+1;
  5449. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5450. if( len > CHAT_SIZE_MAX ) {
  5451. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  5452. len = CHAT_SIZE_MAX;
  5453. }
  5454. std::unique_ptr<char> buf(new char[8+len]);
  5455. WBUFW(buf.get(),0)=0x8d;
  5456. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5457. WBUFL(buf.get(),4)=bl->id;
  5458. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5459. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5460. }
  5461. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5462. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5463. 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)
  5464. {
  5465. nullpo_retv(mes);
  5466. if (len < 2)
  5467. return;
  5468. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5469. WBUFW(buf.get(),0) = 0x1c3;
  5470. WBUFW(buf.get(),2) = len + 16;
  5471. WBUFL(buf.get(),4) = fontColor;
  5472. WBUFW(buf.get(),8) = fontType;
  5473. WBUFW(buf.get(),10) = fontSize;
  5474. WBUFW(buf.get(),12) = fontAlign;
  5475. WBUFW(buf.get(),14) = fontY;
  5476. memcpy(WBUFP(buf.get(),16), mes, len);
  5477. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5478. }
  5479. /*
  5480. * Display *msg to all *users in channel
  5481. */
  5482. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5483. DBIterator *iter;
  5484. struct map_session_data *user;
  5485. unsigned short msg_len = 0, len = 0;
  5486. unsigned char buf[CHAT_SIZE_MAX];
  5487. if (!channel || !msg)
  5488. return;
  5489. msg_len = (unsigned short)(strlen(msg) + 1);
  5490. if( msg_len > sizeof(buf)-12 ) {
  5491. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5492. msg_len = sizeof(buf)-12;
  5493. }
  5494. WBUFW(buf,0) = 0x2C1;
  5495. WBUFW(buf,2) = (len = msg_len + 12);
  5496. WBUFL(buf,4) = 0;
  5497. WBUFL(buf,8) = color;
  5498. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5499. iter = db_iterator(channel->users);
  5500. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5501. clif_send(buf, len, &user->bl, SELF);
  5502. }
  5503. dbi_destroy(iter);
  5504. }
  5505. /// Displays heal effect.
  5506. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5507. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5508. /// var id:
  5509. /// 5 = HP (SP_HP)
  5510. /// 7 = SP (SP_SP)
  5511. /// ? = ignored
  5512. void clif_heal(int fd,int type,int val) {
  5513. #if PACKETVER < 20141022
  5514. const int cmd = 0x13d;
  5515. #else
  5516. const int cmd = 0xa27;
  5517. #endif
  5518. WFIFOHEAD(fd, packet_len(cmd));
  5519. WFIFOW(fd,0) = cmd;
  5520. WFIFOW(fd,2) = type;
  5521. #if PACKETVER < 20141022
  5522. WFIFOW(fd,4) = min(val, INT16_MAX);
  5523. #else
  5524. WFIFOL(fd,4) = min(val, INT32_MAX);
  5525. #endif
  5526. WFIFOSET(fd, packet_len(cmd));
  5527. }
  5528. /// Displays resurrection effect (ZC_RESURRECTION).
  5529. /// 0148 <id>.L <type>.W
  5530. /// type:
  5531. /// ignored
  5532. void clif_resurrection(struct block_list *bl,int type)
  5533. {
  5534. unsigned char buf[16];
  5535. nullpo_retv(bl);
  5536. WBUFW(buf,0)=0x148;
  5537. WBUFL(buf,2)=bl->id;
  5538. WBUFW(buf,6)=0;
  5539. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5540. if (disguised(bl))
  5541. clif_spawn(bl);
  5542. }
  5543. /// Sets the map property
  5544. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5545. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5546. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5547. {
  5548. #if PACKETVER >= 20121010
  5549. short cmd = 0x99b;
  5550. unsigned char buf[8];
  5551. #else
  5552. short cmd = 0x199;
  5553. unsigned char buf[4];
  5554. #endif
  5555. WBUFW(buf,0)=cmd;
  5556. WBUFW(buf,2)=property;
  5557. #if PACKETVER >= 20121010
  5558. struct map_data *mapdata = map_getmapdata(bl->m);
  5559. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5560. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5561. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5562. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5563. ((mapdata->flag[MF_NOLOCKON] || mapdata_flag_vs(mapdata)?1:0)<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5564. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5565. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5566. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5567. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5568. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5569. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5570. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5571. #endif
  5572. clif_send(buf,packet_len(cmd),bl,t);
  5573. }
  5574. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5575. /// 01d6 <type>.W
  5576. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5577. {
  5578. int fd;
  5579. nullpo_retv(sd);
  5580. fd=sd->fd;
  5581. WFIFOHEAD(fd,packet_len(0x1D6));
  5582. WFIFOW(fd,0)=0x1D6;
  5583. WFIFOW(fd,2)=type;
  5584. WFIFOSET(fd,packet_len(0x1D6));
  5585. }
  5586. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5587. /// 019a <id>.L <ranking>.L <total>.L
  5588. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5589. {
  5590. if(type == 2) {
  5591. int fd = sd->fd;
  5592. WFIFOHEAD(fd,packet_len(0x19a));
  5593. WFIFOW(fd,0) = 0x19a;
  5594. WFIFOL(fd,2) = sd->bl.id;
  5595. WFIFOL(fd,6) = pvprank;
  5596. WFIFOL(fd,10) = pvpnum;
  5597. WFIFOSET(fd,packet_len(0x19a));
  5598. } else {
  5599. unsigned char buf[32];
  5600. WBUFW(buf,0) = 0x19a;
  5601. WBUFL(buf,2) = sd->bl.id;
  5602. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5603. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5604. else
  5605. WBUFL(buf,6) = pvprank;
  5606. WBUFL(buf,10) = pvpnum;
  5607. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5608. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5609. else if(!type)
  5610. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5611. else
  5612. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5613. }
  5614. }
  5615. /*==========================================
  5616. *
  5617. *------------------------------------------*/
  5618. void clif_map_property_mapall(int map_idx, enum map_property property)
  5619. {
  5620. struct block_list bl;
  5621. bl.id = 0;
  5622. bl.type = BL_NUL;
  5623. bl.m = map_idx;
  5624. clif_map_property( &bl, property, ALL_SAMEMAP );
  5625. }
  5626. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5627. /// 0188 <result>.W <index>.W <refine>.W
  5628. /// result:
  5629. /// 0 = success
  5630. /// 1 = failure
  5631. /// 2 = downgrade
  5632. void clif_refine(int fd, int fail, int index, int val)
  5633. {
  5634. WFIFOHEAD(fd,packet_len(0x188));
  5635. WFIFOW(fd,0)=0x188;
  5636. WFIFOW(fd,2)=fail;
  5637. WFIFOW(fd,4)=index+2;
  5638. WFIFOW(fd,6)=val;
  5639. WFIFOSET(fd,packet_len(0x188));
  5640. }
  5641. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5642. /// 0223 <result>.L <nameid>.W
  5643. /// result:
  5644. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5645. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5646. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5647. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5648. void clif_upgrademessage( struct map_session_data* sd, int result, unsigned short item_id ){
  5649. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5650. p.packetType = 0x223;
  5651. p.result = result;
  5652. p.itemId = client_nameid( item_id );
  5653. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5654. }
  5655. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5656. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5657. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5658. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5659. int fd;
  5660. nullpo_retv(sd);
  5661. fd = sd->fd;
  5662. #if PACKETVER < 20091104
  5663. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5664. WFIFOW(fd,0) = 0x97;
  5665. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5666. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5667. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5668. WFIFOSET(fd,WFIFOW(fd,2));
  5669. #else
  5670. struct map_session_data *ssd = map_nick2sd(nick,false);
  5671. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5672. WFIFOW(fd,0) = 0x97;
  5673. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5674. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5675. // If it is not a message from the server or a player from another map-server
  5676. if( ssd ){
  5677. gmlvl = pc_get_group_level(ssd);
  5678. }
  5679. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5680. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5681. WFIFOSET(fd,WFIFOW(fd,2));
  5682. #endif
  5683. }
  5684. /// Inform the player about the result of his whisper action
  5685. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5686. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5687. /// result:
  5688. /// 0 = success to send wisper
  5689. /// 1 = target character is not loged in
  5690. /// 2 = ignored by target
  5691. /// 3 = everyone ignored by target
  5692. void clif_wis_end(int fd, int result)
  5693. {
  5694. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5695. #if PACKETVER < 20131223
  5696. const int cmd = 0x98;
  5697. #else
  5698. const int cmd = 0x9df;
  5699. #endif
  5700. if (!sd)
  5701. return;
  5702. WFIFOHEAD(fd,packet_len(cmd));
  5703. WFIFOW(fd,0) = cmd;
  5704. WFIFOB(fd,2) = (char)result;
  5705. #if PACKETVER >= 20131223
  5706. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5707. #endif
  5708. WFIFOSET(fd,packet_len(cmd));
  5709. }
  5710. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5711. /// 0194 <char id>.L <name>.24B
  5712. /// 0af7 <flag>.W <char id>.L <name>.24B
  5713. void clif_solved_charname(int fd, int charid, const char* name)
  5714. {
  5715. #if PACKETVER >= 20180221
  5716. WFIFOHEAD(fd,packet_len(0xaf7));
  5717. WFIFOW(fd,0) = 0xaf7;
  5718. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5719. WFIFOL(fd,4) = charid;
  5720. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5721. WFIFOSET(fd,packet_len(0x0af7));
  5722. #else
  5723. WFIFOHEAD(fd,packet_len(0x194));
  5724. WFIFOW(fd,0)=0x194;
  5725. WFIFOL(fd,2)=charid;
  5726. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5727. WFIFOSET(fd,packet_len(0x194));
  5728. #endif
  5729. }
  5730. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5731. /// 017b <packet len>.W { <name id>.W }*
  5732. void clif_use_card(struct map_session_data *sd,int idx)
  5733. {
  5734. int i,c,ep;
  5735. int fd=sd->fd;
  5736. nullpo_retv(sd);
  5737. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5738. return;
  5739. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5740. return; //Avoid parsing invalid item indexes (no card/no item)
  5741. ep=sd->inventory_data[idx]->equip;
  5742. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5743. WFIFOW(fd,0)=0x17b;
  5744. for(i=c=0;i<MAX_INVENTORY;i++){
  5745. int j;
  5746. if(sd->inventory_data[i] == NULL)
  5747. continue;
  5748. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5749. continue;
  5750. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5751. continue;
  5752. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5753. continue;
  5754. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5755. continue;
  5756. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5757. continue;
  5758. 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.
  5759. continue;
  5760. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5761. if( j == sd->inventory_data[i]->slot ) // No room
  5762. continue;
  5763. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5764. continue;
  5765. WFIFOW(fd,4+c*2)=i+2;
  5766. c++;
  5767. }
  5768. if( !c ) return; // no item is available for card insertion
  5769. WFIFOW(fd,2)=4+c*2;
  5770. WFIFOSET(fd,WFIFOW(fd,2));
  5771. }
  5772. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5773. /// 017d <equip index>.W <card index>.W <result>.B
  5774. /// result:
  5775. /// 0 = success
  5776. /// 1 = failure
  5777. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5778. {
  5779. int fd;
  5780. nullpo_retv(sd);
  5781. fd=sd->fd;
  5782. WFIFOHEAD(fd,packet_len(0x17d));
  5783. WFIFOW(fd,0)=0x17d;
  5784. WFIFOW(fd,2)=idx_equip+2;
  5785. WFIFOW(fd,4)=idx_card+2;
  5786. WFIFOB(fd,6)=flag;
  5787. WFIFOSET(fd,packet_len(0x17d));
  5788. }
  5789. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5790. /// 0177 <packet len>.W { <index>.W }*
  5791. void clif_item_identify_list(struct map_session_data *sd)
  5792. {
  5793. int i,c;
  5794. int fd;
  5795. nullpo_retv(sd);
  5796. fd=sd->fd;
  5797. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5798. WFIFOW(fd,0)=0x177;
  5799. for(i=c=0;i<MAX_INVENTORY;i++){
  5800. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5801. WFIFOW(fd,c*2+4)=i+2;
  5802. c++;
  5803. }
  5804. }
  5805. if(c > 0) {
  5806. WFIFOW(fd,2)=c*2+4;
  5807. WFIFOSET(fd,WFIFOW(fd,2));
  5808. sd->menuskill_id = MC_IDENTIFY;
  5809. sd->menuskill_val = c;
  5810. sd->state.workinprogress = WIP_DISABLE_ALL;
  5811. }
  5812. }
  5813. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5814. /// 0179 <index>.W <result>.B
  5815. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5816. {
  5817. int fd;
  5818. nullpo_retv(sd);
  5819. fd=sd->fd;
  5820. WFIFOHEAD(fd,packet_len(0x179));
  5821. WFIFOW(fd, 0)=0x179;
  5822. WFIFOW(fd, 2)=idx+2;
  5823. WFIFOB(fd, 4)=flag;
  5824. WFIFOSET(fd,packet_len(0x179));
  5825. }
  5826. /// Presents a list of items that can be repaired.
  5827. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  5828. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  5829. nullpo_retv( sd );
  5830. nullpo_retv( dstsd );
  5831. int fd = sd->fd;
  5832. if( !session_isActive( fd ) ){
  5833. return;
  5834. }
  5835. int len = MAX_INVENTORY * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5836. // Preallocate the maximum size
  5837. WFIFOHEAD( fd, len );
  5838. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  5839. int c = 0;
  5840. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5841. 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)){
  5842. p->items[c].index = i;
  5843. p->items[c].itemId = dstsd->inventory.u.items_inventory[i].nameid;
  5844. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  5845. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  5846. c++;
  5847. }
  5848. }
  5849. if( c > 0 ){
  5850. p->packetType = 0x1fc;
  5851. // Recalculate real length
  5852. len = c * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5853. p->packetLength = len;
  5854. WFIFOSET( fd, len );
  5855. sd->menuskill_id = BS_REPAIRWEAPON;
  5856. sd->menuskill_val = dstsd->bl.id;
  5857. sd->menuskill_val2 = lv;
  5858. }else{
  5859. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  5860. }
  5861. }
  5862. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5863. /// 01fe <index>.W <result>.B
  5864. /// index:
  5865. /// ignored (inventory index)
  5866. /// result:
  5867. /// 0 = Item repair success.
  5868. /// 1 = Item repair failure.
  5869. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5870. {
  5871. int fd;
  5872. nullpo_retv(sd);
  5873. fd = sd->fd;
  5874. WFIFOHEAD(fd,packet_len(0x1fe));
  5875. WFIFOW(fd, 0)=0x1fe;
  5876. WFIFOW(fd, 2)=idx+2;
  5877. WFIFOB(fd, 4)=flag;
  5878. WFIFOSET(fd,packet_len(0x1fe));
  5879. }
  5880. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5881. /// 02bb <equip location>.W <account id>.L
  5882. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5883. {
  5884. int fd = sd->fd;
  5885. WFIFOHEAD(fd,packet_len(0x2bb));
  5886. WFIFOW(fd,0) = 0x2bb;
  5887. WFIFOW(fd,2) = position;
  5888. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5889. WFIFOSET(fd,packet_len(0x2bb));
  5890. }
  5891. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5892. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5893. void clif_item_refine_list( struct map_session_data *sd ){
  5894. nullpo_retv( sd );
  5895. int fd = sd->fd;
  5896. if( !session_isActive( fd ) ){
  5897. return;
  5898. }
  5899. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * MAX_INVENTORY );
  5900. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)WFIFOP( fd, 0 );
  5901. p->packetType = 0x221;
  5902. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  5903. int refine_item[5];
  5904. refine_item[0] = -1;
  5905. refine_item[1] = pc_search_inventory( sd, ITEMID_PHRACON );
  5906. refine_item[2] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  5907. refine_item[3] = refine_item[4] = pc_search_inventory( sd, ITEMID_ORIDECON );
  5908. int count = 0;
  5909. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5910. unsigned char wlv;
  5911. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5912. sd->inventory.u.items_inventory[i].identify && ( wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid ) ) >= 1 &&
  5913. refine_item[wlv] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  5914. p->items[count].index = client_index( i );
  5915. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  5916. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  5917. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  5918. count++;
  5919. }
  5920. }
  5921. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  5922. WFIFOSET( fd, p->packetLength );
  5923. if( count > 0 ){
  5924. sd->menuskill_id = WS_WEAPONREFINE;
  5925. sd->menuskill_val = skill_lv;
  5926. }
  5927. }
  5928. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5929. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5930. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  5931. nullpo_retv( sd );
  5932. struct PACKET_ZC_AUTORUN_SKILL p;
  5933. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  5934. p.skill_id = skill_id;
  5935. p.skill_type = skill_get_inf( skill_id );
  5936. p.skill_lv = skill_lv;
  5937. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  5938. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  5939. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  5940. p.up_flag = false;
  5941. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5942. }
  5943. /// Adds an item to character's cart.
  5944. /// 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)
  5945. /// 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)
  5946. /// 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)
  5947. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  5948. nullpo_retv( sd );
  5949. int fd = sd->fd;
  5950. if( !session_isActive( fd ) ){
  5951. return;
  5952. }
  5953. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0 ){
  5954. return;
  5955. }
  5956. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  5957. p.packetType = cartaddType;
  5958. p.index = client_index( n );
  5959. p.amount = amount;
  5960. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  5961. #if PACKETVER >= 5
  5962. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  5963. #endif
  5964. p.identified = sd->cart.u.items_cart[n].identify;
  5965. p.damaged = sd->cart.u.items_cart[n].attribute;
  5966. p.refine = sd->cart.u.items_cart[n].refine;
  5967. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  5968. #if PACKETVER >= 20150226
  5969. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  5970. #endif
  5971. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5972. }
  5973. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5974. /* Acknowledge an item have been added to cart
  5975. * 012c <result>B
  5976. * result :
  5977. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5978. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5979. */
  5980. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5981. {
  5982. int fd;
  5983. unsigned char *buf;
  5984. nullpo_retv(sd);
  5985. fd = sd->fd;
  5986. buf = WFIFOP(fd,0);
  5987. WBUFW(buf,0) = 0x12c;
  5988. WBUFB(buf,2) = flag;
  5989. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5990. }
  5991. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5992. void clif_bank_open(struct map_session_data *sd){
  5993. int fd;
  5994. nullpo_retv(sd);
  5995. fd = sd->fd;
  5996. WFIFOHEAD(fd,4);
  5997. WFIFOW(fd,0) = 0x09b7;
  5998. WFIFOW(fd,2) = 0;
  5999. WFIFOSET(fd,4);
  6000. }
  6001. /*
  6002. * Request to Open the banking system
  6003. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6004. */
  6005. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6006. //TODO check if preventing trade or stuff like that
  6007. //also mark something in case char ain't available for saving, should we check now ?
  6008. nullpo_retv(sd);
  6009. if( !battle_config.feature_banking ) {
  6010. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6011. return;
  6012. }
  6013. else {
  6014. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6015. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6016. if(sd->status.account_id == aid){
  6017. sd->state.banking = 1;
  6018. //request save ?
  6019. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6020. //on succes open bank ?
  6021. clif_bank_open(sd);
  6022. }
  6023. }
  6024. }
  6025. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6026. void clif_bank_close(struct map_session_data *sd){
  6027. int fd;
  6028. nullpo_retv(sd);
  6029. fd = sd->fd;
  6030. WFIFOHEAD(fd,4);
  6031. WFIFOW(fd,0) = 0x09B9;
  6032. WFIFOW(fd,2) = 0;
  6033. WFIFOSET(fd,4);
  6034. }
  6035. /*
  6036. * Request to close the banking system
  6037. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6038. */
  6039. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6040. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6041. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6042. nullpo_retv(sd);
  6043. if( !battle_config.feature_banking ) {
  6044. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6045. //still allow to go trough to not stuck player if we have disable it while they was in
  6046. }
  6047. if(sd->status.account_id == aid){
  6048. sd->state.banking = 0;
  6049. clif_bank_close(sd);
  6050. }
  6051. }
  6052. /*
  6053. * Display how much we got in bank (I suppose)
  6054. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6055. */
  6056. void clif_Bank_Check(struct map_session_data* sd) {
  6057. unsigned char buf[13];
  6058. struct s_packet_db* info;
  6059. int16 len;
  6060. int cmd = 0;
  6061. nullpo_retv(sd);
  6062. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6063. if(!cmd) cmd = 0x09A6; //default
  6064. info = &packet_db[cmd];
  6065. len = info->len;
  6066. if(!len) return; //version as packet disable
  6067. // sd->state.banking = 1; //mark opening and closing
  6068. WBUFW(buf,0) = cmd;
  6069. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6070. WBUFW(buf,info->pos[1]) = 0; //reason
  6071. clif_send(buf,len,&sd->bl,SELF);
  6072. }
  6073. /*
  6074. * Requesting the data in bank
  6075. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6076. */
  6077. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6078. nullpo_retv(sd);
  6079. if( !battle_config.feature_banking ) {
  6080. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6081. return;
  6082. }
  6083. else {
  6084. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6085. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6086. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6087. clif_Bank_Check(sd);
  6088. }
  6089. }
  6090. /*
  6091. * Acknowledge of deposit some money in bank
  6092. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6093. */
  6094. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6095. unsigned char buf[17];
  6096. struct s_packet_db* info;
  6097. int16 len;
  6098. int cmd =0;
  6099. nullpo_retv(sd);
  6100. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6101. if(!cmd) cmd = 0x09A8;
  6102. info = &packet_db[cmd];
  6103. len = info->len;
  6104. if(!len) return; //version as packet disable
  6105. WBUFW(buf,0) = cmd;
  6106. WBUFW(buf,info->pos[0]) = (short)reason;
  6107. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6108. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6109. clif_send(buf,len,&sd->bl,SELF);
  6110. }
  6111. /*
  6112. * Request saving some money in bank
  6113. * @author : original [Yommy/Hercules]
  6114. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6115. */
  6116. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6117. nullpo_retv(sd);
  6118. if( !battle_config.feature_banking ) {
  6119. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6120. return;
  6121. }
  6122. else {
  6123. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6124. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6125. int money = RFIFOL(fd,info->pos[1]);
  6126. if(sd->status.account_id == aid){
  6127. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6128. clif_bank_deposit(sd,reason);
  6129. }
  6130. }
  6131. }
  6132. /*
  6133. * Acknowledge of withdrawing some money from bank
  6134. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6135. */
  6136. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6137. unsigned char buf[17];
  6138. struct s_packet_db* info;
  6139. int16 len;
  6140. int cmd;
  6141. nullpo_retv(sd);
  6142. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6143. if(!cmd) cmd = 0x09AA;
  6144. info = &packet_db[cmd];
  6145. len = info->len;
  6146. if(!len) return; //version as packet disable
  6147. WBUFW(buf,0) = cmd;
  6148. WBUFW(buf,info->pos[0]) = (short)reason;
  6149. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6150. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6151. clif_send(buf,len,&sd->bl,SELF);
  6152. }
  6153. /*
  6154. * Request Withdrawing some money from bank
  6155. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6156. */
  6157. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6158. nullpo_retv(sd);
  6159. if( !battle_config.feature_banking ) {
  6160. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6161. return;
  6162. }
  6163. else {
  6164. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6165. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6166. int money = RFIFOL(fd,info->pos[1]);
  6167. if(sd->status.account_id == aid){
  6168. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6169. clif_bank_withdraw(sd,reason);
  6170. }
  6171. }
  6172. }
  6173. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6174. /// 0125 <index>.W <amount>.L
  6175. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6176. {
  6177. int fd;
  6178. nullpo_retv(sd);
  6179. fd=sd->fd;
  6180. WFIFOHEAD(fd,packet_len(0x125));
  6181. WFIFOW(fd,0)=0x125;
  6182. WFIFOW(fd,2)=n+2;
  6183. WFIFOL(fd,4)=amount;
  6184. WFIFOSET(fd,packet_len(0x125));
  6185. }
  6186. /// Opens the shop creation menu (ZC_OPENSTORE).
  6187. /// 012d <num>.W
  6188. /// num:
  6189. /// number of allowed item slots
  6190. void clif_openvendingreq(struct map_session_data* sd, int num)
  6191. {
  6192. int fd;
  6193. nullpo_retv(sd);
  6194. fd = sd->fd;
  6195. WFIFOHEAD(fd,packet_len(0x12d));
  6196. WFIFOW(fd,0) = 0x12d;
  6197. WFIFOW(fd,2) = num;
  6198. WFIFOSET(fd,packet_len(0x12d));
  6199. }
  6200. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6201. /// 0131 <owner id>.L <message>.80B
  6202. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6203. {
  6204. unsigned char buf[128];
  6205. nullpo_retv(bl);
  6206. WBUFW(buf,0) = 0x131;
  6207. WBUFL(buf,2) = bl->id;
  6208. safestrncpy(WBUFCP(buf,6), message, 80);
  6209. if( fd ) {
  6210. WFIFOHEAD(fd,packet_len(0x131));
  6211. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6212. WFIFOSET(fd,packet_len(0x131));
  6213. } else {
  6214. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6215. }
  6216. }
  6217. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6218. /// 0132 <owner id>.L
  6219. void clif_closevendingboard(struct block_list* bl, int fd)
  6220. {
  6221. unsigned char buf[16];
  6222. nullpo_retv(bl);
  6223. WBUFW(buf,0) = 0x132;
  6224. WBUFL(buf,2) = bl->id;
  6225. if( fd ) {
  6226. WFIFOHEAD(fd,packet_len(0x132));
  6227. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6228. WFIFOSET(fd,packet_len(0x132));
  6229. } else {
  6230. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6231. }
  6232. }
  6233. /// Sends a list of items in a shop.
  6234. /// 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)
  6235. /// 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)
  6236. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6237. nullpo_retv( sd );
  6238. nullpo_retv( vsd );
  6239. nullpo_retv( vsd->vending );
  6240. int fd = sd->fd;
  6241. if( !session_isActive( fd ) ){
  6242. return;
  6243. }
  6244. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6245. WFIFOHEAD( fd, len );
  6246. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6247. p->packetType = vendinglistType;
  6248. p->packetLength = len;
  6249. p->AID = vsd->status.account_id;
  6250. #if PACKETVER >= 20100105
  6251. p->venderId = vsd->vender_id;
  6252. #endif
  6253. for( int i = 0; i < vsd->vend_num; i++ ){
  6254. int index = vsd->vending[i].index;
  6255. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6256. p->items[i].price = vsd->vending[i].value;
  6257. p->items[i].amount = vsd->vending[i].amount;
  6258. p->items[i].index = client_index( index );
  6259. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6260. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6261. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6262. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6263. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6264. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6265. #if PACKETVER >= 20150226
  6266. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6267. #if PACKETVER >= 20160921
  6268. p->items[i].location = pc_equippoint_sub( sd, data );
  6269. p->items[i].viewSprite = data->look;
  6270. #endif
  6271. #endif
  6272. }
  6273. WFIFOSET( fd, len );
  6274. }
  6275. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6276. /// 0135 <index>.W <amount>.W <result>.B
  6277. /// result:
  6278. /// 0 = success
  6279. /// 1 = not enough zeny
  6280. /// 2 = overweight
  6281. /// 4 = out of stock
  6282. /// 5 = "cannot use an npc shop while in a trade"
  6283. /// 6 = Because the store information was incorrect the item was not purchased.
  6284. /// 7 = No sales information.
  6285. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6286. {
  6287. int fd;
  6288. nullpo_retv(sd);
  6289. fd = sd->fd;
  6290. WFIFOHEAD(fd,packet_len(0x135));
  6291. WFIFOW(fd,0) = 0x135;
  6292. WFIFOW(fd,2) = index+2;
  6293. WFIFOW(fd,4) = amount;
  6294. WFIFOB(fd,6) = fail;
  6295. WFIFOSET(fd,packet_len(0x135));
  6296. }
  6297. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6298. /// 0a28 <Result>.B
  6299. /// result:
  6300. /// 0 = Successed
  6301. /// 1 = Failed
  6302. void clif_openvending_ack(struct map_session_data* sd, int result)
  6303. {
  6304. int fd;
  6305. nullpo_retv(sd);
  6306. fd = sd->fd;
  6307. WFIFOHEAD(fd, 3);
  6308. WFIFOW(fd,0) = 0xa28;
  6309. WFIFOB(fd,2) = result;
  6310. WFIFOSET(fd, 3);
  6311. }
  6312. /// Shop creation success.
  6313. /// 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)
  6314. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6315. nullpo_retv( sd );
  6316. nullpo_retv( vending );
  6317. int fd = sd->fd;
  6318. if( !session_isActive( fd ) ){
  6319. return;
  6320. }
  6321. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6322. WFIFOHEAD( fd, len );
  6323. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6324. p->packetType = 0x136;
  6325. p->packetLength = len;
  6326. p->AID = id;
  6327. for( int i = 0; i < sd->vend_num; i++ ) {
  6328. int index = vending[i].index;
  6329. p->items[i].price = vending[i].value;
  6330. p->items[i].index = client_index( index );
  6331. p->items[i].amount = vending[i].amount;
  6332. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6333. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6334. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6335. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6336. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6337. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6338. #if PACKETVER >= 20150226
  6339. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6340. #endif
  6341. }
  6342. WFIFOSET( fd, len );
  6343. #if PACKETVER >= 20141022
  6344. /// 0 = Successed
  6345. /// 1 = Failed
  6346. clif_openvending_ack( sd, 0 );
  6347. #endif
  6348. }
  6349. /// Inform merchant that someone has bought an item.
  6350. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6351. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6352. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6353. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6354. const int cmd = 0x137;
  6355. #else
  6356. const int cmd = 0x9e5;
  6357. #endif
  6358. int fd = sd->fd;
  6359. nullpo_retv(sd);
  6360. WFIFOHEAD(fd,packet_len(cmd));
  6361. WFIFOW(fd,0) = cmd;
  6362. WFIFOW(fd,2) = index+2;
  6363. WFIFOW(fd,4) = amount;
  6364. #if PACKETVER >= 20141016
  6365. WFIFOL(fd,6) = char_id; // GID
  6366. WFIFOL(fd,10) = (int)time(NULL); // Date
  6367. WFIFOL(fd,14) = zeny; // zeny
  6368. #endif
  6369. WFIFOSET(fd,packet_len(cmd));
  6370. }
  6371. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6372. /// 00fa <result>.B
  6373. /// result:
  6374. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6375. /// 1 = MsgStringTable[78]="party name already exists"
  6376. /// 2 = MsgStringTable[79]="already in a party"
  6377. /// 3 = cannot organize parties on this map
  6378. /// ? = nothing
  6379. void clif_party_created(struct map_session_data *sd,int result)
  6380. {
  6381. int fd;
  6382. nullpo_retv(sd);
  6383. fd=sd->fd;
  6384. WFIFOHEAD(fd,packet_len(0xfa));
  6385. WFIFOW(fd,0)=0xfa;
  6386. WFIFOB(fd,2)=result;
  6387. WFIFOSET(fd,packet_len(0xfa));
  6388. }
  6389. /// Adds new member to a party.
  6390. /// 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)
  6391. /// 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)
  6392. /// 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)
  6393. /// role:
  6394. /// 0 = leader
  6395. /// 1 = normal
  6396. /// state:
  6397. /// 0 = connected
  6398. /// 1 = disconnected
  6399. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6400. {
  6401. int i;
  6402. #if PACKETVER < 20170502
  6403. unsigned char buf[81];
  6404. int cmd = 0x1e9;
  6405. int offset = 0;
  6406. #else
  6407. unsigned char buf[85];
  6408. int cmd = 0xa43;
  6409. int offset = 4;
  6410. #endif
  6411. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6412. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6413. } else {
  6414. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6415. }
  6416. if (i >= MAX_PARTY) return; //Should never happen...
  6417. sd = p->data[i].sd;
  6418. WBUFW(buf, 0) = cmd;
  6419. WBUFL(buf, 2) = sd->status.account_id;
  6420. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6421. #if PACKETVER >= 20170502
  6422. WBUFW(buf,10) = sd->status.class_;
  6423. WBUFW(buf,12) = sd->status.base_level;
  6424. #endif
  6425. WBUFW(buf,offset+10) = sd->bl.x;
  6426. WBUFW(buf,offset+12) = sd->bl.y;
  6427. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6428. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6429. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6430. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6431. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6432. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6433. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6434. }
  6435. /// Sends party information (ZC_GROUP_LIST).
  6436. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6437. /// role:
  6438. /// 0 = leader
  6439. /// 1 = normal
  6440. /// state:
  6441. /// 0 = connected
  6442. /// 1 = disconnected
  6443. /// 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
  6444. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6445. {
  6446. struct map_session_data* party_sd = NULL;
  6447. int i, c;
  6448. #if PACKETVER < 20170502
  6449. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6450. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6451. int cmd = 0xfb;
  6452. #else
  6453. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6454. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6455. int cmd = 0xa44;
  6456. #endif
  6457. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6458. nullpo_retv(p);
  6459. WBUFW(buf,0) = cmd;
  6460. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6461. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6462. {
  6463. struct party_member* m = &p->party.member[i];
  6464. if(!m->account_id) continue;
  6465. if(party_sd == NULL) party_sd = p->data[i].sd;
  6466. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6467. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6468. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6469. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6470. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6471. #if PACKETVER >= 20170502
  6472. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6473. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6474. #endif
  6475. c++;
  6476. }
  6477. #if PACKETVER < 20170502
  6478. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6479. #else
  6480. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6481. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6482. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6483. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6484. #endif
  6485. if(sd) { // send only to self
  6486. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6487. } else if (party_sd) { // send to whole party
  6488. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6489. }
  6490. }
  6491. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6492. /// 02c9 <flag>.B
  6493. /// flag:
  6494. /// 0 = allow party invites
  6495. /// 1 = auto-deny party invites
  6496. void clif_partyinvitationstate(struct map_session_data* sd)
  6497. {
  6498. int fd;
  6499. nullpo_retv(sd);
  6500. fd = sd->fd;
  6501. WFIFOHEAD(fd, packet_len(0x2c9));
  6502. WFIFOW(fd, 0) = 0x2c9;
  6503. WFIFOB(fd, 2) = 0; // not implemented
  6504. WFIFOSET(fd, packet_len(0x2c9));
  6505. }
  6506. /// Party invitation request.
  6507. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6508. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6509. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6510. {
  6511. #if PACKETVER < 20070821
  6512. const int cmd = 0xfe;
  6513. #else
  6514. const int cmd = 0x2c6;
  6515. #endif
  6516. int fd;
  6517. struct party_data *p;
  6518. nullpo_retv(sd);
  6519. nullpo_retv(tsd);
  6520. fd=tsd->fd;
  6521. if( (p=party_search(sd->status.party_id))==NULL )
  6522. return;
  6523. WFIFOHEAD(fd,packet_len(cmd));
  6524. WFIFOW(fd,0)=cmd;
  6525. WFIFOL(fd,2)=sd->status.party_id;
  6526. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6527. WFIFOSET(fd,packet_len(cmd));
  6528. }
  6529. /// Party invite result.
  6530. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6531. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6532. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6533. {
  6534. int fd;
  6535. nullpo_retv(sd);
  6536. fd=sd->fd;
  6537. #if PACKETVER < 20070904
  6538. if( reply == PARTY_REPLY_OFFLINE ) {
  6539. clif_displaymessage(fd, msg_txt(sd,3));
  6540. return;
  6541. }
  6542. #endif
  6543. #if PACKETVER < 20070821
  6544. WFIFOHEAD(fd,packet_len(0xfd));
  6545. WFIFOW(fd,0) = 0xfd;
  6546. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6547. WFIFOB(fd,26) = reply;
  6548. WFIFOSET(fd,packet_len(0xfd));
  6549. #else
  6550. WFIFOHEAD(fd,packet_len(0x2c5));
  6551. WFIFOW(fd,0) = 0x2c5;
  6552. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6553. WFIFOL(fd,26) = reply;
  6554. WFIFOSET(fd,packet_len(0x2c5));
  6555. #endif
  6556. }
  6557. /// Updates party settings.
  6558. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6559. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6560. /// exp option:
  6561. /// 0 = exp sharing disabled
  6562. /// 1 = exp sharing enabled
  6563. /// 2 = cannot change exp sharing
  6564. ///
  6565. /// flag:
  6566. /// 0 = send to party
  6567. /// 1 = send to sd
  6568. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6569. {
  6570. unsigned char buf[16];
  6571. #if PACKETVER < 20090603
  6572. const int cmd = 0x101;
  6573. #else
  6574. const int cmd = 0x7d8;
  6575. #endif
  6576. nullpo_retv(p);
  6577. if(!sd && flag==0){
  6578. int i;
  6579. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6580. if (i < MAX_PARTY)
  6581. sd = p->data[i].sd;
  6582. }
  6583. if(!sd) return;
  6584. WBUFW(buf,0)=cmd;
  6585. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6586. #if PACKETVER >= 20090603
  6587. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6588. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6589. #endif
  6590. if(flag==0)
  6591. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6592. else
  6593. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6594. }
  6595. /**
  6596. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6597. * @param sd Send the notification for this player
  6598. * @param account_id Account ID of kicked member
  6599. * @param name Name of kicked member
  6600. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6601. * @param target Send target
  6602. **/
  6603. 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) {
  6604. unsigned char buf[2+4+NAME_LENGTH+1];
  6605. if (!sd)
  6606. return;
  6607. WBUFW(buf,0) = 0x0105;
  6608. WBUFL(buf,2) = account_id;
  6609. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6610. WBUFB(buf,6+NAME_LENGTH) = result;
  6611. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6612. }
  6613. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6614. /// 0109 <packet len>.W <account id>.L <message>.?B
  6615. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6616. {
  6617. struct map_session_data *sd;
  6618. int i;
  6619. nullpo_retv(p);
  6620. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6621. if(i < MAX_PARTY){
  6622. unsigned char buf[1024];
  6623. if( len > sizeof(buf)-8 )
  6624. {
  6625. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6626. len = sizeof(buf)-8;
  6627. }
  6628. sd = p->data[i].sd;
  6629. WBUFW(buf,0)=0x109;
  6630. WBUFW(buf,2)=len+8;
  6631. WBUFL(buf,4)=account_id;
  6632. safestrncpy(WBUFCP(buf,8), mes, len);
  6633. clif_send(buf,len+8,&sd->bl,PARTY);
  6634. }
  6635. }
  6636. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6637. /// 0107 <account id>.L <x>.W <y>.W
  6638. void clif_party_xy(struct map_session_data *sd)
  6639. {
  6640. unsigned char buf[16];
  6641. nullpo_retv(sd);
  6642. WBUFW(buf,0)=0x107;
  6643. WBUFL(buf,2)=sd->status.account_id;
  6644. WBUFW(buf,6)=sd->bl.x;
  6645. WBUFW(buf,8)=sd->bl.y;
  6646. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6647. }
  6648. /*==========================================
  6649. * Sends x/y dot to a single fd. [Skotlex]
  6650. *------------------------------------------*/
  6651. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6652. {
  6653. WFIFOHEAD(fd,packet_len(0x107));
  6654. WFIFOW(fd,0)=0x107;
  6655. WFIFOL(fd,2)=sd->status.account_id;
  6656. WFIFOW(fd,6)=sd->bl.x;
  6657. WFIFOW(fd,8)=sd->bl.y;
  6658. WFIFOSET(fd,packet_len(0x107));
  6659. }
  6660. /// Updates HP bar of a party member.
  6661. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6662. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6663. void clif_party_hp(struct map_session_data *sd)
  6664. {
  6665. unsigned char buf[16];
  6666. #if PACKETVER < 20100126
  6667. const int cmd = 0x106;
  6668. #else
  6669. const int cmd = 0x80e;
  6670. #endif
  6671. nullpo_retv(sd);
  6672. WBUFW(buf,0)=cmd;
  6673. WBUFL(buf,2)=sd->status.account_id;
  6674. #if PACKETVER < 20100126
  6675. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6676. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6677. WBUFW(buf,8) = 100;
  6678. } else {
  6679. WBUFW(buf,6) = sd->battle_status.hp;
  6680. WBUFW(buf,8) = sd->battle_status.max_hp;
  6681. }
  6682. #else
  6683. WBUFL(buf,6) = sd->battle_status.hp;
  6684. WBUFL(buf,10) = sd->battle_status.max_hp;
  6685. #endif
  6686. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6687. }
  6688. /// Notifies the party members of a character's death or revival.
  6689. /// 0AB2 <GID>.L <dead>.B
  6690. void clif_party_dead( struct map_session_data *sd ){
  6691. #if PACKETVER >= 20170502
  6692. unsigned char buf[7];
  6693. nullpo_retv(sd);
  6694. WBUFW(buf, 0) = 0xab2;
  6695. WBUFL(buf, 2) = sd->status.account_id;
  6696. WBUFB(buf, 6) = pc_isdead(sd);
  6697. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6698. #endif
  6699. }
  6700. /// Updates the job and level of a party member
  6701. /// 0abd <account id>.L <job>.W <level>.W
  6702. void clif_party_job_and_level(struct map_session_data *sd){
  6703. #if PACKETVER >= 20170502
  6704. unsigned char buf[10];
  6705. nullpo_retv(sd);
  6706. WBUFW(buf, 0) = 0xabd;
  6707. WBUFL(buf, 2) = sd->status.account_id;
  6708. WBUFW(buf, 6) = sd->status.class_;
  6709. WBUFW(buf, 8) = sd->status.base_level;
  6710. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6711. #endif
  6712. }
  6713. /*==========================================
  6714. * Sends HP bar to a single fd. [Skotlex]
  6715. *------------------------------------------*/
  6716. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6717. {
  6718. #if PACKETVER < 20100126
  6719. const int cmd = 0x106;
  6720. #else
  6721. const int cmd = 0x80e;
  6722. #endif
  6723. WFIFOHEAD(fd,packet_len(cmd));
  6724. WFIFOW(fd,0) = cmd;
  6725. WFIFOL(fd,2) = id;
  6726. #if PACKETVER < 20100126
  6727. if( maxhp > INT16_MAX )
  6728. {// To correctly display the %hp bar. [Skotlex]
  6729. WFIFOW(fd,6) = hp/(maxhp/100);
  6730. WFIFOW(fd,8) = 100;
  6731. } else {
  6732. WFIFOW(fd,6) = hp;
  6733. WFIFOW(fd,8) = maxhp;
  6734. }
  6735. #else
  6736. WFIFOL(fd,6) = hp;
  6737. WFIFOL(fd,10) = maxhp;
  6738. #endif
  6739. WFIFOSET(fd, packet_len(cmd));
  6740. }
  6741. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6742. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6743. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6744. {
  6745. int fd;
  6746. nullpo_retv(sd);
  6747. nullpo_retv(bl);
  6748. fd=sd->fd;
  6749. WFIFOHEAD(fd,packet_len(0x139));
  6750. WFIFOW(fd, 0)=0x139;
  6751. WFIFOL(fd, 2)=bl->id;
  6752. WFIFOW(fd, 6)=bl->x;
  6753. WFIFOW(fd, 8)=bl->y;
  6754. WFIFOW(fd,10)=sd->bl.x;
  6755. WFIFOW(fd,12)=sd->bl.y;
  6756. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6757. WFIFOSET(fd,packet_len(0x139));
  6758. }
  6759. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6760. /// 018f <result>.W <name id>.W
  6761. /// result:
  6762. /// 0 = success
  6763. /// 1 = failure
  6764. /// 2 = success (alchemist)
  6765. /// 3 = failure (alchemist)
  6766. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid){
  6767. nullpo_retv( sd );
  6768. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6769. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6770. p.packetType = 0x18f;
  6771. p.result = flag;
  6772. p.itemId = client_nameid( nameid );
  6773. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6774. }
  6775. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6776. /// 019e
  6777. void clif_catch_process(struct map_session_data *sd)
  6778. {
  6779. int fd;
  6780. nullpo_retv(sd);
  6781. fd=sd->fd;
  6782. WFIFOHEAD(fd,packet_len(0x19e));
  6783. WFIFOW(fd,0)=0x19e;
  6784. WFIFOSET(fd,packet_len(0x19e));
  6785. }
  6786. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6787. /// 01a0 <result>.B
  6788. /// 0 = failure
  6789. /// 1 = success
  6790. void clif_pet_roulette(struct map_session_data *sd,int data)
  6791. {
  6792. int fd;
  6793. nullpo_retv(sd);
  6794. fd=sd->fd;
  6795. WFIFOHEAD(fd,packet_len(0x1a0));
  6796. WFIFOW(fd,0)=0x1a0;
  6797. WFIFOB(fd,2)=data;
  6798. WFIFOSET(fd,packet_len(0x1a0));
  6799. }
  6800. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6801. /// 01a6 <packet len>.W { <index>.W }*
  6802. void clif_sendegg(struct map_session_data *sd)
  6803. {
  6804. int i,n=0,fd;
  6805. nullpo_retv(sd);
  6806. fd=sd->fd;
  6807. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6808. clif_displaymessage(fd, msg_txt(sd,666));
  6809. return;
  6810. }
  6811. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6812. WFIFOW(fd,0)=0x1a6;
  6813. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6814. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6815. sd->inventory_data[i]->type != IT_PETEGG ||
  6816. sd->inventory.u.items_inventory[i].amount <= 0)
  6817. continue;
  6818. WFIFOW(fd,n*2+4)=i+2;
  6819. n++;
  6820. }
  6821. WFIFOW(fd,2)=4+n*2;
  6822. WFIFOSET(fd,WFIFOW(fd,2));
  6823. sd->menuskill_id = SA_TAMINGMONSTER;
  6824. sd->menuskill_val = -1;
  6825. }
  6826. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6827. /// 01a4 <type>.B <id>.L <data>.L
  6828. /// type:
  6829. /// 0 = pre-init (data = 0)
  6830. /// 1 = intimacy (data = 0~4)
  6831. /// 2 = hunger (data = 0~4)
  6832. /// 3 = accessory
  6833. /// 4 = performance (data = 1~3: normal, 4: special)
  6834. /// 5 = hairstyle
  6835. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6836. ///
  6837. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6838. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6839. {
  6840. uint8 buf[16];
  6841. nullpo_retv(pd);
  6842. WBUFW(buf,0) = 0x1a4;
  6843. WBUFB(buf,2) = type;
  6844. WBUFL(buf,3) = pd->bl.id;
  6845. WBUFL(buf,7) = param;
  6846. if (sd)
  6847. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6848. else
  6849. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6850. }
  6851. /// Pet's base data (ZC_PROPERTY_PET).
  6852. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6853. void clif_send_petstatus(struct map_session_data *sd)
  6854. {
  6855. int fd;
  6856. struct s_pet *pet;
  6857. nullpo_retv(sd);
  6858. nullpo_retv(sd->pd);
  6859. fd=sd->fd;
  6860. pet = &sd->pd->pet;
  6861. WFIFOHEAD(fd,packet_len(0x1a2));
  6862. WFIFOW(fd,0)=0x1a2;
  6863. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6864. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6865. WFIFOW(fd,27)=pet->level;
  6866. WFIFOW(fd,29)=pet->hungry;
  6867. WFIFOW(fd,31)=pet->intimate;
  6868. WFIFOW(fd,33)=pet->equip;
  6869. #if PACKETVER >= 20081126
  6870. WFIFOW(fd,35)=pet->class_;
  6871. #endif
  6872. WFIFOSET(fd,packet_len(0x1a2));
  6873. }
  6874. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6875. /// 01aa <id>.L <data>.L
  6876. /// data:
  6877. /// @see CZ_PET_ACT.
  6878. void clif_pet_emotion(struct pet_data *pd,int param)
  6879. {
  6880. unsigned char buf[16];
  6881. nullpo_retv(pd);
  6882. memset(buf,0,packet_len(0x1aa));
  6883. WBUFW(buf,0)=0x1aa;
  6884. WBUFL(buf,2)=pd->bl.id;
  6885. WBUFL(buf,6)=param;
  6886. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6887. }
  6888. /// Result of request to feed a pet (ZC_FEED_PET).
  6889. /// 01a3 <result>.B <name id>.W
  6890. /// result:
  6891. /// 0 = failure
  6892. /// 1 = success
  6893. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  6894. nullpo_retv( sd );
  6895. struct PACKET_ZC_FEED_PET p;
  6896. p.packetType = 0x1a3;
  6897. p.result = fail;
  6898. p.itemId = client_nameid( foodid );
  6899. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6900. }
  6901. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6902. /// 01cd { <skill id>.L }*7
  6903. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6904. {
  6905. nullpo_retv(sd);
  6906. int fd = sd->fd;
  6907. #ifdef RENEWAL
  6908. uint16 autospell_skill[][2] = {
  6909. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  6910. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  6911. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  6912. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  6913. };
  6914. int count = 0;
  6915. WFIFOHEAD(fd, 2 * 6 + 4);
  6916. WFIFOW(fd, 0) = 0x442;
  6917. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  6918. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  6919. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  6920. count++;
  6921. }
  6922. }
  6923. WFIFOW(fd, 2) = 8 + count * 2;
  6924. WFIFOL(fd, 4) = count;
  6925. WFIFOSET(fd, WFIFOW(fd, 2));
  6926. #else
  6927. WFIFOHEAD(fd,packet_len(0x1cd));
  6928. WFIFOW(fd, 0)=0x1cd;
  6929. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6930. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6931. else
  6932. WFIFOL(fd,2)= 0x00000000;
  6933. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6934. WFIFOL(fd,6)= MG_COLDBOLT;
  6935. else
  6936. WFIFOL(fd,6)= 0x00000000;
  6937. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6938. WFIFOL(fd,10)= MG_FIREBOLT;
  6939. else
  6940. WFIFOL(fd,10)= 0x00000000;
  6941. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6942. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6943. else
  6944. WFIFOL(fd,14)= 0x00000000;
  6945. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6946. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6947. else
  6948. WFIFOL(fd,18)= 0x00000000;
  6949. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6950. WFIFOL(fd,22)= MG_FIREBALL;
  6951. else
  6952. WFIFOL(fd,22)= 0x00000000;
  6953. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6954. WFIFOL(fd,26)= MG_FROSTDIVER;
  6955. else
  6956. WFIFOL(fd,26)= 0x00000000;
  6957. WFIFOSET(fd,packet_len(0x1cd));
  6958. #endif
  6959. sd->menuskill_id = SA_AUTOSPELL;
  6960. sd->menuskill_val = skill_lv;
  6961. }
  6962. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6963. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6964. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6965. {
  6966. unsigned char buf[56];
  6967. nullpo_retv(src);
  6968. memset(buf,0,packet_len(0x1cf));
  6969. WBUFW(buf,0) = 0x1cf;
  6970. WBUFL(buf,2) = src->id;
  6971. if( src->type == BL_MER )
  6972. {
  6973. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6974. if( md && md->master && md->devotion_flag )
  6975. WBUFL(buf,6) = md->master->bl.id;
  6976. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  6977. }
  6978. else
  6979. {
  6980. int i;
  6981. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6982. if( sd == NULL )
  6983. return;
  6984. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6985. WBUFL(buf,6+4*i) = sd->devotion[i];
  6986. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  6987. }
  6988. if( tsd )
  6989. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6990. else
  6991. clif_send(buf, packet_len(0x1cf), src, AREA);
  6992. }
  6993. /*==========================================
  6994. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6995. * Notifies clients in an area of an object's spirits.
  6996. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6997. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6998. *------------------------------------------*/
  6999. void clif_spiritball(struct block_list *bl) {
  7000. unsigned char buf[16];
  7001. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7002. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7003. nullpo_retv(bl);
  7004. WBUFW(buf, 0) = 0x1d0;
  7005. WBUFL(buf, 2) = bl->id;
  7006. WBUFW(buf, 6) = 0; //init to 0
  7007. switch(bl->type){
  7008. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7009. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7010. }
  7011. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7012. }
  7013. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7014. /// 01d2 <account id>.L <delay>.L
  7015. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7016. {
  7017. unsigned char buf[32];
  7018. nullpo_retv(bl);
  7019. WBUFW(buf,0)=0x1d2;
  7020. WBUFL(buf,2)=bl->id;
  7021. WBUFL(buf,6)=client_tick(wait);
  7022. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7023. }
  7024. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7025. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7026. /// flag:
  7027. /// 0 = inactive
  7028. /// 1 = active
  7029. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7030. {
  7031. unsigned char buf[32];
  7032. nullpo_retv(src);
  7033. WBUFW(buf,0)=0x1d1;
  7034. WBUFL(buf,2)=src->id;
  7035. WBUFL(buf,6)=dst_id;
  7036. WBUFL(buf,10)=active;
  7037. clif_send(buf,packet_len(0x1d1),src,AREA);
  7038. }
  7039. /// MVP effect (ZC_MVP).
  7040. /// 010c <account id>.L
  7041. void clif_mvp_effect(struct map_session_data *sd)
  7042. {
  7043. unsigned char buf[16];
  7044. nullpo_retv(sd);
  7045. WBUFW(buf,0)=0x10c;
  7046. WBUFL(buf,2)=sd->bl.id;
  7047. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7048. }
  7049. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7050. /// 010a <name id>.W
  7051. void clif_mvp_item( struct map_session_data *sd, unsigned short nameid ){
  7052. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7053. p.packetType = 0x10a;
  7054. p.itemId = client_nameid( nameid );
  7055. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7056. }
  7057. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7058. /// 010b <exp>.L
  7059. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7060. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7061. if (battle_config.mvp_exp_reward_message) {
  7062. char e_msg[CHAT_SIZE_MAX];
  7063. sprintf(e_msg, msg_txt(sd, 717), exp);
  7064. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7065. }
  7066. #else
  7067. int fd;
  7068. nullpo_retv(sd);
  7069. fd = sd->fd;
  7070. WFIFOHEAD(fd, packet_len(0x10b));
  7071. WFIFOW(fd,0) = 0x10b;
  7072. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7073. WFIFOSET(fd, packet_len(0x10b));
  7074. #endif
  7075. }
  7076. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7077. /// 010d
  7078. ///
  7079. /// "You are the MVP, but cannot obtain the reward because
  7080. /// you are overweight."
  7081. void clif_mvp_noitem(struct map_session_data* sd)
  7082. {
  7083. int fd = sd->fd;
  7084. WFIFOHEAD(fd,packet_len(0x10d));
  7085. WFIFOW(fd,0) = 0x10d;
  7086. WFIFOSET(fd,packet_len(0x10d));
  7087. }
  7088. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7089. /// 0167 <result>.B
  7090. /// result:
  7091. /// 0 = "Guild has been created."
  7092. /// 1 = "You are already in a Guild."
  7093. /// 2 = "That Guild Name already exists."
  7094. /// 3 = "You need the neccessary item to create a Guild."
  7095. void clif_guild_created(struct map_session_data *sd,int flag)
  7096. {
  7097. int fd;
  7098. nullpo_retv(sd);
  7099. fd=sd->fd;
  7100. WFIFOHEAD(fd,packet_len(0x167));
  7101. WFIFOW(fd,0)=0x167;
  7102. WFIFOB(fd,2)=flag;
  7103. WFIFOSET(fd,packet_len(0x167));
  7104. }
  7105. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7106. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7107. /// mode:
  7108. /// &0x01 = allow invite
  7109. /// &0x10 = allow expel
  7110. void clif_guild_belonginfo(struct map_session_data *sd)
  7111. {
  7112. int ps,fd;
  7113. struct guild* g;
  7114. nullpo_retv(sd);
  7115. nullpo_retv(g = sd->guild);
  7116. fd=sd->fd;
  7117. ps=guild_getposition(sd);
  7118. WFIFOHEAD(fd,packet_len(0x16c));
  7119. WFIFOW(fd,0)=0x16c;
  7120. WFIFOL(fd,2)=g->guild_id;
  7121. WFIFOL(fd,6)=g->emblem_id;
  7122. WFIFOL(fd,10)=g->position[ps].mode;
  7123. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7124. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7125. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7126. WFIFOSET(fd,packet_len(0x16c));
  7127. }
  7128. /// Guild member login notice.
  7129. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7130. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7131. /// status:
  7132. /// 0 = offline
  7133. /// 1 = online
  7134. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7135. {
  7136. unsigned char buf[64];
  7137. struct map_session_data* sd;
  7138. nullpo_retv(g);
  7139. WBUFW(buf, 0)=0x1f2;
  7140. WBUFL(buf, 2)=g->member[idx].account_id;
  7141. WBUFL(buf, 6)=g->member[idx].char_id;
  7142. WBUFL(buf,10)=flag;
  7143. if( ( sd = g->member[idx].sd ) != NULL )
  7144. {
  7145. WBUFW(buf,14) = sd->status.sex;
  7146. WBUFW(buf,16) = sd->status.hair;
  7147. WBUFW(buf,18) = sd->status.hair_color;
  7148. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7149. }
  7150. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7151. {
  7152. WBUFW(buf,14) = 0;
  7153. WBUFW(buf,16) = 0;
  7154. WBUFW(buf,18) = 0;
  7155. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7156. }
  7157. }
  7158. // Function `clif_guild_memberlogin_notice` sends info about
  7159. // logins and logouts of a guild member to the rest members.
  7160. // But at the 1st time (after a player login or map changing)
  7161. // the client won't show the message.
  7162. // So I suggest use this function for sending "first-time-info"
  7163. // to some player on entering the game or changing location.
  7164. // At next time the client would always show the message.
  7165. // The function sends all the statuses in the single packet
  7166. // to economize traffic. [LuzZza]
  7167. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7168. {
  7169. struct guild *g;
  7170. unsigned char buf[14*128];
  7171. int i, count=0, p_len;
  7172. nullpo_retv(sd);
  7173. p_len = packet_len(0x16d);
  7174. if(!(g = sd->guild))
  7175. return;
  7176. for(i=0; i<g->max_member; i++) {
  7177. if(g->member[i].account_id > 0 &&
  7178. g->member[i].account_id != sd->status.account_id) {
  7179. WBUFW(buf,count*p_len) = 0x16d;
  7180. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7181. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7182. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7183. count++;
  7184. }
  7185. }
  7186. clif_send(buf, p_len*count, &sd->bl, SELF);
  7187. }
  7188. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7189. /// 014e <menu flag>.L
  7190. /// menu flag:
  7191. /// 0x00 = Basic Info (always on)
  7192. /// &0x01 = Member manager
  7193. /// &0x02 = Positions
  7194. /// &0x04 = Skills
  7195. /// &0x10 = Expulsion list
  7196. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7197. /// &0x80 = Notice
  7198. void clif_guild_masterormember(struct map_session_data *sd)
  7199. {
  7200. int fd;
  7201. nullpo_retv(sd);
  7202. fd=sd->fd;
  7203. WFIFOHEAD(fd,packet_len(0x14e));
  7204. WFIFOW(fd,0) = 0x14e;
  7205. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7206. WFIFOSET(fd,packet_len(0x14e));
  7207. }
  7208. /// Guild basic information (Territories [Valaris])
  7209. /// 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)
  7210. /// 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)
  7211. /// 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)
  7212. void clif_guild_basicinfo(struct map_session_data *sd) {
  7213. int fd;
  7214. struct guild *g;
  7215. #if PACKETVER < 20160622
  7216. int cmd = 0x1b6;
  7217. int offset = NAME_LENGTH;
  7218. #else
  7219. int cmd = 0xa84;
  7220. int offset = 0;
  7221. #endif
  7222. nullpo_retv(sd);
  7223. fd = sd->fd;
  7224. if( (g = sd->guild) == NULL )
  7225. return;
  7226. WFIFOHEAD(fd,packet_len(cmd));
  7227. WFIFOW(fd, 0)=cmd;
  7228. WFIFOL(fd, 2)=g->guild_id;
  7229. WFIFOL(fd, 6)=g->guild_lv;
  7230. WFIFOL(fd,10)=g->connect_member;
  7231. WFIFOL(fd,14)=g->max_member;
  7232. WFIFOL(fd,18)=g->average_lv;
  7233. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7234. WFIFOL(fd,26)=g->next_exp;
  7235. WFIFOL(fd,30)=0; // Tax Points
  7236. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7237. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7238. WFIFOL(fd,42)=g->emblem_id;
  7239. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7240. #if PACKETVER < 20160622
  7241. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7242. #endif
  7243. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7244. WFIFOL(fd,70+offset+16) = 0; // zeny
  7245. #if PACKETVER >= 20160622
  7246. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7247. #endif
  7248. WFIFOSET(fd,packet_len(cmd));
  7249. }
  7250. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7251. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7252. void clif_guild_allianceinfo(struct map_session_data *sd)
  7253. {
  7254. int fd,i,c;
  7255. struct guild *g;
  7256. nullpo_retv(sd);
  7257. if( (g = sd->guild) == NULL )
  7258. return;
  7259. fd = sd->fd;
  7260. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7261. WFIFOW(fd, 0)=0x14c;
  7262. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7263. struct guild_alliance *a=&g->alliance[i];
  7264. if(a->guild_id>0){
  7265. WFIFOL(fd,c*32+4)=a->opposition;
  7266. WFIFOL(fd,c*32+8)=a->guild_id;
  7267. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7268. c++;
  7269. }
  7270. }
  7271. WFIFOW(fd, 2)=c*32+4;
  7272. WFIFOSET(fd,WFIFOW(fd,2));
  7273. }
  7274. /// Guild member manager information
  7275. /// 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)
  7276. /// state:
  7277. /// 0 = offline
  7278. /// 1 = online
  7279. /// memo:
  7280. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7281. /// 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)
  7282. void clif_guild_memberlist(struct map_session_data *sd)
  7283. {
  7284. int fd;
  7285. int i,c;
  7286. struct guild *g;
  7287. #if PACKETVER < 20161026
  7288. int cmd = 0x154;
  7289. int size = 104;
  7290. #else
  7291. int cmd = 0xaa5;
  7292. int size = 34;
  7293. #endif
  7294. nullpo_retv(sd);
  7295. if( (fd = sd->fd) == 0 )
  7296. return;
  7297. if( (g = sd->guild) == NULL )
  7298. return;
  7299. WFIFOHEAD(fd, g->max_member * size + 4);
  7300. WFIFOW(fd, 0)=cmd;
  7301. for(i=0,c=0;i<g->max_member;i++){
  7302. struct guild_member *m=&g->member[i];
  7303. if(m->account_id==0)
  7304. continue;
  7305. WFIFOL(fd,c*size+ 4)=m->account_id;
  7306. WFIFOL(fd,c*size+ 8)=m->char_id;
  7307. WFIFOW(fd,c*size+12)=m->hair;
  7308. WFIFOW(fd,c*size+14)=m->hair_color;
  7309. WFIFOW(fd,c*size+16)=m->gender;
  7310. WFIFOW(fd,c*size+18)=m->class_;
  7311. WFIFOW(fd,c*size+20)=m->lv;
  7312. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7313. WFIFOL(fd,c*size+26)=m->online;
  7314. WFIFOL(fd,c*size+30)=m->position;
  7315. #if PACKETVER < 20161026
  7316. memset(WFIFOP(fd,c*size+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  7317. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7318. #else
  7319. WFIFOL(fd,c*size+34)=m->last_login;
  7320. #endif
  7321. c++;
  7322. }
  7323. WFIFOW(fd, 2)=c*size+4;
  7324. WFIFOSET(fd,WFIFOW(fd,2));
  7325. }
  7326. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7327. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7328. void clif_guild_positionnamelist(struct map_session_data *sd)
  7329. {
  7330. int i,fd;
  7331. struct guild *g;
  7332. nullpo_retv(sd);
  7333. if( (g = sd->guild) == NULL )
  7334. return;
  7335. fd = sd->fd;
  7336. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7337. WFIFOW(fd, 0)=0x166;
  7338. for(i=0;i<MAX_GUILDPOSITION;i++){
  7339. WFIFOL(fd,i*28+4)=i;
  7340. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7341. }
  7342. WFIFOW(fd,2)=i*28+4;
  7343. WFIFOSET(fd,WFIFOW(fd,2));
  7344. }
  7345. /// Guild position information (ZC_POSITION_INFO).
  7346. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7347. /// mode:
  7348. /// &0x01 = allow invite
  7349. /// &0x10 = allow expel
  7350. /// ranking:
  7351. /// TODO
  7352. void clif_guild_positioninfolist(struct map_session_data *sd)
  7353. {
  7354. int i,fd;
  7355. struct guild *g;
  7356. nullpo_retv(sd);
  7357. if( (g = sd->guild) == NULL )
  7358. return;
  7359. fd = sd->fd;
  7360. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7361. WFIFOW(fd, 0)=0x160;
  7362. for(i=0;i<MAX_GUILDPOSITION;i++){
  7363. struct guild_position *p=&g->position[i];
  7364. WFIFOL(fd,i*16+ 4)=i;
  7365. WFIFOL(fd,i*16+ 8)=p->mode;
  7366. WFIFOL(fd,i*16+12)=i;
  7367. WFIFOL(fd,i*16+16)=p->exp_mode;
  7368. }
  7369. WFIFOW(fd, 2)=i*16+4;
  7370. WFIFOSET(fd,WFIFOW(fd,2));
  7371. }
  7372. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7373. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7374. /// mode:
  7375. /// &0x01 = allow invite
  7376. /// &0x10 = allow expel
  7377. /// ranking:
  7378. /// TODO
  7379. void clif_guild_positionchanged(struct guild *g,int idx)
  7380. {
  7381. // FIXME: This packet is intended to update the clients after a
  7382. // commit of position info changes, not sending one packet per
  7383. // position.
  7384. struct map_session_data *sd;
  7385. unsigned char buf[128];
  7386. nullpo_retv(g);
  7387. WBUFW(buf, 0)=0x174;
  7388. WBUFW(buf, 2)=44; // packet len
  7389. // GUILD_REG_POSITION_INFO{
  7390. WBUFL(buf, 4)=idx;
  7391. WBUFL(buf, 8)=g->position[idx].mode;
  7392. WBUFL(buf,12)=idx;
  7393. WBUFL(buf,16)=g->position[idx].exp_mode;
  7394. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7395. // }*
  7396. if( (sd=guild_getavailablesd(g))!=NULL )
  7397. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7398. }
  7399. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7400. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7401. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7402. {
  7403. // FIXME: This packet is intended to update the clients after a
  7404. // commit of member position assignment changes, not sending one
  7405. // packet per position.
  7406. struct map_session_data *sd;
  7407. unsigned char buf[64];
  7408. nullpo_retv(g);
  7409. WBUFW(buf, 0)=0x156;
  7410. WBUFW(buf, 2)=16; // packet len
  7411. // MEMBER_POSITION_INFO{
  7412. WBUFL(buf, 4)=g->member[idx].account_id;
  7413. WBUFL(buf, 8)=g->member[idx].char_id;
  7414. WBUFL(buf,12)=g->member[idx].position;
  7415. // }*
  7416. if( (sd=guild_getavailablesd(g))!=NULL )
  7417. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7418. }
  7419. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7420. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7421. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7422. {
  7423. int fd;
  7424. nullpo_retv(sd);
  7425. nullpo_retv(g);
  7426. fd = sd->fd;
  7427. if( g->emblem_len <= 0 )
  7428. return;
  7429. WFIFOHEAD(fd,g->emblem_len+12);
  7430. WFIFOW(fd,0)=0x152;
  7431. WFIFOW(fd,2)=g->emblem_len+12;
  7432. WFIFOL(fd,4)=g->guild_id;
  7433. WFIFOL(fd,8)=g->emblem_id;
  7434. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7435. WFIFOSET(fd,WFIFOW(fd,2));
  7436. }
  7437. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7438. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7439. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7440. void clif_guild_emblem_area(struct block_list* bl)
  7441. {
  7442. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7443. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7444. PACKET_ZC_CHANGE_GUILD p{};
  7445. p.packetType = changeGuildEmblem;
  7446. p.guild_id = status_get_guild_id(bl);
  7447. p.emblem_id = status_get_emblem_id(bl);
  7448. #if PACKETVER < 20190724
  7449. p.aid = bl->id;
  7450. #else
  7451. p.unknown = 0;
  7452. #endif
  7453. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7454. }
  7455. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7456. /// 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 }*
  7457. void clif_guild_skillinfo(struct map_session_data* sd)
  7458. {
  7459. int fd;
  7460. struct guild* g;
  7461. int i,c;
  7462. nullpo_retv(sd);
  7463. if( (g = sd->guild) == NULL )
  7464. return;
  7465. fd = sd->fd;
  7466. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7467. WFIFOW(fd,0) = 0x0162;
  7468. WFIFOW(fd,4) = g->skill_point;
  7469. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7470. {
  7471. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7472. {
  7473. int id = g->skill[i].id;
  7474. int p = 6 + c*37;
  7475. WFIFOW(fd,p+0) = id;
  7476. WFIFOL(fd,p+2) = skill_get_inf(id);
  7477. WFIFOW(fd,p+6) = g->skill[i].lv;
  7478. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7479. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7480. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7481. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7482. c++;
  7483. }
  7484. }
  7485. WFIFOW(fd,2) = 6 + c*37;
  7486. WFIFOSET(fd,WFIFOW(fd,2));
  7487. }
  7488. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7489. /// 016f <subject>.60B <notice>.120B
  7490. void clif_guild_notice(struct map_session_data* sd)
  7491. {
  7492. int fd;
  7493. struct guild* g;
  7494. nullpo_retv(sd);
  7495. nullpo_retv(g = sd->guild);
  7496. fd = sd->fd;
  7497. if ( !session_isActive(fd) )
  7498. return;
  7499. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7500. return;
  7501. WFIFOHEAD(fd,packet_len(0x16f));
  7502. WFIFOW(fd,0) = 0x16f;
  7503. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7504. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7505. WFIFOSET(fd,packet_len(0x16f));
  7506. }
  7507. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7508. /// 016a <guild id>.L <guild name>.24B
  7509. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7510. {
  7511. int fd;
  7512. nullpo_retv(sd);
  7513. nullpo_retv(g);
  7514. fd=sd->fd;
  7515. WFIFOHEAD(fd,packet_len(0x16a));
  7516. WFIFOW(fd,0)=0x16a;
  7517. WFIFOL(fd,2)=g->guild_id;
  7518. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7519. WFIFOSET(fd,packet_len(0x16a));
  7520. }
  7521. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7522. /// 0169 <answer>.B
  7523. /// answer:
  7524. /// 0 = Already in guild.
  7525. /// 1 = Offer rejected.
  7526. /// 2 = Offer accepted.
  7527. /// 3 = Guild full.
  7528. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7529. {
  7530. int fd;
  7531. nullpo_retv(sd);
  7532. fd=sd->fd;
  7533. WFIFOHEAD(fd,packet_len(0x169));
  7534. WFIFOW(fd,0)=0x169;
  7535. WFIFOB(fd,2)=flag;
  7536. WFIFOSET(fd,packet_len(0x169));
  7537. }
  7538. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7539. /// 015a <char name>.24B <reason>.40B
  7540. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7541. {
  7542. unsigned char buf[128];
  7543. nullpo_retv(sd);
  7544. WBUFW(buf, 0)=0x15a;
  7545. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7546. memcpy(WBUFP(buf,26),mes,40);
  7547. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7548. }
  7549. /// Notifies clients of a guild of an expelled member.
  7550. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7551. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7552. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7553. {
  7554. unsigned char buf[128];
  7555. #if PACKETVER < 20100803
  7556. const unsigned short cmd = 0x15c;
  7557. #else
  7558. const unsigned short cmd = 0x839;
  7559. #endif
  7560. nullpo_retv(sd);
  7561. WBUFW(buf,0) = cmd;
  7562. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7563. safestrncpy(WBUFCP(buf,26), mes, 40);
  7564. #if PACKETVER < 20100803
  7565. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7566. #endif
  7567. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7568. }
  7569. /// Guild expulsion list (ZC_BAN_LIST).
  7570. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7571. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7572. void clif_guild_expulsionlist(struct map_session_data* sd)
  7573. {
  7574. #if PACKETVER < 20100803
  7575. const int offset = NAME_LENGTH*2+40;
  7576. #else
  7577. const int offset = NAME_LENGTH+40;
  7578. #endif
  7579. int fd, i, c = 0;
  7580. struct guild* g;
  7581. nullpo_retv(sd);
  7582. if( (g = sd->guild) == NULL )
  7583. return;
  7584. fd = sd->fd;
  7585. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7586. WFIFOW(fd,0) = 0x163;
  7587. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7588. {
  7589. struct guild_expulsion* e = &g->expulsion[i];
  7590. if( e->account_id > 0 )
  7591. {
  7592. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7593. #if PACKETVER < 20100803
  7594. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7595. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7596. #else
  7597. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7598. #endif
  7599. c++;
  7600. }
  7601. }
  7602. WFIFOW(fd,2) = 4 + c*offset;
  7603. WFIFOSET(fd,WFIFOW(fd,2));
  7604. }
  7605. /// Guild chat message (ZC_GUILD_CHAT).
  7606. /// 017f <packet len>.W <message>.?B
  7607. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7608. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7609. struct map_session_data *sd;
  7610. uint8 buf[256];
  7611. if( len == 0 )
  7612. {
  7613. return;
  7614. }
  7615. else if( len > sizeof(buf)-5 )
  7616. {
  7617. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7618. len = sizeof(buf)-5;
  7619. }
  7620. WBUFW(buf, 0) = 0x17f;
  7621. WBUFW(buf, 2) = len + 5;
  7622. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7623. if ((sd = guild_getavailablesd(g)) != NULL)
  7624. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7625. }
  7626. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7627. /// 0171 <inviter account id>.L <guild name>.24B
  7628. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7629. {
  7630. int fd;
  7631. nullpo_retv(sd);
  7632. fd=sd->fd;
  7633. WFIFOHEAD(fd,packet_len(0x171));
  7634. WFIFOW(fd,0)=0x171;
  7635. WFIFOL(fd,2)=account_id;
  7636. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7637. WFIFOSET(fd,packet_len(0x171));
  7638. }
  7639. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7640. /// 0173 <answer>.B
  7641. /// answer:
  7642. /// 0 = Already allied.
  7643. /// 1 = You rejected the offer.
  7644. /// 2 = You accepted the offer.
  7645. /// 3 = They have too any alliances.
  7646. /// 4 = You have too many alliances.
  7647. /// 5 = Alliances are disabled.
  7648. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7649. {
  7650. int fd;
  7651. nullpo_retv(sd);
  7652. fd=sd->fd;
  7653. WFIFOHEAD(fd,packet_len(0x173));
  7654. WFIFOW(fd,0)=0x173;
  7655. WFIFOL(fd,2)=flag;
  7656. WFIFOSET(fd,packet_len(0x173));
  7657. }
  7658. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7659. /// 0184 <other guild id>.L <relation>.L
  7660. /// relation:
  7661. /// 0 = Ally
  7662. /// 1 = Enemy
  7663. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7664. {
  7665. int fd;
  7666. nullpo_retv(sd);
  7667. fd = sd->fd;
  7668. if (fd <= 0)
  7669. return;
  7670. WFIFOHEAD(fd,packet_len(0x184));
  7671. WFIFOW(fd,0)=0x184;
  7672. WFIFOL(fd,2)=guild_id;
  7673. WFIFOL(fd,6)=flag;
  7674. WFIFOSET(fd,packet_len(0x184));
  7675. }
  7676. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7677. /// 0181 <result>.B
  7678. /// result:
  7679. /// 0 = Antagonist has been set.
  7680. /// 1 = Guild has too many Antagonists.
  7681. /// 2 = Already set as an Antagonist.
  7682. /// 3 = Antagonists are disabled.
  7683. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7684. {
  7685. int fd;
  7686. nullpo_retv(sd);
  7687. fd=sd->fd;
  7688. WFIFOHEAD(fd,packet_len(0x181));
  7689. WFIFOW(fd,0)=0x181;
  7690. WFIFOB(fd,2)=flag;
  7691. WFIFOSET(fd,packet_len(0x181));
  7692. }
  7693. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7694. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7695. /*
  7696. void clif_guild_allianceadded(struct guild *g,int idx)
  7697. {
  7698. unsigned char buf[64];
  7699. WBUFW(buf,0)=0x185;
  7700. WBUFL(buf,2)=g->alliance[idx].opposition;
  7701. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7702. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7703. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7704. }
  7705. */
  7706. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7707. /// 015e <reason>.L
  7708. /// 0 = success
  7709. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7710. /// 2 = there are still members in the guild
  7711. void clif_guild_broken(struct map_session_data *sd,int flag)
  7712. {
  7713. int fd;
  7714. nullpo_retv(sd);
  7715. fd=sd->fd;
  7716. WFIFOHEAD(fd,packet_len(0x15e));
  7717. WFIFOW(fd,0)=0x15e;
  7718. WFIFOL(fd,2)=flag;
  7719. WFIFOSET(fd,packet_len(0x15e));
  7720. }
  7721. /// Displays emotion on an object (ZC_EMOTION).
  7722. /// 00c0 <id>.L <type>.B
  7723. /// type:
  7724. /// enum emotion_type
  7725. void clif_emotion(struct block_list *bl,int type)
  7726. {
  7727. unsigned char buf[8];
  7728. nullpo_retv(bl);
  7729. WBUFW(buf,0)=0xc0;
  7730. WBUFL(buf,2)=bl->id;
  7731. WBUFB(buf,6)=type;
  7732. clif_send(buf,packet_len(0xc0),bl,AREA);
  7733. }
  7734. /// Displays the contents of a talkiebox trap.
  7735. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7736. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7737. nullpo_retv( bl );
  7738. nullpo_retv( talkie );
  7739. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7740. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7741. p.aid = bl->id;
  7742. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7743. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7744. }
  7745. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7746. /// 01ea <id>.L
  7747. void clif_wedding_effect(struct block_list *bl)
  7748. {
  7749. unsigned char buf[6];
  7750. nullpo_retv(bl);
  7751. WBUFW(buf,0) = 0x1ea;
  7752. WBUFL(buf,2) = bl->id;
  7753. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7754. }
  7755. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7756. /// 01e6 <partner name>.24B
  7757. void clif_callpartner(struct map_session_data *sd)
  7758. {
  7759. unsigned char buf[26];
  7760. nullpo_retv(sd);
  7761. WBUFW(buf,0) = 0x1e6;
  7762. if( sd->status.partner_id ) {
  7763. const char *p = map_charid2nick(sd->status.partner_id);
  7764. struct map_session_data *p_sd = pc_get_partner(sd);
  7765. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7766. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7767. else
  7768. WBUFB(buf,2) = 0;
  7769. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7770. WBUFB(buf,2) = 0;
  7771. }
  7772. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7773. }
  7774. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7775. /// 01e4
  7776. /// This packet while still implemented by the client is no longer being officially used.
  7777. /*
  7778. void clif_marriage_process(struct map_session_data *sd)
  7779. {
  7780. int fd;
  7781. nullpo_retv(sd);
  7782. fd=sd->fd;
  7783. WFIFOHEAD(fd,packet_len(0x1e4));
  7784. WFIFOW(fd,0)=0x1e4;
  7785. WFIFOSET(fd,packet_len(0x1e4));
  7786. }
  7787. */
  7788. /// Notice of divorce (ZC_DIVORCE).
  7789. /// 0205 <partner name>.24B
  7790. void clif_divorced(struct map_session_data* sd, const char* name)
  7791. {
  7792. int fd;
  7793. nullpo_retv(sd);
  7794. fd=sd->fd;
  7795. WFIFOHEAD(fd,packet_len(0x205));
  7796. WFIFOW(fd,0)=0x205;
  7797. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7798. WFIFOSET(fd, packet_len(0x205));
  7799. }
  7800. /// Marriage proposal (ZC_REQ_COUPLE).
  7801. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7802. /// This packet while still implemented by the client is no longer being officially used.
  7803. /*
  7804. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7805. {
  7806. nullpo_retv(sd);
  7807. WFIFOHEAD(fd,packet_len(0x1e2));
  7808. WFIFOW(fd,0) = 0x1e2;
  7809. WFIFOL(fd,2) = ssd->status.account_id;
  7810. WFIFOL(fd,6) = ssd->status.char_id;
  7811. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7812. WFIFOSET(fd, packet_len(0x1e2));
  7813. }
  7814. */
  7815. /*==========================================
  7816. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7817. *------------------------------------------*/
  7818. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7819. {
  7820. unsigned char buf[256];
  7821. if( len == 0 ) {
  7822. return;
  7823. } else if( len > sizeof(buf)-5 ) {
  7824. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7825. len = sizeof(buf)-5;
  7826. }
  7827. WBUFW(buf, 0) = 0x17f;
  7828. WBUFW(buf, 2) = len + 5;
  7829. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7830. clif_send(buf, WBUFW(buf,2), src, target);
  7831. }
  7832. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7833. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7834. /// 00cd <result>.B
  7835. /// result:
  7836. /// 0 = failure
  7837. /// 1 = success
  7838. void clif_GM_kickack(struct map_session_data *sd, int id)
  7839. {
  7840. int fd;
  7841. nullpo_retv(sd);
  7842. fd = sd->fd;
  7843. WFIFOHEAD(fd,packet_len(0xcd));
  7844. WFIFOW(fd,0) = 0xcd;
  7845. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7846. WFIFOSET(fd, packet_len(0xcd));
  7847. }
  7848. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7849. {
  7850. int fd;
  7851. nullpo_retv(tsd);
  7852. fd = tsd->fd;
  7853. if (sd == NULL)
  7854. tsd->state.keepshop = true;
  7855. if (fd > 0)
  7856. clif_authfail_fd(fd, 15);
  7857. else
  7858. map_quit(tsd);
  7859. if (sd)
  7860. clif_GM_kickack(sd, tsd->status.account_id);
  7861. }
  7862. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7863. /// 014a <result>.L
  7864. /// result:
  7865. /// 0 = "A manner point has been successfully aligned."
  7866. /// 1 = MP_FAILURE_EXHAUST
  7867. /// 2 = MP_FAILURE_ALREADY_GIVING
  7868. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7869. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7870. /// 5 = "You got a good point from %s."
  7871. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7872. {
  7873. int fd;
  7874. nullpo_retv(sd);
  7875. fd = sd->fd;
  7876. WFIFOHEAD(fd,packet_len(0x14a));
  7877. WFIFOW(fd,0) = 0x14a;
  7878. WFIFOL(fd,2) = type;
  7879. WFIFOSET(fd, packet_len(0x14a));
  7880. }
  7881. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7882. /// 014b <type>.B <GM name>.24B
  7883. /// type:
  7884. /// 0 = positive (unmute)
  7885. /// 1 = negative (mute)
  7886. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7887. {
  7888. int fd;
  7889. nullpo_retv(sd);
  7890. nullpo_retv(tsd);
  7891. fd = tsd->fd;
  7892. WFIFOHEAD(fd,packet_len(0x14b));
  7893. WFIFOW(fd,0) = 0x14b;
  7894. WFIFOB(fd,2) = type;
  7895. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7896. WFIFOSET(fd, packet_len(0x14b));
  7897. }
  7898. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7899. /// 00d1 <type>.B <result>.B
  7900. /// type:
  7901. /// 0 = /ex (deny)
  7902. /// 1 = /in (allow)
  7903. /// result:
  7904. /// 0 = success
  7905. /// 1 = failure
  7906. /// 2 = too many blocks
  7907. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7908. {
  7909. int fd;
  7910. nullpo_retv(sd);
  7911. fd=sd->fd;
  7912. WFIFOHEAD(fd,packet_len(0xd1));
  7913. WFIFOW(fd,0)=0xd1;
  7914. WFIFOB(fd,2)=type;
  7915. WFIFOB(fd,3)=flag;
  7916. WFIFOSET(fd,packet_len(0xd1));
  7917. }
  7918. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7919. /// 00d2 <type>.B <result>.B
  7920. /// type:
  7921. /// 0 = /exall (deny)
  7922. /// 1 = /inall (allow)
  7923. /// result:
  7924. /// 0 = success
  7925. /// 1 = failure
  7926. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7927. {
  7928. int fd;
  7929. nullpo_retv(sd);
  7930. fd=sd->fd;
  7931. WFIFOHEAD(fd,packet_len(0xd2));
  7932. WFIFOW(fd,0)=0xd2;
  7933. WFIFOB(fd,2)=type;
  7934. WFIFOB(fd,3)=flag;
  7935. WFIFOSET(fd,packet_len(0xd2));
  7936. }
  7937. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7938. /// 07fe <bgm>.24B
  7939. void clif_playBGM(struct map_session_data* sd, const char* name)
  7940. {
  7941. int fd;
  7942. nullpo_retv(sd);
  7943. fd = sd->fd;
  7944. WFIFOHEAD(fd,packet_len(0x7fe));
  7945. WFIFOW(fd,0) = 0x7fe;
  7946. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7947. WFIFOSET(fd,packet_len(0x7fe));
  7948. }
  7949. /// Plays/stops a wave sound (ZC_SOUND).
  7950. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7951. /// file name:
  7952. /// relative to data\wav
  7953. /// act:
  7954. /// 0 = play (once)
  7955. /// 1 = play (repeat, does not work)
  7956. /// 2 = stops all sound instances of file name (does not work)
  7957. /// term:
  7958. /// unknown purpose, only relevant to act = 1
  7959. /// npc id:
  7960. /// The accustic direction of the sound is determined by the
  7961. /// relative position of the NPC to the player (3D sound).
  7962. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7963. {
  7964. int fd;
  7965. nullpo_retv(sd);
  7966. nullpo_retv(bl);
  7967. fd = sd->fd;
  7968. WFIFOHEAD(fd,packet_len(0x1d3));
  7969. WFIFOW(fd,0) = 0x1d3;
  7970. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7971. WFIFOB(fd,26) = type;
  7972. WFIFOL(fd,27) = 0;
  7973. WFIFOL(fd,31) = bl->id;
  7974. WFIFOSET(fd,packet_len(0x1d3));
  7975. }
  7976. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7977. {
  7978. unsigned char buf[40];
  7979. nullpo_retv(bl);
  7980. WBUFW(buf,0) = 0x1d3;
  7981. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7982. WBUFB(buf,26) = type;
  7983. WBUFL(buf,27) = 0;
  7984. WBUFL(buf,31) = bl->id;
  7985. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7986. }
  7987. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7988. /// 01f3 <id>.L <effect id>.L
  7989. /// effect id:
  7990. /// @see doc/effect_list.txt
  7991. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7992. {
  7993. unsigned char buf[24];
  7994. nullpo_retv(bl);
  7995. memset(buf, 0, packet_len(0x1f3));
  7996. WBUFW(buf,0) = 0x1f3;
  7997. WBUFL(buf,2) = bl->id;
  7998. WBUFL(buf,6) = type;
  7999. clif_send(buf, packet_len(0x1f3), bl, target);
  8000. if (disguised(bl)) {
  8001. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8002. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8003. }
  8004. }
  8005. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8006. {
  8007. WFIFOHEAD(fd,10);
  8008. WFIFOW(fd,0) = 0x1f3;
  8009. WFIFOL(fd,2) = bl->id;
  8010. WFIFOL(fd,6) = type;
  8011. WFIFOSET(fd,10);
  8012. }
  8013. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8014. /// 0284 <id>.L <effect id>.L <num data>.L
  8015. /// effect id:
  8016. /// @see doc/effect_list.txt
  8017. /// num data:
  8018. /// effect-dependent value
  8019. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8020. {
  8021. uint8 buf[14];
  8022. WBUFW(buf,0) = 0x284;
  8023. WBUFL(buf,2) = bl->id;
  8024. WBUFL(buf,6) = effect_id;
  8025. WBUFL(buf,10) = num;
  8026. clif_send(buf, packet_len(0x284), bl, target);
  8027. if( disguised(bl) )
  8028. {
  8029. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8030. clif_send(buf, packet_len(0x284), bl, SELF);
  8031. }
  8032. }
  8033. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8034. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8035. 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) {
  8036. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8037. uint8 buf[CHAT_SIZE_MAX];
  8038. nullpo_retv(bl);
  8039. if (msg_len > sizeof(buf) - 12) {
  8040. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8041. msg_len = sizeof(buf) - 12;
  8042. }
  8043. if (rgb2bgr)
  8044. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8045. WBUFW(buf,0) = 0x2C1;
  8046. WBUFW(buf,2) = msg_len + 12;
  8047. WBUFL(buf,4) = bl->id;
  8048. WBUFL(buf,8) = color;
  8049. memcpy(WBUFCP(buf,12), msg, msg_len);
  8050. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8051. }
  8052. /**
  8053. * Notifies the client that the storage window is still open
  8054. *
  8055. * Should only be used in cases where the client closed the
  8056. * storage window without server's consent
  8057. */
  8058. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8059. // Notify the client that the storage is open
  8060. if( sd->state.storage_flag == 1 ) {
  8061. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8062. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8063. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8064. }
  8065. // Notify the client that the gstorage is open otherwise it will
  8066. // remain locked forever and nobody will be able to access it
  8067. if( sd->state.storage_flag == 2 ) {
  8068. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8069. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8070. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8071. else {
  8072. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8073. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8074. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8075. }
  8076. }
  8077. }
  8078. // refresh the client's screen, getting rid of any effects
  8079. void clif_refresh(struct map_session_data *sd)
  8080. {
  8081. nullpo_retv(sd);
  8082. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8083. clif_inventorylist(sd);
  8084. clif_equipswitch_list(sd);
  8085. if(pc_iscarton(sd)) {
  8086. clif_cartlist(sd);
  8087. clif_updatestatus(sd,SP_CARTINFO);
  8088. }
  8089. clif_updatestatus(sd,SP_WEIGHT);
  8090. clif_updatestatus(sd,SP_MAXWEIGHT);
  8091. clif_updatestatus(sd,SP_STR);
  8092. clif_updatestatus(sd,SP_AGI);
  8093. clif_updatestatus(sd,SP_VIT);
  8094. clif_updatestatus(sd,SP_INT);
  8095. clif_updatestatus(sd,SP_DEX);
  8096. clif_updatestatus(sd,SP_LUK);
  8097. if (sd->spiritball)
  8098. clif_spiritball_single(sd->fd, sd);
  8099. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8100. clif_spiritcharm_single(sd->fd, sd);
  8101. if (sd->soulball)
  8102. clif_soulball_single(sd->fd, sd);
  8103. if (sd->vd.cloth_color)
  8104. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8105. if (sd->vd.body_style)
  8106. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8107. if(hom_is_active(sd->hd))
  8108. clif_send_homdata(sd,SP_ACK,0);
  8109. if( sd->md ) {
  8110. clif_mercenary_info(sd);
  8111. clif_mercenary_skillblock(sd);
  8112. }
  8113. if( sd->ed )
  8114. clif_elemental_info(sd);
  8115. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8116. clif_weather_check(sd);
  8117. if( sd->chatID )
  8118. chat_leavechat(sd,0);
  8119. if( sd->state.vending )
  8120. clif_openvending(sd, sd->bl.id, sd->vending);
  8121. if( pc_issit(sd) )
  8122. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8123. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8124. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8125. else
  8126. clif_changed_dir(&sd->bl, SELF);
  8127. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8128. //Issue #2143
  8129. //Cancel Trading State
  8130. if (sd->state.trading)
  8131. trade_tradecancel(sd);
  8132. //Cancel Buying/Selling State
  8133. if (sd->state.buyingstore)
  8134. buyingstore_close(sd);
  8135. mail_clear(sd);
  8136. clif_loadConfirm( sd );
  8137. if( disguised(&sd->bl) ) {/* refresh-da */
  8138. short disguise = sd->disguise;
  8139. pc_disguise(sd, 0);
  8140. pc_disguise(sd, disguise);
  8141. }
  8142. clif_refresh_storagewindow(sd);
  8143. }
  8144. /// Updates the object's (bl) name on client.
  8145. /// Used to update when a char leaves a party/guild. [Skotlex]
  8146. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8147. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8148. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8149. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8150. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8151. nullpo_retv( src );
  8152. nullpo_retv( bl );
  8153. switch( bl->type ){
  8154. case BL_PC: {
  8155. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8156. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8157. packet.gid = bl->id;
  8158. map_session_data *sd = (map_session_data *)bl;
  8159. //Requesting your own "shadow" name. [Skotlex]
  8160. if( src == bl && target == SELF && sd->disguise ){
  8161. packet.gid = -bl->id;
  8162. }
  8163. if( sd->fakename[0] ) {
  8164. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8165. clif_send( &packet, sizeof(packet), src, target );
  8166. return;
  8167. }
  8168. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8169. party_data *p = nullptr;
  8170. if( sd->status.party_id ){
  8171. p = party_search( sd->status.party_id );
  8172. }
  8173. // do not display party unless the player is also in a guild
  8174. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8175. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8176. }
  8177. if( sd->guild ){
  8178. int position;
  8179. // Will get the position of the guild the player is in
  8180. position = guild_getposition( sd );
  8181. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8182. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8183. }else if( sd->clan ){
  8184. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8185. }
  8186. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8187. packet.title_id = sd->status.title_id; // Title ID
  8188. #endif
  8189. clif_send(&packet, sizeof(packet), src, target);
  8190. }
  8191. break;
  8192. //[blackhole89]
  8193. case BL_HOM:
  8194. case BL_MER:
  8195. case BL_PET:
  8196. case BL_NPC:
  8197. case BL_ELEM: {
  8198. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8199. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8200. packet.gid = bl->id;
  8201. switch (bl->type) {
  8202. case BL_HOM:
  8203. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8204. break;
  8205. case BL_MER:
  8206. memcpy(packet.name, ((TBL_MER *)bl)->db->name, NAME_LENGTH);
  8207. break;
  8208. case BL_PET:
  8209. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8210. break;
  8211. case BL_NPC:
  8212. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8213. break;
  8214. case BL_ELEM:
  8215. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name, NAME_LENGTH);
  8216. break;
  8217. }
  8218. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8219. unit_data *ud = unit_bl2ud(bl);
  8220. if (ud != nullptr) {
  8221. memcpy(packet.title, ud->title, NAME_LENGTH);
  8222. packet.groupId = ud->group_id;
  8223. }
  8224. #endif
  8225. clif_send(&packet, sizeof(packet), src, target);
  8226. }
  8227. break;
  8228. case BL_MOB: {
  8229. mob_data *md = (mob_data *)bl;
  8230. if( md->guardian_data && md->guardian_data->guild_id ){
  8231. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8232. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8233. packet.gid = bl->id;
  8234. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8235. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8236. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8237. clif_send(&packet, sizeof(packet), src, target);
  8238. }else if( battle_config.show_mob_info ){
  8239. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8240. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8241. packet.gid = bl->id;
  8242. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8243. char mobhp[50], *str_p = mobhp;
  8244. if( battle_config.show_mob_info&4 ){
  8245. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8246. }
  8247. if( battle_config.show_mob_info&1 ){
  8248. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8249. }
  8250. if( battle_config.show_mob_info&2 ){
  8251. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8252. }
  8253. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8254. if( str_p != mobhp ){
  8255. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8256. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8257. }
  8258. clif_send(&packet, sizeof(packet), src, target);
  8259. } else {
  8260. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8261. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8262. packet.gid = bl->id;
  8263. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8264. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8265. unit_data *ud = unit_bl2ud(bl);
  8266. if (ud != nullptr) {
  8267. memcpy(packet.title, ud->title, NAME_LENGTH);
  8268. packet.groupId = ud->group_id;
  8269. }
  8270. #endif
  8271. clif_send(&packet, sizeof(packet), src, target);
  8272. }
  8273. }
  8274. break;
  8275. case BL_CHAT:
  8276. case BL_SKILL:
  8277. // Newer clients request this, but do not need an answer
  8278. return;
  8279. default:
  8280. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8281. return;
  8282. }
  8283. }
  8284. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8285. /// 01ff <id>.L <x>.W <y>.W
  8286. ///
  8287. /// Visually moves(instant) a character to x,y. The char moves even
  8288. /// when the target cell isn't walkable. If the char is sitting it
  8289. /// stays that way.
  8290. void clif_slide(struct block_list *bl, int x, int y)
  8291. {
  8292. unsigned char buf[10];
  8293. nullpo_retv(bl);
  8294. WBUFW(buf, 0) = 0x01ff;
  8295. WBUFL(buf, 2) = bl->id;
  8296. WBUFW(buf, 6) = x;
  8297. WBUFW(buf, 8) = y;
  8298. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8299. if( disguised(bl) )
  8300. {
  8301. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8302. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8303. }
  8304. }
  8305. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8306. /// 008d <packet len>.W <id>.L <message>.?B
  8307. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8308. {
  8309. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8310. int len_mes = strlen(mes)+1; //Account for \0
  8311. if (len_mes > sizeof(buf)-8) {
  8312. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8313. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8314. }
  8315. // send message to others
  8316. if (flag == AREA) {
  8317. WBUFW(buf,0) = 0x8d;
  8318. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8319. WBUFL(buf,4) = bl->id;
  8320. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8321. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8322. }
  8323. // send back message to the speaker
  8324. if( bl->type == BL_PC ) {
  8325. WBUFW(buf,0) = 0x8e;
  8326. WBUFW(buf, 2) = len_mes + 4;
  8327. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8328. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8329. }
  8330. }
  8331. /*==========================
  8332. * Minimap fix [Kevin]
  8333. * Remove dot from minimap
  8334. *--------------------------*/
  8335. void clif_party_xy_remove(struct map_session_data *sd)
  8336. {
  8337. unsigned char buf[16];
  8338. nullpo_retv(sd);
  8339. WBUFW(buf,0)=0x107;
  8340. WBUFL(buf,2)=sd->status.account_id;
  8341. WBUFW(buf,6)=-1;
  8342. WBUFW(buf,8)=-1;
  8343. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8344. }
  8345. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8346. /// 0215 <msg id>.L
  8347. /// msg id:
  8348. /// 0x15 = End all negative status (PA_GOSPEL)
  8349. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8350. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8351. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8352. /// 0x19 = All stats +20 (PA_GOSPEL)
  8353. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8354. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8355. /// 0x1e = DEF +25% (PA_GOSPEL)
  8356. /// 0x1f = ATK +100% (PA_GOSPEL)
  8357. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8358. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8359. /// ? = nothing
  8360. void clif_gospel_info(struct map_session_data *sd, int type)
  8361. {
  8362. int fd=sd->fd;
  8363. WFIFOHEAD(fd,packet_len(0x215));
  8364. WFIFOW(fd,0)=0x215;
  8365. WFIFOL(fd,2)=type;
  8366. WFIFOSET(fd, packet_len(0x215));
  8367. }
  8368. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8369. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8370. /// result:
  8371. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8372. /// star:
  8373. /// 0 = Place of the Sun
  8374. /// 1 = Place of the Moon
  8375. /// 2 = Place of the Stars
  8376. /// 1 = Star Gladiator %s's %s: <mapname>
  8377. /// star:
  8378. /// 0 = Place of the Sun
  8379. /// 1 = Place of the Moon
  8380. /// 2 = Place of the Stars
  8381. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8382. /// star:
  8383. /// 0 = Target of the Sun
  8384. /// 1 = Target of the Moon
  8385. /// 2 = Target of the Stars
  8386. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8387. /// star:
  8388. /// 0 = Monster of the Sun
  8389. /// 1 = Monster of the Moon
  8390. /// 2 = Monster of the Stars
  8391. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8392. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8393. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8394. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8395. /// 40 = Target HP : <monster_id used as HP>
  8396. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8397. {
  8398. int fd = sd->fd;
  8399. WFIFOHEAD(fd,packet_len(0x20e));
  8400. WFIFOW(fd,0) = 0x20e;
  8401. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8402. WFIFOL(fd,26) = monster_id;
  8403. WFIFOB(fd,30) = star;
  8404. WFIFOB(fd,31) = result;
  8405. WFIFOSET(fd,packet_len(0x20e));
  8406. }
  8407. /*==========================================
  8408. * Info about Star Glaldiator save map [Komurka]
  8409. * type: 1: Information, 0: Map registered
  8410. *------------------------------------------*/
  8411. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8412. {
  8413. char mapname[MAP_NAME_LENGTH_EXT];
  8414. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8415. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8416. }
  8417. /*==========================================
  8418. * Info about Star Glaldiator hate mob [Komurka]
  8419. * type: 1: Register mob, 0: Information.
  8420. *------------------------------------------*/
  8421. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8422. {
  8423. if( pcdb_checkid(class_) ) {
  8424. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8425. } else if( mobdb_checkid(class_) ) {
  8426. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8427. } else {
  8428. 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);
  8429. }
  8430. }
  8431. /*==========================================
  8432. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8433. *------------------------------------------*/
  8434. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8435. {
  8436. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8437. }
  8438. /*==========================================
  8439. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8440. *------------------------------------------*/
  8441. void clif_feel_hate_reset(struct map_session_data *sd)
  8442. {
  8443. clif_starskill(sd, "", 0, 0, 30);
  8444. }
  8445. /// Send out reply to configuration change
  8446. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8447. /// type: see enum e_config_type
  8448. /// value:
  8449. /// false = disabled
  8450. /// true = enabled
  8451. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8452. int fd;
  8453. nullpo_retv(sd);
  8454. fd = sd->fd;
  8455. WFIFOHEAD(fd, packet_len(0x2d9));
  8456. WFIFOW(fd, 0) = 0x2d9;
  8457. WFIFOL(fd, 2) = type;
  8458. WFIFOL(fd, 6) = enabled;
  8459. WFIFOSET(fd, packet_len(0x2d9));
  8460. }
  8461. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8462. /// 02da <open equip window>.B
  8463. /// open equip window:
  8464. /// 0 = disabled
  8465. /// 1 = enabled
  8466. void clif_equipcheckbox(struct map_session_data* sd)
  8467. {
  8468. int fd;
  8469. nullpo_retv(sd);
  8470. fd = sd->fd;
  8471. WFIFOHEAD(fd, packet_len(0x2da));
  8472. WFIFOW(fd, 0) = 0x2da;
  8473. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8474. WFIFOSET(fd, packet_len(0x2da));
  8475. }
  8476. /// Sends info about a player's equipped items.
  8477. /// 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)
  8478. /// 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)
  8479. /// 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)
  8480. /// 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)
  8481. /// 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)
  8482. /// 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)
  8483. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8484. nullpo_retv( sd );
  8485. nullpo_retv( tsd );
  8486. struct packet_viewequip_ack packet;
  8487. int equip = 0;
  8488. for( int i = 0; i < EQI_MAX; i++ ){
  8489. int k = tsd->equip_index[i];
  8490. if( k >= 0 ){
  8491. if( tsd->inventory.u.items_inventory[k].nameid <= 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8492. continue;
  8493. }
  8494. if( !tsd->inventory.u.items_inventory[k].equip ){
  8495. continue;
  8496. }
  8497. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8498. continue;
  8499. }
  8500. clif_item_equip( client_index( k ), &packet.list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8501. }
  8502. }
  8503. packet.PacketType = viewequipackType;
  8504. packet.PacketLength = ( sizeof( packet ) - sizeof( packet.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  8505. safestrncpy( packet.characterName, tsd->status.name, NAME_LENGTH );
  8506. packet.job = tsd->status.class_;
  8507. packet.head = tsd->vd.hair_style;
  8508. packet.accessory = tsd->vd.head_bottom;
  8509. packet.accessory2 = tsd->vd.head_mid;
  8510. packet.accessory3 = tsd->vd.head_top;
  8511. #if PACKETVER >= 20110111
  8512. packet.robe = tsd->vd.robe;
  8513. #endif
  8514. packet.headpalette = tsd->vd.hair_color;
  8515. packet.bodypalette = tsd->vd.cloth_color;
  8516. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8517. packet.body2 = tsd->vd.body_style;
  8518. #endif
  8519. packet.sex = tsd->vd.sex;
  8520. clif_send( &packet, packet.PacketLength, &sd->bl, SELF );
  8521. }
  8522. /// Display msgstringtable.txt string (ZC_MSG).
  8523. /// 0291 <message>.W
  8524. void clif_msg(struct map_session_data* sd, unsigned short id)
  8525. {
  8526. int fd;
  8527. nullpo_retv(sd);
  8528. fd = sd->fd;
  8529. WFIFOHEAD(fd, packet_len(0x291));
  8530. WFIFOW(fd, 0) = 0x291;
  8531. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8532. WFIFOSET(fd, packet_len(0x291));
  8533. }
  8534. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8535. /// 0x7e2 <message>.W <value>.L
  8536. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8537. {
  8538. int fd = sd->fd;
  8539. WFIFOHEAD(fd, packet_len(0x7e2));
  8540. WFIFOW(fd,0) = 0x7e2;
  8541. WFIFOW(fd,2) = id;
  8542. WFIFOL(fd,4) = value;
  8543. WFIFOSET(fd, packet_len(0x7e2));
  8544. }
  8545. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8546. /// 07e6 <skill id>.W <msg id>.L
  8547. ///
  8548. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8549. /// "[SkillName] Message"
  8550. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8551. {
  8552. int fd = sd->fd;
  8553. WFIFOHEAD(fd, packet_len(0x7e6));
  8554. WFIFOW(fd,0) = 0x7e6;
  8555. WFIFOW(fd,2) = skill_id;
  8556. WFIFOL(fd,4) = msg_id;
  8557. WFIFOSET(fd, packet_len(0x7e6));
  8558. }
  8559. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8560. /// 09cd <msg id>.W <color>.L
  8561. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8562. nullpo_retv(sd);
  8563. int fd = sd->fd;
  8564. WFIFOHEAD(fd, packet_len(0x9cd));
  8565. WFIFOW(fd, 0) = 0x9cd;
  8566. WFIFOW(fd, 2) = msg_id;
  8567. WFIFOL(fd, 4) = color;
  8568. WFIFOSET(fd, packet_len(0x9cd));
  8569. }
  8570. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8571. /// Returns true if the packet was parsed successfully.
  8572. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8573. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8574. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8575. const char* seperator = " : ";
  8576. int fd;
  8577. struct s_packet_db* info;
  8578. uint16 packetLength, inputLength;
  8579. const char *input, *name, *message;
  8580. size_t nameLength, messageLength;
  8581. fd = sd->fd;
  8582. info = &packet_db[RFIFOW(fd,0)];
  8583. packetLength = RFIFOW(fd,info->pos[0]);
  8584. input = RFIFOCP(fd,info->pos[1]);
  8585. // basic structure check for the 4-byte header
  8586. if( packetLength < 4 ){
  8587. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8588. return false;
  8589. }else{
  8590. inputLength = packetLength - 4;
  8591. }
  8592. // process <name> part of the packet
  8593. if( whisperFormat ) {
  8594. // name has fixed width
  8595. if( inputLength < NAME_LENGTH + 1 ) {
  8596. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8597. return false;
  8598. }
  8599. name = input;
  8600. // validate name
  8601. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8602. // only restriction is that the name must be zero-terminated
  8603. if( name[nameLength] != '\0' ) {
  8604. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8605. return false;
  8606. }
  8607. message = input + NAME_LENGTH;
  8608. messageLength = inputLength - NAME_LENGTH;
  8609. }else{
  8610. // name and message are separated by ' : '
  8611. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8612. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8613. // check if there's enough data provided
  8614. if( inputLength < nameLength + seperatorLength + 1 ){
  8615. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8616. return false;
  8617. }
  8618. name = input;
  8619. // validate name
  8620. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8621. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8622. {
  8623. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8624. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8625. set_eof(sd->fd); // Just kick them out to correct it.
  8626. return false;
  8627. }
  8628. message = input + nameLength + seperatorLength;
  8629. messageLength = inputLength - nameLength - seperatorLength;
  8630. }
  8631. #if PACKETVER < 20151001
  8632. // the declared length must match real length
  8633. if( messageLength != strnlen(message, messageLength)+1 ) {
  8634. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8635. return false;
  8636. }
  8637. // verify <message> part of the packet
  8638. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8639. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8640. return false;
  8641. }
  8642. #else
  8643. // No zero termination anymore
  8644. messageLength += 1;
  8645. #endif
  8646. // messages mustn't be too long
  8647. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8648. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8649. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8650. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8651. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8652. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8653. return false;
  8654. }
  8655. // If it is not a whisper message, set the name to the fakename of the player
  8656. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8657. strcpy( out_name, sd->fakename );
  8658. }else{
  8659. safestrncpy( out_name, name, nameLength + 1 );
  8660. }
  8661. safestrncpy( out_message, message, messageLength );
  8662. if( whisperFormat ){
  8663. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8664. out_full_message[nameLength] = '\0';
  8665. }else{
  8666. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8667. }
  8668. if( is_atcommand( fd, sd, out_message, 1 ) )
  8669. return false;
  8670. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8671. return false; //no "chatting" while muted.
  8672. if( battle_config.min_chat_delay ) { //[Skotlex]
  8673. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8674. return false;
  8675. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8676. }
  8677. if (battle_config.idletime_option&IDLE_CHAT)
  8678. sd->idletime = last_tick;
  8679. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8680. sd->idletime_hom = last_tick;
  8681. return true;
  8682. }
  8683. /**
  8684. * Displays a message if the player enters a PK Zone (during pk_mode)
  8685. * @param sd: Player data
  8686. */
  8687. inline void clif_pk_mode_message(struct map_session_data * sd)
  8688. {
  8689. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8690. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8691. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8692. char output[CHAT_SIZE_MAX];
  8693. // 1504: You've entered a PK Zone (safe until level %d).
  8694. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8695. battle_config.pk_min_level);
  8696. clif_showscript(&sd->bl, output, SELF);
  8697. } else {
  8698. // 1503: You've entered a PK Zone.
  8699. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8700. }
  8701. }
  8702. return;
  8703. }
  8704. // ---------------------
  8705. // clif_parse_wanttoconnect
  8706. // ---------------------
  8707. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8708. // error codes:
  8709. // 0 - Success
  8710. // 1 - Unknown packet_ver
  8711. // 2 - Invalid account_id
  8712. // 3 - Invalid char_id
  8713. // 4 - Invalid login_id1 (reserved)
  8714. // 5 - Invalid client_tick (reserved)
  8715. // 6 - Invalid sex
  8716. // Only the first 'invalid' error that appears is used.
  8717. static int clif_parse_WantToConnection_sub(int fd)
  8718. {
  8719. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8720. unsigned short cmd;
  8721. //By default, start searching on the default one.
  8722. cmd = RFIFOW(fd, 0);
  8723. packet_len = RFIFOREST(fd);
  8724. // FIXME: If the packet is not received at once, this will FAIL.
  8725. // Figure out, when it happens, that only part of the packet is
  8726. // received, or fix the function to be able to deal with that
  8727. // case.
  8728. if( packet_len != packet_db[cmd].len )
  8729. return 1; /* wrong length */
  8730. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8731. return 2; /* invalid account_id */
  8732. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8733. return 3; /* invalid char_id */
  8734. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8735. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8736. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8737. return 6; /* invalid sex */
  8738. else
  8739. return 0;
  8740. }
  8741. /// Request to connect to map-server.
  8742. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8743. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8744. /// There are various variants of this packet, some of them have padding between fields.
  8745. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8746. {
  8747. struct block_list* bl;
  8748. struct auth_node* node;
  8749. int cmd, account_id, char_id, login_id1, sex, err;
  8750. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8751. if (sd) {
  8752. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8753. return;
  8754. }
  8755. cmd = RFIFOW(fd, 0);
  8756. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8757. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8758. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8759. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8760. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8761. err = clif_parse_WantToConnection_sub(fd);
  8762. if( err ){ // connection rejected
  8763. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8764. err == 1 ? "." :
  8765. err == 2 ? ", possibly for having an invalid account_id." :
  8766. err == 3 ? ", possibly for having an invalid char_id." :
  8767. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8768. err == 4 ? ", possibly for having an invalid login_id1." :
  8769. err == 5 ? ", possibly for having an invalid client_tick." :
  8770. */
  8771. err == 6 ? ", possibly for having an invalid sex." :
  8772. ". ERROR invalid error code"));
  8773. WFIFOHEAD(fd,packet_len(0x6a));
  8774. WFIFOW(fd,0) = 0x6a;
  8775. WFIFOB(fd,2) = err;
  8776. WFIFOSET(fd,packet_len(0x6a));
  8777. #ifdef DUMP_INVALID_PACKET
  8778. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8779. #endif
  8780. RFIFOSKIP(fd, RFIFOREST(fd));
  8781. set_eof(fd);
  8782. return;
  8783. }
  8784. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8785. clif_authfail_fd(fd,1);// server closed
  8786. return;
  8787. }
  8788. //Check for double login.
  8789. bl = map_id2bl(account_id);
  8790. if(bl && bl->type != BL_PC) {
  8791. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8792. WFIFOHEAD(fd,packet_len(0x6a));
  8793. WFIFOW(fd,0) = 0x6a;
  8794. WFIFOB(fd,2) = 3; // Rejected by server
  8795. WFIFOSET(fd,packet_len(0x6a));
  8796. set_eof(fd);
  8797. return;
  8798. }
  8799. if (bl ||
  8800. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8801. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8802. {
  8803. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8804. return;
  8805. }
  8806. CREATE(sd, TBL_PC, 1);
  8807. sd->fd = fd;
  8808. #ifdef PACKET_OBFUSCATION
  8809. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8810. #endif
  8811. session[fd]->session_data = sd;
  8812. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8813. #if PACKETVER < 20070521
  8814. WFIFOHEAD(fd,4);
  8815. WFIFOL(fd,0) = sd->bl.id;
  8816. WFIFOSET(fd,4);
  8817. #else
  8818. WFIFOHEAD(fd,packet_len(0x283));
  8819. WFIFOW(fd,0) = 0x283;
  8820. WFIFOL(fd,2) = sd->bl.id;
  8821. WFIFOSET(fd,packet_len(0x283));
  8822. #endif
  8823. chrif_authreq(sd,false);
  8824. }
  8825. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8826. /// 007d
  8827. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8828. {
  8829. bool guild_notice = false;
  8830. if(sd->bl.prev != NULL)
  8831. return;
  8832. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8833. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8834. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8835. sd->state.connect_new = 0;
  8836. return;
  8837. }
  8838. if (sd->state.rewarp) { //Rewarp player.
  8839. sd->state.rewarp = 0;
  8840. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8841. return;
  8842. }
  8843. sd->state.warping = 0;
  8844. // look
  8845. #if PACKETVER < 4
  8846. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8847. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8848. #else
  8849. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8850. #endif
  8851. pc_set_costume_view(sd);
  8852. if(sd->vd.cloth_color)
  8853. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8854. if(sd->vd.body_style)
  8855. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8856. // item
  8857. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8858. pc_checkitem(sd);
  8859. clif_equipswitch_list(sd);
  8860. // cart
  8861. if(pc_iscarton(sd)) {
  8862. clif_cartlist(sd);
  8863. clif_updatestatus(sd,SP_CARTINFO);
  8864. }
  8865. // weight
  8866. clif_updatestatus(sd,SP_WEIGHT);
  8867. clif_updatestatus(sd,SP_MAXWEIGHT);
  8868. // guild
  8869. // (needs to go before clif_spawn() to show guild emblems correctly)
  8870. if(sd->status.guild_id)
  8871. guild_send_memberinfoshort(sd,1);
  8872. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8873. if(battle_config.pc_invincible_time > 0) {
  8874. if(mapdata_flag_gvg(mapdata))
  8875. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8876. else
  8877. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8878. }
  8879. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8880. map_spawnmobs(sd->bl.m);
  8881. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8882. mapdata->users_pvp++;
  8883. }
  8884. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8885. // reset the callshop flag if the player changes map
  8886. sd->state.callshop = 0;
  8887. if(map_addblock(&sd->bl))
  8888. return;
  8889. clif_spawn(&sd->bl);
  8890. // Party
  8891. // (needs to go after clif_spawn() to show hp bars correctly)
  8892. if(sd->status.party_id) {
  8893. party_send_movemap(sd);
  8894. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8895. }
  8896. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8897. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8898. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8899. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8900. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8901. sd->pvp_rank = 0;
  8902. sd->pvp_lastusers = 0;
  8903. sd->pvp_point = 5;
  8904. sd->pvp_won = 0;
  8905. sd->pvp_lost = 0;
  8906. }
  8907. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8908. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8909. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8910. else if (mapdata->flag[MF_GVG_DUNGEON])
  8911. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8912. else if( mapdata_flag_gvg(mapdata) )
  8913. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8914. else
  8915. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8916. // info about nearby objects
  8917. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8918. 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);
  8919. // pet
  8920. if( sd->pd ) {
  8921. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8922. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8923. pet_return_egg( sd, sd->pd );
  8924. } else {
  8925. if(map_addblock(&sd->pd->bl))
  8926. return;
  8927. clif_spawn(&sd->pd->bl);
  8928. clif_send_petdata(sd,sd->pd,0,0);
  8929. clif_send_petstatus(sd);
  8930. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8931. }
  8932. }
  8933. //homunculus [blackhole89]
  8934. if( hom_is_active(sd->hd) ) {
  8935. if(map_addblock(&sd->hd->bl))
  8936. return;
  8937. clif_spawn(&sd->hd->bl);
  8938. clif_send_homdata(sd,SP_ACK,0);
  8939. clif_hominfo(sd,sd->hd,1);
  8940. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8941. clif_homskillinfoblock(sd);
  8942. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8943. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8944. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8945. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8946. }
  8947. if( sd->md ) {
  8948. if(map_addblock(&sd->md->bl))
  8949. return;
  8950. clif_spawn(&sd->md->bl);
  8951. clif_mercenary_info(sd);
  8952. clif_mercenary_skillblock(sd);
  8953. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8954. }
  8955. if( sd->ed ) {
  8956. if (map_addblock(&sd->ed->bl))
  8957. return;
  8958. clif_spawn(&sd->ed->bl);
  8959. clif_elemental_info(sd);
  8960. clif_elemental_updatestatus(sd,SP_HP);
  8961. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8962. clif_elemental_updatestatus(sd,SP_SP);
  8963. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8964. }
  8965. if(sd->state.connect_new) {
  8966. int lv;
  8967. guild_notice = true;
  8968. clif_skillinfoblock(sd);
  8969. clif_hotkeys_send(sd,0);
  8970. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  8971. clif_hotkeys_send(sd,1);
  8972. #endif
  8973. clif_updatestatus(sd,SP_BASEEXP);
  8974. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8975. clif_updatestatus(sd,SP_JOBEXP);
  8976. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8977. clif_updatestatus(sd,SP_SKILLPOINT);
  8978. clif_initialstatus(sd);
  8979. if (sd->sc.option&OPTION_FALCON)
  8980. clif_status_load(&sd->bl, EFST_FALCON, 1);
  8981. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  8982. clif_status_load(&sd->bl, EFST_RIDING, 1);
  8983. else if (sd->sc.option&OPTION_WUGRIDER)
  8984. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  8985. else if (sd->sc.option&OPTION_MADOGEAR)
  8986. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106
  8987. clif_status_load( &sd->bl, EFST_MADOGEAR, 1 );
  8988. #else
  8989. clif_status_load( &sd->bl, EFST_RIDING, 1 );
  8990. #endif
  8991. else if (sd->sc.data[SC_ALL_RIDING])
  8992. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  8993. if(sd->status.manner < 0)
  8994. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8995. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8996. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8997. if(sd->bl.m == sd->feel_map[0].m
  8998. || sd->bl.m == sd->feel_map[1].m
  8999. || sd->bl.m == sd->feel_map[2].m)
  9000. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9001. }
  9002. if(sd->pd && sd->pd->pet.intimate > 900)
  9003. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9004. if(hom_is_active(sd->hd))
  9005. hom_init_timers(sd->hd);
  9006. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9007. sd->state.night = 1;
  9008. clif_status_load(&sd->bl, EFST_SKE, 1);
  9009. }
  9010. // Notify everyone that this char logged in [Skotlex].
  9011. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9012. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9013. //Login Event
  9014. npc_script_event(sd, NPCE_LOGIN);
  9015. }
  9016. } else {
  9017. //For some reason the client "loses" these on warp/map-change.
  9018. clif_updatestatus(sd,SP_STR);
  9019. clif_updatestatus(sd,SP_AGI);
  9020. clif_updatestatus(sd,SP_VIT);
  9021. clif_updatestatus(sd,SP_INT);
  9022. clif_updatestatus(sd,SP_DEX);
  9023. clif_updatestatus(sd,SP_LUK);
  9024. // abort currently running script
  9025. sd->state.using_fake_npc = 0;
  9026. sd->state.menu_or_input = 0;
  9027. sd->npc_menu = 0;
  9028. if(sd->npc_id)
  9029. npc_event_dequeue(sd);
  9030. }
  9031. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9032. #if PACKETVER >= 20070918
  9033. clif_partyinvitationstate(sd);
  9034. clif_equipcheckbox(sd);
  9035. #endif
  9036. #if PACKETVER >= 20141008
  9037. if( battle_config.pet_autofeed_always ){
  9038. // Always send ON or OFF
  9039. if( sd->pd && battle_config.feature_pet_autofeed ){
  9040. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  9041. }else{
  9042. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  9043. }
  9044. }else{
  9045. // Only send when enabled
  9046. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9047. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9048. }
  9049. }
  9050. #endif
  9051. #if PACKETVER >= 20170920
  9052. if( battle_config.homunculus_autofeed_always ){
  9053. // Always send ON or OFF
  9054. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9055. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9056. }else{
  9057. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9058. }
  9059. }else{
  9060. // Only send when enabled
  9061. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9062. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9063. }
  9064. }
  9065. #endif
  9066. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9067. clif_guild_notice(sd); // Displays after VIP
  9068. guild_notice = false; // Do not display it twice
  9069. }
  9070. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9071. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9072. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9073. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9074. }
  9075. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9076. { //Display night.
  9077. if( !sd->state.night )
  9078. {
  9079. sd->state.night = 1;
  9080. clif_status_load(&sd->bl, EFST_SKE, 1);
  9081. }
  9082. }
  9083. else if( sd->state.night )
  9084. { //Clear night display.
  9085. sd->state.night = 0;
  9086. clif_status_load(&sd->bl, EFST_SKE, 0);
  9087. }
  9088. if( mapdata->flag[MF_BATTLEGROUND] )
  9089. {
  9090. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9091. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9092. clif_bg_updatescore_single(sd);
  9093. }
  9094. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9095. {
  9096. char output[128];
  9097. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9098. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9099. }
  9100. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9101. mapdata->hpmeter_visible++;
  9102. sd->state.hpmeter_visible = 1;
  9103. }
  9104. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9105. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9106. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9107. #ifdef VIP_ENABLE
  9108. if (!sd->state.connect_new &&
  9109. !sd->vip.disableshowrate &&
  9110. sd->state.pmap != sd->bl.m &&
  9111. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9112. )
  9113. {
  9114. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9115. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9116. }
  9117. #endif
  9118. // Instances do not need their own channels
  9119. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9120. channel_mjoin(sd); //join new map
  9121. clif_pk_mode_message(sd);
  9122. }
  9123. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9124. clif_guild_notice(sd); // Displays at end
  9125. }
  9126. mail_clear(sd);
  9127. /* Guild Aura Init */
  9128. if( sd->guild && sd->state.gmaster_flag ) {
  9129. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9130. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9131. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9132. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9133. }
  9134. if( sd->state.vending ) { /* show we have a vending */
  9135. clif_openvending(sd,sd->bl.id,sd->vending);
  9136. clif_showvendingboard(&sd->bl,sd->message,0);
  9137. }
  9138. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9139. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9140. npc_script_event(sd, NPCE_LOADMAP);
  9141. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9142. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9143. if (sd->sc.opt2) //Client loses these on warp.
  9144. clif_changeoption(&sd->bl);
  9145. if ((sd->sc.data[SC_MONSTER_TRANSFORM] || sd->sc.data[SC_ACTIVE_MONSTER_TRANSFORM]) && battle_config.mon_trans_disable_in_gvg && mapdata_flag_gvg2(mapdata)) {
  9146. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9147. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9148. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9149. }
  9150. clif_weather_check(sd);
  9151. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9152. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9153. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9154. else
  9155. sd->areanpc.clear();
  9156. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9157. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9158. pc_setdead(sd);
  9159. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9160. if(pc_isdead(sd))
  9161. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9162. else {
  9163. skill_usave_trigger(sd);
  9164. if (battle_config.spawn_direction)
  9165. clif_changed_dir(&sd->bl, SELF);
  9166. }
  9167. // Trigger skill effects if you appear standing on them
  9168. if(!battle_config.pc_invincible_time)
  9169. skill_unit_move(&sd->bl,gettick(),1);
  9170. pc_show_questinfo_reinit(sd);
  9171. pc_show_questinfo(sd);
  9172. #if PACKETVER >= 20150513
  9173. if( sd->mail.inbox.unread ){
  9174. clif_Mail_new(sd, 0, NULL, NULL);
  9175. }
  9176. #endif
  9177. sd->state.connect_new = 0;
  9178. sd->state.changemap = false;
  9179. }
  9180. /// Server's tick (ZC_NOTIFY_TIME).
  9181. /// 007f <time>.L
  9182. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9183. {
  9184. int fd = sd->fd;
  9185. WFIFOHEAD(fd,packet_len(0x7f));
  9186. WFIFOW(fd,0) = 0x7f;
  9187. WFIFOL(fd,2) = client_tick(time);
  9188. WFIFOSET(fd,packet_len(0x7f));
  9189. }
  9190. /// Request for server's tick.
  9191. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9192. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9193. /// There are various variants of this packet, some of them have padding between fields.
  9194. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9195. {
  9196. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9197. clif_notify_time(sd, gettick());
  9198. }
  9199. /// Sends hotkey bar.
  9200. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9201. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9202. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9203. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9204. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9205. #ifdef HOTKEY_SAVING
  9206. nullpo_retv( sd );
  9207. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9208. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9209. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9210. if( tab == 0 ){
  9211. p.rotate = sd->status.hotkey_rowshift;
  9212. }else{
  9213. p.rotate = sd->status.hotkey_rowshift2;
  9214. }
  9215. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9216. p.tab = tab;
  9217. #endif
  9218. #endif
  9219. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9220. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9221. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9222. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9223. }
  9224. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9225. #endif
  9226. }
  9227. /// Request to update a position on the hotkey row bar
  9228. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9229. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9230. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9231. if( p->tab == 0 ){
  9232. sd->status.hotkey_rowshift = p->rowshift;
  9233. }else{
  9234. sd->status.hotkey_rowshift2 = p->rowshift;
  9235. }
  9236. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9237. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9238. sd->status.hotkey_rowshift = p->rowshift;
  9239. #endif
  9240. }
  9241. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9242. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9243. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9244. #ifdef HOTKEY_SAVING
  9245. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9246. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9247. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9248. if( idx >= MAX_HOTKEYS_DB ){
  9249. return;
  9250. }
  9251. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9252. sd->status.hotkeys[idx].id = p->hotkey.id;
  9253. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9254. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9255. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9256. const unsigned short idx = p->index;
  9257. if( idx >= MAX_HOTKEYS_DB ){
  9258. return;
  9259. }
  9260. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9261. sd->status.hotkeys[idx].id = p->hotkey.id;
  9262. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9263. #endif
  9264. #endif
  9265. }
  9266. /// Displays cast-like progress bar (ZC_PROGRESS).
  9267. /// 02f0 <color>.L <time>.L
  9268. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9269. {
  9270. int fd = sd->fd;
  9271. WFIFOHEAD(fd,packet_len(0x2f0));
  9272. WFIFOW(fd,0) = 0x2f0;
  9273. WFIFOL(fd,2) = color;
  9274. WFIFOL(fd,6) = second;
  9275. WFIFOSET(fd,packet_len(0x2f0));
  9276. }
  9277. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9278. /// 02f2
  9279. void clif_progressbar_abort(struct map_session_data * sd)
  9280. {
  9281. int fd = sd->fd;
  9282. WFIFOHEAD(fd,packet_len(0x2f2));
  9283. WFIFOW(fd,0) = 0x2f2;
  9284. WFIFOSET(fd,packet_len(0x2f2));
  9285. }
  9286. /// Notification from the client, that the progress bar has reached 100%.
  9287. /// 02f1 (CZ_PROGRESS)
  9288. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9289. // No progressbar active, ignore it
  9290. if( !sd->progressbar.npc_id ){
  9291. return;
  9292. }
  9293. int npc_id = sd->progressbar.npc_id;
  9294. bool closing = false;
  9295. // Check if the progress was canceled
  9296. if( gettick() < sd->progressbar.timeout && sd->st ){
  9297. closing = true;
  9298. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9299. // If a message window was open, offer a close button to the user
  9300. if( sd->st->mes_active ){
  9301. clif_scriptclose( sd, npc_id );
  9302. }
  9303. }
  9304. sd->progressbar.npc_id = 0;
  9305. sd->progressbar.timeout = 0;
  9306. sd->state.workinprogress = WIP_DISABLE_NONE;
  9307. npc_scriptcont(sd, npc_id, closing);
  9308. }
  9309. /// Displays cast-like progress bar on a NPC
  9310. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9311. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9312. #if PACKETVER >= 20130821
  9313. unsigned char buf[14];
  9314. if( nd->progressbar.timeout > 0 ){
  9315. WBUFW(buf,0) = 0x9d1;
  9316. WBUFL(buf,2) = nd->bl.id;
  9317. WBUFL(buf,6) = nd->progressbar.color;
  9318. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9319. if( sd ){
  9320. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9321. }else{
  9322. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9323. }
  9324. }
  9325. #endif
  9326. }
  9327. /// Request to walk to a certain position on the current map.
  9328. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9329. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9330. /// There are various variants of this packet, some of them have padding between fields.
  9331. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9332. {
  9333. short x, y;
  9334. if (pc_isdead(sd)) {
  9335. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9336. return;
  9337. }
  9338. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9339. ; //You CAN walk on this OPT1 value.
  9340. else if (sd->progressbar.npc_id) {
  9341. clif_progressbar_abort(sd);
  9342. return; // First walk attempt cancels the progress bar
  9343. } else if (pc_cant_act(sd))
  9344. return;
  9345. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9346. return;
  9347. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9348. //A move command one cell west is only valid if the target cell is free
  9349. if(battle_config.official_cell_stack_limit > 0
  9350. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9351. return;
  9352. // Cloaking wall check is actually updated when you click to process next movement
  9353. // not when you move each cell. This is official behaviour.
  9354. if (sd->sc.data[SC_CLOAKING])
  9355. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9356. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9357. pc_delinvincibletimer(sd);
  9358. //Set last idle time... [Skotlex]
  9359. if (battle_config.idletime_option&IDLE_WALK)
  9360. sd->idletime = last_tick;
  9361. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9362. sd->idletime_hom = last_tick;
  9363. unit_walktoxy(&sd->bl, x, y, 4);
  9364. }
  9365. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9366. /// 018b <result>.W
  9367. /// result:
  9368. /// 0 = disconnect (quit)
  9369. /// 1 = cannot disconnect (wait 10 seconds)
  9370. /// ? = ignored
  9371. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9372. {
  9373. int fd = sd->fd;
  9374. WFIFOHEAD(fd,packet_len(0x18b));
  9375. WFIFOW(fd,0) = 0x18b;
  9376. WFIFOW(fd,2) = result;
  9377. WFIFOSET(fd,packet_len(0x18b));
  9378. }
  9379. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9380. /// 018a <type>.W
  9381. /// type:
  9382. /// 0 = quit
  9383. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9384. {
  9385. /* Rovert's prevent logout option fixed [Valaris] */
  9386. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9387. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] && !sd->sc.data[SC_NEWMOON] &&
  9388. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9389. {
  9390. set_eof(fd);
  9391. pc_damage_log_clear(sd,0);
  9392. clif_disconnect_ack(sd, 0);
  9393. } else {
  9394. clif_disconnect_ack(sd, 1);
  9395. }
  9396. }
  9397. /// Requesting unit's name.
  9398. /// 0094 <id>.L (CZ_REQNAME)
  9399. /// 0368 <id>.L (CZ_REQNAME2)
  9400. /// There are various variants of this packet, some of them have padding between fields.
  9401. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9402. {
  9403. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9404. struct block_list* bl;
  9405. //struct status_change *sc;
  9406. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9407. id = sd->bl.id;
  9408. bl = map_id2bl(id);
  9409. if( bl == NULL )
  9410. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9411. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9412. return; // Block namerequests past view range
  9413. // 'see people in GM hide' cheat detection
  9414. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9415. sc = status_get_sc(bl);
  9416. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9417. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9418. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9419. ) {
  9420. char gm_msg[256];
  9421. 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);
  9422. ShowWarning(gm_msg);
  9423. // information is sent to all online GMs
  9424. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9425. return;
  9426. }
  9427. */
  9428. clif_name(&sd->bl,bl,SELF);
  9429. }
  9430. /// Validates and processes global messages
  9431. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9432. /// There are various variants of this packet.
  9433. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9434. {
  9435. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9436. size_t length;
  9437. // validate packet and retrieve name and message
  9438. if( !clif_process_message(sd, false, name, message, output ) )
  9439. return;
  9440. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9441. channel_send(sd->gcbind,sd,message);
  9442. return;
  9443. }
  9444. // send message to others (using the send buffer for temp. storage)
  9445. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9446. length = strlen(output) + 1;
  9447. // send back message to the speaker
  9448. WFIFOHEAD(fd,4+length);
  9449. WFIFOW(fd,0) = 0x8e;
  9450. WFIFOW(fd,2) = (uint16)(4+length);
  9451. safestrncpy(WFIFOCP(fd,4), output, length );
  9452. WFIFOSET(fd, WFIFOW(fd,2));
  9453. #ifdef PCRE_SUPPORT
  9454. // trigger listening npcs
  9455. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9456. #endif
  9457. // Chat logging type 'O' / Global Chat
  9458. 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);
  9459. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9460. }
  9461. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9462. /// Request to warp to a map on given coordinates.
  9463. /// 0140 <map name>.16B <x>.W <y>.W
  9464. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9465. {
  9466. char command[MAP_NAME_LENGTH_EXT+25];
  9467. char* map_name;
  9468. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9469. map_name = RFIFOCP(fd,info->pos[0]);
  9470. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9471. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9472. RFIFOW(fd,info->pos[1]), //x
  9473. RFIFOW(fd,info->pos[2])); //y
  9474. is_atcommand(fd, sd, command, 1);
  9475. }
  9476. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9477. /// 009c <id>.L <head dir>.W <dir>.B
  9478. /// head dir:
  9479. /// 0 = straight
  9480. /// 1 = turned CW
  9481. /// 2 = turned CCW
  9482. /// dir:
  9483. /// 0 = north
  9484. /// 1 = northwest
  9485. /// 2 = west
  9486. /// 3 = southwest
  9487. /// 4 = south
  9488. /// 5 = southeast
  9489. /// 6 = east
  9490. /// 7 = northeast
  9491. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9492. {
  9493. unsigned char buf[64];
  9494. WBUFW(buf,0) = 0x9c;
  9495. WBUFL(buf,2) = bl->id;
  9496. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9497. WBUFB(buf,8) = unit_getdir(bl);
  9498. clif_send(buf, packet_len(0x9c), bl, target);
  9499. if (disguised(bl)) {
  9500. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9501. WBUFW(buf,6) = 0;
  9502. clif_send(buf, packet_len(0x9c), bl, SELF);
  9503. }
  9504. }
  9505. /// Request to change own body and head direction.
  9506. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9507. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9508. /// There are various variants of this packet, some of them have padding between fields.
  9509. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9510. {
  9511. unsigned char headdir, dir;
  9512. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9513. headdir = RFIFOB(fd,info->pos[0]);
  9514. dir = RFIFOB(fd,info->pos[1]);
  9515. pc_setdir(sd, dir, headdir);
  9516. clif_changed_dir(&sd->bl, AREA_WOS);
  9517. }
  9518. /// Request to show an emotion (CZ_REQ_EMOTION).
  9519. /// 00bf <type>.B
  9520. /// type:
  9521. /// @see enum emotion_type
  9522. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9523. {
  9524. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9525. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9526. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9527. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9528. return;
  9529. }
  9530. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9531. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9532. sd->emotionlasttime = time(NULL);
  9533. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9534. return;
  9535. }
  9536. sd->emotionlasttime = time(NULL);
  9537. if (battle_config.idletime_option&IDLE_EMOTION)
  9538. sd->idletime = last_tick;
  9539. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9540. sd->idletime_hom = last_tick;
  9541. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9542. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9543. return;
  9544. }
  9545. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9546. emoticon = rnd()%6+ET_DICE1;
  9547. }
  9548. clif_emotion(&sd->bl, emoticon);
  9549. } else
  9550. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9551. }
  9552. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9553. /// 00c2 <count>.L
  9554. void clif_user_count(struct map_session_data* sd, int count)
  9555. {
  9556. int fd = sd->fd;
  9557. WFIFOHEAD(fd,packet_len(0xc2));
  9558. WFIFOW(fd,0) = 0xc2;
  9559. WFIFOL(fd,2) = count;
  9560. WFIFOSET(fd,packet_len(0xc2));
  9561. }
  9562. /// /w /who (CZ_REQ_USER_COUNT).
  9563. /// Request to display amount of currently connected players.
  9564. /// 00c1
  9565. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9566. {
  9567. clif_user_count(sd, map_getusers());
  9568. }
  9569. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9570. {
  9571. if (pc_isdead(sd)) {
  9572. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9573. return;
  9574. }
  9575. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9576. // (not all are included in pc_can_attack)
  9577. if (sd->sc.count &&
  9578. (sd->sc.data[SC_TRICKDEAD] ||
  9579. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9580. sd->sc.data[SC_BLADESTOP] ||
  9581. sd->sc.data[SC__MANHOLE] ||
  9582. sd->sc.data[SC_SUHIDE] ||
  9583. sd->sc.data[SC_GRAVITYCONTROL]))
  9584. return;
  9585. if(action_type != 0x00 && action_type != 0x07)
  9586. pc_stop_walking(sd, 1);
  9587. pc_stop_attack(sd);
  9588. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9589. target_id = sd->bl.id;
  9590. switch(action_type)
  9591. {
  9592. case 0x00: // once attack
  9593. case 0x07: // continuous attack
  9594. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9595. return;
  9596. if( sd->sc.option&OPTION_COSTUME )
  9597. return;
  9598. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9599. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9600. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9601. return;
  9602. }
  9603. }
  9604. pc_delinvincibletimer(sd);
  9605. if (battle_config.idletime_option&IDLE_ATTACK)
  9606. sd->idletime = last_tick;
  9607. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9608. sd->idletime_hom = last_tick;
  9609. unit_attack(&sd->bl, target_id, action_type != 0);
  9610. break;
  9611. case 0x02: // sitdown
  9612. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9613. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9614. break;
  9615. }
  9616. if(pc_issit(sd)) {
  9617. //Bugged client? Just refresh them.
  9618. clif_sitting(&sd->bl);
  9619. return;
  9620. }
  9621. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9622. break;
  9623. if (sd->sc.count && (
  9624. sd->sc.data[SC_DANCING] ||
  9625. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9626. )) //No sitting during these states either.
  9627. break;
  9628. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9629. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9630. break;
  9631. }
  9632. if (battle_config.idletime_option&IDLE_SIT)
  9633. sd->idletime = last_tick;
  9634. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9635. sd->idletime_hom = last_tick;
  9636. pc_setsit(sd);
  9637. skill_sit(sd, true);
  9638. clif_sitting(&sd->bl);
  9639. break;
  9640. case 0x03: // standup
  9641. if (!pc_issit(sd)) {
  9642. //Bugged client? Just refresh them.
  9643. clif_standing(&sd->bl);
  9644. return;
  9645. }
  9646. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9647. break;
  9648. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9649. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9650. break;
  9651. }
  9652. if (pc_setstand(sd, false)) {
  9653. if (battle_config.idletime_option&IDLE_SIT)
  9654. sd->idletime = last_tick;
  9655. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9656. sd->idletime_hom = last_tick;
  9657. skill_sit(sd, false);
  9658. clif_standing(&sd->bl);
  9659. }
  9660. break;
  9661. }
  9662. }
  9663. /// Request for an action.
  9664. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9665. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9666. /// action:
  9667. /// 0 = attack
  9668. /// 1 = pick up item
  9669. /// 2 = sit down
  9670. /// 3 = stand up
  9671. /// 7 = continous attack
  9672. /// 12 = (touch skill?)
  9673. /// There are various variants of this packet, some of them have padding between fields.
  9674. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9675. {
  9676. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9677. clif_parse_ActionRequest_sub(sd,
  9678. RFIFOB(fd,info->pos[1]),
  9679. RFIFOL(fd,info->pos[0]),
  9680. gettick()
  9681. );
  9682. }
  9683. /// Response to the death/system menu (CZ_RESTART).
  9684. /// 00b2 <type>.B
  9685. /// type:
  9686. /// 0 = restart (respawn)
  9687. /// 1 = char-select (disconnect)
  9688. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9689. {
  9690. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9691. case 0x00:
  9692. pc_respawn(sd,CLR_OUTSIGHT);
  9693. break;
  9694. case 0x01:
  9695. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9696. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] && !sd->sc.data[SC_NEWMOON] &&
  9697. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9698. { //Send to char-server for character selection.
  9699. pc_damage_log_clear(sd,0);
  9700. chrif_charselectreq(sd, session[fd]->client_addr);
  9701. } else {
  9702. clif_disconnect_ack(sd, 1);
  9703. }
  9704. break;
  9705. }
  9706. }
  9707. /// Validates and processes whispered messages (CZ_WHISPER).
  9708. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9709. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9710. {
  9711. struct map_session_data* dstsd;
  9712. int i;
  9713. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9714. // validate packet and retrieve name and message
  9715. if( !clif_process_message( sd, true, target, message, output ) )
  9716. return;
  9717. // Chat logging type 'W' / Whisper
  9718. 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);
  9719. //-------------------------------------------------------//
  9720. // Lordalfa - Paperboy - To whisper NPC commands //
  9721. //-------------------------------------------------------//
  9722. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9723. {
  9724. char* str = target+4; //Skip the NPC: string part.
  9725. struct npc_data* npc;
  9726. if ((npc = npc_name2id(str))) {
  9727. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9728. char *split;
  9729. char event[EVENT_NAME_LENGTH];
  9730. str = message;
  9731. // skip codepage indicator, if detected
  9732. if( str[0] == '|' && strlen(str) >= 4 )
  9733. str += 3;
  9734. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9735. split = strchr(str,'#');
  9736. if( split == NULL ) { // use the remaining string
  9737. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9738. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9739. split_data[i][0] = '\0';
  9740. break;
  9741. }
  9742. *split = '\0';
  9743. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9744. str = split+1;
  9745. }
  9746. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9747. char variablename[CHAT_SIZE_MAX];
  9748. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9749. set_var_str( sd, variablename, split_data[i] );
  9750. }
  9751. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9752. npc_event(sd,event,0); // Calls the NPC label
  9753. return;
  9754. }
  9755. } else if( target[0] == '#' ) {
  9756. struct Channel *channel = NULL;
  9757. char* chname = target;
  9758. channel = channel_name2channel(chname,sd,3);
  9759. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9760. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9761. channel_send(channel,sd,message);
  9762. }
  9763. else if( channel->pass[0] == '\0') { //no pass needed
  9764. if (channel_join(channel,sd)==0)
  9765. channel_send(channel,sd,message); //join success
  9766. }
  9767. else {
  9768. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9769. }
  9770. return;
  9771. }
  9772. }
  9773. // searching destination character
  9774. dstsd = map_nick2sd(target,false);
  9775. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9776. // player is not on this map-server
  9777. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9778. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9779. // and if we ask for 'Test', we must not contact 'test' player
  9780. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9781. intif_wis_message(sd, target, message, strlen(message) + 1);
  9782. return;
  9783. }
  9784. // if player ignores everyone
  9785. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9786. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9787. clif_wis_end(fd, 1); // 1: target character is not logged in
  9788. else
  9789. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9790. return;
  9791. }
  9792. // if player is autotrading
  9793. if (dstsd->state.autotrade == 1){
  9794. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9795. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9796. return;
  9797. }
  9798. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9799. // if player ignores the source character
  9800. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9801. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9802. clif_wis_end(fd, 2); // 2: ignored by target
  9803. return;
  9804. }
  9805. }
  9806. // notify sender of success
  9807. clif_wis_end(fd, 0); // 0: success to send wisper
  9808. // Normal message
  9809. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9810. }
  9811. /// /b /nb (CZ_BROADCAST).
  9812. /// Request to broadcast a message on whole server.
  9813. /// 0099 <packet len>.W <text>.?B 00
  9814. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9815. char command[CHAT_SIZE_MAX+11];
  9816. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9817. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9818. char* msg = RFIFOCP(fd,info->pos[1]);
  9819. // as the length varies depending on the command used, just block unreasonably long strings
  9820. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9821. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9822. is_atcommand(fd, sd, command, 1);
  9823. }
  9824. /// Request to pick up an item.
  9825. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9826. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9827. /// There are various variants of this packet, some of them have padding between fields.
  9828. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9829. {
  9830. struct flooritem_data *fitem;
  9831. int map_object_id;
  9832. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9833. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9834. do {
  9835. if (pc_isdead(sd)) {
  9836. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9837. break;
  9838. }
  9839. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9840. break;
  9841. if (pc_cant_act(sd))
  9842. break;
  9843. if (!pc_takeitem(sd, fitem))
  9844. break;
  9845. return;
  9846. } while (0);
  9847. // Client REQUIRES a fail packet or you can no longer pick items.
  9848. clif_additem(sd,0,0,6);
  9849. }
  9850. /// Request to drop an item.
  9851. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9852. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9853. /// There are various variants of this packet, some of them have padding between fields.
  9854. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9855. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9856. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9857. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9858. for(;;) {
  9859. if (pc_isdead(sd))
  9860. break;
  9861. if (pc_cant_act2(sd) || sd->npc_id)
  9862. break;
  9863. if (sd->sc.count && (
  9864. sd->sc.data[SC_AUTOCOUNTER] ||
  9865. sd->sc.data[SC_BLADESTOP] ||
  9866. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9867. ))
  9868. break;
  9869. if (!pc_dropitem(sd, item_index, item_amount))
  9870. break;
  9871. if (battle_config.idletime_option&IDLE_DROPITEM)
  9872. sd->idletime = last_tick;
  9873. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9874. sd->idletime_hom = last_tick;
  9875. return;
  9876. }
  9877. //Because the client does not like being ignored.
  9878. clif_dropitem(sd, item_index,0);
  9879. }
  9880. /// Request to use an item.
  9881. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9882. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9883. /// There are various variants of this packet, some of them have padding between fields.
  9884. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9885. {
  9886. int n;
  9887. if (pc_isdead(sd)) {
  9888. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9889. return;
  9890. }
  9891. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9892. clif_msg(sd, WORK_IN_PROGRESS);
  9893. return;
  9894. }
  9895. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9896. if (battle_config.idletime_option&IDLE_USEITEM)
  9897. sd->idletime = last_tick;
  9898. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9899. sd->idletime_hom = last_tick;
  9900. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9901. if(n <0 || n >= MAX_INVENTORY)
  9902. return;
  9903. if (!pc_useitem(sd,n))
  9904. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9905. }
  9906. /// Request to equip an item
  9907. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9908. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9909. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9910. {
  9911. int index;
  9912. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9913. if(pc_isdead(sd)) {
  9914. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9915. return;
  9916. }
  9917. index = RFIFOW(fd,info->pos[0])-2;
  9918. if (index < 0 || index >= MAX_INVENTORY)
  9919. return; //Out of bounds check.
  9920. if(sd->npc_id && !sd->npc_item_flag) {
  9921. return;
  9922. } else if (sd->state.storage_flag || sd->sc.opt1)
  9923. ; //You can equip/unequip stuff while storage is open/under status changes
  9924. else if (pc_cant_act2(sd))
  9925. return;
  9926. if(!sd->inventory.u.items_inventory[index].identify) {
  9927. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9928. return;
  9929. }
  9930. if(!sd->inventory_data[index])
  9931. return;
  9932. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9933. pet_equipitem(sd,index);
  9934. return;
  9935. }
  9936. if (battle_config.idletime_option&IDLE_USEITEM)
  9937. sd->idletime = last_tick;
  9938. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9939. sd->idletime_hom = last_tick;
  9940. //Client doesn't send the position for ammo.
  9941. if(sd->inventory_data[index]->type == IT_AMMO)
  9942. pc_equipitem(sd,index,EQP_AMMO);
  9943. else {
  9944. int req_pos;
  9945. #if PACKETVER >= 20120925
  9946. req_pos = RFIFOL(fd,info->pos[1]);
  9947. #else
  9948. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9949. #endif
  9950. pc_equipitem(sd,index,req_pos);
  9951. }
  9952. }
  9953. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9954. /// 00ab <index>.W
  9955. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9956. {
  9957. int index;
  9958. if(pc_isdead(sd)) {
  9959. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9960. return;
  9961. }
  9962. if (sd->npc_id && !sd->npc_item_flag) {
  9963. return;
  9964. } else if (sd->state.storage_flag || sd->sc.opt1)
  9965. ; //You can equip/unequip stuff while storage is open/under status changes
  9966. else if (pc_cant_act2(sd))
  9967. return;
  9968. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9969. if (battle_config.idletime_option&IDLE_USEITEM)
  9970. sd->idletime = last_tick;
  9971. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9972. sd->idletime_hom = last_tick;
  9973. pc_unequipitem(sd,index,1);
  9974. }
  9975. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9976. /// 0090 <id>.L <type>.B
  9977. /// type:
  9978. /// 1 = click
  9979. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9980. {
  9981. struct block_list *bl;
  9982. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9983. if(pc_isdead(sd)) {
  9984. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9985. return;
  9986. }
  9987. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  9988. #ifdef RENEWAL
  9989. clif_msg( sd, WORK_IN_PROGRESS );
  9990. #endif
  9991. return;
  9992. }
  9993. if( sd->state.mail_writing )
  9994. return;
  9995. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9996. //type = RFIFOB(fd,info->pos[1]);
  9997. if (!bl) return;
  9998. switch (bl->type) {
  9999. case BL_MOB:
  10000. case BL_PC:
  10001. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10002. break;
  10003. case BL_NPC:
  10004. #ifdef RENEWAL
  10005. 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
  10006. clif_msg(sd, WORK_IN_PROGRESS);
  10007. break;
  10008. }
  10009. #endif
  10010. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10011. struct npc_data* nd = (struct npc_data*)bl;
  10012. // Progressbar is running
  10013. if( nd->progressbar.timeout > 0 ){
  10014. return;
  10015. }
  10016. npc_click(sd,nd);
  10017. }
  10018. break;
  10019. }
  10020. }
  10021. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10022. /// 00c5 <id>.L <type>.B
  10023. /// type:
  10024. /// 0 = buy
  10025. /// 1 = sell
  10026. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10027. {
  10028. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10029. if (sd->state.trading)
  10030. return;
  10031. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10032. }
  10033. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10034. /// 00ca <result>.B
  10035. /// result:
  10036. /// 0 = "The deal has successfully completed."
  10037. /// 1 = "You do not have enough zeny."
  10038. /// 2 = "You are over your Weight Limit."
  10039. /// 3 = "Out of the maximum capacity, you have too many items."
  10040. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10041. /// 10 = "Props open-air store sales will be traded in RODEX"
  10042. /// 11 = "The exchange failed."
  10043. /// 12 = "The exchange was well done."
  10044. /// 13 = "The item is already sold and out of stock."
  10045. /// 14 = "There is not enough goods to exchange."
  10046. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10047. {
  10048. int fd = sd->fd;
  10049. WFIFOHEAD(fd,packet_len(0xca));
  10050. WFIFOW(fd,0) = 0xca;
  10051. WFIFOB(fd,2) = result;
  10052. WFIFOSET(fd,packet_len(0xca));
  10053. }
  10054. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10055. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10056. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10057. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10058. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10059. int result;
  10060. if( sd->state.trading || !sd->npc_shopid )
  10061. result = 1;
  10062. else
  10063. result = npc_buylist( sd, n, (struct s_npc_buy_list*)p->items );
  10064. sd->npc_shopid = 0; //Clear shop data.
  10065. clif_npc_buy_result(sd, result);
  10066. }
  10067. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10068. /// 00cb <result>.B
  10069. /// result:
  10070. /// 0 = "The deal has successfully completed."
  10071. /// 1 = "The deal has failed."
  10072. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10073. {
  10074. int fd = sd->fd;
  10075. WFIFOHEAD(fd,packet_len(0xcb));
  10076. WFIFOW(fd,0) = 0xcb;
  10077. WFIFOB(fd,2) = result;
  10078. WFIFOSET(fd,packet_len(0xcb));
  10079. }
  10080. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10081. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10082. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10083. {
  10084. int fail=0,n;
  10085. unsigned short *item_list;
  10086. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10087. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10088. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10089. if (sd->state.trading || !sd->npc_shopid)
  10090. fail = 1;
  10091. else
  10092. fail = npc_selllist(sd,n,item_list);
  10093. sd->npc_shopid = 0; //Clear shop data.
  10094. clif_npc_sell_result(sd, fail);
  10095. }
  10096. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10097. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10098. /// type:
  10099. /// 0 = private
  10100. /// 1 = public
  10101. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10102. {
  10103. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10104. int len = RFIFOW(fd,info->pos[0])-15;
  10105. int limit = RFIFOW(fd,info->pos[1]);
  10106. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10107. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10108. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10109. char s_password[CHATROOM_PASS_SIZE];
  10110. char s_title[CHATROOM_TITLE_SIZE];
  10111. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10112. return;
  10113. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10114. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10115. return;
  10116. }
  10117. if( npc_isnear(&sd->bl) ) {
  10118. // uncomment to send msg_txt.
  10119. //char output[150];
  10120. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10121. //clif_displaymessage(sd->fd, output);
  10122. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10123. return;
  10124. }
  10125. if( len <= 0 )
  10126. return; // invalid input
  10127. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10128. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10129. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10130. }
  10131. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10132. /// 00d9 <chat ID>.L <passwd>.8B
  10133. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10134. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10135. int chatid = RFIFOL(fd,info->pos[0]);
  10136. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10137. chat_joinchat(sd,chatid,password);
  10138. }
  10139. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10140. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10141. /// type:
  10142. /// 0 = private
  10143. /// 1 = public
  10144. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10145. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10146. int len = RFIFOW(fd,info->pos[0])-15;
  10147. int limit = RFIFOW(fd,info->pos[1]);
  10148. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10149. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10150. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10151. char s_password[CHATROOM_PASS_SIZE];
  10152. char s_title[CHATROOM_TITLE_SIZE];
  10153. if( len <= 0 )
  10154. return; // invalid input
  10155. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10156. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10157. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10158. }
  10159. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10160. /// 00e0 <role>.L <nick>.24B
  10161. /// role:
  10162. /// 0 = owner
  10163. /// 1 = normal
  10164. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10165. {
  10166. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10167. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10168. }
  10169. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10170. /// 00e2 <name>.24B
  10171. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10172. {
  10173. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10174. }
  10175. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10176. /// 00e3
  10177. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10178. {
  10179. chat_leavechat(sd,0);
  10180. }
  10181. //Handles notifying asker and rejecter of what has just ocurred.
  10182. //Type is used to determine the correct msg_txt to use:
  10183. //0:
  10184. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10185. {
  10186. const char* msg;
  10187. char output[256];
  10188. // Your request has been rejected by autoreject option.
  10189. msg = msg_txt(sd,392);
  10190. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10191. //Notice that a request was rejected.
  10192. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10193. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10194. }
  10195. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10196. /// 00e4 <account id>.L
  10197. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10198. {
  10199. struct map_session_data *t_sd;
  10200. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10201. if(!sd->chatID && pc_cant_act(sd))
  10202. return; //You can trade while in a chatroom.
  10203. if(t_sd){
  10204. // @noask [LuzZza]
  10205. if(t_sd->state.noask) {
  10206. clif_noask_sub(sd, t_sd, 0);
  10207. return;
  10208. }
  10209. if (t_sd->state.mail_writing) {
  10210. int old = sd->trade_partner;
  10211. // Fake trading
  10212. sd->trade_partner = t_sd->status.account_id;
  10213. clif_tradestart(sd, 5);
  10214. // Restore old state
  10215. sd->trade_partner = old;
  10216. return;
  10217. }
  10218. }
  10219. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10220. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10221. return;
  10222. }
  10223. trade_traderequest(sd,t_sd);
  10224. }
  10225. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10226. /// 00e6 <result>.B
  10227. /// result:
  10228. /// 3 = accepted
  10229. /// 4 = rejected
  10230. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10231. {
  10232. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10233. }
  10234. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10235. /// 00e8 <index>.W <amount>.L
  10236. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10237. {
  10238. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10239. short index = RFIFOW(fd,info->pos[0]);
  10240. int amount = RFIFOL(fd,info->pos[1]);
  10241. if( index == 0 )
  10242. trade_tradeaddzeny(sd, amount);
  10243. else
  10244. trade_tradeadditem(sd, index, (short)amount);
  10245. }
  10246. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10247. /// 00eb
  10248. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10249. {
  10250. trade_tradeok(sd);
  10251. }
  10252. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10253. /// 00ed
  10254. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10255. {
  10256. trade_tradecancel(sd);
  10257. }
  10258. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10259. /// 00ef
  10260. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10261. {
  10262. trade_tradecommit(sd);
  10263. }
  10264. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10265. /// 0118
  10266. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10267. {
  10268. pc_stop_attack(sd);
  10269. if (sd) sd->ud.state.attack_continue = 0;
  10270. }
  10271. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10272. /// 0126 <index>.W <amount>.L
  10273. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10274. {
  10275. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10276. if (pc_istrading(sd))
  10277. return;
  10278. if (!pc_iscarton(sd))
  10279. return;
  10280. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10281. }
  10282. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10283. /// 0127 <index>.W <amount>.L
  10284. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10285. {
  10286. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10287. if (!pc_iscarton(sd))
  10288. return;
  10289. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10290. }
  10291. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10292. /// 012a
  10293. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10294. {
  10295. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10296. #ifdef NEW_CARTS
  10297. && sd->sc.data[SC_PUSH_CART] )
  10298. pc_setcart(sd,0);
  10299. #else
  10300. )
  10301. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10302. #endif
  10303. else // priority to remove this option before we can clear cart
  10304. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10305. }
  10306. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10307. /// 097f <Length>.W <identity>.L <type>.B
  10308. void clif_SelectCart(struct map_session_data *sd) {
  10309. #if PACKETVER >= 20150826
  10310. int i = 0, carts = 3;
  10311. int fd = sd->fd;
  10312. WFIFOHEAD(fd,8 + carts);
  10313. WFIFOW(fd,0) = 0x97f;
  10314. WFIFOW(fd,2) = 8 + carts;
  10315. WFIFOL(fd,4) = sd->status.account_id;
  10316. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10317. for( i = 0; i < carts; i++ ) {
  10318. WFIFOB(fd,8 + i) = 10 + i;
  10319. }
  10320. WFIFOSET(fd,8 + carts);
  10321. #endif
  10322. }
  10323. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10324. /// 0980 <identity>.L <type>.B
  10325. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10326. #if PACKETVER >= 20150826
  10327. int type;
  10328. // Check identity
  10329. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10330. return;
  10331. type = (int)RFIFOB(fd,6);
  10332. // Check type
  10333. if( type < 10 || type > MAX_CARTS )
  10334. return;
  10335. pc_setcart(sd, type);
  10336. #endif
  10337. }
  10338. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10339. /// 01af <num>.W
  10340. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10341. {// TODO: State tracking?
  10342. int type;
  10343. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10344. return;
  10345. #ifdef RENEWAL
  10346. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10347. clif_msg(sd, WORK_IN_PROGRESS);
  10348. return;
  10349. }
  10350. #endif
  10351. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10352. if(
  10353. #ifdef NEW_CARTS
  10354. (type == 9 && sd->status.base_level > 130) ||
  10355. (type == 8 && sd->status.base_level > 120) ||
  10356. (type == 7 && sd->status.base_level > 110) ||
  10357. (type == 6 && sd->status.base_level > 100) ||
  10358. #endif
  10359. (type == 5 && sd->status.base_level > 90) ||
  10360. (type == 4 && sd->status.base_level > 80) ||
  10361. (type == 3 && sd->status.base_level > 65) ||
  10362. (type == 2 && sd->status.base_level > 40) ||
  10363. (type == 1))
  10364. pc_setcart(sd, type);
  10365. }
  10366. /// Request to increase status (CZ_STATUS_CHANGE).
  10367. /// 00bb <status id>.W <amount>.B
  10368. /// status id:
  10369. /// SP_STR ~ SP_LUK
  10370. /// amount:
  10371. /// Old clients always send 1 for this, even when using /str+ and the like.
  10372. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10373. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10374. {
  10375. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10376. if( increase_amount < 0 ) {
  10377. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10378. fd, increase_amount);
  10379. }
  10380. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10381. }
  10382. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10383. /// 0112 <skill id>.W
  10384. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10385. {
  10386. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10387. }
  10388. 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)
  10389. {
  10390. int lv;
  10391. if( !hd )
  10392. return;
  10393. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10394. clif_emotion(&hd->bl, ET_THINK);
  10395. return;
  10396. }
  10397. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10398. target_id = hd->bl.id;
  10399. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10400. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10401. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10402. clif_emotion(&hd->bl, ET_THINK);
  10403. if (hd->master)
  10404. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10405. return;
  10406. }
  10407. lv = hom_checkskill(hd, skill_id);
  10408. if( skill_lv > lv )
  10409. skill_lv = lv;
  10410. if( skill_lv )
  10411. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10412. }
  10413. 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)
  10414. {
  10415. int lv;
  10416. if( !hd )
  10417. return;
  10418. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10419. clif_emotion(&hd->bl, ET_THINK);
  10420. return;
  10421. }
  10422. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10423. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10424. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10425. clif_emotion(&hd->bl, ET_THINK);
  10426. if (hd->master)
  10427. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10428. return;
  10429. }
  10430. #ifdef RENEWAL
  10431. if (hd->sc.data[SC_BASILICA_CELL])
  10432. #else
  10433. if (hd->sc.data[SC_BASILICA])
  10434. #endif
  10435. return;
  10436. lv = hom_checkskill(hd, skill_id);
  10437. if( skill_lv > lv )
  10438. skill_lv = lv;
  10439. if( skill_lv )
  10440. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10441. }
  10442. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10443. {
  10444. int lv;
  10445. if( !md )
  10446. return;
  10447. if( skill_isNotOk_mercenary(skill_id, md) )
  10448. return;
  10449. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10450. target_id = md->bl.id;
  10451. if( md->ud.skilltimer != INVALID_TIMER )
  10452. {
  10453. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10454. }
  10455. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10456. return;
  10457. lv = mercenary_checkskill(md, skill_id);
  10458. if( skill_lv > lv )
  10459. skill_lv = lv;
  10460. if( skill_lv )
  10461. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10462. }
  10463. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10464. {
  10465. int lv;
  10466. if( !md )
  10467. return;
  10468. if( skill_isNotOk_mercenary(skill_id, md) )
  10469. return;
  10470. if( md->ud.skilltimer != INVALID_TIMER )
  10471. return;
  10472. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10473. {
  10474. if (md->master)
  10475. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10476. return;
  10477. }
  10478. #ifdef RENEWAL
  10479. if (md->sc.data[SC_BASILICA_CELL])
  10480. #else
  10481. if (md->sc.data[SC_BASILICA])
  10482. #endif
  10483. return;
  10484. lv = mercenary_checkskill(md, skill_id);
  10485. if( skill_lv > lv )
  10486. skill_lv = lv;
  10487. if( skill_lv )
  10488. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10489. }
  10490. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10491. t_tick tick = gettick();
  10492. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10493. int inf = skill_get_inf(skill_id);
  10494. if (inf&INF_GROUND_SKILL || !inf)
  10495. return; //Using a ground/passive skill on a target? WRONG.
  10496. if (sd->state.block_action & PCBLOCK_SKILL) {
  10497. clif_msg(sd, WORK_IN_PROGRESS);
  10498. return;
  10499. }
  10500. if( SKILL_CHK_HOMUN(skill_id) ) {
  10501. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10502. return;
  10503. }
  10504. if( SKILL_CHK_MERC(skill_id) ) {
  10505. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10506. return;
  10507. }
  10508. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10509. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10510. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10511. sd->idletime = last_tick;
  10512. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10513. sd->idletime_hom = last_tick;
  10514. if( sd->npc_id ){
  10515. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10516. #ifdef RENEWAL
  10517. clif_msg( sd, WORK_IN_PROGRESS );
  10518. #endif
  10519. return;
  10520. }
  10521. }
  10522. if ((pc_cant_act2(sd) || sd->chatID) &&
  10523. skill_id != RK_REFRESH &&
  10524. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10525. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10526. return;
  10527. if( pc_issit(sd) )
  10528. return;
  10529. if( skill_isNotOk(skill_id, sd) )
  10530. return;
  10531. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10532. target_id = sd->bl.id; // never trust the client
  10533. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10534. target_id = sd->bl.id;
  10535. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10536. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10537. return;
  10538. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10539. if( sd->skillitem != skill_id ) {
  10540. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10541. return;
  10542. }
  10543. }
  10544. if( sd->sc.option&OPTION_COSTUME )
  10545. return;
  10546. #ifndef RENEWAL
  10547. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10548. return; // On basilica only caster can use Basilica again to stop it.
  10549. #endif
  10550. if( sd->menuskill_id ) {
  10551. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10552. clif_menuskill_clear(sd); //Cancel pet capture.
  10553. }else if( sd->menuskill_id == SG_FEEL ){
  10554. clif_menuskill_clear( sd ); // Cancel selection
  10555. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10556. return; //Can't use skills while a menu is open.
  10557. }
  10558. if( sd->skillitem == skill_id ) {
  10559. if( skill_lv != sd->skillitemlv )
  10560. skill_lv = sd->skillitemlv;
  10561. if( !(inf&INF_SELF_SKILL) )
  10562. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10563. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10564. return;
  10565. }
  10566. sd->skillitem = sd->skillitemlv = 0;
  10567. if( SKILL_CHK_GUILD(skill_id) ) {
  10568. if( sd->state.gmaster_flag )
  10569. skill_lv = guild_checkskill(sd->guild, skill_id);
  10570. else
  10571. skill_lv = 0;
  10572. } else {
  10573. if( skill_id != ALL_EQSWITCH ){
  10574. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10575. }
  10576. }
  10577. pc_delinvincibletimer(sd);
  10578. if( skill_lv )
  10579. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10580. }
  10581. /// Request to use a targeted skill.
  10582. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10583. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10584. /// There are various variants of this packet, some of them have padding between fields.
  10585. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10586. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10587. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10588. }
  10589. /*==========================================
  10590. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10591. *------------------------------------------*/
  10592. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10593. {
  10594. t_tick tick = gettick();
  10595. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10596. return; //Using a target skill on the ground? WRONG.
  10597. if (sd->state.block_action & PCBLOCK_SKILL) {
  10598. clif_msg(sd, WORK_IN_PROGRESS);
  10599. return;
  10600. }
  10601. if( SKILL_CHK_HOMUN(skill_id) ) {
  10602. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10603. return;
  10604. }
  10605. if( SKILL_CHK_MERC(skill_id) ) {
  10606. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10607. return;
  10608. }
  10609. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10610. #ifdef RENEWAL
  10611. clif_msg( sd, WORK_IN_PROGRESS );
  10612. #endif
  10613. return;
  10614. }
  10615. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10616. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10617. sd->idletime = last_tick;
  10618. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10619. sd->idletime_hom = last_tick;
  10620. if( skill_isNotOk(skill_id, sd) )
  10621. return;
  10622. if( skillmoreinfo != -1 ) {
  10623. if( pc_issit(sd) ) {
  10624. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10625. return;
  10626. }
  10627. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10628. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10629. }
  10630. if( sd->ud.skilltimer != INVALID_TIMER )
  10631. return;
  10632. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10633. if( sd->skillitem != skill_id ) {
  10634. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10635. return;
  10636. }
  10637. }
  10638. if( sd->sc.option&OPTION_COSTUME )
  10639. return;
  10640. #ifndef RENEWAL
  10641. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10642. return; // On basilica only caster can use Basilica again to stop it.
  10643. #endif
  10644. if( sd->menuskill_id ) {
  10645. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10646. clif_menuskill_clear(sd); //Cancel pet capture.
  10647. }else if( sd->menuskill_id == SG_FEEL ){
  10648. clif_menuskill_clear( sd ); // Cancel selection
  10649. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10650. return; //Can't use skills while a menu is open.
  10651. }
  10652. pc_delinvincibletimer(sd);
  10653. if( sd->skillitem == skill_id ) {
  10654. if( skill_lv != sd->skillitemlv )
  10655. skill_lv = sd->skillitemlv;
  10656. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10657. } else {
  10658. int lv;
  10659. sd->skillitem = sd->skillitemlv = 0;
  10660. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10661. if( skill_lv > lv )
  10662. skill_lv = lv;
  10663. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10664. }
  10665. }
  10666. }
  10667. /// Request to use a ground skill.
  10668. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10669. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10670. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10671. /// There are various variants of this packet, some of them have padding between fields.
  10672. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10673. {
  10674. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10675. if (pc_cant_act(sd))
  10676. return;
  10677. if (pc_issit(sd))
  10678. return;
  10679. clif_parse_UseSkillToPosSub(fd, sd,
  10680. RFIFOW(fd,info->pos[0]), //skill lv
  10681. RFIFOW(fd,info->pos[1]), //skill num
  10682. RFIFOW(fd,info->pos[2]), //pos x
  10683. RFIFOW(fd,info->pos[3]), //pos y
  10684. // TODO: find out what this is intended to do
  10685. //RFIFOB(fd, info->pos[4])
  10686. -1 //Skill more info.
  10687. );
  10688. }
  10689. /// Request to use a ground skill with text.
  10690. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10691. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10692. /// There are various variants of this packet, some of them have padding between fields.
  10693. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10694. {
  10695. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10696. if (pc_cant_act(sd))
  10697. return;
  10698. if (pc_issit(sd))
  10699. return;
  10700. clif_parse_UseSkillToPosSub(fd, sd,
  10701. RFIFOW(fd,info->pos[0]), //Skill lv
  10702. RFIFOW(fd,info->pos[1]), //Skill num
  10703. RFIFOW(fd,info->pos[2]), //pos x
  10704. RFIFOW(fd,info->pos[3]), //pos y
  10705. info->pos[4] //skill more info
  10706. );
  10707. }
  10708. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10709. /// 011b <skill id>.W <map name>.16B
  10710. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10711. {
  10712. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10713. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10714. char map_name[MAP_NAME_LENGTH];
  10715. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10716. sd->state.workinprogress = WIP_DISABLE_NONE;
  10717. if(skill_id != sd->menuskill_id)
  10718. return;
  10719. //It is possible to use teleport with the storage window open bugreport:8027
  10720. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10721. clif_menuskill_clear(sd);
  10722. return;
  10723. }
  10724. pc_delinvincibletimer(sd);
  10725. skill_castend_map(sd,skill_id,map_name);
  10726. }
  10727. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10728. /// 011d
  10729. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10730. {
  10731. if (!pc_isdead(sd))
  10732. pc_memo(sd,-1);
  10733. }
  10734. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10735. /// 018e <name id>.W { <material id>.W }*3
  10736. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10737. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10738. switch( sd->menuskill_id ) {
  10739. case -1:
  10740. case AM_PHARMACY:
  10741. case RK_RUNEMASTERY:
  10742. case GC_RESEARCHNEWPOISON:
  10743. break;
  10744. default:
  10745. return;
  10746. }
  10747. if (pc_istrading(sd)) {
  10748. //Make it fail to avoid shop exploits where you sell something different than you see.
  10749. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10750. clif_menuskill_clear(sd);
  10751. return;
  10752. }
  10753. int produce_idx;
  10754. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10755. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10756. clif_menuskill_clear(sd);
  10757. }
  10758. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10759. /// 025b <mk type>.W <name id>.W
  10760. /// mk type:
  10761. /// 1 = cooking
  10762. /// 2 = arrow
  10763. /// 3 = elemental
  10764. /// 4 = GN_MIX_COOKING
  10765. /// 5 = GN_MAKEBOMB
  10766. /// 6 = GN_S_PHARMACY
  10767. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10768. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10769. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10770. short food_idx = -1;
  10771. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10772. return;
  10773. if (pc_istrading(sd)) {
  10774. //Make it fail to avoid shop exploits where you sell something different than you see.
  10775. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10776. clif_menuskill_clear(sd);
  10777. return;
  10778. }
  10779. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10780. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10781. clif_menuskill_clear(sd);
  10782. }
  10783. /// Answer to repair weapon item selection dialog
  10784. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10785. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10786. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  10787. const struct PACKET_CZ_REQ_ITEMREPAIR *p = (struct PACKET_CZ_REQ_ITEMREPAIR *)RFIFOP( fd, 0 );
  10788. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10789. return;
  10790. if (pc_istrading(sd)) {
  10791. //Make it fail to avoid shop exploits where you sell something different than you see.
  10792. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10793. clif_menuskill_clear(sd);
  10794. return;
  10795. }
  10796. skill_repairweapon( sd, p->index );
  10797. clif_menuskill_clear(sd);
  10798. }
  10799. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10800. /// 0222 <index>.L
  10801. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  10802. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10803. return;
  10804. if (pc_istrading(sd)) {
  10805. //Make it fail to avoid shop exploits where you sell something different than you see.
  10806. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10807. clif_menuskill_clear(sd);
  10808. return;
  10809. }
  10810. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  10811. clif_menuskill_clear(sd);
  10812. }
  10813. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10814. /// 00b8 <npc id>.L <choice>.B
  10815. /// choice:
  10816. /// 1~254 = menu item
  10817. /// 255 = cancel
  10818. /// NOTE: If there were more than 254 items in the list, choice
  10819. /// overflows to choice%256.
  10820. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10821. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10822. int npc_id = RFIFOL(fd,info->pos[0]);
  10823. uint8 select = RFIFOB(fd,info->pos[1]);
  10824. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10825. #ifdef SECURE_NPCTIMEOUT
  10826. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10827. #endif
  10828. TBL_NPC* nd = map_id2nd(npc_id);
  10829. 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);
  10830. clif_GM_kick(NULL,sd);
  10831. #ifdef SECURE_NPCTIMEOUT
  10832. }
  10833. #endif
  10834. return;
  10835. }
  10836. sd->npc_menu = select;
  10837. npc_scriptcont(sd,npc_id, false);
  10838. }
  10839. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10840. /// 00b9 <npc id>.L
  10841. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10842. {
  10843. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10844. }
  10845. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10846. /// 0143 <npc id>.L <value>.L
  10847. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10848. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10849. int npcid = RFIFOL(fd,info->pos[0]);
  10850. int amount = (int)RFIFOL(fd,info->pos[1]);
  10851. sd->npc_amount = amount;
  10852. npc_scriptcont(sd, npcid, false);
  10853. }
  10854. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10855. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10856. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10857. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10858. int message_len = RFIFOW(fd,info->pos[0])-8;
  10859. int npcid = RFIFOL(fd,info->pos[1]);
  10860. const char* message = RFIFOCP(fd,info->pos[2]);
  10861. if( message_len <= 0 )
  10862. return; // invalid input
  10863. #if PACKETVER >= 20151001
  10864. message_len++;
  10865. #endif
  10866. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10867. npc_scriptcont(sd, npcid, false);
  10868. }
  10869. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10870. /// 0146 <npc id>.L
  10871. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10872. {
  10873. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10874. return;
  10875. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10876. }
  10877. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10878. /// 0178 <index>.W
  10879. /// index:
  10880. /// -1 = cancel
  10881. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10882. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10883. if (sd->menuskill_id != MC_IDENTIFY)
  10884. return;
  10885. // Ignore the request
  10886. // - Invalid item index
  10887. // - Invalid item ID or item doesn't exist
  10888. // - Item is already identified
  10889. if (idx < 0 || idx >= MAX_INVENTORY ||
  10890. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10891. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10892. sd->state.workinprogress = WIP_DISABLE_NONE;
  10893. clif_menuskill_clear(sd);
  10894. return;
  10895. }
  10896. skill_identify(sd, idx);
  10897. clif_menuskill_clear(sd);
  10898. }
  10899. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10900. /// 01ae <name id>.W
  10901. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10902. if (pc_istrading(sd)) {
  10903. //Make it fail to avoid shop exploits where you sell something different than you see.
  10904. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10905. clif_menuskill_clear(sd);
  10906. return;
  10907. }
  10908. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  10909. switch (sd->menuskill_id) {
  10910. case AC_MAKINGARROW:
  10911. skill_arrow_create(sd,p->itemId);
  10912. break;
  10913. case SA_CREATECON:
  10914. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  10915. break;
  10916. case WL_READING_SB:
  10917. skill_spellbook(sd,p->itemId);
  10918. break;
  10919. case GC_POISONINGWEAPON:
  10920. skill_poisoningweapon(sd,p->itemId);
  10921. break;
  10922. case NC_MAGICDECOY:
  10923. skill_magicdecoy(sd,p->itemId);
  10924. break;
  10925. }
  10926. clif_menuskill_clear(sd);
  10927. }
  10928. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10929. /// 01ce <skill id>.L
  10930. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10931. {
  10932. if (sd->menuskill_id != SA_AUTOSPELL)
  10933. return;
  10934. sd->state.workinprogress = WIP_DISABLE_NONE;
  10935. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10936. clif_menuskill_clear(sd);
  10937. }
  10938. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10939. /// 017a <card index>.W
  10940. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10941. {
  10942. if (sd->state.trading != 0)
  10943. return;
  10944. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10945. }
  10946. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10947. /// 017c <card index>.W <equip index>.W
  10948. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10949. {
  10950. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10951. if (sd->state.trading != 0)
  10952. return;
  10953. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10954. }
  10955. /// Request of character's name by char ID.
  10956. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10957. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10958. /// There are various variants of this packet, some of them have padding between fields.
  10959. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10960. {
  10961. int charid;
  10962. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10963. map_reqnickdb(sd, charid);
  10964. }
  10965. /// /resetskill /resetstate (CZ_RESET).
  10966. /// Request to reset stats or skills.
  10967. /// 0197 <type>.W
  10968. /// type:
  10969. /// 0 = state
  10970. /// 1 = skill
  10971. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10972. char cmd[15];
  10973. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10974. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10975. else
  10976. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10977. is_atcommand(fd, sd, cmd, 1);
  10978. }
  10979. /// /lb /nlb (CZ_LOCALBROADCAST).
  10980. /// Request to broadcast a message on current map.
  10981. /// 019c <packet len>.W <text>.?B
  10982. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10983. {
  10984. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10985. char command[CHAT_SIZE_MAX+16];
  10986. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10987. char* msg = RFIFOCP(fd,info->pos[1]);
  10988. // as the length varies depending on the command used, just block unreasonably long strings
  10989. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10990. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10991. is_atcommand(fd, sd, command, 1);
  10992. }
  10993. /// Request to move an item from inventory to storage.
  10994. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10995. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10996. /// There are various variants of this packet, some of them have padding between fields.
  10997. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10998. {
  10999. int item_index, item_amount;
  11000. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11001. if (pc_istrading(sd))
  11002. return;
  11003. item_index = RFIFOW(fd,info->pos[0])-2;
  11004. item_amount = RFIFOL(fd,info->pos[1]);
  11005. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11006. return;
  11007. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11008. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11009. return;
  11010. }
  11011. if (sd->state.storage_flag == 1)
  11012. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11013. else
  11014. if (sd->state.storage_flag == 2)
  11015. storage_guild_storageadd(sd, item_index, item_amount);
  11016. else if (sd->state.storage_flag == 3)
  11017. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11018. }
  11019. /// Request to move an item from storage to inventory.
  11020. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11021. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11022. /// There are various variants of this packet, some of them have padding between fields.
  11023. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11024. {
  11025. int item_index, item_amount;
  11026. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11027. item_index = RFIFOW(fd,info->pos[0])-1;
  11028. item_amount = RFIFOL(fd,info->pos[1]);
  11029. if (sd->state.storage_flag == 1)
  11030. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11031. else if(sd->state.storage_flag == 2)
  11032. storage_guild_storageget(sd, item_index, item_amount);
  11033. else if(sd->state.storage_flag == 3)
  11034. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11035. }
  11036. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11037. /// 0129 <index>.W <amount>.L
  11038. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11039. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11040. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11041. int amount = RFIFOL(fd,info->pos[1]);
  11042. if( sd->state.vending )
  11043. return;
  11044. if (!pc_iscarton(sd))
  11045. return;
  11046. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11047. return;
  11048. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11049. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11050. return;
  11051. }
  11052. if (sd->state.storage_flag == 1)
  11053. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11054. else if (sd->state.storage_flag == 2)
  11055. storage_guild_storageaddfromcart(sd, idx, amount);
  11056. else if (sd->state.storage_flag == 3)
  11057. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11058. }
  11059. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11060. /// 0128 <index>.W <amount>.L
  11061. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11062. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11063. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11064. int amount = RFIFOL(fd,info->pos[1]);
  11065. if( sd->state.vending )
  11066. return;
  11067. if (!pc_iscarton(sd))
  11068. return;
  11069. if (sd->state.storage_flag == 1)
  11070. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11071. else
  11072. if (sd->state.storage_flag == 2)
  11073. storage_guild_storagegettocart(sd, idx, amount);
  11074. else if (sd->state.storage_flag == 3)
  11075. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11076. }
  11077. /// Request to close storage (CZ_CLOSE_STORE).
  11078. /// 00f7
  11079. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11080. {
  11081. if( sd->state.storage_flag == 1 )
  11082. storage_storageclose(sd);
  11083. else
  11084. if( sd->state.storage_flag == 2 )
  11085. storage_guild_storageclose(sd);
  11086. else if( sd->state.storage_flag == 3 )
  11087. storage_premiumStorage_close(sd);
  11088. }
  11089. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11090. /// 023a <info>.W
  11091. /// info:
  11092. /// 0 = password has not been set yet
  11093. /// 1 = storage is password-protected
  11094. /// 8 = too many wrong passwords
  11095. /// ? = ignored
  11096. /// NOTE: This packet is only available on certain non-kRO clients.
  11097. void clif_storagepassword(struct map_session_data* sd, short info)
  11098. {
  11099. int fd = sd->fd;
  11100. WFIFOHEAD(fd,packet_len(0x23a));
  11101. WFIFOW(fd,0) = 0x23a;
  11102. WFIFOW(fd,2) = info;
  11103. WFIFOSET(fd,packet_len(0x23a));
  11104. }
  11105. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11106. /// 023b <type>.W <password>.16B <new password>.16B
  11107. /// type:
  11108. /// 2 = change password
  11109. /// 3 = check password
  11110. /// NOTE: This packet is only available on certain non-kRO clients.
  11111. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11112. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11113. // int type = RFIFOW(fd,info->pos[0]);
  11114. // char* password = RFIFOP(fd,info->pos[1]);
  11115. // char* new_password = RFIFOP(fd,info->pos[2]);
  11116. // storage_changepass(sd,password,new_password);
  11117. }
  11118. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11119. /// 023c <result>.W <error count>.W
  11120. /// result:
  11121. /// 4 = password change success
  11122. /// 5 = password change failure
  11123. /// 6 = password check success
  11124. /// 7 = password check failure
  11125. /// 8 = too many wrong passwords
  11126. /// ? = ignored
  11127. /// NOTE: This packet is only available on certain non-kRO clients.
  11128. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11129. {
  11130. int fd = sd->fd;
  11131. WFIFOHEAD(fd,packet_len(0x23c));
  11132. WFIFOW(fd,0) = 0x23c;
  11133. WFIFOW(fd,2) = result;
  11134. WFIFOW(fd,4) = error_count;
  11135. WFIFOSET(fd,packet_len(0x23c));
  11136. }
  11137. /// Party creation request
  11138. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11139. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11140. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11141. name[NAME_LENGTH-1] = '\0';
  11142. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11143. clif_displaymessage(fd, msg_txt(sd,227));
  11144. return;
  11145. }
  11146. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11147. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11148. return;
  11149. }
  11150. party_create(sd,name,0,0);
  11151. }
  11152. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11153. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11154. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11155. char* name = RFIFOCP(fd,info->pos[0]);
  11156. int item1 = RFIFOB(fd,info->pos[1]);
  11157. int item2 = RFIFOB(fd,info->pos[2]);
  11158. name[NAME_LENGTH-1] = '\0';
  11159. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11160. clif_displaymessage(fd, msg_txt(sd,227));
  11161. return;
  11162. }
  11163. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11164. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11165. return;
  11166. }
  11167. party_create(sd,name,item1,item2);
  11168. }
  11169. /// Party invitation request
  11170. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11171. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11172. {
  11173. struct map_session_data *t_sd;
  11174. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11175. clif_displaymessage(fd, msg_txt(sd,227));
  11176. return;
  11177. }
  11178. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11179. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11180. clif_noask_sub(sd, t_sd, 1);
  11181. return;
  11182. }
  11183. party_invite(sd, t_sd);
  11184. }
  11185. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11186. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11187. struct map_session_data *t_sd;
  11188. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11189. name[NAME_LENGTH-1] = '\0';
  11190. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11191. clif_displaymessage(fd, msg_txt(sd,227));
  11192. return;
  11193. }
  11194. t_sd = map_nick2sd(name,false);
  11195. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11196. clif_noask_sub(sd, t_sd, 1);
  11197. return;
  11198. }
  11199. party_invite(sd, t_sd);
  11200. }
  11201. /// Party invitation reply
  11202. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11203. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11204. /// flag:
  11205. /// 0 = reject
  11206. /// 1 = accept
  11207. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11208. {
  11209. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11210. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11211. RFIFOL(fd,info->pos[1]));
  11212. }
  11213. //(CZ_PARTY_JOIN_REQ_ACK)
  11214. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11215. {
  11216. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11217. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11218. RFIFOB(fd,info->pos[1]));
  11219. }
  11220. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11221. /// 0100
  11222. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11223. {
  11224. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11225. clif_displaymessage(fd, msg_txt(sd,227));
  11226. return;
  11227. }
  11228. party_leave(sd);
  11229. }
  11230. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11231. /// 0103 <account id>.L <char name>.24B
  11232. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11233. {
  11234. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11235. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11236. clif_displaymessage(fd, msg_txt(sd,227));
  11237. return;
  11238. }
  11239. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11240. RFIFOCP(fd,info->pos[1]));
  11241. }
  11242. /// Request to change party options.
  11243. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11244. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11245. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11246. {
  11247. struct party_data *p;
  11248. int i,expflag;
  11249. int cmd = RFIFOW(fd,0);
  11250. struct s_packet_db* info = &packet_db[cmd];
  11251. if( !sd->status.party_id )
  11252. return;
  11253. p = party_search(sd->status.party_id);
  11254. if( p == NULL )
  11255. return;
  11256. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11257. if( i == MAX_PARTY )
  11258. return; //Shouldn't happen
  11259. if( !p->party.member[i].leader )
  11260. return;
  11261. expflag = RFIFOL(fd,info->pos[0]);
  11262. if(cmd == 0x0102){ //Client can't change the item-field
  11263. party_changeoption(sd, expflag, p->party.item);
  11264. }
  11265. else {
  11266. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11267. party_changeoption(sd, expflag, itemflag);
  11268. }
  11269. }
  11270. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11271. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11272. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11273. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11274. // validate packet and retrieve name and message
  11275. if( !clif_process_message( sd, false, name, message, output ) )
  11276. return;
  11277. party_send_message(sd, output, strlen(output) + 1 );
  11278. }
  11279. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11280. /// 07da <account id>.L
  11281. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11282. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11283. }
  11284. /// Party Booking in KRO [Spiria]
  11285. ///
  11286. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11287. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11288. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11290. short level = RFIFOW(fd,info->pos[0]);
  11291. short mapid = RFIFOW(fd,info->pos[1]);
  11292. int idxpbj = info->pos[2];
  11293. short job[MAX_PARTY_BOOKING_JOBS];
  11294. int i;
  11295. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11296. job[i] = RFIFOB(fd,idxpbj+i*2);
  11297. party_booking_register(sd, level, mapid, job);
  11298. }
  11299. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11300. /// 0803 <result>.W
  11301. /// result:
  11302. /// 0 = success
  11303. /// 1 = failure
  11304. /// 2 = already registered
  11305. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11306. {
  11307. int fd = sd->fd;
  11308. WFIFOHEAD(fd,packet_len(0x803));
  11309. WFIFOW(fd,0) = 0x803;
  11310. WFIFOW(fd,2) = flag;
  11311. WFIFOSET(fd,packet_len(0x803));
  11312. }
  11313. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11314. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11315. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11316. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11317. short level = RFIFOW(fd,info->pos[0]);
  11318. short mapid = RFIFOW(fd,info->pos[1]);
  11319. short job = RFIFOW(fd,info->pos[2]);
  11320. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11321. short resultcount = RFIFOW(fd,info->pos[4]);
  11322. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11323. }
  11324. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11325. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11326. /// more results:
  11327. /// 0 = no
  11328. /// 1 = yes
  11329. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11330. {
  11331. int i, j;
  11332. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11333. struct party_booking_ad_info *pb_ad;
  11334. WFIFOHEAD(fd,size*count + 5);
  11335. WFIFOW(fd,0) = 0x805;
  11336. WFIFOW(fd,2) = size*count + 5;
  11337. WFIFOB(fd,4) = more_result;
  11338. for(i=0; i<count; i++)
  11339. {
  11340. pb_ad = results[i];
  11341. WFIFOL(fd,i*size+5) = pb_ad->index;
  11342. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11343. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11344. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11345. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11346. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11347. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11348. }
  11349. WFIFOSET(fd,WFIFOW(fd,2));
  11350. }
  11351. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11352. /// 0806
  11353. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11354. {
  11355. if(party_booking_delete(sd))
  11356. clif_PartyBookingDeleteAck(sd, 0);
  11357. }
  11358. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11359. /// 0807 <result>.W
  11360. /// result:
  11361. /// 0 = success
  11362. /// 1 = success (auto-removed expired ad)
  11363. /// 2 = failure
  11364. /// 3 = nothing registered
  11365. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11366. {
  11367. int fd = sd->fd;
  11368. WFIFOHEAD(fd,packet_len(0x807));
  11369. WFIFOW(fd,0) = 0x807;
  11370. WFIFOW(fd,2) = flag;
  11371. WFIFOSET(fd,packet_len(0x807));
  11372. }
  11373. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11374. /// 0808 { <job>.W }*6
  11375. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11376. {
  11377. short job[MAX_PARTY_BOOKING_JOBS];
  11378. int i;
  11379. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11380. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11381. job[i] = RFIFOW(fd,idxpbu+i*2);
  11382. party_booking_update(sd, job);
  11383. }
  11384. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11385. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11386. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11387. {
  11388. int i;
  11389. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11390. if(pb_ad == NULL) return;
  11391. WBUFW(buf,0) = 0x809;
  11392. WBUFL(buf,2) = pb_ad->index;
  11393. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11394. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11395. WBUFW(buf,34) = pb_ad->p_detail.level;
  11396. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11397. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11398. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11399. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11400. }
  11401. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11402. /// 080a <index>.L { <job>.W }*6
  11403. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11404. {
  11405. int i;
  11406. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11407. if(pb_ad == NULL) return;
  11408. WBUFW(buf,0) = 0x80a;
  11409. WBUFL(buf,2) = pb_ad->index;
  11410. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11411. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11412. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11413. }
  11414. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11415. /// 080b <index>.L
  11416. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11417. {
  11418. uint8 buf[6];
  11419. WBUFW(buf,0) = 0x80b;
  11420. WBUFL(buf,2) = index;
  11421. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11422. }
  11423. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11424. /// 012e
  11425. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11426. {
  11427. vending_closevending(sd);
  11428. }
  11429. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11430. /// 0130 <account id>.L
  11431. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11432. {
  11433. if( sd->npc_id ) {// using an NPC
  11434. return;
  11435. }
  11436. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11437. }
  11438. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11439. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11440. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11441. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11442. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11443. int id = (int)RFIFOL(fd,info->pos[1]);
  11444. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11445. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11446. // whether it fails or not, the buy window is closed
  11447. sd->vended_id = 0;
  11448. }
  11449. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11450. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11451. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11452. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11453. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11454. int aid = (int)RFIFOL(fd,info->pos[1]);
  11455. int uid = (int)RFIFOL(fd,info->pos[2]);
  11456. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11457. vending_purchasereq(sd, aid, uid, data, len/4);
  11458. // whether it fails or not, the buy window is closed
  11459. sd->vended_id = 0;
  11460. }
  11461. /// Confirm or cancel the shop preparation window.
  11462. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11463. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11464. /// result:
  11465. /// 0 = canceled
  11466. /// 1 = open
  11467. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11468. int cmd = RFIFOW(fd,0);
  11469. struct s_packet_db* info = &packet_db[cmd];
  11470. short len = (short)RFIFOW(fd,info->pos[0]);
  11471. const char* message = RFIFOCP(fd,info->pos[1]);
  11472. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11473. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11474. len -= 84;
  11475. }
  11476. else { //(CZ_REQ_OPENSTORE2)
  11477. bool flag;
  11478. len -= 85;
  11479. flag = RFIFOB(fd,info->pos[2]) != 0;
  11480. if (!flag) {
  11481. sd->state.prevend = 0;
  11482. sd->state.workinprogress = WIP_DISABLE_NONE;
  11483. }
  11484. }
  11485. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11486. return;
  11487. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11488. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11489. return;
  11490. }
  11491. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11492. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11493. return;
  11494. }
  11495. if( message[0] == '\0' ) // invalid input
  11496. return;
  11497. vending_openvending(sd, message, data, len/8, NULL);
  11498. }
  11499. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11500. /// 0165 <char id>.L <guild name>.24B
  11501. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11502. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11503. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11504. name[NAME_LENGTH-1] = '\0';
  11505. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11506. clif_displaymessage(fd, msg_txt(sd,228));
  11507. return;
  11508. }
  11509. if(sd->clan){
  11510. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11511. return;
  11512. }
  11513. guild_create(sd, name);
  11514. }
  11515. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11516. /// 014d
  11517. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11518. {
  11519. clif_guild_masterormember(sd);
  11520. }
  11521. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11522. /// 014f <type>.L
  11523. /// type:
  11524. /// 0 = basic info
  11525. /// 1 = member manager
  11526. /// 2 = positions
  11527. /// 3 = skills
  11528. /// 4 = expulsion list
  11529. /// 5 = unknown (GM_ALLGUILDLIST)
  11530. /// 6 = notice
  11531. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11532. {
  11533. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11534. if( !sd->status.guild_id && !sd->bg_id )
  11535. return;
  11536. switch( type )
  11537. {
  11538. case 0: // Basic Information Guild, hostile alliance information
  11539. clif_guild_basicinfo(sd);
  11540. clif_guild_allianceinfo(sd);
  11541. break;
  11542. case 1: // Members list, list job title
  11543. clif_guild_positionnamelist(sd);
  11544. clif_guild_memberlist(sd);
  11545. break;
  11546. case 2: // List job title, title information list
  11547. clif_guild_positionnamelist(sd);
  11548. clif_guild_positioninfolist(sd);
  11549. break;
  11550. case 3: // Skill list
  11551. clif_guild_skillinfo(sd);
  11552. break;
  11553. case 4: // Expulsion list
  11554. clif_guild_expulsionlist(sd);
  11555. break;
  11556. default:
  11557. ShowError("clif: guild request info: unknown type %d\n", type);
  11558. break;
  11559. }
  11560. }
  11561. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11562. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11563. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11564. {
  11565. int i;
  11566. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11567. int len = RFIFOW(fd,info->pos[0]);
  11568. int idxgpos = info->pos[1];
  11569. if(!sd->state.gmaster_flag)
  11570. return;
  11571. for(i = idxgpos; i < len; i += 40 ){
  11572. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11573. }
  11574. }
  11575. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11576. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11577. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11578. {
  11579. int i;
  11580. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11581. int len = RFIFOW(fd,info->pos[0]);
  11582. int idxgpos = info->pos[1];
  11583. if(!sd->state.gmaster_flag)
  11584. return;
  11585. // Guild leadership change
  11586. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11587. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11588. clif_msg(sd, GUILD_MASTER_WOE);
  11589. return;
  11590. }
  11591. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11592. clif_msg(sd, GUILD_MASTER_DELAY);
  11593. return;
  11594. }
  11595. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11596. return;
  11597. }
  11598. for(i=idxgpos;i<len;i+=12){
  11599. int position = RFIFOL(fd,i+8);
  11600. if( position > 0 ){
  11601. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11602. }
  11603. }
  11604. }
  11605. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11606. /// 0151 <guild id>.L
  11607. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11608. {
  11609. struct guild* g;
  11610. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11611. if( (g = guild_search(guild_id)) != NULL )
  11612. clif_guild_emblem(sd,g);
  11613. }
  11614. /// Validates data of a guild emblem (compressed bitmap)
  11615. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11616. EMBVALIDATE_SUCCESS = 0,
  11617. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11618. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11619. };
  11620. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11621. {
  11622. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11623. unsigned long buf_len = sizeof(buf);
  11624. int offset = 0;
  11625. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11626. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11627. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11628. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11629. ))
  11630. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11631. if(battle_config.emblem_transparency_limit != 100) {
  11632. int i, transcount = 1, tmp[3];
  11633. for(i = offset; i < buf_len-1; i++) {
  11634. int j = i%3;
  11635. tmp[j] = RBUFL(buf,i);
  11636. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11637. transcount++;
  11638. }
  11639. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11640. return EMBVALIDATE_ERR_TRANSPARENCY;
  11641. }
  11642. return EMBVALIDATE_SUCCESS;
  11643. }
  11644. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11645. /// 0153 <packet len>.W <emblem data>.?B
  11646. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11647. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11648. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11649. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11650. int emb_val=0;
  11651. if( !emblem_len || !sd->state.gmaster_flag )
  11652. return;
  11653. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11654. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11655. return;
  11656. }
  11657. emb_val = clif_validate_emblem(emblem, emblem_len);
  11658. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11659. 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);
  11660. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11661. return;
  11662. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11663. char output[128];
  11664. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11665. 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"
  11666. return;
  11667. }
  11668. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11669. }
  11670. /// Request to update the guild emblem id (version, according to Gravity)
  11671. /// 0b46 <guild id>.L <version>.L
  11672. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11673. nullpo_retv(sd);
  11674. #if PACKETVER >= 20190724
  11675. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11676. guild* g = sd->guild;
  11677. if (g == nullptr || g->guild_id != p->guild_id)
  11678. return;
  11679. if (!sd->state.gmaster_flag)
  11680. return;
  11681. if (!battle_config.emblem_woe_change && is_agit_start()) {
  11682. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11683. return;
  11684. }
  11685. guild_change_emblem_version(sd, p->version);
  11686. #endif
  11687. }
  11688. /// Guild notice update request (CZ_GUILD_NOTICE).
  11689. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11690. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11691. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11692. int guild_id = RFIFOL(fd,info->pos[0]);
  11693. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11694. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11695. if(!sd->state.gmaster_flag)
  11696. return;
  11697. // compensate for some client defects when using multilanguage mode
  11698. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11699. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11700. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11701. guild_change_notice(sd, guild_id, msg1, msg2);
  11702. }
  11703. // Helper function for guild invite functions
  11704. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11705. {
  11706. if (t_sd == NULL) // not online or does not exist
  11707. return 1;
  11708. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11709. clif_displaymessage(fd, msg_txt(sd,228));
  11710. return 1;
  11711. }
  11712. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11713. clif_noask_sub(sd, t_sd, 2);
  11714. return 1;
  11715. }
  11716. // Players in a clan can not join a guild
  11717. if(t_sd && t_sd->clan){
  11718. return 1;
  11719. }
  11720. guild_invite(sd, t_sd);
  11721. return 0;
  11722. }
  11723. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11724. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11725. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11726. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11727. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11728. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11729. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11730. if (clif_sub_guild_invite(fd, sd, t_sd))
  11731. return;
  11732. }
  11733. /// Guild invite request (/guildinvite)
  11734. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11735. void
  11736. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11737. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11738. if (clif_sub_guild_invite(fd, sd, t_sd))
  11739. return;
  11740. }
  11741. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11742. /// 016b <guild id>.L <answer>.L
  11743. /// answer:
  11744. /// 0 = refuse
  11745. /// 1 = accept
  11746. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11747. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11748. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11749. RFIFOL(fd,info->pos[1]));
  11750. }
  11751. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11752. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11753. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11754. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11755. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11756. clif_displaymessage(fd, msg_txt(sd,228));
  11757. return;
  11758. }
  11759. if( sd->bg_id ) {
  11760. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11761. return;
  11762. }
  11763. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11764. RFIFOL(fd,info->pos[1]),
  11765. RFIFOL(fd,info->pos[2]),
  11766. RFIFOCP(fd,info->pos[3]));
  11767. }
  11768. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11769. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11770. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11771. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11772. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11773. { // Guild locked.
  11774. clif_displaymessage(fd, msg_txt(sd,228));
  11775. return;
  11776. }
  11777. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11778. RFIFOL(fd,info->pos[1]),
  11779. RFIFOL(fd,info->pos[2]),
  11780. RFIFOCP(fd,info->pos[3]));
  11781. }
  11782. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11783. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11784. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11785. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11786. // validate packet and retrieve name and message
  11787. if( !clif_process_message( sd, false, name, message, output ) )
  11788. return;
  11789. if( sd->bg_id )
  11790. bg_send_message(sd, output, strlen(output) );
  11791. else
  11792. guild_send_message(sd, output, strlen(output) );
  11793. }
  11794. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11795. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11796. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11797. {
  11798. struct map_session_data *t_sd;
  11799. if(!sd->state.gmaster_flag)
  11800. return;
  11801. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11802. clif_displaymessage(fd, msg_txt(sd,228));
  11803. return;
  11804. }
  11805. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11806. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11807. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11808. // @noask [LuzZza]
  11809. if(t_sd && t_sd->state.noask) {
  11810. clif_noask_sub(sd, t_sd, 3);
  11811. return;
  11812. }
  11813. guild_reqalliance(sd,t_sd);
  11814. }
  11815. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11816. /// 0172 <inviter account id>.L <answer>.L
  11817. /// answer:
  11818. /// 0 = refuse
  11819. /// 1 = accept
  11820. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11821. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11822. guild_reply_reqalliance(sd,
  11823. RFIFOL(fd,info->pos[0]),
  11824. RFIFOL(fd,info->pos[1]));
  11825. }
  11826. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11827. /// 0183 <opponent guild id>.L <relation>.L
  11828. /// relation:
  11829. /// 0 = Ally
  11830. /// 1 = Enemy
  11831. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11832. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11833. if(!sd->state.gmaster_flag)
  11834. return;
  11835. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11836. clif_displaymessage(fd, msg_txt(sd,228));
  11837. return;
  11838. }
  11839. guild_delalliance(sd,
  11840. RFIFOL(fd,info->pos[0]),
  11841. RFIFOL(fd,info->pos[1]));
  11842. }
  11843. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11844. /// 0180 <account id>.L
  11845. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11846. {
  11847. struct map_session_data *t_sd;
  11848. if(!sd->state.gmaster_flag)
  11849. return;
  11850. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11851. clif_displaymessage(fd, msg_txt(sd,228));
  11852. return;
  11853. }
  11854. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11855. // @noask [LuzZza]
  11856. if(t_sd && t_sd->state.noask) {
  11857. clif_noask_sub(sd, t_sd, 4);
  11858. return;
  11859. }
  11860. guild_opposition(sd,t_sd);
  11861. }
  11862. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11863. /// 015d <key>.40B
  11864. /// key:
  11865. /// now guild name; might have been (intended) email, since the
  11866. /// field name and size is same as the one in CH_DELETE_CHAR.
  11867. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11868. {
  11869. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11870. clif_displaymessage(fd, msg_txt(sd,228));
  11871. return;
  11872. }
  11873. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11874. }
  11875. /// Pet
  11876. ///
  11877. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11878. /// 01a1 <type>.B
  11879. /// type:
  11880. /// 0 = pet information
  11881. /// 1 = feed
  11882. /// 2 = performance
  11883. /// 3 = return to egg
  11884. /// 4 = unequip accessory
  11885. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11886. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11887. }
  11888. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11889. /// 019f <id>.L
  11890. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11891. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11892. }
  11893. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11894. /// 01a7 <index>.W
  11895. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11896. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11897. return;
  11898. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11899. clif_menuskill_clear(sd);
  11900. }
  11901. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11902. /// 01a9 <data>.L
  11903. /// data:
  11904. /// is either emotion (@see enum emotion_type) or a compound value
  11905. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11906. /// entry (given in parentheses) in data\pettalktable.xml
  11907. /// act id:
  11908. /// 0 = feeding
  11909. /// 1 = hunting
  11910. /// 2 = danger
  11911. /// 3 = dead
  11912. /// 4 = normal (stand)
  11913. /// 5 = special performance (perfor_s)
  11914. /// 6 = level up (levelup)
  11915. /// 7 = performance 1 (perfor_1)
  11916. /// 8 = performance 2 (perfor_2)
  11917. /// 9 = performance 3 (perfor_3)
  11918. /// 10 = log-in greeting (connect)
  11919. /// hungry value:
  11920. /// 0 = very hungry (hungry)
  11921. /// 1 = hungry (bit_hungry)
  11922. /// 2 = satisfied (noting)
  11923. /// 3 = stuffed (full)
  11924. /// 4 = full (so_full)
  11925. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11926. {
  11927. if(sd->pd)
  11928. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11929. }
  11930. /// Request to change pet's name (CZ_RENAME_PET).
  11931. /// 01a5 <name>.24B
  11932. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11933. {
  11934. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11935. }
  11936. /// /kill (CZ_DISCONNECT_CHARACTER).
  11937. /// Request to disconnect a character.
  11938. /// 00cc <account id>.L
  11939. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11940. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11941. {
  11942. struct block_list *target;
  11943. int tid;
  11944. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11945. target = map_id2bl(tid);
  11946. if (!target) {
  11947. clif_GM_kickack(sd, 0);
  11948. return;
  11949. }
  11950. switch (target->type) {
  11951. case BL_PC:
  11952. {
  11953. char command[NAME_LENGTH+6];
  11954. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11955. is_atcommand(fd, sd, command, 1);
  11956. }
  11957. break;
  11958. /**
  11959. * This one does not invoke any atcommand, so we need to check for permissions.
  11960. */
  11961. case BL_MOB:
  11962. {
  11963. char command[100];
  11964. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11965. clif_GM_kickack(sd, 0);
  11966. return;
  11967. }
  11968. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11969. log_atcommand(sd, command);
  11970. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11971. }
  11972. break;
  11973. case BL_NPC:
  11974. {
  11975. struct npc_data* nd = (struct npc_data *)target;
  11976. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11977. npc_unload_duplicates(nd);
  11978. npc_unload(nd,true);
  11979. npc_read_event_script();
  11980. }
  11981. }
  11982. break;
  11983. default:
  11984. clif_GM_kickack(sd, 0);
  11985. }
  11986. }
  11987. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11988. /// Request to disconnect all characters.
  11989. /// 00ce
  11990. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11991. char cmd[15];
  11992. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11993. is_atcommand(fd, sd, cmd, 1);
  11994. }
  11995. /// /remove (CZ_REMOVE_AID).
  11996. /// Request to warp to a character with given login ID.
  11997. /// 01ba <account name>.24B
  11998. /// /shift (CZ_SHIFT).
  11999. /// Request to warp to a character with given name.
  12000. /// 01bb <char name>.24B
  12001. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12002. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12003. char *player_name;
  12004. char command[NAME_LENGTH+8];
  12005. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12006. player_name[NAME_LENGTH-1] = '\0';
  12007. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12008. is_atcommand(fd, sd, command, 1);
  12009. }
  12010. /// /remove (CZ_REMOVE_AID_SSO).
  12011. /// Request to warp to a character with given account ID.
  12012. /// 0843 <account id>.L
  12013. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12014. {
  12015. uint32 account_id;
  12016. struct map_session_data* pl_sd;
  12017. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12018. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12019. char command[NAME_LENGTH+8];
  12020. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12021. is_atcommand(fd, sd, command, 1);
  12022. }
  12023. }
  12024. /// /recall (CZ_RECALL).
  12025. /// Request to summon a player with given login ID to own position.
  12026. /// 01bc <account name>.24B
  12027. /// /summon (CZ_RECALL_GID).
  12028. /// Request to summon a player with given name to own position.
  12029. /// 01bd <char name>.24B
  12030. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12031. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12032. char *player_name;
  12033. char command [NAME_LENGTH+8];
  12034. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12035. player_name[NAME_LENGTH-1] = '\0';
  12036. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12037. is_atcommand(fd, sd, command, 1);
  12038. }
  12039. /// /recall (CZ_RECALL_SSO).
  12040. /// Request to summon a player with given account ID to own position.
  12041. /// 0842 <account id>.L
  12042. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12043. {
  12044. uint32 account_id;
  12045. struct map_session_data* pl_sd;
  12046. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12047. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12048. char command[NAME_LENGTH+8];
  12049. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12050. is_atcommand(fd, sd, command, 1);
  12051. }
  12052. }
  12053. /// /item /monster (CZ_ITEM_CREATE).
  12054. /// Request to execute GM commands.
  12055. /// Usage:
  12056. /// /item n - summon n monster or acquire n item/s
  12057. /// /item money - grants 2147483647 zenies
  12058. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12059. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12060. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12061. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12062. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12063. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12064. /// 013f <item/mob name>.24B
  12065. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12066. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12067. {
  12068. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12069. int mob_id = 0;
  12070. struct item_data *id = NULL;
  12071. struct mob_db *mob = NULL;
  12072. StringBuf command;
  12073. char *str;
  12074. //#if PACKETVER >= 20131218
  12075. // char str[100];
  12076. //#else
  12077. // char str[24];
  12078. //#endif
  12079. str = RFIFOCP(fd,info->pos[0]);
  12080. if (!str || str[0] == '\0')
  12081. return;
  12082. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12083. return;
  12084. trim(str);
  12085. // Zeny
  12086. if( strcmpi(str, "money") == 0 ) {
  12087. StringBuf_Init(&command);
  12088. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12089. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12090. StringBuf_Destroy(&command);
  12091. return;
  12092. }
  12093. // Item
  12094. if( (id = itemdb_searchname(str)) ) {
  12095. StringBuf_Init(&command);
  12096. if( !itemdb_isstackable2(id) ) //Nonstackable
  12097. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12098. else {
  12099. if (id->flag.guid)
  12100. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12101. else
  12102. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12103. }
  12104. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12105. StringBuf_Destroy(&command);
  12106. return;
  12107. }
  12108. // Monster
  12109. if ((mob_id = mobdb_searchname(str)) == 0)
  12110. mob_id = mobdb_checkid(atoi(str));
  12111. if( (mob = mob_db(mob_id)) ) {
  12112. StringBuf_Init(&command);
  12113. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12114. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12115. StringBuf_Destroy(&command);
  12116. return;
  12117. }
  12118. }
  12119. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12120. /// 019d <effect state>.L
  12121. /// effect state:
  12122. /// TODO: Any OPTION_* ?
  12123. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12124. char cmd[6];
  12125. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12126. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12127. is_atcommand(fd, sd, cmd, 1);
  12128. }
  12129. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12130. /// 0149 <account id>.L <type>.B <value>.W
  12131. /// type:
  12132. /// 0 = positive points
  12133. /// 1 = negative points
  12134. /// 2 = self mute (+10 minutes)
  12135. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12136. {
  12137. int id, type, value;
  12138. struct map_session_data *dstsd;
  12139. char command[NAME_LENGTH+15];
  12140. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12141. id = RFIFOL(fd,info->pos[0]);
  12142. type = RFIFOB(fd,info->pos[1]);
  12143. value = RFIFOW(fd,info->pos[2]);
  12144. if( type == 0 )
  12145. value = -value;
  12146. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12147. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12148. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12149. return;
  12150. dstsd = map_id2sd(id);
  12151. if( dstsd == NULL )
  12152. return;
  12153. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12154. is_atcommand(fd, sd, command, 1);
  12155. }
  12156. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12157. /// GM adjustment of a player's manner value by -60.
  12158. /// 0212 <char name>.24B
  12159. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12160. {
  12161. char command[NAME_LENGTH+15];
  12162. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12163. name[NAME_LENGTH-1] = '\0';
  12164. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12165. is_atcommand(fd, sd, command, 1);
  12166. }
  12167. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12168. /// 01e0 <account id>.L <account name>.24B
  12169. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12170. {
  12171. WFIFOHEAD(fd,packet_len(0x1e0));
  12172. WFIFOW(fd,0) = 0x1e0;
  12173. WFIFOL(fd,2) = account_id;
  12174. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12175. WFIFOSET(fd,packet_len(0x1e0));
  12176. }
  12177. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12178. /// 01df <account id>.L
  12179. //! TODO: Figure out how does this actually work
  12180. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12181. {
  12182. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12183. /*
  12184. char query[30];
  12185. safesnprintf(query,sizeof(query),"%d", account_id);
  12186. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12187. */
  12188. clif_account_name(fd, account_id, "");
  12189. }
  12190. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12191. /// GM single cell type change request.
  12192. /// 0198 <x>.W <y>.W <type>.W
  12193. /// type:
  12194. /// 0 = not walkable
  12195. /// 1 = walkable
  12196. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12197. {
  12198. int x,y,type;
  12199. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12200. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12201. return;
  12202. x = RFIFOW(fd,info->pos[0]);
  12203. y = RFIFOW(fd,info->pos[1]);
  12204. type = RFIFOW(fd,info->pos[2]);
  12205. map_setgatcell(sd->bl.m,x,y,type);
  12206. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12207. //FIXME: once players leave the map, the client 'forgets' this information.
  12208. }
  12209. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12210. /// Request to allow/deny whispers from a nick.
  12211. /// 00cf <nick>.24B <type>.B
  12212. /// type:
  12213. /// 0 = (/ex nick) deny speech from nick
  12214. /// 1 = (/in nick) allow speech from nick
  12215. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12216. {
  12217. char* nick;
  12218. uint8 type;
  12219. int i;
  12220. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12221. nick = RFIFOCP(fd,info->pos[0]);
  12222. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12223. type = RFIFOB(fd,info->pos[1]);
  12224. if( type == 0 ) { // Add name to ignore list (block)
  12225. if (strcmp(wisp_server_name, nick) == 0) {
  12226. clif_wisexin(sd, type, 1); // fail
  12227. return;
  12228. }
  12229. // try to find a free spot, while checking for duplicates at the same time
  12230. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12231. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12232. clif_wisexin(sd, type, 2); // too many blocks
  12233. return;
  12234. }
  12235. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12236. clif_wisexin(sd, type, 0); // Aegis reports success.
  12237. return;
  12238. }
  12239. //Insert in position i
  12240. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12241. } else { // Remove name from ignore list (unblock)
  12242. // find entry
  12243. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12244. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12245. clif_wisexin(sd, type, 1); // fail
  12246. return;
  12247. }
  12248. // move everything one place down to overwrite removed entry
  12249. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12250. // wipe last entry
  12251. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12252. }
  12253. clif_wisexin(sd, type, 0); // success
  12254. }
  12255. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12256. /// Request to allow/deny all whispers.
  12257. /// 00d0 <type>.B
  12258. /// type:
  12259. /// 0 = (/exall) deny all speech
  12260. /// 1 = (/inall) allow all speech
  12261. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12262. {
  12263. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12264. if( type == 0 ) {// Deny all
  12265. if( sd->state.ignoreAll ) {
  12266. flag = 1; // fail
  12267. } else {
  12268. sd->state.ignoreAll = 1;
  12269. flag = 0; // success
  12270. }
  12271. } else {//Unblock everyone
  12272. if( sd->state.ignoreAll ) {
  12273. sd->state.ignoreAll = 0;
  12274. flag = 0; // success
  12275. } else {
  12276. if (sd->ignore[0].name[0] != '\0')
  12277. { //Wipe the ignore list.
  12278. memset(sd->ignore, 0, sizeof(sd->ignore));
  12279. flag = 0; // success
  12280. } else {
  12281. flag = 1; // fail
  12282. }
  12283. }
  12284. }
  12285. clif_wisall(sd, type, flag);
  12286. }
  12287. /// Whisper ignore list (ZC_WHISPER_LIST).
  12288. /// 00d4 <packet len>.W { <char name>.24B }*
  12289. void clif_PMIgnoreList(struct map_session_data* sd)
  12290. {
  12291. int i, fd = sd->fd;
  12292. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12293. WFIFOW(fd,0) = 0xd4;
  12294. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12295. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12296. }
  12297. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12298. WFIFOSET(fd,WFIFOW(fd,2));
  12299. }
  12300. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12301. /// 00d3
  12302. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12303. {
  12304. clif_PMIgnoreList(sd);
  12305. }
  12306. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12307. /// 01e7
  12308. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12309. {
  12310. if (sd->state.doridori) return;
  12311. switch (sd->class_&MAPID_UPPERMASK) {
  12312. case MAPID_SOUL_LINKER:
  12313. case MAPID_STAR_GLADIATOR:
  12314. case MAPID_TAEKWON:
  12315. if (!sd->state.rest)
  12316. break;
  12317. case MAPID_SUPER_NOVICE:
  12318. case MAPID_SUPER_BABY:
  12319. case MAPID_SUPER_NOVICE_E:
  12320. case MAPID_SUPER_BABY_E:
  12321. sd->state.doridori=1;
  12322. break;
  12323. }
  12324. }
  12325. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12326. /// 01ed
  12327. /// Note: This packet is caused by 7 lines of any text, followed by
  12328. /// the prayer and an another line of any text. The prayer is
  12329. /// defined by lines 790~793 in data\msgstringtable.txt
  12330. /// "Dear angel, can you hear my voice?"
  12331. /// "I am" (space separated player name) "Super Novice~"
  12332. /// "Help me out~ Please~ T_T"
  12333. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12334. {
  12335. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12336. unsigned int next = pc_nextbaseexp(sd);
  12337. if( next ) {
  12338. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12339. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12340. sc_start(&sd->bl,&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12341. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12342. }
  12343. }
  12344. }
  12345. }
  12346. /// Friends List
  12347. ///
  12348. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12349. /// 0206 <account id>.L <char id>.L <state>.B
  12350. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12351. /// state:
  12352. /// 0 = online
  12353. /// 1 = offline
  12354. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12355. {
  12356. int i, fd = sd->fd;
  12357. //Seek friend.
  12358. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12359. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12360. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12361. return; //Not found
  12362. WFIFOHEAD(fd,packet_len(0x206));
  12363. WFIFOW(fd, 0) = 0x206;
  12364. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12365. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12366. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12367. #if PACKETVER >= 20180221
  12368. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12369. #endif
  12370. WFIFOSET(fd, packet_len(0x206));
  12371. }
  12372. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12373. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12374. {
  12375. uint32 account_id, char_id, online;
  12376. account_id = va_arg(ap, int);
  12377. char_id = va_arg(ap, int);
  12378. online = va_arg(ap, int);
  12379. clif_friendslist_toggle(sd, account_id, char_id, online);
  12380. return 0;
  12381. }
  12382. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12383. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12384. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12385. void clif_friendslist_send(struct map_session_data *sd)
  12386. {
  12387. int i = 0, n, fd = sd->fd;
  12388. #if PACKETVER >= 20180221
  12389. const int size = 8;
  12390. #else
  12391. const int size = 8 + NAME_LENGTH;
  12392. #endif
  12393. // Send friends list
  12394. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12395. WFIFOW(fd, 0) = 0x201;
  12396. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12397. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12398. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12399. #if PACKETVER < 20180221
  12400. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12401. #endif
  12402. }
  12403. if (i) {
  12404. WFIFOW(fd,2) = 4 + size * i;
  12405. WFIFOSET(fd, WFIFOW(fd,2));
  12406. }
  12407. for (n = 0; n < i; n++) { //Sending the online players
  12408. if (map_charid2sd(sd->status.friends[n].char_id))
  12409. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12410. }
  12411. }
  12412. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12413. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12414. /// result:
  12415. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12416. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12417. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12418. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12419. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12420. {
  12421. int fd;
  12422. nullpo_retv(sd);
  12423. fd = sd->fd;
  12424. WFIFOHEAD(fd,packet_len(0x209));
  12425. WFIFOW(fd,0) = 0x209;
  12426. WFIFOW(fd,2) = type;
  12427. if (f_sd) {
  12428. WFIFOL(fd,4) = f_sd->status.account_id;
  12429. WFIFOL(fd,8) = f_sd->status.char_id;
  12430. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12431. }
  12432. WFIFOSET(fd, packet_len(0x209));
  12433. }
  12434. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12435. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12436. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12437. {
  12438. int fd = sd->fd;
  12439. WFIFOHEAD(fd,packet_len(0x207));
  12440. WFIFOW(fd,0) = 0x207;
  12441. WFIFOL(fd,2) = account_id;
  12442. WFIFOL(fd,6) = char_id;
  12443. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12444. WFIFOSET(fd,packet_len(0x207));
  12445. }
  12446. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12447. /// 0202 <name>.24B
  12448. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12449. {
  12450. struct map_session_data *f_sd;
  12451. int i;
  12452. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12453. // Friend doesn't exist (no player with this name)
  12454. if (f_sd == NULL) {
  12455. clif_displaymessage(fd, msg_txt(sd,3));
  12456. return;
  12457. }
  12458. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12459. return;
  12460. }
  12461. // ensure that the request player's friend list is not full
  12462. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12463. if( i == MAX_FRIENDS ){
  12464. clif_friendslist_reqack(sd, f_sd, 2);
  12465. return;
  12466. }
  12467. // @noask [LuzZza]
  12468. if(f_sd->state.noask) {
  12469. clif_noask_sub(sd, f_sd, 5);
  12470. return;
  12471. }
  12472. // Friend already exists
  12473. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12474. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12475. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12476. return;
  12477. }
  12478. }
  12479. f_sd->friend_req = sd->status.char_id;
  12480. sd->friend_req = f_sd->status.char_id;
  12481. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12482. }
  12483. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12484. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12485. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12486. /// reply:
  12487. /// 0 = rejected
  12488. /// 1 = accepted
  12489. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12490. {
  12491. struct map_session_data *f_sd;
  12492. uint32 account_id;
  12493. char reply;
  12494. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12495. account_id = RFIFOL(fd,info->pos[0]);
  12496. //char_id = RFIFOL(fd,info->pos[1]);
  12497. #if PACKETVER < 6
  12498. reply = RFIFOB(fd,info->pos[2]);
  12499. #else
  12500. reply = RFIFOL(fd,info->pos[2]);
  12501. #endif
  12502. if( sd->bl.id == account_id ) {// adding oneself as friend
  12503. return;
  12504. }
  12505. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12506. if (f_sd == NULL)
  12507. return;
  12508. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12509. clif_friendslist_reqack(f_sd, sd, 1);
  12510. else {
  12511. int i;
  12512. // Find an empty slot
  12513. for (i = 0; i < MAX_FRIENDS; i++)
  12514. if (f_sd->status.friends[i].char_id == 0)
  12515. break;
  12516. if (i == MAX_FRIENDS) {
  12517. clif_friendslist_reqack(f_sd, sd, 2);
  12518. return;
  12519. }
  12520. f_sd->status.friends[i].account_id = sd->status.account_id;
  12521. f_sd->status.friends[i].char_id = sd->status.char_id;
  12522. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12523. clif_friendslist_reqack(f_sd, sd, 0);
  12524. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12525. if (battle_config.friend_auto_add) {
  12526. // Also add f_sd to sd's friendlist.
  12527. for (i = 0; i < MAX_FRIENDS; i++) {
  12528. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12529. return; //No need to add anything.
  12530. if (sd->status.friends[i].char_id == 0)
  12531. break;
  12532. }
  12533. if (i == MAX_FRIENDS) {
  12534. clif_friendslist_reqack(sd, f_sd, 2);
  12535. return;
  12536. }
  12537. sd->status.friends[i].account_id = f_sd->status.account_id;
  12538. sd->status.friends[i].char_id = f_sd->status.char_id;
  12539. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12540. clif_friendslist_reqack(sd, f_sd, 0);
  12541. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12542. }
  12543. }
  12544. }
  12545. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12546. /// 0203 <account id>.L <char id>.L
  12547. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12548. {
  12549. struct map_session_data *f_sd = NULL;
  12550. uint32 account_id, char_id;
  12551. int i, j;
  12552. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12553. account_id = RFIFOL(fd,info->pos[0]);
  12554. char_id = RFIFOL(fd,info->pos[1]);
  12555. // Search friend
  12556. for (i = 0; i < MAX_FRIENDS &&
  12557. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12558. if (i == MAX_FRIENDS) {
  12559. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12560. return;
  12561. }
  12562. //remove from friend's list first
  12563. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12564. for (i = 0; i < MAX_FRIENDS &&
  12565. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12566. if (i != MAX_FRIENDS) {
  12567. // move all chars up
  12568. for(j = i + 1; j < MAX_FRIENDS; j++)
  12569. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12570. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12571. //should the guy be notified of some message? we should add it here if so
  12572. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12573. WFIFOW(f_sd->fd,0) = 0x20a;
  12574. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12575. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12576. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12577. }
  12578. } else { //friend not online -- ask char server to delete from his friendlist
  12579. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12580. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12581. return;
  12582. }
  12583. }
  12584. // We can now delete from original requester
  12585. for (i = 0; i < MAX_FRIENDS &&
  12586. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12587. // move all chars up
  12588. for(j = i + 1; j < MAX_FRIENDS; j++)
  12589. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12590. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12591. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12592. WFIFOHEAD(fd,packet_len(0x20a));
  12593. WFIFOW(fd,0) = 0x20a;
  12594. WFIFOL(fd,2) = account_id;
  12595. WFIFOL(fd,6) = char_id;
  12596. WFIFOSET(fd, packet_len(0x20a));
  12597. }
  12598. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12599. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12600. void clif_PVPInfo(struct map_session_data* sd)
  12601. {
  12602. int fd = sd->fd;
  12603. WFIFOHEAD(fd,packet_len(0x210));
  12604. WFIFOW(fd,0) = 0x210;
  12605. WFIFOL(fd,2) = sd->status.char_id;
  12606. WFIFOL(fd,6) = sd->status.account_id;
  12607. WFIFOL(fd,10) = sd->pvp_won; // times won
  12608. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12609. WFIFOL(fd,18) = sd->pvp_point;
  12610. WFIFOSET(fd, packet_len(0x210));
  12611. }
  12612. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12613. /// 020f <char id>.L <account id>.L
  12614. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12615. {
  12616. // TODO: Is there a way to use this on an another player (char/acc id)?
  12617. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12618. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12619. clif_PVPInfo(sd);
  12620. }
  12621. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12622. /// 0254 <which>.B
  12623. /// which: (unused atm for security purpose)
  12624. /// 0 = sun
  12625. /// 1 = moon
  12626. /// 2 = star
  12627. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12628. {
  12629. int i;
  12630. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12631. if (sd->menuskill_id != SG_FEEL)
  12632. return;
  12633. i = sd->menuskill_val-1;
  12634. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12635. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12636. sd->feel_map[i].m = sd->bl.m;
  12637. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12638. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12639. // clif_misceffect2(&sd->bl, 0x1b0);
  12640. // clif_misceffect2(&sd->bl, 0x21f);
  12641. clif_feel_info(sd, i, 0);
  12642. clif_menuskill_clear(sd);
  12643. }
  12644. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12645. /// 0253 <which>.B
  12646. /// which:
  12647. /// 0 = sun
  12648. /// 1 = moon
  12649. /// 2 = star
  12650. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12651. {
  12652. WFIFOHEAD(fd,packet_len(0x253));
  12653. WFIFOW(fd,0)=0x253;
  12654. WFIFOB(fd,2)=TOB(skill_lv-1);
  12655. WFIFOSET(fd, packet_len(0x253));
  12656. sd->menuskill_id = SG_FEEL;
  12657. sd->menuskill_val = skill_lv;
  12658. }
  12659. /// Request to change homunculus' name (CZ_RENAME_MER).
  12660. /// 0231 <name>.24B
  12661. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12662. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12663. }
  12664. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12665. /// 0234 <id>.L
  12666. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12667. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12668. struct block_list *bl = NULL;
  12669. struct unit_data *ud = NULL;
  12670. if( sd->md && sd->md->bl.id == id )
  12671. bl = &sd->md->bl;
  12672. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12673. bl = &sd->hd->bl; // Moving Homunculus
  12674. else
  12675. return;
  12676. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12677. ud = unit_bl2ud(bl);
  12678. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12679. }
  12680. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12681. /// 0232 <id>.L <position data>.3B
  12682. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12683. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12684. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12685. struct block_list *bl = NULL;
  12686. short x, y;
  12687. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12688. if( sd->md && sd->md->bl.id == id )
  12689. bl = &sd->md->bl; // Moving Mercenary
  12690. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12691. bl = &sd->hd->bl; // Moving Homunculus
  12692. else
  12693. return;
  12694. unit_walktoxy(bl, x, y, 4);
  12695. }
  12696. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12697. /// 0233 <id>.L <target id>.L <action>.B
  12698. /// action:
  12699. /// always 0
  12700. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12701. {
  12702. struct block_list *bl = NULL;
  12703. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12704. int id = RFIFOL(fd,info->pos[0]);
  12705. int target_id = RFIFOL(fd,info->pos[1]);
  12706. int action_type = RFIFOB(fd,info->pos[2]);
  12707. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12708. bl = &sd->hd->bl;
  12709. else if( sd->md && sd->md->bl.id == id )
  12710. bl = &sd->md->bl;
  12711. else return;
  12712. unit_stop_attack(bl);
  12713. unit_attack(bl, target_id, action_type != 0);
  12714. }
  12715. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12716. /// 022d <type>.W <command>.B
  12717. /// type:
  12718. /// always 0
  12719. /// command:
  12720. /// 0 = homunculus information
  12721. /// 1 = feed
  12722. /// 2 = delete
  12723. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12724. { //[orn]
  12725. int cmd = RFIFOW(fd,0);
  12726. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12727. if(!hom_is_active(sd->hd))
  12728. return;
  12729. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12730. }
  12731. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12732. /// 0292
  12733. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12734. {
  12735. pc_revive_item(sd);
  12736. }
  12737. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12738. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12739. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12740. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12741. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12742. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12743. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12744. void clif_check(int fd, struct map_session_data* pl_sd)
  12745. {
  12746. WFIFOHEAD(fd,packet_len(0x214));
  12747. WFIFOW(fd, 0) = 0x214;
  12748. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12749. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12750. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12751. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12752. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12753. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12754. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12755. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12756. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12757. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12758. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12759. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12760. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12761. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12762. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12763. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12764. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12765. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12766. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12767. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12768. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12769. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12770. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12771. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12772. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12773. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12774. WFIFOSET(fd,packet_len(0x214));
  12775. }
  12776. /// /check (CZ_REQ_STATUS_GM).
  12777. /// Request character's status values.
  12778. /// 0213 <char name>.24B
  12779. void clif_parse_Check(int fd, struct map_session_data *sd)
  12780. {
  12781. char charname[NAME_LENGTH];
  12782. struct map_session_data* pl_sd;
  12783. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12784. return;
  12785. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12786. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12787. {
  12788. return;
  12789. }
  12790. clif_check(fd, pl_sd);
  12791. }
  12792. /// MAIL SYSTEM
  12793. /// By Zephyrus
  12794. ///
  12795. /// Notification about the result of adding an item to mail
  12796. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12797. /// result:
  12798. /// 0 = success
  12799. /// 1 = failure
  12800. /// 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)
  12801. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12802. /// result:
  12803. /// 0 = success
  12804. /// 1 = over weight
  12805. /// 2 = fatal error
  12806. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  12807. int fd = sd->fd;
  12808. #if PACKETVER < 20150513
  12809. WFIFOHEAD(fd,packet_len(0x255));
  12810. WFIFOW(fd,0) = 0x255;
  12811. WFIFOW(fd,2) = index;
  12812. WFIFOB(fd,4) = flag;
  12813. WFIFOSET(fd,packet_len(0x255));
  12814. #else
  12815. struct PACKET_ZC_ADD_ITEM_TO_MAIL p;
  12816. if( flag ){
  12817. memset( &p, 0, sizeof( p ) );
  12818. }else{
  12819. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  12820. p.index = index;
  12821. p.count = amount;
  12822. p.itemId = client_nameid( item->nameid );
  12823. p.type = itemtype( item->nameid );
  12824. p.IsIdentified = item->identify ? 1 : 0;
  12825. p.IsDamaged = item->attribute ? 1 : 0;
  12826. p.refiningLevel = item->refine;
  12827. clif_addcards( &p.slot, item );
  12828. clif_add_random_options( p.optionData, item );
  12829. p.weight = 0;
  12830. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  12831. if( sd->mail.item[i].nameid == 0 ){
  12832. continue;
  12833. }
  12834. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12835. }
  12836. p.favorite = item->favorite;
  12837. p.location = pc_equippoint( sd, server_index( index ) );
  12838. }
  12839. p.PacketType = rodexadditem;
  12840. p.result = flag;
  12841. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  12842. #endif
  12843. }
  12844. /// Notification about the result of retrieving a mail attachment
  12845. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12846. /// result:
  12847. /// 0 = success
  12848. /// 1 = failure
  12849. /// 2 = too many items
  12850. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12851. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12852. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12853. int fd = sd->fd;
  12854. #if PACKETVER < 20150513
  12855. WFIFOHEAD(fd,packet_len(0x245));
  12856. WFIFOW(fd,0) = 0x245;
  12857. WFIFOB(fd,2) = result;
  12858. WFIFOSET(fd,packet_len(0x245));
  12859. #else
  12860. switch( type ){
  12861. case MAIL_ATT_ITEM:
  12862. case MAIL_ATT_ZENY:
  12863. break;
  12864. default:
  12865. return;
  12866. }
  12867. WFIFOHEAD(fd, 12);
  12868. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12869. WFIFOQ(fd, 2) = msg->id;
  12870. WFIFOB(fd, 10) = msg->type;
  12871. WFIFOB(fd, 11) = result;
  12872. WFIFOSET(fd, 12);
  12873. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12874. #endif
  12875. }
  12876. /// Notification about the result of sending a mail
  12877. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12878. /// result:
  12879. /// 0 = success
  12880. /// 1 = recipinent does not exist
  12881. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12882. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12883. int fd = sd->fd;
  12884. #if PACKETVER < 20150513
  12885. WFIFOHEAD(fd,packet_len(0x249));
  12886. WFIFOW(fd,0) = 0x249;
  12887. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12888. WFIFOSET(fd,packet_len(0x249));
  12889. #else
  12890. WFIFOHEAD(fd, 3);
  12891. WFIFOW(fd, 0) = 0x9ed;
  12892. WFIFOB(fd, 2) = result;
  12893. WFIFOSET(fd, 3);
  12894. #endif
  12895. }
  12896. /// Notification about the result of deleting a mail.
  12897. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12898. /// result:
  12899. /// 0 = success
  12900. /// 1 = failure
  12901. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12902. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12903. int fd = sd->fd;
  12904. #if PACKETVER < 20150513
  12905. WFIFOHEAD(fd, packet_len(0x257));
  12906. WFIFOW(fd,0) = 0x257;
  12907. WFIFOL(fd,2) = msg->id;
  12908. WFIFOW(fd,6) = !success;
  12909. WFIFOSET(fd, packet_len(0x257));
  12910. #else
  12911. // This is only a success notification
  12912. if( success ){
  12913. WFIFOHEAD(fd, 11);
  12914. WFIFOW(fd, 0) = 0x9f6;
  12915. WFIFOB(fd, 2) = msg->type;
  12916. WFIFOQ(fd, 3) = msg->id;
  12917. WFIFOSET(fd, 11);
  12918. }
  12919. #endif
  12920. }
  12921. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12922. /// 0274 <mail id>.L <result>.W
  12923. /// result:
  12924. /// 0 = success
  12925. /// 1 = failure
  12926. void clif_Mail_return(int fd, int mail_id, short fail)
  12927. {
  12928. WFIFOHEAD(fd,packet_len(0x274));
  12929. WFIFOW(fd,0) = 0x274;
  12930. WFIFOL(fd,2) = mail_id;
  12931. WFIFOW(fd,6) = fail;
  12932. WFIFOSET(fd,packet_len(0x274));
  12933. }
  12934. /// Notification about new mail.
  12935. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12936. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12937. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12938. int fd = sd->fd;
  12939. #if PACKETVER < 20150513
  12940. WFIFOHEAD(fd,packet_len(0x24a));
  12941. WFIFOW(fd,0) = 0x24a;
  12942. WFIFOL(fd,2) = mail_id;
  12943. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12944. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12945. WFIFOSET(fd,packet_len(0x24a));
  12946. #else
  12947. WFIFOHEAD(fd,3);
  12948. WFIFOW(fd,0) = 0x9e7;
  12949. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12950. WFIFOSET(fd,3);
  12951. #endif
  12952. }
  12953. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12954. /// 0260 <type>.L
  12955. /// type:
  12956. /// 0 = open
  12957. /// 1 = close
  12958. void clif_Mail_window(int fd, int flag)
  12959. {
  12960. WFIFOHEAD(fd,packet_len(0x260));
  12961. WFIFOW(fd,0) = 0x260;
  12962. WFIFOL(fd,2) = flag;
  12963. WFIFOSET(fd,packet_len(0x260));
  12964. }
  12965. /// Lists mails stored in inbox.
  12966. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12967. /// read:
  12968. /// 0 = unread
  12969. /// 1 = read
  12970. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12971. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12972. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12973. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12974. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12975. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12976. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12977. #if PACKETVER < 20150513
  12978. int fd = sd->fd;
  12979. struct mail_data *md = &sd->mail.inbox;
  12980. struct mail_message *msg;
  12981. int len, i, j;
  12982. len = 8 + (73 * md->amount);
  12983. WFIFOHEAD(fd,len);
  12984. WFIFOW(fd,0) = 0x240;
  12985. WFIFOW(fd,2) = len;
  12986. WFIFOL(fd,4) = md->amount;
  12987. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12988. {
  12989. msg = &md->msg[i];
  12990. if (msg->id < 1)
  12991. continue;
  12992. WFIFOL(fd,8+73*j) = msg->id;
  12993. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12994. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12995. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12996. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12997. j++;
  12998. }
  12999. WFIFOSET(fd,len);
  13000. if( md->full ) {// TODO: is this official?
  13001. char output[100];
  13002. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13003. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13004. }
  13005. #else
  13006. int fd = sd->fd;
  13007. struct mail_data *md = &sd->mail.inbox;
  13008. struct mail_message *msg;
  13009. int i, j, k, offset, titleLength;
  13010. uint8 mailType, amount, remaining;
  13011. uint32 now = (uint32)time(NULL);
  13012. #if PACKETVER >= 20170419
  13013. int cmd = 0xac2;
  13014. #elif PACKETVER >= 20160601
  13015. int cmd = 0xa7d;
  13016. #else
  13017. int cmd = 0x9f0;
  13018. #endif
  13019. if( battle_config.mail_daily_count ){
  13020. mail_refresh_remaining_amount(sd);
  13021. }
  13022. #if PACKETVER >= 20170419
  13023. // Always send all
  13024. i = md->amount;
  13025. #else
  13026. // If a starting mail id was sent
  13027. if( mailID != 0 ){
  13028. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13029. // Unknown mail
  13030. if( i == md->amount ){
  13031. // Ignore the request for now
  13032. return; // TODO: Should we just show the first page instead?
  13033. }
  13034. // It was actually the oldest/first mail, there is no further page
  13035. if( i == 0 ){
  13036. return;
  13037. }
  13038. // We actually want the next/older mail
  13039. i -= 1;
  13040. }else{
  13041. i = md->amount;
  13042. }
  13043. #endif
  13044. // Count the remaining mails from the starting mail or the beginning
  13045. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13046. for( j = i, remaining = 0; j >= 0; j-- ){
  13047. msg = &md->msg[j];
  13048. if (msg->id < 1)
  13049. continue;
  13050. #if PACKETVER < 20170419
  13051. if (msg->type != type)
  13052. continue;
  13053. #endif
  13054. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13055. continue;
  13056. remaining++;
  13057. }
  13058. #if PACKETVER >= 20170419
  13059. // Always send all
  13060. amount = remaining;
  13061. #else
  13062. if( remaining > MAIL_PAGE_SIZE ){
  13063. amount = MAIL_PAGE_SIZE;
  13064. }else{
  13065. amount = remaining;
  13066. }
  13067. #endif
  13068. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13069. WFIFOW(fd, 0) = cmd;
  13070. #if PACKETVER >= 20170419
  13071. WFIFOB(fd, 4) = 1; // Unknown
  13072. offset = 5;
  13073. #else
  13074. WFIFOB(fd, 4) = type;
  13075. WFIFOB(fd, 5) = amount;
  13076. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13077. offset = 7;
  13078. #endif
  13079. for( amount = 0; i >= 0; i-- ){
  13080. msg = &md->msg[i];
  13081. if (msg->id < 1)
  13082. continue;
  13083. #if PACKETVER < 20170419
  13084. if (msg->type != type)
  13085. continue;
  13086. #endif
  13087. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13088. continue;
  13089. #if PACKETVER >= 20170419
  13090. WFIFOB(fd, offset) = msg->type;
  13091. offset += 1;
  13092. #endif
  13093. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13094. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13095. mailType = MAIL_TYPE_TEXT; // Normal letter
  13096. if( msg->zeny > 0 ){
  13097. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13098. }
  13099. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13100. if( msg->item[k].nameid > 0 ){
  13101. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13102. break;
  13103. }
  13104. }
  13105. #if PACKETVER >= 20170419
  13106. // If it came from an npc?
  13107. if( !msg->send_id ){
  13108. mailType |= MAIL_TYPE_NPC;
  13109. }
  13110. #endif
  13111. WFIFOB(fd, offset + 9) = mailType;
  13112. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13113. #if PACKETVER < 20170419
  13114. // How much time has passed since you received the mail
  13115. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13116. offset += 4;
  13117. #endif
  13118. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13119. if( msg->scheduled_deletion > 0 ){
  13120. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13121. }else{
  13122. // Fake the scheduled deletion to one year in the future
  13123. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13124. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13125. }
  13126. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13127. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13128. offset += 40 + titleLength;
  13129. }
  13130. WFIFOW(fd, 2) = (int16)offset;
  13131. WFIFOSET(fd, offset);
  13132. #endif
  13133. }
  13134. /// Mail inbox list request.
  13135. /// 023f (CZ_MAIL_GET_LIST)
  13136. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13137. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13138. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13139. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13140. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13141. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13142. #if PACKETVER < 20150513
  13143. struct mail_data* md = &sd->mail.inbox;
  13144. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13145. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13146. else
  13147. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13148. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13149. mail_removezeny(sd, false);
  13150. #else
  13151. int cmd = RFIFOW(fd, 0);
  13152. #if PACKETVER < 20170419
  13153. uint8 openType = RFIFOB(fd, 2);
  13154. uint64 mailId = RFIFOQ(fd, 3);
  13155. #else
  13156. uint8 openType;
  13157. uint64 mailId = RFIFOQ(fd, 2);
  13158. int i;
  13159. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13160. if( i == MAIL_MAX_INBOX ){
  13161. openType = MAIL_INBOX_NORMAL;
  13162. mailId = 0;
  13163. }else{
  13164. openType = sd->mail.inbox.msg[i].type;
  13165. mailId = 0;
  13166. }
  13167. #endif
  13168. switch( openType ){
  13169. case MAIL_INBOX_NORMAL:
  13170. case MAIL_INBOX_ACCOUNT:
  13171. case MAIL_INBOX_RETURNED:
  13172. break;
  13173. default:
  13174. // Unknown type: ignore request
  13175. return;
  13176. }
  13177. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13178. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13179. return;
  13180. }
  13181. // If it is not a next page request
  13182. if( cmd != 0x9ee ){
  13183. mailId = 0;
  13184. }
  13185. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13186. #endif
  13187. }
  13188. /// Opens a mail
  13189. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13190. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13191. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13192. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13193. /// { }*n
  13194. // TODO: Packet description => for repeated block
  13195. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13196. int i, fd = sd->fd;
  13197. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13198. if( i == MAIL_MAX_INBOX ) {
  13199. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13200. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13201. return;
  13202. } else {
  13203. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13204. struct item *item;
  13205. struct item_data *data;
  13206. int msg_len = strlen(msg->body);
  13207. if( msg_len == 0 ) {
  13208. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13209. msg_len = strlen(msg->body);
  13210. }
  13211. #if PACKETVER < 20150513
  13212. item = &msg->item[0];
  13213. int len = 101 + msg_len;
  13214. WFIFOHEAD(fd,len);
  13215. WFIFOW(fd,0) = 0x242;
  13216. WFIFOW(fd,2) = len;
  13217. WFIFOL(fd,4) = msg->id;
  13218. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13219. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13220. WFIFOL(fd,72) = 0;
  13221. WFIFOL(fd,76) = msg->zeny;
  13222. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13223. WFIFOL(fd,80) = item->amount;
  13224. WFIFOW(fd,84) = client_nameid( item->nameid );
  13225. WFIFOW(fd,86) = itemtype( item->nameid );
  13226. WFIFOB(fd,88) = item->identify;
  13227. WFIFOB(fd,89) = item->attribute;
  13228. WFIFOB(fd,90) = item->refine;
  13229. WFIFOW(fd,91) = item->card[0];
  13230. WFIFOW(fd,93) = item->card[1];
  13231. WFIFOW(fd,95) = item->card[2];
  13232. WFIFOW(fd,97) = item->card[3];
  13233. } else // no item, set all to zero
  13234. memset(WFIFOP(fd,80), 0x00, 19);
  13235. WFIFOB(fd,99) = (unsigned char)msg_len;
  13236. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13237. WFIFOSET(fd,len);
  13238. #else
  13239. msg_len += 1; // Zero Termination
  13240. int length = sizeof( struct PACKET_ZC_READ_MAIL ) + MAIL_BODY_LENGTH + sizeof( struct mail_item ) * MAIL_MAX_ITEM;
  13241. WFIFOHEAD( fd, length );
  13242. struct PACKET_ZC_READ_MAIL *p = (struct PACKET_ZC_READ_MAIL *)WFIFOP( fd, 0 );
  13243. p->PacketType = rodexread;
  13244. p->PacketLength = length;
  13245. p->opentype = msg->type;
  13246. p->MailID = msg->id;
  13247. p->TextcontentsLength = msg_len;
  13248. p->zeny = msg->zeny;
  13249. int offset = sizeof( struct PACKET_ZC_READ_MAIL );
  13250. safestrncpy( WFIFOCP( fd, offset ), msg->body, msg_len );
  13251. offset += msg_len;
  13252. int count = 0;
  13253. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13254. item = &msg->item[j];
  13255. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13256. struct mail_item* mailitem = (struct mail_item *)WFIFOP( fd, offset );
  13257. mailitem->ITID = client_nameid( item->nameid );
  13258. mailitem->count = item->amount;
  13259. mailitem->type = itemtype( item->nameid );
  13260. mailitem->IsIdentified = item->identify ? 1 : 0;
  13261. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13262. mailitem->refiningLevel = item->refine;
  13263. mailitem->location = pc_equippoint_sub( sd, data );
  13264. mailitem->viewSprite = data->look;
  13265. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13266. clif_addcards( &mailitem->slot, item );
  13267. clif_add_random_options( mailitem->optionData, item );
  13268. offset += sizeof( struct mail_item );
  13269. count++;
  13270. }
  13271. }
  13272. p->ItemCnt = count;
  13273. p->PacketLength = sizeof( struct PACKET_ZC_READ_MAIL ) + p->TextcontentsLength + sizeof( struct mail_item ) * p->ItemCnt;
  13274. WFIFOSET( fd, p->PacketLength );
  13275. #endif
  13276. if (msg->status == MAIL_UNREAD) {
  13277. msg->status = MAIL_READ;
  13278. intif_Mail_read(mail_id);
  13279. clif_parse_Mail_refreshinbox(fd, sd);
  13280. sd->mail.inbox.unread--;
  13281. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13282. }
  13283. }
  13284. }
  13285. /// Request to open a mail.
  13286. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13287. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13288. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13289. #if PACKETVER < 20150513
  13290. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13291. #else
  13292. //uint8 openType = RFIFOB(fd, 2);
  13293. int mail_id = (int)RFIFOQ(fd, 3);
  13294. #endif
  13295. if( mail_id <= 0 )
  13296. return;
  13297. if( mail_invalid_operation(sd) )
  13298. return;
  13299. clif_Mail_read(sd, mail_id);
  13300. }
  13301. /// Allow a player to begin writing a mail
  13302. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13303. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13304. int fd = sd->fd;
  13305. WFIFOHEAD(fd, 27);
  13306. WFIFOW(fd, 0) = 0xa12;
  13307. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13308. WFIFOB(fd, 26) = success;
  13309. WFIFOSET(fd, 27);
  13310. }
  13311. /// Request to start writing a mail
  13312. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13313. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13314. char name[NAME_LENGTH];
  13315. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13316. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13317. clif_send_Mail_beginwrite_ack(sd, name, false);
  13318. return;
  13319. }
  13320. mail_clear(sd);
  13321. sd->state.mail_writing = true;
  13322. clif_send_Mail_beginwrite_ack(sd, name,true);
  13323. }
  13324. /// Notification that the client cancelled writing a mail
  13325. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13326. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13327. sd->state.mail_writing = false;
  13328. }
  13329. /// Give the client information about the recipient, if available
  13330. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13331. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13332. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13333. int fd = sd->fd;
  13334. #if PACKETVER <= 20160302
  13335. int cmd = 0xa14;
  13336. #else
  13337. int cmd = 0xa51;
  13338. #endif
  13339. WFIFOHEAD(fd, packet_len(cmd));
  13340. WFIFOW(fd, 0) = cmd;
  13341. WFIFOL(fd, 2) = char_id;
  13342. WFIFOW(fd, 6) = class_;
  13343. WFIFOW(fd, 8) = level;
  13344. #if PACKETVER >= 20160302
  13345. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13346. #endif
  13347. WFIFOSET(fd, packet_len(cmd));
  13348. }
  13349. /// Request information about the recipient
  13350. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13351. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13352. static char name[NAME_LENGTH];
  13353. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13354. intif_mail_checkreceiver(sd, name);
  13355. }
  13356. /// Request to receive mail's attachment.
  13357. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13358. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13359. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13360. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13361. int i;
  13362. struct mail_message* msg;
  13363. #if PACKETVER < 20150513
  13364. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13365. int attachment = MAIL_ATT_ALL;
  13366. #else
  13367. uint16 packet_id = RFIFOW(fd, 0);
  13368. int mail_id = (int)RFIFOQ(fd, 2);
  13369. //int openType = RFIFOB(fd, 10);
  13370. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13371. #endif
  13372. if( !chrif_isconnected() )
  13373. return;
  13374. if( mail_id <= 0 )
  13375. return;
  13376. if( mail_invalid_operation(sd) )
  13377. return;
  13378. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13379. if( i == MAIL_MAX_INBOX )
  13380. return;
  13381. msg = &sd->mail.inbox.msg[i];
  13382. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13383. attachment &= ~MAIL_ATT_ZENY;
  13384. }
  13385. if( attachment&MAIL_ATT_ITEM ){
  13386. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13387. // No items were found
  13388. if( i == MAIL_MAX_ITEM ){
  13389. attachment &= ~MAIL_ATT_ITEM;
  13390. }
  13391. }
  13392. // Either no attachment requested at all or there are no zeny or items in the mail
  13393. if( attachment == MAIL_ATT_NONE ){
  13394. return;
  13395. }
  13396. if( attachment&MAIL_ATT_ZENY ){
  13397. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13398. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13399. return;
  13400. }else{
  13401. // To make sure another request fails
  13402. msg->zeny = 0;
  13403. }
  13404. }
  13405. if( attachment&MAIL_ATT_ITEM ){
  13406. int new_ = 0, totalweight = 0;
  13407. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13408. struct item* item = &msg->item[i];
  13409. if( item->nameid > 0 && item->amount > 0 ){
  13410. struct item_data *data;
  13411. if((data = itemdb_exists(item->nameid)) == NULL)
  13412. continue;
  13413. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13414. case CHKADDITEM_NEW:
  13415. new_++;
  13416. break;
  13417. case CHKADDITEM_OVERAMOUNT:
  13418. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13419. return;
  13420. }
  13421. totalweight += data->weight * item->amount;
  13422. }
  13423. }
  13424. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13425. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13426. return;
  13427. }else if( pc_inventoryblank(sd) < new_ ){
  13428. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13429. return;
  13430. }
  13431. // To make sure another request fails
  13432. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13433. }
  13434. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13435. clif_Mail_read(sd, mail_id);
  13436. }
  13437. /// Request to delete a mail.
  13438. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13439. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13440. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13441. #if PACKETVER < 20150513
  13442. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13443. #else
  13444. //int openType = RFIFOB(fd, 2);
  13445. int mail_id = (int)RFIFOQ(fd, 3);
  13446. #endif
  13447. int i, j;
  13448. if( !chrif_isconnected() )
  13449. return;
  13450. if( mail_id <= 0 )
  13451. return;
  13452. if( mail_invalid_operation(sd) )
  13453. return;
  13454. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13455. if (i < MAIL_MAX_INBOX) {
  13456. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13457. // can't delete mail without removing zeny first
  13458. if( msg->zeny > 0 ){
  13459. clif_mail_delete(sd, msg, false);
  13460. return;
  13461. }
  13462. // can't delete mail without removing attachment(s) first
  13463. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13464. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13465. clif_mail_delete(sd, msg, false);
  13466. return;
  13467. }
  13468. }
  13469. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13470. sd->mail.inbox.unread--;
  13471. clif_Mail_new(sd,0,NULL,NULL);
  13472. }
  13473. }
  13474. }
  13475. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13476. /// 0273 <mail id>.L <receive name>.24B
  13477. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13478. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13479. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13480. int i;
  13481. if( mail_id <= 0 )
  13482. return;
  13483. if( mail_invalid_operation(sd) )
  13484. return;
  13485. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13486. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13487. intif_Mail_return(sd->status.char_id, mail_id);
  13488. else
  13489. clif_Mail_return(sd->fd, mail_id, 1);
  13490. }
  13491. /// Request to add an item or Zeny to mail.
  13492. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13493. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13494. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13495. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13496. int idx = RFIFOW(fd,info->pos[0]);
  13497. #if PACKETVER < 20150513
  13498. int amount = RFIFOL(fd,info->pos[1]);
  13499. #else
  13500. int amount = RFIFOW(fd,info->pos[1]);
  13501. #endif
  13502. unsigned char flag;
  13503. if( !chrif_isconnected() )
  13504. return;
  13505. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13506. return;
  13507. flag = mail_setitem(sd, idx, amount);
  13508. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13509. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13510. }else{
  13511. clif_Mail_setattachment(sd,idx,amount,flag);
  13512. }
  13513. }
  13514. /// Remove an item from a mail
  13515. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13516. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13517. int fd = sd->fd;
  13518. WFIFOHEAD(fd, 9);
  13519. WFIFOW(fd, 0) = 0xa07;
  13520. WFIFOB(fd, 2) = success;
  13521. WFIFOW(fd, 3) = index;
  13522. WFIFOW(fd, 5) = amount;
  13523. int total = 0;
  13524. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13525. if( sd->mail.item[i].nameid == 0 ){
  13526. break;
  13527. }
  13528. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13529. }
  13530. WFIFOW(fd, 7) = total;
  13531. WFIFOSET(fd, 9);
  13532. }
  13533. /// Request to reset mail item and/or Zeny
  13534. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13535. /// type:
  13536. /// 0 = reset all
  13537. /// 1 = remove item
  13538. /// 2 = remove zeny
  13539. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13540. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13541. {
  13542. #if PACKETVER < 20150513
  13543. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13544. if (type == 0 || type == 1)
  13545. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13546. if (type == 0 || type == 2)
  13547. mail_removezeny(sd, false);
  13548. #else
  13549. uint16 index = RFIFOW(fd, 2);
  13550. uint16 count = RFIFOW(fd, 4);
  13551. mail_removeitem(sd,0,index,count);
  13552. #endif
  13553. }
  13554. /// Request to send mail
  13555. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13556. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13557. /// 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)
  13558. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13559. #if PACKETVER < 20150513
  13560. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13561. if( !chrif_isconnected() )
  13562. return;
  13563. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13564. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13565. return;
  13566. }
  13567. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13568. #else
  13569. uint16 length = RFIFOW(fd, 2);
  13570. if( length < 0x3e ){
  13571. ShowWarning("Too short...\n");
  13572. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13573. return;
  13574. }
  13575. // Forged request without a begin writing packet?
  13576. if( !sd->state.mail_writing ){
  13577. return; // Ignore it
  13578. }
  13579. char receiver[NAME_LENGTH];
  13580. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13581. // char sender[NAME_LENGTH];
  13582. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13583. uint64 zeny = RFIFOQ(fd, 52);
  13584. uint16 titleLength = RFIFOW(fd, 60);
  13585. uint16 textLength = RFIFOW(fd, 62);
  13586. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13587. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13588. char title[MAIL_TITLE_LENGTH];
  13589. char text[MAIL_BODY_LENGTH];
  13590. #if PACKETVER <= 20160330
  13591. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13592. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13593. #else
  13594. // 64 = <char id>.L
  13595. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13596. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13597. #endif
  13598. if( zeny > 0 ){
  13599. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13600. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13601. return;
  13602. }
  13603. }
  13604. mail_send(sd, receiver, title, text, realTextLength);
  13605. #endif
  13606. }
  13607. /// AUCTION SYSTEM
  13608. /// By Zephyrus
  13609. ///
  13610. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13611. /// 025f <type>.L
  13612. /// type:
  13613. /// 0 = open
  13614. /// 1 = close
  13615. void clif_Auction_openwindow(struct map_session_data *sd)
  13616. {
  13617. int fd = sd->fd;
  13618. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13619. return;
  13620. if( !battle_config.feature_auction )
  13621. return;
  13622. WFIFOHEAD(fd,packet_len(0x25f));
  13623. WFIFOW(fd,0) = 0x25f;
  13624. WFIFOL(fd,2) = 0;
  13625. WFIFOSET(fd,packet_len(0x25f));
  13626. }
  13627. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13628. /// 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 }*
  13629. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13630. {
  13631. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13632. struct auction_data auction;
  13633. WFIFOHEAD(fd,12 + (count * 83));
  13634. WFIFOW(fd,0) = 0x252;
  13635. WFIFOW(fd,2) = 12 + (count * 83);
  13636. WFIFOL(fd,4) = pages;
  13637. WFIFOL(fd,8) = count;
  13638. for( i = 0; i < count; i++ ) {
  13639. int k = 12 + (i * 83);
  13640. memcpy(&auction, RBUFP(buf,i * len), len);
  13641. WFIFOL(fd,k) = auction.auction_id;
  13642. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13643. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13644. WFIFOL(fd,30+k) = auction.type;
  13645. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13646. WFIFOB(fd,36+k) = auction.item.identify;
  13647. WFIFOB(fd,37+k) = auction.item.attribute;
  13648. WFIFOB(fd,38+k) = auction.item.refine;
  13649. WFIFOW(fd,39+k) = auction.item.card[0];
  13650. WFIFOW(fd,41+k) = auction.item.card[1];
  13651. WFIFOW(fd,43+k) = auction.item.card[2];
  13652. WFIFOW(fd,45+k) = auction.item.card[3];
  13653. WFIFOL(fd,47+k) = auction.price;
  13654. WFIFOL(fd,51+k) = auction.buynow;
  13655. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13656. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13657. }
  13658. WFIFOSET(fd,WFIFOW(fd,2));
  13659. }
  13660. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13661. /// 0256 <index>.W <result>.B
  13662. /// result:
  13663. /// 0 = success
  13664. /// 1 = failure
  13665. static void clif_Auction_setitem(int fd, int index, bool fail)
  13666. {
  13667. WFIFOHEAD(fd,packet_len(0x256));
  13668. WFIFOW(fd,0) = 0x256;
  13669. WFIFOW(fd,2) = index;
  13670. WFIFOB(fd,4) = fail;
  13671. WFIFOSET(fd,packet_len(0x256));
  13672. }
  13673. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13674. /// 024b <type>.W
  13675. /// type:
  13676. /// 0 = create (any other action in auction window)
  13677. /// 1 = cancel (cancel pressed on register tab)
  13678. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13679. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13680. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13681. if( sd->auction.amount > 0 )
  13682. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13683. sd->auction.amount = 0;
  13684. }
  13685. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13686. /// 024c <index>.W <count>.L
  13687. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13688. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13689. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13690. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13691. struct item_data *item;
  13692. if( !battle_config.feature_auction )
  13693. return;
  13694. if( sd->auction.amount > 0 )
  13695. sd->auction.amount = 0;
  13696. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13697. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13698. return;
  13699. }
  13700. 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.
  13701. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13702. return;
  13703. }
  13704. if( (item = itemdb_exists(sd->inventory.u.items_inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC || item->type == IT_SHADOWGEAR) )
  13705. { // Consumable or pets are not allowed
  13706. clif_Auction_setitem(sd->fd, idx, true);
  13707. return;
  13708. }
  13709. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13710. !sd->inventory.u.items_inventory[idx].identify ||
  13711. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13712. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13713. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13714. clif_Auction_setitem(sd->fd, idx, true);
  13715. return;
  13716. }
  13717. sd->auction.index = idx;
  13718. sd->auction.amount = amount;
  13719. clif_Auction_setitem(fd, idx + 2, false);
  13720. }
  13721. /// Result from an auction action (ZC_AUCTION_RESULT).
  13722. /// 0250 <result>.B
  13723. /// result:
  13724. /// 0 = You have failed to bid into the auction
  13725. /// 1 = You have successfully bid in the auction
  13726. /// 2 = The auction has been canceled
  13727. /// 3 = An auction with at least one bidder cannot be canceled
  13728. /// 4 = You cannot register more than 5 items in an auction at a time
  13729. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13730. /// 6 = You have won the auction
  13731. /// 7 = You have failed to win the auction
  13732. /// 8 = You do not have enough Zeny
  13733. /// 9 = You cannot place more than 5 bids at a time
  13734. void clif_Auction_message(int fd, unsigned char flag)
  13735. {
  13736. WFIFOHEAD(fd,packet_len(0x250));
  13737. WFIFOW(fd,0) = 0x250;
  13738. WFIFOB(fd,2) = flag;
  13739. WFIFOSET(fd,packet_len(0x250));
  13740. }
  13741. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13742. /// 025e <result>.W
  13743. /// result:
  13744. /// 0 = You have ended the auction
  13745. /// 1 = You cannot end the auction
  13746. /// 2 = Auction ID is incorrect
  13747. void clif_Auction_close(int fd, unsigned char flag)
  13748. {
  13749. WFIFOHEAD(fd,packet_len(0x25e));
  13750. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13751. WFIFOW(fd,2) = flag;
  13752. WFIFOSET(fd,packet_len(0x25e));
  13753. }
  13754. /// Request to add an auction (CZ_AUCTION_ADD).
  13755. /// 024d <now money>.L <max money>.L <delete hour>.W
  13756. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13757. {
  13758. struct auction_data auction;
  13759. struct item_data *item;
  13760. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13761. if( !battle_config.feature_auction )
  13762. return;
  13763. auction.price = RFIFOL(fd,info->pos[0]);
  13764. auction.buynow = RFIFOL(fd,info->pos[1]);
  13765. auction.hours = RFIFOW(fd,info->pos[2]);
  13766. // Invalid Situations...
  13767. if( sd->auction.amount < 1 ) {
  13768. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13769. return;
  13770. }
  13771. if( auction.price >= auction.buynow ) {
  13772. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13773. return;
  13774. }
  13775. if( auction.hours < 1 || auction.hours > 48 ) {
  13776. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13777. return;
  13778. }
  13779. // Auction checks...
  13780. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13781. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13782. clif_Auction_message(fd, 2); // The auction has been canceled
  13783. return;
  13784. }
  13785. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13786. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13787. return;
  13788. }
  13789. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13790. auction.buynow = battle_config.auction_maximumprice;
  13791. if( auction.price >= auction.buynow )
  13792. auction.price = auction.buynow - 1;
  13793. }
  13794. auction.auction_id = 0;
  13795. auction.seller_id = sd->status.char_id;
  13796. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13797. auction.buyer_id = 0;
  13798. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13799. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13800. {
  13801. clif_Auction_message(fd, 2); // The auction has been canceled
  13802. return;
  13803. }
  13804. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13805. { // Just in case
  13806. clif_Auction_message(fd, 2); // The auction has been canceled
  13807. return;
  13808. }
  13809. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13810. auction.type = item->type;
  13811. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13812. auction.item.amount = 1;
  13813. auction.timestamp = 0;
  13814. if( !intif_Auction_register(&auction) )
  13815. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13816. else
  13817. {
  13818. int zeny = auction.hours*battle_config.auction_feeperhour;
  13819. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13820. sd->auction.amount = 0;
  13821. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13822. }
  13823. }
  13824. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13825. /// 024e <auction id>.L
  13826. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13827. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13828. intif_Auction_cancel(sd->status.char_id, auction_id);
  13829. }
  13830. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13831. /// 025d <auction id>.L
  13832. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13833. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13834. intif_Auction_close(sd->status.char_id, auction_id);
  13835. }
  13836. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13837. /// 024f <auction id>.L <money>.L
  13838. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13839. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13840. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13841. int bid = RFIFOL(fd,info->pos[1]);
  13842. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13843. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13844. return;
  13845. }
  13846. if( bid <= 0 )
  13847. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13848. else if( bid > sd->status.zeny )
  13849. clif_Auction_message(fd, 8); // You do not have enough zeny
  13850. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13851. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13852. else {
  13853. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13854. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13855. }
  13856. }
  13857. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13858. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13859. /// search type:
  13860. /// 0 = armor
  13861. /// 1 = weapon
  13862. /// 2 = card
  13863. /// 3 = misc
  13864. /// 4 = name search
  13865. /// 5 = auction id search
  13866. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13867. char search_text[NAME_LENGTH];
  13868. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13869. short type = RFIFOW(fd,info->pos[0]);
  13870. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13871. int page = RFIFOW(fd,info->pos[3]);
  13872. if( !battle_config.feature_auction )
  13873. return;
  13874. clif_parse_Auction_cancelreg(fd, sd);
  13875. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13876. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13877. }
  13878. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13879. /// 025c <type>.W
  13880. /// type:
  13881. /// 0 = sell (own auctions)
  13882. /// 1 = buy (own bids)
  13883. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13884. {
  13885. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13886. if( !battle_config.feature_auction )
  13887. return;
  13888. clif_parse_Auction_cancelreg(fd, sd);
  13889. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13890. }
  13891. /// CASH/POINT SHOP
  13892. ///
  13893. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  13894. nullpo_retv( sd );
  13895. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  13896. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  13897. p.cashPoints = sd->cashPoints;
  13898. p.kafraPoints = sd->kafraPoints;
  13899. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  13900. p.tab = tab;
  13901. #endif
  13902. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13903. }
  13904. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13905. nullpo_retv( sd );
  13906. int tab = 0;
  13907. #if PACKETVER >= 20191224
  13908. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  13909. tab = p->tab;
  13910. #endif
  13911. sd->state.cashshop_open = true;
  13912. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13913. clif_cashshop_open( sd, tab );
  13914. }
  13915. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13916. sd->state.cashshop_open = false;
  13917. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13918. // No need to do anything here
  13919. }
  13920. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13921. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13922. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13923. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13924. int j;
  13925. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13926. return;
  13927. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13928. WFIFOW(fd, 0) = 0x8c0;
  13929. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13930. WFIFOL(fd, 4) = tab;
  13931. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13932. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13933. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  13934. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13935. }
  13936. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13937. }
  13938. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13939. void clif_cashshop_list( struct map_session_data* sd ){
  13940. nullpo_retv( sd );
  13941. int fd = sd->fd;
  13942. if( !session_isActive( fd ) ){
  13943. return;
  13944. }
  13945. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13946. // Skip empty tabs, the client only expects filled ones
  13947. if( cash_shop_items[tab].count == 0 ){
  13948. continue;
  13949. }
  13950. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  13951. WFIFOHEAD( fd, len );
  13952. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  13953. p->packetType = 0x8ca;
  13954. p->packetLength = len;
  13955. p->count = cash_shop_items[tab].count;
  13956. p->tabNum = tab;
  13957. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  13958. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  13959. p->items[i].price = cash_shop_items[tab].item[i]->price;
  13960. }
  13961. WFIFOSET( fd, len );
  13962. }
  13963. }
  13964. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13965. if( !sd->status.cashshop_sent ) {
  13966. clif_cashshop_list( sd );
  13967. #if PACKETVER_SUPPORTS_SALES
  13968. sale_notify_login(sd);
  13969. #endif
  13970. sd->status.cashshop_sent = true;
  13971. }
  13972. }
  13973. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13974. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13975. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13976. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  13977. nullpo_retv( sd );
  13978. nullpo_retv( nd );
  13979. int fd = sd->fd;
  13980. if( !session_isActive( fd ) ){
  13981. return;
  13982. }
  13983. sd->npc_shopid = nd->bl.id;
  13984. int cost[2] = { 0, 0 };
  13985. npc_shop_currency_type( sd, nd, cost, true );
  13986. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  13987. WFIFOHEAD( fd, len );
  13988. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  13989. p->packetType = 0x287;
  13990. p->packetLength = len;
  13991. p->cashPoints = cost[0];
  13992. #if PACKETVER >= 20070711
  13993. p->kafraPoints = cost[1];
  13994. #endif
  13995. for( int i = 0; i < nd->u.shop.count; i++ ) {
  13996. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  13997. p->items[i].price = nd->u.shop.shop_item[i].value;
  13998. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  13999. p->items[i].itemType = itemtype( id->nameid );
  14000. p->items[i].itemId = client_nameid( id->nameid );
  14001. }
  14002. WFIFOSET( fd, len );
  14003. }
  14004. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14005. /// 0289 <cash point>.L <error>.W
  14006. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14007. /// error:
  14008. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14009. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14010. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14011. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14012. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14013. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14014. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14015. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14016. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14017. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14018. {
  14019. int fd, cost[2] = { 0, 0 };
  14020. struct npc_data *nd;
  14021. nullpo_retv(sd);
  14022. fd = sd->fd;
  14023. nd = map_id2nd(sd->npc_shopid);
  14024. npc_shop_currency_type(sd, nd, cost, false);
  14025. WFIFOHEAD(fd, packet_len(0x289));
  14026. WFIFOW(fd,0) = 0x289;
  14027. WFIFOL(fd,2) = cost[0];
  14028. #if PACKETVER < 20070711
  14029. WFIFOW(fd,6) = TOW(error);
  14030. #else
  14031. WFIFOL(fd,6) = cost[1];
  14032. WFIFOW(fd,10) = TOW(error);
  14033. #endif
  14034. WFIFOSET(fd, packet_len(0x289));
  14035. }
  14036. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  14037. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14038. nullpo_retv( sd );
  14039. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14040. packet.packetType = 0x849;
  14041. packet.itemId = client_nameid( item_id );
  14042. packet.result = result;
  14043. packet.cashPoints = sd->cashPoints;
  14044. packet.kafraPoints = sd->kafraPoints;
  14045. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14046. #endif
  14047. }
  14048. /// Request to buy item(s) from cash shop.
  14049. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14050. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14051. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14052. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14053. nullpo_retv( sd );
  14054. if( sd->state.trading || !sd->npc_shopid ){
  14055. clif_cashshop_ack( sd, 1 );
  14056. return;
  14057. }
  14058. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14059. #if PACKETVER < 20070711
  14060. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14061. #elif PACKETVER < 20101116
  14062. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14063. #else
  14064. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14065. 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 ){
  14066. 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 );
  14067. return;
  14068. }
  14069. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, p->count, p->items ) );
  14070. #endif
  14071. }
  14072. /// Request to buy item(s) from cash shop.
  14073. /// 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)
  14074. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14075. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14076. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14077. 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 ){
  14078. 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 );
  14079. return;
  14080. }
  14081. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14082. }
  14083. /// Adoption System
  14084. ///
  14085. /// Adoption message (ZC_BABYMSG).
  14086. /// 0216 <msg>.L
  14087. /// msg:
  14088. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14089. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14090. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14091. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14092. {
  14093. int fd = sd->fd;
  14094. WFIFOHEAD(fd,6);
  14095. WFIFOW(fd,0) = 0x216;
  14096. WFIFOL(fd,2) = type;
  14097. WFIFOSET(fd,6);
  14098. }
  14099. /// Adoption confirmation (ZC_REQ_BABY).
  14100. /// 01f6 <account id>.L <char id>.L <name>.B
  14101. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14102. {
  14103. int fd = sd->fd;
  14104. WFIFOHEAD(fd,34);
  14105. WFIFOW(fd,0) = 0x1f6;
  14106. WFIFOL(fd,2) = src->status.account_id;
  14107. WFIFOL(fd,6) = p_id;
  14108. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14109. WFIFOSET(fd,34);
  14110. }
  14111. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14112. /// 01f9 <account id>.L
  14113. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14114. {
  14115. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14116. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14117. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14118. {
  14119. tsd->adopt_invite = sd->status.account_id;
  14120. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14121. }
  14122. }
  14123. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14124. /// 01f7 <account id>.L <char id>.L <answer>.L
  14125. /// answer:
  14126. /// 0 = rejected
  14127. /// 1 = accepted
  14128. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14129. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14130. int p1_id = RFIFOL(fd,info->pos[0]);
  14131. int p2_id = RFIFOL(fd,info->pos[1]);
  14132. int result = RFIFOL(fd,info->pos[2]);
  14133. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14134. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14135. int pid = sd->adopt_invite;
  14136. sd->adopt_invite = 0;
  14137. if( p1_sd == NULL || p2_sd == NULL )
  14138. return; // Both players need to be online
  14139. if( pid != p1_sd->status.account_id )
  14140. return; // Incorrect values
  14141. if( result == 0 )
  14142. return; // Rejected
  14143. pc_adoption(p1_sd, p2_sd, sd);
  14144. }
  14145. /// Convex Mirror (ZC_BOSS_INFO).
  14146. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14147. /// infoType:
  14148. /// BOSS_INFO_NOT = No boss on this map.
  14149. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14150. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14151. /// BOSS_INFO_DEAD = Boss is dead.
  14152. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14153. {
  14154. int fd = sd->fd;
  14155. WFIFOHEAD(fd,70);
  14156. memset(WFIFOP(fd,0),0,70);
  14157. WFIFOW(fd,0) = 0x293;
  14158. switch (flag) {
  14159. case BOSS_INFO_NOT:
  14160. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14161. // No data required
  14162. break;
  14163. case BOSS_INFO_ALIVE:
  14164. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14165. // Update X/Y
  14166. WFIFOL(fd,3) = md->bl.x;
  14167. WFIFOL(fd,7) = md->bl.y;
  14168. break;
  14169. case BOSS_INFO_ALIVE_WITHMSG:
  14170. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14171. // Current X/Y
  14172. WFIFOL(fd,3) = md->bl.x;
  14173. WFIFOL(fd,7) = md->bl.y;
  14174. break;
  14175. case BOSS_INFO_DEAD:
  14176. {
  14177. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14178. unsigned int seconds;
  14179. int hours, minutes;
  14180. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14181. hours = seconds / (60 * 60);
  14182. seconds = seconds - (60 * 60 * hours);
  14183. minutes = seconds / 60;
  14184. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14185. // Add respawn info
  14186. WFIFOW(fd,11) = hours; // Hours
  14187. WFIFOW(fd,13) = minutes; // Minutes
  14188. }
  14189. break;
  14190. }
  14191. if (md != NULL)
  14192. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14193. WFIFOSET(fd,70);
  14194. }
  14195. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14196. /// 02d6 <account id>.L
  14197. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14198. {
  14199. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14200. struct map_session_data* tsd = map_id2sd(aid);
  14201. if (!tsd)
  14202. return;
  14203. if (sd->bl.m != tsd->bl.m)
  14204. return;
  14205. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14206. clif_viewequip_ack(sd, tsd);
  14207. else
  14208. clif_msg(sd, VIEW_EQUIP_FAIL);
  14209. }
  14210. /// Request to a configuration.
  14211. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14212. /// type: see enum e_config_type
  14213. /// flag:
  14214. /// false = disabled
  14215. /// true = enabled
  14216. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14217. int cmd = RFIFOW(fd,0);
  14218. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14219. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14220. switch( type ){
  14221. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14222. sd->status.show_equip = flag;
  14223. break;
  14224. case CONFIG_PET_AUTOFEED:
  14225. // Player can not click this if he does not have a pet
  14226. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14227. return;
  14228. }
  14229. sd->pd->pet.autofeed = flag;
  14230. break;
  14231. case CONFIG_HOMUNCULUS_AUTOFEED:
  14232. // Player can not click this if he does not have a homunculus or it is vaporized
  14233. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14234. return;
  14235. }
  14236. sd->hd->homunculus.autofeed = flag;
  14237. break;
  14238. default:
  14239. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14240. return;
  14241. }
  14242. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14243. }
  14244. /// Request to change party invitation tick.
  14245. /// value:
  14246. /// 0 = disabled
  14247. /// 1 = enabled
  14248. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14249. {
  14250. bool flag = RFIFOB(fd,6) ? true : false;
  14251. sd->status.allow_party = flag;
  14252. clif_partytickack(sd, flag);
  14253. }
  14254. /// Questlog System [Kevin] [Inkfish]
  14255. ///
  14256. /**
  14257. * Safe check to init packet len & quest num for player.
  14258. * @param def_len
  14259. * @param info_len Length of each quest info.
  14260. * @param avail_quests Avail quests that player has.
  14261. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14262. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14263. **/
  14264. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14265. (*limit_out) = (0xFFFF - def_len) / info_len;
  14266. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14267. (*len_out) = ((*limit_out) * info_len) + def_len;
  14268. }
  14269. /// Sends list of all quest states
  14270. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14271. /// 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)
  14272. /// 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)
  14273. void clif_quest_send_list(struct map_session_data *sd)
  14274. {
  14275. int fd = sd->fd;
  14276. int i;
  14277. int offset = 8;
  14278. int limit = 0;
  14279. #if PACKETVER >= 20141022
  14280. #if PACKETVER >= 20150513
  14281. int size = 22 + NAME_LENGTH;
  14282. #else
  14283. int size = 10 + NAME_LENGTH;
  14284. #endif
  14285. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14286. WFIFOHEAD(fd,i);
  14287. #if PACKETVER >= 20150513
  14288. WFIFOW(fd, 0) = 0x9f8;
  14289. #else
  14290. WFIFOW(fd, 0) = 0x97a;
  14291. #endif
  14292. WFIFOL(fd, 4) = limit;
  14293. for (i = 0; i < limit; i++) {
  14294. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14295. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14296. offset += 4;
  14297. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14298. offset++;
  14299. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14300. offset += 4;
  14301. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14302. offset += 4;
  14303. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14304. offset += 2;
  14305. if (!qi->objectives.empty()) {
  14306. struct mob_db *mob;
  14307. for (int j = 0; j < qi->objectives.size(); j++) {
  14308. mob = mob_db(qi->objectives[j]->mob_id);
  14309. #if PACKETVER >= 20150513
  14310. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14311. offset += 4;
  14312. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14313. offset += 4;
  14314. #endif
  14315. WFIFOL(fd, offset) = qi->objectives[j]->mob_id;
  14316. offset += 4;
  14317. #if PACKETVER >= 20150513
  14318. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14319. offset += 2;
  14320. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14321. offset += 2;
  14322. #endif
  14323. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14324. offset += 2;
  14325. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14326. offset += 2;
  14327. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14328. offset += NAME_LENGTH;
  14329. }
  14330. }
  14331. }
  14332. WFIFOW(fd, 2) = offset;
  14333. WFIFOSET(fd, offset);
  14334. #else
  14335. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14336. WFIFOHEAD(fd,i);
  14337. WFIFOW(fd, 0) = 0x2b1;
  14338. WFIFOL(fd, 4) = limit;
  14339. for (i = 0; i < limit; i++) {
  14340. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14341. offset += 4;
  14342. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14343. offset += 1;
  14344. }
  14345. WFIFOW(fd, 2) = offset;
  14346. WFIFOSET(fd, offset);
  14347. #endif
  14348. }
  14349. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14350. /// 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
  14351. void clif_quest_send_mission(struct map_session_data *sd)
  14352. {
  14353. int fd = sd->fd;
  14354. int limit = 0;
  14355. int len = sd->avail_quests*104+8;
  14356. struct mob_db *mob;
  14357. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14358. WFIFOHEAD(fd, len);
  14359. WFIFOW(fd, 0) = 0x2b2;
  14360. WFIFOW(fd, 2) = len;
  14361. WFIFOL(fd, 4) = limit;
  14362. for (int i = 0; i < limit; i++) {
  14363. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14364. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14365. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14366. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14367. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14368. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14369. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j]->mob_id;
  14370. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14371. mob = mob_db(qi->objectives[j]->mob_id);
  14372. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14373. }
  14374. }
  14375. WFIFOSET(fd, len);
  14376. }
  14377. /// Notification about a new quest
  14378. /// 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)
  14379. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14380. /// 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)
  14381. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14382. {
  14383. int fd = sd->fd;
  14384. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14385. #if PACKETVER >= 20150513
  14386. int cmd = 0x9f9;
  14387. #else
  14388. int cmd = 0x2b3;
  14389. #endif
  14390. WFIFOHEAD(fd, packet_len(cmd));
  14391. WFIFOW(fd, 0) = cmd;
  14392. WFIFOL(fd, 2) = qd->quest_id;
  14393. WFIFOB(fd, 6) = qd->state;
  14394. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14395. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14396. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14397. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14398. struct mob_db *mob;
  14399. #if PACKETVER >= 20150513
  14400. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14401. offset += 4;
  14402. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14403. offset += 4;
  14404. #endif
  14405. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14406. offset += 4;
  14407. #if PACKETVER >= 20150513
  14408. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14409. offset += 2;
  14410. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14411. offset += 2;
  14412. #endif
  14413. WFIFOW(fd, offset) = qd->count[i];
  14414. offset += 2;
  14415. mob = mob_db(qi->objectives[i]->mob_id);
  14416. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14417. offset += NAME_LENGTH;
  14418. }
  14419. WFIFOSET(fd, packet_len(cmd));
  14420. #if PACKETVER >= 20150513
  14421. int len = 4 + qi->objectives.size() * 12;
  14422. WFIFOHEAD(fd, len);
  14423. WFIFOW(fd, 0) = 0x8fe;
  14424. WFIFOW(fd, 2) = len;
  14425. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14426. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14427. WFIFOL(fd, offset+4) = qi->objectives[i]->mob_id;
  14428. WFIFOW(fd, offset + 10) = qi->objectives[i]->count;
  14429. WFIFOW(fd, offset + 12) = qd->count[i];
  14430. }
  14431. WFIFOSET(fd, len);
  14432. #endif
  14433. }
  14434. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14435. /// 02b4 <quest id>.L
  14436. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14437. {
  14438. int fd = sd->fd;
  14439. WFIFOHEAD(fd, packet_len(0x2b4));
  14440. WFIFOW(fd, 0) = 0x2b4;
  14441. WFIFOL(fd, 2) = quest_id;
  14442. WFIFOSET(fd, packet_len(0x2b4));
  14443. }
  14444. /// Notification of an update to the hunting mission counter
  14445. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14446. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14447. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14448. {
  14449. int fd = sd->fd;
  14450. int offset = 6;
  14451. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14452. int len = qi->objectives.size() * 12 + 6;
  14453. #if PACKETVER >= 20150513
  14454. int cmd = 0x9fa;
  14455. #else
  14456. int cmd = 0x2b5;
  14457. #endif
  14458. WFIFOHEAD(fd, len);
  14459. WFIFOW(fd, 0) = cmd;
  14460. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14461. for (int i = 0; i < qi->objectives.size(); i++) {
  14462. if (mobid == 0 || mobid == qi->objectives[i]->mob_id) {
  14463. WFIFOL(fd, offset) = qd->quest_id;
  14464. offset += 4;
  14465. #if PACKETVER >= 20150513
  14466. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14467. offset += 4;
  14468. #else
  14469. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14470. offset += 4;
  14471. #endif
  14472. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14473. offset += 2;
  14474. WFIFOW(fd, offset) = qd->count[i];
  14475. offset += 2;
  14476. }
  14477. }
  14478. WFIFOW(fd, 2) = offset;
  14479. WFIFOSET(fd, offset);
  14480. }
  14481. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14482. /// 02b6 <quest id>.L <active>.B
  14483. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14484. {
  14485. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14486. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14487. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14488. }
  14489. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14490. /// 02b7 <quest id>.L <active>.B
  14491. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14492. {
  14493. int fd = sd->fd;
  14494. WFIFOHEAD(fd, packet_len(0x2b7));
  14495. WFIFOW(fd, 0) = 0x2b7;
  14496. WFIFOL(fd, 2) = quest_id;
  14497. WFIFOB(fd, 6) = active;
  14498. WFIFOSET(fd, packet_len(0x2b7));
  14499. }
  14500. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14501. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14502. /// effect:
  14503. /// 0 = none
  14504. /// 1 = exclamation mark icon
  14505. /// 2 = question mark icon
  14506. /// color:
  14507. /// 0 = yellow
  14508. /// 1 = orange
  14509. /// 2 = green
  14510. /// 3 = purple
  14511. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14512. {
  14513. #if PACKETVER >= 20090218
  14514. nullpo_retv(sd);
  14515. nullpo_retv(bl);
  14516. int fd = sd->fd;
  14517. WFIFOHEAD(fd, packet_len(0x446));
  14518. WFIFOW(fd, 0) = 0x446;
  14519. WFIFOL(fd, 2) = bl->id;
  14520. WFIFOW(fd, 6) = bl->x;
  14521. WFIFOW(fd, 8) = bl->y;
  14522. WFIFOW(fd, 10) = effect;
  14523. WFIFOW(fd, 12) = color;
  14524. WFIFOSET(fd, packet_len(0x446));
  14525. #endif
  14526. }
  14527. /// Mercenary System
  14528. ///
  14529. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14530. /// 02a2 <var id>.W <value>.L
  14531. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14532. {
  14533. struct mercenary_data *md;
  14534. struct status_data *status;
  14535. int fd;
  14536. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14537. return;
  14538. fd = sd->fd;
  14539. status = &md->battle_status;
  14540. WFIFOHEAD(fd,packet_len(0x2a2));
  14541. WFIFOW(fd,0) = 0x2a2;
  14542. WFIFOW(fd,2) = type;
  14543. switch( type ) {
  14544. case SP_ATK1:
  14545. {
  14546. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14547. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14548. }
  14549. break;
  14550. case SP_MATK1:
  14551. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14552. break;
  14553. case SP_HIT:
  14554. WFIFOL(fd,4) = status->hit;
  14555. break;
  14556. case SP_CRITICAL:
  14557. WFIFOL(fd,4) = status->cri/10;
  14558. break;
  14559. case SP_DEF1:
  14560. WFIFOL(fd,4) = status->def;
  14561. break;
  14562. case SP_MDEF1:
  14563. WFIFOL(fd,4) = status->mdef;
  14564. break;
  14565. case SP_MERCFLEE:
  14566. WFIFOL(fd,4) = status->flee;
  14567. break;
  14568. case SP_ASPD:
  14569. WFIFOL(fd,4) = status->amotion;
  14570. break;
  14571. case SP_HP:
  14572. WFIFOL(fd,4) = status->hp;
  14573. break;
  14574. case SP_MAXHP:
  14575. WFIFOL(fd,4) = status->max_hp;
  14576. break;
  14577. case SP_SP:
  14578. WFIFOL(fd,4) = status->sp;
  14579. break;
  14580. case SP_MAXSP:
  14581. WFIFOL(fd,4) = status->max_sp;
  14582. break;
  14583. case SP_MERCKILLS:
  14584. WFIFOL(fd,4) = md->mercenary.kill_count;
  14585. break;
  14586. case SP_MERCFAITH:
  14587. WFIFOL(fd,4) = mercenary_get_faith(md);
  14588. break;
  14589. }
  14590. WFIFOSET(fd,packet_len(0x2a2));
  14591. }
  14592. /// Mercenary base status data (ZC_MER_INIT).
  14593. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14594. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14595. /// <calls>.L <kills>.L <atk range>.W
  14596. void clif_mercenary_info(struct map_session_data *sd)
  14597. {
  14598. int fd;
  14599. struct mercenary_data *md;
  14600. struct status_data *status;
  14601. int atk;
  14602. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14603. return;
  14604. fd = sd->fd;
  14605. status = &md->battle_status;
  14606. WFIFOHEAD(fd,packet_len(0x29b));
  14607. WFIFOW(fd,0) = 0x29b;
  14608. WFIFOL(fd,2) = md->bl.id;
  14609. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14610. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14611. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14612. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14613. WFIFOW(fd,10) = status->hit;
  14614. WFIFOW(fd,12) = status->cri/10;
  14615. WFIFOW(fd,14) = status->def;
  14616. WFIFOW(fd,16) = status->mdef;
  14617. WFIFOW(fd,18) = status->flee;
  14618. WFIFOW(fd,20) = status->amotion;
  14619. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14620. WFIFOW(fd,46) = md->db->lv;
  14621. WFIFOL(fd,48) = status->hp;
  14622. WFIFOL(fd,52) = status->max_hp;
  14623. WFIFOL(fd,56) = status->sp;
  14624. WFIFOL(fd,60) = status->max_sp;
  14625. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14626. WFIFOW(fd,68) = mercenary_get_faith(md);
  14627. WFIFOL(fd,70) = mercenary_get_calls(md);
  14628. WFIFOL(fd,74) = md->mercenary.kill_count;
  14629. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14630. WFIFOSET(fd,packet_len(0x29b));
  14631. }
  14632. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14633. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14634. void clif_mercenary_skillblock(struct map_session_data *sd)
  14635. {
  14636. struct mercenary_data *md;
  14637. int fd, i, len = 4;
  14638. if( sd == NULL || (md = sd->md) == NULL )
  14639. return;
  14640. fd = sd->fd;
  14641. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14642. WFIFOW(fd,0) = 0x29d;
  14643. for( i = 0; i < MAX_MERCSKILL; i++ )
  14644. {
  14645. uint16 id;
  14646. short idx = -1;
  14647. if( (id = md->db->skill[i].id) == 0 )
  14648. continue;
  14649. if ((idx = mercenary_skill_get_index(id)) == -1)
  14650. continue;
  14651. WFIFOW(fd,len) = id;
  14652. WFIFOL(fd,len+2) = skill_get_inf(id);
  14653. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14654. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14655. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14656. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14657. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14658. len += 37;
  14659. }
  14660. WFIFOW(fd,2) = len;
  14661. WFIFOSET(fd,len);
  14662. }
  14663. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14664. /// 029f <command>.B
  14665. /// 1 = mercenary information
  14666. /// 2 = delete
  14667. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14668. {
  14669. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14670. if( sd->md == NULL )
  14671. return;
  14672. if( option == 2 ) mercenary_delete(sd->md, 2);
  14673. }
  14674. /// Mercenary Message
  14675. /// message:
  14676. /// 0 = Mercenary soldier's duty hour is over.
  14677. /// 1 = Your mercenary soldier has been killed.
  14678. /// 2 = Your mercenary soldier has been fired.
  14679. /// 3 = Your mercenary soldier has ran away.
  14680. void clif_mercenary_message(struct map_session_data* sd, int message){
  14681. clif_msg(sd, MERC_MSG_BASE + message);
  14682. }
  14683. /// Notification about the remaining time of a rental item.
  14684. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  14685. void clif_rental_time( struct map_session_data* sd, unsigned short nameid, int seconds ){
  14686. // '<ItemName>' item will disappear in <seconds/60> minutes.
  14687. struct PACKET_ZC_CASH_TIME_COUNTER p;
  14688. p.packetType = 0x298;
  14689. p.itemId = client_nameid( nameid );
  14690. p.seconds = seconds;
  14691. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14692. }
  14693. /// Deletes a rental item from client's inventory.
  14694. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  14695. void clif_rental_expired( struct map_session_data* sd, int index, unsigned short nameid ){
  14696. // '<ItemName>' item has been deleted from the Inventory
  14697. struct PACKET_ZC_CASH_ITEM_DELETE p;
  14698. p.packetType = 0x299;
  14699. p.index = client_index( index );
  14700. p.itemId = client_nameid( nameid );
  14701. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14702. }
  14703. /// Book Reading (ZC_READ_BOOK).
  14704. /// 0294 <book id>.L <page>.L
  14705. void clif_readbook(int fd, int book_id, int page)
  14706. {
  14707. WFIFOHEAD(fd,packet_len(0x294));
  14708. WFIFOW(fd,0) = 0x294;
  14709. WFIFOL(fd,2) = book_id;
  14710. WFIFOL(fd,6) = page;
  14711. WFIFOSET(fd,packet_len(0x294));
  14712. }
  14713. /// Battlegrounds
  14714. ///
  14715. /// Updates HP bar of a camp member.
  14716. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14717. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14718. void clif_bg_hp(struct map_session_data *sd) {
  14719. #if PACKETVER < 20140613
  14720. unsigned char buf[34];
  14721. const int cmd = 0x2e0;
  14722. #else
  14723. unsigned char buf[14];
  14724. const int cmd = 0xa0e;
  14725. #endif
  14726. nullpo_retv(sd);
  14727. WBUFW(buf,0) = cmd;
  14728. WBUFL(buf,2) = sd->status.account_id;
  14729. #if PACKETVER < 20140613
  14730. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14731. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14732. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14733. WBUFW(buf,32) = 100;
  14734. } else {
  14735. WBUFW(buf,30) = sd->battle_status.hp;
  14736. WBUFW(buf,32) = sd->battle_status.max_hp;
  14737. }
  14738. #else
  14739. if( sd->battle_status.max_hp > INT32_MAX ) {
  14740. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14741. WBUFL(buf,10) = 100;
  14742. } else {
  14743. WBUFL(buf,6) = sd->battle_status.hp;
  14744. WBUFL(buf,10) = sd->battle_status.max_hp;
  14745. }
  14746. #endif
  14747. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14748. }
  14749. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14750. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14751. void clif_bg_xy(struct map_session_data *sd)
  14752. {
  14753. unsigned char buf[36];
  14754. nullpo_retv(sd);
  14755. WBUFW(buf,0)=0x2df;
  14756. WBUFL(buf,2)=sd->status.account_id;
  14757. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14758. WBUFW(buf,30)=sd->status.class_;
  14759. WBUFW(buf,32)=sd->bl.x;
  14760. WBUFW(buf,34)=sd->bl.y;
  14761. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14762. }
  14763. void clif_bg_xy_remove(struct map_session_data *sd)
  14764. {
  14765. unsigned char buf[36];
  14766. nullpo_retv(sd);
  14767. WBUFW(buf,0)=0x2df;
  14768. WBUFL(buf,2)=sd->status.account_id;
  14769. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14770. WBUFW(buf,30)=0;
  14771. WBUFW(buf,32)=-1;
  14772. WBUFW(buf,34)=-1;
  14773. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14774. }
  14775. /// Notifies clients of a battleground message.
  14776. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14777. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14778. struct map_session_data *sd = bg_getavailablesd( bg );
  14779. if( sd == nullptr ){
  14780. return;
  14781. }
  14782. // limit length
  14783. len = min( len + 1, CHAT_SIZE_MAX );
  14784. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14785. WBUFW(buf,0) = 0x2dc;
  14786. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14787. WBUFL(buf,4) = src_id;
  14788. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14789. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14790. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14791. }
  14792. /// Validates and processes battlechat messages.
  14793. /// All messages that are sent after enabling battleground chat with /battlechat.
  14794. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14795. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14796. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14797. if( !clif_process_message( sd, false, name, message, output ) )
  14798. return;
  14799. bg_send_message(sd, output, strlen(output) );
  14800. }
  14801. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14802. /// 02de <camp A points>.W <camp B points>.W
  14803. void clif_bg_updatescore(int16 m)
  14804. {
  14805. struct block_list bl;
  14806. unsigned char buf[6];
  14807. struct map_data *mapdata = map_getmapdata(m);
  14808. bl.id = 0;
  14809. bl.type = BL_NUL;
  14810. bl.m = m;
  14811. WBUFW(buf,0) = 0x2de;
  14812. WBUFW(buf,2) = mapdata->bgscore_lion;
  14813. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14814. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14815. }
  14816. void clif_bg_updatescore_single(struct map_session_data *sd)
  14817. {
  14818. int fd;
  14819. nullpo_retv(sd);
  14820. fd = sd->fd;
  14821. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14822. WFIFOHEAD(fd,packet_len(0x2de));
  14823. WFIFOW(fd,0) = 0x2de;
  14824. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14825. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14826. WFIFOSET(fd,packet_len(0x2de));
  14827. }
  14828. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14829. /// 02dd <account id>.L <name>.24B <camp>.W
  14830. void clif_sendbgemblem_area(struct map_session_data *sd)
  14831. {
  14832. unsigned char buf[33];
  14833. nullpo_retv(sd);
  14834. WBUFW(buf, 0) = 0x2dd;
  14835. WBUFL(buf,2) = sd->bl.id;
  14836. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14837. WBUFW(buf,30) = sd->bg_id;
  14838. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14839. }
  14840. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14841. {
  14842. nullpo_retv(sd);
  14843. WFIFOHEAD(fd,32);
  14844. WFIFOW(fd,0) = 0x2dd;
  14845. WFIFOL(fd,2) = sd->bl.id;
  14846. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14847. WFIFOW(fd,30) = sd->bg_id;
  14848. WFIFOSET(fd,packet_len(0x2dd));
  14849. }
  14850. /// Battlegrounds queue incoming apply request from client.
  14851. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  14852. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  14853. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  14854. {
  14855. if (!battle_config.feature_bgqueue)
  14856. return;
  14857. nullpo_retv(sd);
  14858. short type = RFIFOW(fd,2);
  14859. char name[NAME_LENGTH];
  14860. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  14861. if (sd->bg_queue_id > 0) {
  14862. //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);
  14863. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  14864. return;
  14865. } else if (type == 1) // Solo
  14866. bg_queue_join_solo(name, sd);
  14867. else if (type == 2) // Party
  14868. bg_queue_join_party(name, sd);
  14869. else if (type == 4) // Guild
  14870. bg_queue_join_guild(name, sd);
  14871. else {
  14872. 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);
  14873. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  14874. return;
  14875. }
  14876. }
  14877. /// Outgoing battlegrounds queue apply result.
  14878. /// Result types: @see e_bg_queue_apply_ack
  14879. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  14880. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  14881. {
  14882. nullpo_retv(sd);
  14883. int fd = sd->fd;
  14884. WFIFOHEAD(fd, packet_len(0x8d8));
  14885. WFIFOW(fd,0) = 0x8d8;
  14886. WFIFOB(fd,2) = result;
  14887. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14888. WFIFOSET(fd, packet_len(0x8d8));
  14889. }
  14890. /// Outgoing battlegrounds queue apply notification.
  14891. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  14892. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  14893. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  14894. {
  14895. nullpo_retv(sd);
  14896. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  14897. if (queue == nullptr) {
  14898. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  14899. return;
  14900. }
  14901. int fd = sd->fd;
  14902. WFIFOHEAD(fd, packet_len(0x8d9));
  14903. WFIFOW(fd,0) = 0x8d9;
  14904. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  14905. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  14906. WFIFOSET(fd, packet_len(0x8d9));
  14907. }
  14908. /// Battlegrounds queue outgoing cancel result.
  14909. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  14910. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  14911. {
  14912. nullpo_retv(sd);
  14913. int fd = sd->fd;
  14914. WFIFOHEAD(fd, packet_len(0x8d8));
  14915. WFIFOW(fd,0) = 0x8db;
  14916. WFIFOB(fd,2) = success;
  14917. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14918. WFIFOSET(fd, packet_len(0x8d8));
  14919. }
  14920. /// Battlegrounds queue incoming cancel request from client.
  14921. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  14922. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  14923. {
  14924. if (!battle_config.feature_bgqueue)
  14925. return;
  14926. nullpo_retv(sd);
  14927. bool success;
  14928. if (sd->bg_queue_id > 0) {
  14929. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  14930. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  14931. 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.
  14932. else
  14933. success = bg_queue_leave(sd);
  14934. } else {
  14935. 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);
  14936. success = false;
  14937. }
  14938. char name[NAME_LENGTH];
  14939. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  14940. clif_bg_queue_cancel_result(success, name, sd);
  14941. }
  14942. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  14943. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  14944. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  14945. {
  14946. nullpo_retv(sd);
  14947. int fd = sd->fd;
  14948. WFIFOHEAD(fd, packet_len(0x8df));
  14949. WFIFOW(fd,0) = 0x8df;
  14950. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  14951. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  14952. WFIFOSET(fd, packet_len(0x8df));
  14953. }
  14954. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  14955. /// Result types: 1(Accept), 2(Decline).
  14956. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  14957. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  14958. {
  14959. nullpo_retv(sd);
  14960. if(sd->bg_queue_id > 0) {
  14961. uint8 result = RFIFOB(fd, 2);
  14962. if(result == 1) { // Accept
  14963. bg_queue_on_accept_invite(sd);
  14964. } else if(result == 2) { // Decline
  14965. bg_queue_leave(sd);
  14966. clif_bg_queue_entry_init(sd);
  14967. }
  14968. }
  14969. }
  14970. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  14971. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  14972. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  14973. {
  14974. nullpo_retv(sd);
  14975. int fd = sd->fd;
  14976. WFIFOHEAD(fd, packet_len(0x8e1));
  14977. WFIFOW(fd,0) = 0x8e1;
  14978. WFIFOB(fd,2) = result;
  14979. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14980. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  14981. WFIFOSET(fd, packet_len(0x8e1));
  14982. }
  14983. /// Battlegrounds queue incoming queue number request from client.
  14984. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  14985. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  14986. {
  14987. nullpo_retv(sd);
  14988. char name[NAME_LENGTH];
  14989. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  14990. clif_bg_queue_apply_notify(name, sd);
  14991. }
  14992. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  14993. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  14994. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  14995. void clif_bg_queue_entry_init(struct map_session_data *sd)
  14996. {
  14997. nullpo_retv(sd);
  14998. int fd = sd->fd;
  14999. WFIFOHEAD(fd, packet_len(0x90e));
  15000. WFIFOW(fd,0) = 0x90e;
  15001. WFIFOSET(fd, packet_len(0x90e));
  15002. }
  15003. /// Custom Fonts (ZC_NOTIFY_FONT).
  15004. /// 02ef <account_id>.L <font id>.W
  15005. void clif_font(struct map_session_data *sd)
  15006. {
  15007. #if PACKETVER >= 20080102
  15008. unsigned char buf[8];
  15009. nullpo_retv(sd);
  15010. WBUFW(buf,0) = 0x2ef;
  15011. WBUFL(buf,2) = sd->bl.id;
  15012. WBUFW(buf,6) = sd->status.font;
  15013. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15014. #endif
  15015. }
  15016. /// Required to start the instancing information window on Client
  15017. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15018. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15019. void clif_instance_create(int instance_id, int num)
  15020. {
  15021. #if PACKETVER >= 20071128
  15022. struct map_session_data *sd = NULL;
  15023. enum send_target target = PARTY;
  15024. unsigned char buf[65];
  15025. instance_getsd(instance_id, sd, &target);
  15026. if (!sd)
  15027. return;
  15028. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15029. if (!db)
  15030. return;
  15031. WBUFW(buf,0) = 0x2cb;
  15032. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15033. WBUFW(buf,63) = num;
  15034. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15035. #endif
  15036. return;
  15037. }
  15038. /// To announce Instancing queue creation if no maps available
  15039. /// S 0x2cc <Standby Position>.W
  15040. void clif_instance_changewait(int instance_id, int num)
  15041. {
  15042. #if PACKETVER >= 20071128
  15043. struct map_session_data *sd = NULL;
  15044. enum send_target target = PARTY;
  15045. unsigned char buf[4];
  15046. instance_getsd(instance_id, sd, &target);
  15047. if (!sd)
  15048. return;
  15049. WBUFW(buf,0) = 0x2cc;
  15050. WBUFW(buf,2) = num;
  15051. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15052. #endif
  15053. return;
  15054. }
  15055. /// Notify the current status to members
  15056. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15057. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15058. {
  15059. #if PACKETVER >= 20071128
  15060. struct map_session_data *sd = NULL;
  15061. enum send_target target = PARTY;
  15062. unsigned char buf[71];
  15063. instance_getsd(instance_id, sd, &target);
  15064. if (!sd)
  15065. return;
  15066. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15067. if (!db)
  15068. return;
  15069. WBUFW(buf,0) = 0x2cd;
  15070. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15071. WBUFL(buf,63) = limit1;
  15072. WBUFL(buf,67) = limit2;
  15073. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15074. #endif
  15075. return;
  15076. }
  15077. /// Notify a status change to members
  15078. /// S 0x2ce <Message ID>.L
  15079. /// 0 = Notification (EnterLimitDate update?)
  15080. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15081. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15082. /// 3 = The Memorial Dungeon has been removed.
  15083. /// 4 = Create failure (removes the instance window)
  15084. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15085. {
  15086. #if PACKETVER >= 20071128
  15087. struct map_session_data *sd = NULL;
  15088. enum send_target target = PARTY;
  15089. unsigned char buf[10];
  15090. instance_getsd(instance_id, sd, &target);
  15091. if (!sd)
  15092. return;
  15093. WBUFW(buf,0) = 0x2ce;
  15094. WBUFL(buf,2) = type;
  15095. WBUFL(buf,6) = limit;
  15096. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15097. #endif
  15098. return;
  15099. }
  15100. /// Destroy an instance from the status window
  15101. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15102. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15103. {
  15104. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15105. return;
  15106. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15107. switch (p->command) {
  15108. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15109. instance_destroy_command(sd);
  15110. break;
  15111. }
  15112. }
  15113. /// Notifies clients about item picked up by a party member.
  15114. /// 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)
  15115. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15116. #if PACKETVER >= 20071002
  15117. nullpo_retv( sd );
  15118. nullpo_retv( item_data );
  15119. struct item_data* id = itemdb_search( item_data->nameid );
  15120. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15121. p.packetType = 0x2b8;
  15122. p.AID = sd->status.account_id;
  15123. p.itemId = item_data->nameid;
  15124. p.identified = item_data->identify;
  15125. p.damaged = item_data->attribute;
  15126. p.refine = item_data->refine;
  15127. clif_addcards( &p.slot, item_data );
  15128. p.location = id->equip; // equip location
  15129. p.itemType = itemtype( id->nameid ); // item type
  15130. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15131. #endif
  15132. }
  15133. /** Display gained exp.
  15134. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15135. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15136. * amount: INT32_MIN ~ INT32_MAX
  15137. * var id:
  15138. * SP_BASEEXP, SP_JOBEXP
  15139. * exp type:
  15140. * 0 = normal exp gained/lost
  15141. * 1 = quest exp gained/lost
  15142. * @param sd Player
  15143. * @param exp EXP value gained/loss
  15144. * @param type SP_BASEEXP, SP_JOBEXP
  15145. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15146. * @param lost True:if lossing EXP
  15147. */
  15148. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  15149. {
  15150. int fd;
  15151. int offset;
  15152. #if PACKETVER >= 20170830
  15153. int cmd = 0xacc;
  15154. #else
  15155. int cmd = 0x7f6;
  15156. #endif
  15157. nullpo_retv(sd);
  15158. fd = sd->fd;
  15159. WFIFOHEAD(fd, packet_len(cmd));
  15160. WFIFOW(fd,0) = cmd;
  15161. WFIFOL(fd,2) = sd->bl.id;
  15162. #if PACKETVER >= 20170830
  15163. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  15164. offset = 4;
  15165. #else
  15166. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  15167. offset = 0;
  15168. #endif
  15169. WFIFOW(fd,10+offset) = type;
  15170. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15171. WFIFOSET(fd,packet_len(cmd));
  15172. }
  15173. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15174. /// type:
  15175. /// 0 = Displays 'value' for 5 seconds.
  15176. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15177. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15178. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15179. /// value:
  15180. /// 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).
  15181. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15182. {
  15183. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15184. WFIFOW(sd->fd,0) = 0x1b1;
  15185. WFIFOB(sd->fd,2) = type;
  15186. WFIFOL(sd->fd,3) = value;
  15187. WFIFOSET(sd->fd, packet_len(0x1b1));
  15188. }
  15189. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15190. /// 021d <state>.L
  15191. /// state:
  15192. /// 0 = Full effects
  15193. /// 1 = Reduced effects
  15194. ///
  15195. /// NOTE: The state is used on Aegis for sending skill unit packet
  15196. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15197. /// whenever possible. Due to the way the decision check is
  15198. /// constructed, this state tracking was rendered useless,
  15199. /// as the only skill unit, that is sent with 0x1c9 is
  15200. /// Graffiti.
  15201. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15202. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15203. sd->state.lesseffect = ( isLess != 0 );
  15204. }
  15205. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15206. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15207. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15208. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15209. int type = RFIFOL(fd,info->pos[1]);
  15210. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15211. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15212. if( sd->state.trading || sd->npc_shopid )
  15213. return;
  15214. if( flag == 0 || n == 0) {
  15215. clif_menuskill_clear(sd);
  15216. return; // Canceled by player.
  15217. }
  15218. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15219. clif_menuskill_clear(sd);
  15220. return; // Prevent hacking.
  15221. }
  15222. switch( type ) {
  15223. case 0: // Change Material
  15224. skill_changematerial(sd,n,item_list);
  15225. break;
  15226. case 1: // Level 1: Pure to Rough
  15227. case 2: // Level 2: Rough to Pure
  15228. skill_elementalanalysis(sd,n,type,item_list);
  15229. break;
  15230. }
  15231. clif_menuskill_clear(sd);
  15232. return;
  15233. }
  15234. /*==========================================
  15235. * Elemental System
  15236. *==========================================*/
  15237. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15238. struct elemental_data *ed;
  15239. struct status_data *status;
  15240. int fd;
  15241. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15242. return;
  15243. fd = sd->fd;
  15244. status = &ed->battle_status;
  15245. WFIFOHEAD(fd,8);
  15246. WFIFOW(fd,0) = 0x81e;
  15247. WFIFOW(fd,2) = type;
  15248. switch( type ) {
  15249. case SP_HP:
  15250. WFIFOL(fd,4) = status->hp;
  15251. break;
  15252. case SP_MAXHP:
  15253. WFIFOL(fd,4) = status->max_hp;
  15254. break;
  15255. case SP_SP:
  15256. WFIFOL(fd,4) = status->sp;
  15257. break;
  15258. case SP_MAXSP:
  15259. WFIFOL(fd,4) = status->max_sp;
  15260. break;
  15261. }
  15262. WFIFOSET(fd,8);
  15263. }
  15264. void clif_elemental_info(struct map_session_data *sd) {
  15265. int fd;
  15266. struct elemental_data *ed;
  15267. struct status_data *status;
  15268. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15269. return;
  15270. fd = sd->fd;
  15271. status = &ed->battle_status;
  15272. WFIFOHEAD(fd,22);
  15273. WFIFOW(fd, 0) = 0x81d;
  15274. WFIFOL(fd, 2) = ed->bl.id;
  15275. WFIFOL(fd, 6) = status->hp;
  15276. WFIFOL(fd,10) = status->max_hp;
  15277. WFIFOL(fd,14) = status->sp;
  15278. WFIFOL(fd,18) = status->max_sp;
  15279. WFIFOSET(fd,22);
  15280. }
  15281. /// Buying Store System
  15282. ///
  15283. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15284. /// 0810 <slots>.B
  15285. void clif_buyingstore_open(struct map_session_data* sd)
  15286. {
  15287. int fd = sd->fd;
  15288. WFIFOHEAD(fd,packet_len(0x810));
  15289. WFIFOW(fd,0) = 0x810;
  15290. WFIFOB(fd,2) = sd->buyingstore.slots;
  15291. WFIFOSET(fd,packet_len(0x810));
  15292. }
  15293. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15294. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15295. /// result:
  15296. /// 0 = cancel
  15297. /// 1 = open
  15298. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15299. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15300. // TODO: Make this check global for all variable length packets.
  15301. // minimum packet length
  15302. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15303. 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 );
  15304. return;
  15305. }
  15306. char storename[MESSAGE_SIZE];
  15307. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15308. // so that buyingstore_create knows, how many elements it has access to
  15309. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15310. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15311. 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 ) );
  15312. return;
  15313. }
  15314. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15315. }
  15316. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15317. /// 0812 <result>.W <total weight>.L
  15318. /// result:
  15319. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15320. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15321. /// 8 = "No sale (purchase) information available." (0x705)
  15322. /// ? = nothing
  15323. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15324. {
  15325. int fd = sd->fd;
  15326. WFIFOHEAD(fd,packet_len(0x812));
  15327. WFIFOW(fd,0) = 0x812;
  15328. WFIFOW(fd,2) = result;
  15329. WFIFOL(fd,4) = weight;
  15330. WFIFOSET(fd,packet_len(0x812));
  15331. }
  15332. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15333. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15334. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15335. nullpo_retv( sd );
  15336. int fd = sd->fd;
  15337. if( !session_isActive( fd ) ){
  15338. return;
  15339. }
  15340. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15341. WFIFOHEAD( fd, length );
  15342. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15343. p->packetType = 0x813;
  15344. p->packetLength = length;
  15345. p->AID = sd->bl.id;
  15346. p->zenyLimit = sd->buyingstore.zenylimit;
  15347. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15348. p->items[i].price = sd->buyingstore.items[i].price;
  15349. p->items[i].amount = sd->buyingstore.items[i].amount;
  15350. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15351. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15352. }
  15353. WFIFOSET( fd, p->packetLength );
  15354. }
  15355. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15356. /// 0814 <account id>.L <store name>.80B
  15357. void clif_buyingstore_entry(struct map_session_data* sd)
  15358. {
  15359. uint8 buf[MESSAGE_SIZE+6];
  15360. WBUFW(buf,0) = 0x814;
  15361. WBUFL(buf,2) = sd->bl.id;
  15362. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15363. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15364. }
  15365. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15366. {
  15367. int fd = sd->fd;
  15368. WFIFOHEAD(fd,packet_len(0x814));
  15369. WFIFOW(fd,0) = 0x814;
  15370. WFIFOL(fd,2) = pl_sd->bl.id;
  15371. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15372. WFIFOSET(fd,packet_len(0x814));
  15373. }
  15374. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15375. /// 0815
  15376. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15377. {
  15378. buyingstore_close(sd);
  15379. }
  15380. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15381. /// 0816 <account id>.L
  15382. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15383. {
  15384. uint8 buf[6];
  15385. WBUFW(buf,0) = 0x816;
  15386. WBUFL(buf,2) = sd->bl.id;
  15387. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15388. }
  15389. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15390. {
  15391. int fd = sd->fd;
  15392. WFIFOHEAD(fd,packet_len(0x816));
  15393. WFIFOW(fd,0) = 0x816;
  15394. WFIFOL(fd,2) = pl_sd->bl.id;
  15395. WFIFOSET(fd,packet_len(0x816));
  15396. }
  15397. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15398. /// 0817 <account id>.L
  15399. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15400. {
  15401. uint32 account_id;
  15402. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15403. buyingstore_open(sd, account_id);
  15404. }
  15405. /// Sends buying store item list.
  15406. /// 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)
  15407. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15408. nullpo_retv( sd );
  15409. nullpo_retv( pl_sd );
  15410. int fd = sd->fd;
  15411. if( !session_isActive( fd ) ){
  15412. return;
  15413. }
  15414. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15415. WFIFOHEAD( fd, length );
  15416. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15417. p->packetType = 0x818;
  15418. p->packetLength = length;
  15419. p->AID = pl_sd->bl.id;
  15420. p->storeId = pl_sd->buyer_id;
  15421. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15422. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15423. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15424. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15425. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15426. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15427. }
  15428. WFIFOSET( fd, p->packetLength );
  15429. }
  15430. /// Request to sell items to a buying store.
  15431. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15432. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15433. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15434. // minimum packet length
  15435. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15436. 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 );
  15437. return;
  15438. }
  15439. // so that buyingstore_trade knows, how many elements it has access to
  15440. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15441. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15442. 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 ) );
  15443. return;
  15444. }
  15445. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15446. }
  15447. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15448. /// 081a <result>.W
  15449. /// result:
  15450. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15451. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15452. /// ? = nothing
  15453. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15454. {
  15455. int fd = sd->fd;
  15456. WFIFOHEAD(fd,packet_len(0x81a));
  15457. WFIFOW(fd,0) = 0x81a;
  15458. WFIFOW(fd,2) = result;
  15459. WFIFOSET(fd,packet_len(0x81a));
  15460. }
  15461. /// Updates the zeny limit and an item in the buying store item list.
  15462. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15463. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15464. void clif_buyingstore_update_item( struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny ){
  15465. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15466. p.packetType = buyingStoreUpdateItemType;
  15467. p.itemId = nameid;
  15468. p.amount = amount;
  15469. p.zenyLimit = sd->buyingstore.zenylimit;
  15470. #if PACKETVER >= 20141016
  15471. p.zeny = zeny;
  15472. p.charId = char_id; // GID
  15473. p.updateTime = (int)time(NULL);
  15474. #endif
  15475. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15476. }
  15477. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15478. /// 081c <index>.W <amount>.W <price>.L
  15479. /// message:
  15480. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15481. ///
  15482. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15483. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15484. {
  15485. int fd = sd->fd;
  15486. WFIFOHEAD(fd,packet_len(0x81c));
  15487. WFIFOW(fd,0) = 0x81c;
  15488. WFIFOW(fd,2) = client_index( index );
  15489. WFIFOW(fd,4) = amount;
  15490. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15491. WFIFOSET(fd,packet_len(0x81c));
  15492. }
  15493. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15494. /// 0824 <result>.W <name id>.W
  15495. /// result:
  15496. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15497. /// 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)
  15498. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15499. /// ? = nothing
  15500. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, unsigned short nameid ){
  15501. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15502. p.packetType = 0x824;
  15503. p.result = result;
  15504. p.itemId = client_nameid( nameid );
  15505. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15506. }
  15507. /// Search Store Info System
  15508. ///
  15509. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15510. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15511. /// type:
  15512. /// 0 = Vending
  15513. /// 1 = Buying Store
  15514. ///
  15515. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15516. /// amount of card slots. If the client does not know about the item it
  15517. /// cannot be searched.
  15518. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15519. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15520. // minimum packet length
  15521. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15522. 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 );
  15523. return;
  15524. }
  15525. // check, if there is enough data for the claimed count of items
  15526. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15527. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15528. 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 ) );
  15529. return;
  15530. }
  15531. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15532. if( count < p->itemsCount + p->cardsCount ){
  15533. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15534. return;
  15535. }
  15536. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15537. }
  15538. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15539. /// 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 }*
  15540. /// is first page:
  15541. /// 0 = appends to existing results
  15542. /// 1 = clears previous results before displaying this result set
  15543. /// is next page:
  15544. /// 0 = no "next" label
  15545. /// 1 = "next" label to retrieve more results
  15546. void clif_search_store_info_ack( struct map_session_data* sd ){
  15547. nullpo_retv( sd );
  15548. int fd = sd->fd;
  15549. if( !session_isActive( fd ) ){
  15550. return;
  15551. }
  15552. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15553. unsigned int end = umin( sd->searchstore.count, start + SEARCHSTORE_RESULTS_PER_PAGE );
  15554. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15555. WFIFOHEAD( fd, len );
  15556. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15557. p->packetType = 0x836;
  15558. p->packetLength = len;
  15559. p->firstPage = !sd->searchstore.pages;
  15560. p->nextPage = searchstore_querynext( sd );
  15561. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15562. for( int i = start; i < end; i++ ) {
  15563. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15564. p->items[i].storeId = ssitem->store_id;
  15565. p->items[i].AID = ssitem->account_id;
  15566. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15567. p->items[i].itemId = client_nameid( ssitem->nameid );
  15568. p->items[i].itemType = itemtype( ssitem->nameid );
  15569. p->items[i].price = ssitem->price;
  15570. p->items[i].amount = ssitem->amount;
  15571. p->items[i].refine = ssitem->refine;
  15572. // make-up an item for clif_addcards
  15573. struct item it;
  15574. memset( &it, 0, sizeof( it ) );
  15575. memcpy( &it.card, &ssitem->card, sizeof( it.card ) );
  15576. it.nameid = ssitem->nameid;
  15577. it.amount = ssitem->amount;
  15578. clif_addcards( &p->items[i].slot, &it );
  15579. #if PACKETVER >= 20150226
  15580. clif_add_random_options( p->items[i].option_data, &it );
  15581. #endif
  15582. }
  15583. WFIFOSET( fd, len );
  15584. }
  15585. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15586. /// 0837 <reason>.B
  15587. /// reason:
  15588. /// 0 = "No matching stores were found." (0x70b)
  15589. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15590. /// 2 = "You cannot search anymore." (0x706)
  15591. /// 3 = "You cannot search yet." (0x708)
  15592. /// 4 = "No sale (purchase) information available." (0x705)
  15593. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15594. {
  15595. int fd = sd->fd;
  15596. WFIFOHEAD(fd,packet_len(0x837));
  15597. WFIFOW(fd,0) = 0x837;
  15598. WFIFOB(fd,2) = reason;
  15599. WFIFOSET(fd,packet_len(0x837));
  15600. }
  15601. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15602. /// 0838
  15603. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15604. {
  15605. searchstore_next(sd);
  15606. }
  15607. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15608. /// 083a <type>.W <remaining uses>.B
  15609. /// type:
  15610. /// 0 = Search Stores
  15611. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15612. void clif_open_search_store_info(struct map_session_data* sd)
  15613. {
  15614. int fd = sd->fd;
  15615. WFIFOHEAD(fd,packet_len(0x83a));
  15616. WFIFOW(fd,0) = 0x83a;
  15617. WFIFOW(fd,2) = sd->searchstore.effect;
  15618. #if PACKETVER > 20100701
  15619. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15620. #endif
  15621. WFIFOSET(fd,packet_len(0x83a));
  15622. }
  15623. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15624. /// 083b
  15625. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15626. {
  15627. searchstore_close(sd);
  15628. }
  15629. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15630. /// 083c <account id>.L <store id>.L <nameid>.W
  15631. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  15632. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  15633. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  15634. }
  15635. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15636. /// 083d <xPos>.W <yPos>.W
  15637. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15638. {
  15639. int fd = sd->fd;
  15640. WFIFOHEAD(fd,packet_len(0x83d));
  15641. WFIFOW(fd,0) = 0x83d;
  15642. WFIFOW(fd,2) = x;
  15643. WFIFOW(fd,4) = y;
  15644. WFIFOSET(fd,packet_len(0x83d));
  15645. }
  15646. /// Parse function for packet debugging.
  15647. void clif_parse_debug(int fd,struct map_session_data *sd)
  15648. {
  15649. int cmd, packet_len;
  15650. // clif_parse ensures, that there is at least 2 bytes of data
  15651. cmd = RFIFOW(fd,0);
  15652. if( sd ) {
  15653. packet_len = packet_db[cmd].len;
  15654. if( packet_len == 0 )
  15655. {// unknown
  15656. packet_len = RFIFOREST(fd);
  15657. }
  15658. else if( packet_len == -1 )
  15659. {// variable length
  15660. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15661. }
  15662. 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);
  15663. }
  15664. else
  15665. {
  15666. packet_len = RFIFOREST(fd);
  15667. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15668. }
  15669. ShowDump(RFIFOP(fd,0), packet_len);
  15670. }
  15671. /*==========================================
  15672. * Server tells client to display a window similar to Magnifier (item) one
  15673. * Server populates the window with avilable elemental converter options according to player's inventory
  15674. *------------------------------------------*/
  15675. void clif_elementalconverter_list( struct map_session_data *sd ){
  15676. nullpo_retv( sd );
  15677. int fd = sd->fd;
  15678. if( !session_isActive( fd ) ){
  15679. return;
  15680. }
  15681. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15682. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15683. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15684. int count = 0;
  15685. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  15686. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  15687. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  15688. count++;
  15689. }
  15690. }
  15691. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15692. WFIFOSET( fd, p->packetLength );
  15693. if( count > 0 ){
  15694. sd->menuskill_id = SA_CREATECON;
  15695. sd->menuskill_val = count;
  15696. }
  15697. }
  15698. /**
  15699. * Rune Knight
  15700. **/
  15701. void clif_millenniumshield(struct block_list *bl, short shields) {
  15702. #if PACKETVER >= 20081217
  15703. unsigned char buf[10];
  15704. WBUFW(buf,0) = 0x440;
  15705. WBUFL(buf,2) = bl->id;
  15706. WBUFW(buf,6) = shields;
  15707. WBUFW(buf,8) = 0;
  15708. clif_send(buf,packet_len(0x440),bl,AREA);
  15709. #endif
  15710. }
  15711. /**
  15712. * Warlock
  15713. **/
  15714. /*==========================================
  15715. * Spellbook list [LimitLine/3CeAM]
  15716. *------------------------------------------*/
  15717. void clif_spellbook_list( struct map_session_data *sd ){
  15718. nullpo_retv( sd );
  15719. int fd = sd->fd;
  15720. if( !session_isActive( fd ) ){
  15721. return;
  15722. }
  15723. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15724. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15725. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15726. int count = 0;
  15727. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15728. if( reading_spellbook_db.findBook( sd->inventory.u.items_inventory[i].nameid ) ){
  15729. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15730. count++;
  15731. }
  15732. }
  15733. if( count > 0 ){
  15734. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15735. WFIFOSET( fd, p->packetLength );
  15736. sd->menuskill_id = WL_READING_SB;
  15737. sd->menuskill_val = count;
  15738. }else{
  15739. status_change_end( &sd->bl, SC_STOP, INVALID_TIMER );
  15740. clif_skill_fail( sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0 );
  15741. }
  15742. }
  15743. /**
  15744. * Mechanic
  15745. **/
  15746. /*==========================================
  15747. * Magic Decoy Material List
  15748. *------------------------------------------*/
  15749. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  15750. nullpo_retv( sd );
  15751. int fd = sd->fd;
  15752. if( !session_isActive( fd ) ){
  15753. return;
  15754. }
  15755. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15756. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  15757. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15758. int count = 0;
  15759. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15760. if( itemdb_group_item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  15761. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15762. count++;
  15763. }
  15764. }
  15765. if( count > 0 ) {
  15766. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15767. WFIFOSET( fd, p->packetLength );
  15768. sd->menuskill_id = NC_MAGICDECOY;
  15769. sd->menuskill_val = skill_lv;
  15770. sd->sc.comet_x = x;
  15771. sd->sc.comet_y = y;
  15772. }else{
  15773. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  15774. }
  15775. }
  15776. /*==========================================
  15777. * Guillotine Cross Poisons List
  15778. *------------------------------------------*/
  15779. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  15780. nullpo_retv( sd );
  15781. int fd = sd->fd;
  15782. if( !session_isActive( fd ) ){
  15783. return;
  15784. }
  15785. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15786. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15787. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15788. int count = 0;
  15789. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15790. if( itemdb_group_item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  15791. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15792. count++;
  15793. }
  15794. }
  15795. if( count > 0 ){
  15796. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15797. WFIFOSET( fd, p->packetLength );
  15798. sd->menuskill_id = GC_POISONINGWEAPON;
  15799. sd->menuskill_val = skill_lv;
  15800. }else{
  15801. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  15802. }
  15803. }
  15804. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15805. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15806. int fd, i, c;
  15807. nullpo_ret(sd);
  15808. fd = sd->fd;
  15809. if( !fd )
  15810. return 0;
  15811. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15812. return 0;
  15813. WFIFOHEAD(fd, 2 * 6 + 4);
  15814. WFIFOW(fd,0) = 0x442;
  15815. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15816. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15817. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15818. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  15819. {
  15820. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15821. c++;
  15822. }
  15823. if( c > 0 ) {
  15824. WFIFOW(fd,2) = 8 + c * 2;
  15825. WFIFOL(fd,4) = c;
  15826. WFIFOSET(fd,WFIFOW(fd,2));
  15827. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15828. sd->menuskill_val = c;
  15829. } else {
  15830. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15831. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15832. }
  15833. return 1;
  15834. }
  15835. /*===========================================
  15836. * Skill list for Four Elemental Analysis
  15837. * and Change Material skills.
  15838. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15839. *------------------------------------------*/
  15840. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15841. #if PACKETVER >= 20090922
  15842. int fd = sd->fd;
  15843. nullpo_ret(sd);
  15844. sd->menuskill_id = skill_id; // To prevent hacking.
  15845. sd->menuskill_val = skill_lv;
  15846. if( skill_id == GN_CHANGEMATERIAL )
  15847. skill_lv = 0; // Changematerial
  15848. WFIFOHEAD(fd, packet_len(0x7e3));
  15849. WFIFOW(fd,0) = 0x7e3;
  15850. WFIFOL(fd,2) = skill_lv;
  15851. WFIFOL(fd,4) = 0;
  15852. WFIFOSET(fd, packet_len(0x7e3));
  15853. #endif
  15854. return 1;
  15855. }
  15856. /*==========================================
  15857. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  15858. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15859. * RFIFOL(fd,2) - type (currently not used)
  15860. *------------------------------------------*/
  15861. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15862. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15863. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15864. if (sd->menuskill_id == SA_AUTOSPELL) {
  15865. sd->state.workinprogress = WIP_DISABLE_NONE;
  15866. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  15867. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  15868. if (pc_istrading(sd)) {
  15869. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  15870. clif_menuskill_clear(sd);
  15871. return;
  15872. }
  15873. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  15874. } else
  15875. return;
  15876. clif_menuskill_clear(sd);
  15877. }
  15878. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15879. /// 08cf <id>.L <type>.W <num>.W
  15880. void clif_spiritcharm(struct map_session_data *sd) {
  15881. unsigned char buf[10];
  15882. nullpo_retv(sd);
  15883. WBUFW(buf,0) = 0x08cf;
  15884. WBUFL(buf,2) = sd->bl.id;
  15885. WBUFW(buf,6) = sd->spiritcharm_type;
  15886. WBUFW(buf,8) = sd->spiritcharm;
  15887. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15888. }
  15889. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15890. /// 0907 <index>.W
  15891. ///
  15892. /// R 0908 <index>.w <type>.b
  15893. /// type:
  15894. /// 0 = move item to personal tab
  15895. /// 1 = move item to normal tab
  15896. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15897. #if PACKETVER >= 20111122
  15898. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15899. int index = RFIFOW(fd,info->pos[0]) - 2;
  15900. int type = RFIFOB(fd, info->pos[1]);
  15901. /* can't move while dead. */
  15902. if(pc_isdead(sd)) {
  15903. return;
  15904. }
  15905. if (index < 0 || index >= MAX_INVENTORY)
  15906. return;
  15907. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15908. sd->inventory.u.items_inventory[index].favorite = 0;
  15909. else if( type == 0 )
  15910. sd->inventory.u.items_inventory[index].favorite = 1;
  15911. else
  15912. return;/* nothing to do. */
  15913. clif_favorite_item(sd, index);
  15914. #endif
  15915. }
  15916. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15917. /// 0900 <index>.W <favorite>.B
  15918. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15919. int fd = sd->fd;
  15920. WFIFOHEAD(fd,packet_len(0x908));
  15921. WFIFOW(fd,0) = 0x908;
  15922. WFIFOW(fd,2) = index+2;
  15923. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15924. WFIFOSET(fd,packet_len(0x908));
  15925. }
  15926. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15927. void clif_snap( struct block_list *bl, short x, short y ) {
  15928. unsigned char buf[10];
  15929. WBUFW(buf,0) = 0x8d2;
  15930. WBUFL(buf,2) = bl->id;
  15931. WBUFW(buf,6) = x;
  15932. WBUFW(buf,8) = y;
  15933. if( disguised(bl) )
  15934. {
  15935. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15936. WBUFL(buf,2) = disguised_bl_id(bl->id);
  15937. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15938. } else
  15939. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15940. }
  15941. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15942. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15943. #if PACKETVER >= 20120404
  15944. WFIFOHEAD(fd,packet_len(0x977));
  15945. WFIFOW(fd,0) = 0x977;
  15946. WFIFOL(fd,2) = md->bl.id;
  15947. WFIFOL(fd,6) = md->status.hp;
  15948. WFIFOL(fd,10) = md->status.max_hp;
  15949. WFIFOSET(fd,packet_len(0x977));
  15950. #endif
  15951. }
  15952. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15953. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15954. return;
  15955. }
  15956. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15957. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15958. WFIFOW(sd->fd,0) = 0x2c9;
  15959. WFIFOB(sd->fd,2) = flag;
  15960. WFIFOSET(sd->fd, packet_len(0x2c9));
  15961. }
  15962. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15963. /// 0979 <world name>.24B <char name>.24B
  15964. void clif_ackworldinfo(struct map_session_data* sd) {
  15965. int fd;
  15966. nullpo_retv(sd);
  15967. fd = sd->fd;
  15968. WFIFOHEAD(fd,packet_len(0x979));
  15969. WFIFOW(fd,0)=0x979;
  15970. //AID -> world name ?
  15971. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15972. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15973. WFIFOSET(fd,packet_len(0x979));
  15974. }
  15975. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15976. /// 0978 <AID>.L
  15977. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15978. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15979. if(sd)
  15980. clif_ackworldinfo(sd);
  15981. }
  15982. static void clif_loadConfirm( struct map_session_data *sd ){
  15983. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  15984. nullpo_retv( sd );
  15985. struct PACKET_ZC_LOAD_CONFIRM p;
  15986. p.packetType = HEADER_ZC_LOAD_CONFIRM;
  15987. clif_send( &p, sizeof(p), &sd->bl, SELF );
  15988. if (sd->instance_id > 0)
  15989. instance_reqinfo(sd, sd->instance_id);
  15990. if (sd->status.party_id > 0)
  15991. party_member_joined(sd);
  15992. if (sd->status.guild_id > 0)
  15993. guild_member_joined(sd);
  15994. if (sd->status.clan_id > 0)
  15995. clan_member_joined(sd);
  15996. #endif
  15997. }
  15998. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15999. /// 0447
  16000. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16001. clif_loadConfirm( sd );
  16002. }
  16003. /// req world info (CZ_CLIENT_VERSION)
  16004. /// 044A <version>.L
  16005. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16006. //if(sd)
  16007. ;
  16008. }
  16009. /// Ranking list
  16010. /// ranking pointlist { <name>.24B <point>.L }*10
  16011. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16012. struct fame_list* list;
  16013. int i, size = MAX_FAME_LIST;
  16014. switch(rankingtype) {
  16015. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16016. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16017. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16018. // PK currently unsupported
  16019. case RANK_KILLER: list = NULL; size = 0; break;
  16020. default:
  16021. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16022. return;
  16023. }
  16024. //Packet size limits this list to 10 elements. [Skotlex]
  16025. for (i = 0; i < min(10,size); i++) {
  16026. if (list[i].id > 0) {
  16027. const char* name;
  16028. if (strcmp(list[i].name, "-") == 0 &&
  16029. (name = map_charid2nick(list[i].id)) != NULL)
  16030. {
  16031. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16032. } else {
  16033. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16034. }
  16035. } else {
  16036. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16037. }
  16038. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16039. }
  16040. for(;i < 10; i++) { //In case the MAX is less than 10.
  16041. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16042. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16043. }
  16044. }
  16045. /// Request for the blacksmith ranklist.
  16046. /// /blacksmith command sends this packet to the server.
  16047. /// 0217 (CZ_BLACKSMITH_RANK)
  16048. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16049. clif_ranklist(sd,RANK_BLACKSMITH);
  16050. }
  16051. /// Request for the alchemist ranklist.
  16052. /// /alchemist command sends this packet to the server.
  16053. /// 0218 (CZ_ALCHEMIST_RANK)
  16054. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16055. clif_ranklist(sd,RANK_ALCHEMIST);
  16056. }
  16057. /// Request for the taekwon ranklist.
  16058. /// /taekwon command sends this packet to the server.
  16059. /// 0225 (CZ_TAEKWON_RANK)
  16060. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16061. clif_ranklist(sd,RANK_TAEKWON);
  16062. }
  16063. /// Request for the killer ranklist.
  16064. /// /pk command sends this packet to the server.
  16065. /// 0237 (CZ_KILLER_RANK)
  16066. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16067. clif_ranklist(sd,RANK_KILLER);
  16068. }
  16069. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16070. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16071. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16072. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16073. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16074. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16075. enum e_rank rank;
  16076. #if PACKETVER < 20130710
  16077. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16078. short cmd;
  16079. switch( rankingType ){
  16080. case RANK_BLACKSMITH: cmd = 0x219; break;
  16081. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16082. case RANK_TAEKWON: cmd = 0x226; break;
  16083. case RANK_KILLER: cmd = 0x238; break;
  16084. default:
  16085. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16086. return;
  16087. }
  16088. // Can be safely casted here, since we validated it before
  16089. rank = (enum e_rank)rankingType;
  16090. WBUFW(buf,0) = cmd;
  16091. clif_sub_ranklist(buf,2,sd,rank);
  16092. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16093. #else
  16094. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16095. int mypoint = 0;
  16096. switch( rankingType ){
  16097. case RANK_BLACKSMITH:
  16098. case RANK_ALCHEMIST:
  16099. case RANK_TAEKWON:
  16100. case RANK_KILLER:
  16101. break;
  16102. default:
  16103. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16104. return;
  16105. }
  16106. // Can be safely casted here, since we validated it before
  16107. rank = (enum e_rank)rankingType;
  16108. WBUFW(buf,0) = 0x97d;
  16109. WBUFW(buf,2) = rank;
  16110. clif_sub_ranklist(buf,4,sd,rank);
  16111. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16112. case MAPID_BLACKSMITH:
  16113. case MAPID_ALCHEMIST:
  16114. case MAPID_TAEKWON:
  16115. mypoint = sd->status.fame;
  16116. }
  16117. WBUFL(buf,284) = mypoint; //mypoint
  16118. clif_send(buf, 288, &sd->bl, SELF);
  16119. #endif
  16120. }
  16121. /*
  16122. * 097c <type> (CZ_REQ_RANKING)
  16123. * type
  16124. * 0: /blacksmith
  16125. * 1: /alchemist
  16126. * 2: /taekwon
  16127. * 3: /pk
  16128. * */
  16129. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16130. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16131. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16132. clif_ranklist(sd,rankingtype);
  16133. }
  16134. /// Updates the fame rank points for the given ranking.
  16135. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16136. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16137. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16138. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16139. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16140. int fd=sd->fd;
  16141. #if PACKETVER < 20130710
  16142. short cmd;
  16143. switch(rankingtype){
  16144. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16145. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16146. case RANK_TAEKWON: cmd = 0x224; break;
  16147. default:
  16148. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16149. return;
  16150. }
  16151. WFIFOHEAD(fd,packet_len(cmd));
  16152. WFIFOW(fd,0) = cmd;
  16153. WFIFOL(fd,2) = point;
  16154. WFIFOL(fd,6) = sd->status.fame;
  16155. WFIFOSET(fd, packet_len(cmd));
  16156. #else
  16157. WFIFOHEAD(fd,packet_len(0x97e));
  16158. WFIFOW(fd,0) = 0x97e;
  16159. WFIFOW(fd,2) = rankingtype;
  16160. WFIFOL(fd,4) = point;
  16161. WFIFOL(fd,8) = sd->status.fame;
  16162. WFIFOSET(fd,packet_len(0x97e));
  16163. #endif
  16164. }
  16165. /**
  16166. * Transmit personal information to player. (rates)
  16167. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16168. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16169. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16170. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16171. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16172. * FIXME!
  16173. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16174. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16175. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16176. */
  16177. #ifdef VIP_ENABLE
  16178. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16179. if (sd) {
  16180. struct s_packet_db* info;
  16181. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16182. int cmd = 0, fd, i = 0;
  16183. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16184. int details_bexp[PINFO_MAX];
  16185. int details_drop[PINFO_MAX];
  16186. int details_penalty[PINFO_MAX];
  16187. /**
  16188. * Set for EXP
  16189. */
  16190. //0:PCRoom
  16191. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16192. if (details_bexp[0] == 100 || !details_bexp[0])
  16193. details_bexp[0] = 0;
  16194. else {
  16195. if (details_bexp[0] < 100) {
  16196. details_bexp[0] = 100 - details_bexp[0];
  16197. details_bexp[0] = 0 - details_bexp[0];
  16198. }
  16199. else
  16200. details_bexp[0] = details_bexp[0] - 100;
  16201. }
  16202. //1:Premium
  16203. if (pc_isvip(sd)) {
  16204. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16205. if (details_bexp[1] < 0)
  16206. details_bexp[1] = 0 - details_bexp[1];
  16207. }
  16208. else
  16209. details_bexp[1] = 0;
  16210. //2:Server
  16211. details_bexp[2] = battle_config.base_exp_rate;
  16212. if (details_bexp[2] == 100)
  16213. details_bexp[2] = 0;
  16214. else {
  16215. if (details_bexp[2] < 100) {
  16216. details_bexp[2] = 100 - details_bexp[2];
  16217. details_bexp[2] = 0 - details_bexp[2];
  16218. }
  16219. else
  16220. details_bexp[2] = details_bexp[2] - 100;
  16221. }
  16222. //3:TPLUS
  16223. details_bexp[3] = 0;
  16224. /* End - EXP set*/
  16225. /**
  16226. * Set for Drop rate
  16227. */
  16228. //0:PCRoom
  16229. details_drop[0] = 0;
  16230. //1:Premium
  16231. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16232. if (pc_isvip(sd)) {
  16233. if (details_drop[1] < 0)
  16234. details_drop[1] = 0 - details_drop[1];
  16235. }
  16236. else
  16237. details_drop[1] = 0;
  16238. //2:Server
  16239. details_drop[2] = battle_config.item_rate_common;
  16240. if (details_drop[2] == 100)
  16241. details_drop[2] = 0;
  16242. else {
  16243. if (details_drop[2] < 100) {
  16244. details_drop[2] = 100 - details_drop[2];
  16245. details_drop[2] = 0 - details_drop[2];
  16246. }
  16247. else
  16248. details_drop[2] = details_drop[2] - 100;
  16249. }
  16250. //3:TPLUS
  16251. details_drop[3] = 0;
  16252. /* End - Drop set*/
  16253. /**
  16254. * Set for Penalty rate
  16255. */
  16256. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16257. //0:PCRoom
  16258. details_penalty[0] = 0;
  16259. //1:Premium
  16260. if (pc_isvip(sd)) {
  16261. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16262. if (details_penalty[1] == 100)
  16263. details_penalty[1] = 0;
  16264. else {
  16265. if (details_penalty[1] < 100) {
  16266. details_penalty[1] = 100 - details_penalty[1];
  16267. details_penalty[1] = 0 - details_penalty[1];
  16268. }
  16269. else
  16270. details_penalty[1] = details_penalty[1] - 100;
  16271. }
  16272. }
  16273. else
  16274. details_penalty[1] = 0;
  16275. //2:Server
  16276. details_penalty[2] = battle_config.death_penalty_base;
  16277. if (details_penalty[2] == 100)
  16278. details_penalty[2] = 0;
  16279. else {
  16280. if (details_penalty[2] < 100) {
  16281. details_penalty[2] = 100 - details_penalty[2];
  16282. details_penalty[2] = 0 - details_penalty[2];
  16283. }
  16284. else
  16285. details_penalty[2] = details_penalty[2] - 100;
  16286. }
  16287. //3:TPLUS
  16288. details_penalty[3] = 0;
  16289. /* End - Penalty set*/
  16290. cmd = packet_db_ack[cmdtype];
  16291. info = &packet_db[cmd];
  16292. len = info->len; //this is the base len without details
  16293. if(!len) return; //version as packet disable
  16294. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16295. szdetails = 7;
  16296. factor = 1;
  16297. }
  16298. else if (cmd == 0x097b) {
  16299. tot_baseexp *= factor;
  16300. tot_drop *= factor;
  16301. tot_penalty *= factor;
  16302. }
  16303. fd = sd->fd;
  16304. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16305. WFIFOW(fd,0) = cmd;
  16306. for (i = 0; i < maxinfotype; i++) {
  16307. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16308. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16309. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16310. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16311. tot_baseexp += details_bexp[i]*factor;
  16312. tot_drop += details_penalty[i]*factor;
  16313. tot_penalty += details_drop[i]*factor;
  16314. len += szdetails;
  16315. }
  16316. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16317. if (cmd == 0x08cb) { //0x08cb version
  16318. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16319. WFIFOW(fd,info->pos[2]) = tot_drop;
  16320. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16321. }
  16322. else { //2013-08-07aRagexe uses 0x097b
  16323. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16324. WFIFOL(fd,info->pos[2]) = tot_drop;
  16325. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16326. }
  16327. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16328. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16329. WFIFOSET(fd,len);
  16330. }
  16331. }
  16332. #endif
  16333. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16334. char cmd[30];
  16335. int t_aid = RFIFOL(fd,2);
  16336. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16337. is_atcommand(fd, sd, cmd, 1);
  16338. }
  16339. /**
  16340. * Marks Crimson Marker target on mini-map to the caster
  16341. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16342. * @param fd
  16343. * @param bl Crimson Marker target
  16344. **/
  16345. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16346. struct s_packet_db* info;
  16347. int cmd = 0;
  16348. int16 len;
  16349. unsigned char buf[11];
  16350. nullpo_retv(sd);
  16351. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16352. if (!cmd)
  16353. cmd = 0x09C1; //default
  16354. info = &packet_db[cmd];
  16355. if (!(len = info->len))
  16356. return;
  16357. WBUFW(buf, 0) = cmd;
  16358. WBUFL(buf, info->pos[0]) = bl->id;
  16359. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16360. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16361. clif_send(buf, len, &sd->bl, SELF);
  16362. }
  16363. /**
  16364. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16365. **/
  16366. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16367. struct s_packet_db *info = NULL;
  16368. int cmd = 0;
  16369. nullpo_retv(sd);
  16370. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16371. info = &packet_db[cmd];
  16372. if (!cmd || !info->len)
  16373. return;
  16374. WFIFOHEAD(sd->fd, info->len);
  16375. WFIFOW(sd->fd, 0) = cmd;
  16376. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16377. WFIFOSET(sd->fd, info->len);
  16378. }
  16379. /**
  16380. * [Ind/Hercules]
  16381. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16382. **/
  16383. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16384. char buf[256];
  16385. size_t len;
  16386. nullpo_retv(bl);
  16387. if(!message)
  16388. return;
  16389. len = strlen(message)+1;
  16390. if( len > sizeof(buf)-8 ) {
  16391. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16392. len = sizeof(buf)-8;
  16393. }
  16394. WBUFW(buf,0) = 0x8b3;
  16395. WBUFW(buf,2) = (uint16)(len+8);
  16396. WBUFL(buf,4) = bl->id;
  16397. safestrncpy(WBUFCP(buf,8), message, len);
  16398. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16399. }
  16400. /**
  16401. * [Ind/Hercules]
  16402. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16403. **/
  16404. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16405. unsigned char buf[10];
  16406. nullpo_retv(sd);
  16407. WBUFW(buf,0) = 0x7fc;
  16408. WBUFL(buf,2) = prev_leader_aid;
  16409. WBUFL(buf,6) = new_leader_aid;
  16410. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16411. }
  16412. /**
  16413. * Sends a clan message to a player
  16414. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16415. **/
  16416. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16417. #if PACKETVER >= 20131223
  16418. struct map_session_data *sd;
  16419. uint8 buf[256];
  16420. if( len == 0 ){
  16421. return;
  16422. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16423. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16424. len = sizeof(buf)-5-NAME_LENGTH;
  16425. }
  16426. WBUFW(buf, 0) = 0x98e;
  16427. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16428. // 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
  16429. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16430. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16431. if((sd = clan_getavailablesd(clan)) != NULL)
  16432. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16433. #endif
  16434. }
  16435. /**
  16436. * Parses a clan message from a player.
  16437. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16438. **/
  16439. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16440. #if PACKETVER >= 20131223
  16441. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16442. // validate packet and retrieve name and message
  16443. if( !clif_process_message(sd, false, name, message, output ) )
  16444. return;
  16445. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16446. #endif
  16447. }
  16448. /**
  16449. * Sends the basic clan informations to the client.
  16450. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16451. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16452. **/
  16453. void clif_clan_basicinfo( struct map_session_data *sd ){
  16454. #if PACKETVER >= 20131223
  16455. int fd, offset, length, i, flag;
  16456. struct clan* clan;
  16457. char mapname[MAP_NAME_LENGTH_EXT];
  16458. nullpo_retv( sd );
  16459. nullpo_retv( clan = sd->clan );
  16460. // Check if the player has a valid session and is not autotrading
  16461. if( !clif_session_isValid( sd ) ){
  16462. return;
  16463. }
  16464. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16465. fd = sd->fd;
  16466. WFIFOHEAD(fd,length);
  16467. memset( WFIFOP(fd, 0), 0, length );
  16468. WFIFOW( fd, 0 ) = 0x98a;
  16469. WFIFOL( fd, 4 ) = clan->id;
  16470. offset = 8;
  16471. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16472. offset += NAME_LENGTH;
  16473. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16474. offset += NAME_LENGTH;
  16475. mapindex_getmapname_ext( clan->map, mapname );
  16476. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16477. offset += MAP_NAME_LENGTH_EXT;
  16478. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16479. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16480. for( flag = 0; flag < 2; flag++ ){
  16481. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16482. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16483. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16484. offset += NAME_LENGTH;
  16485. }
  16486. }
  16487. }
  16488. WFIFOW( fd, 2 ) = offset;
  16489. WFIFOSET(fd,offset);
  16490. #endif
  16491. }
  16492. /**
  16493. * Updates the online and maximum player count of a clan.
  16494. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16495. **/
  16496. void clif_clan_onlinecount( struct clan* clan ){
  16497. #if PACKETVER >= 20131223
  16498. uint8 buf[6];
  16499. struct map_session_data *sd;
  16500. WBUFW(buf,0) = 0x988;
  16501. WBUFW(buf,2) = clan->connect_member;
  16502. WBUFW(buf,4) = clan->max_member;
  16503. if((sd = clan_getavailablesd(clan)) != NULL)
  16504. clif_send(buf, 6, &sd->bl, CLAN);
  16505. #endif
  16506. }
  16507. /**
  16508. * Notifies the client that the player has left his clan.
  16509. * 0989 (ZC_ACK_CLAN_LEAVE)
  16510. **/
  16511. void clif_clan_leave( struct map_session_data* sd ){
  16512. #if PACKETVER >= 20131223
  16513. int fd;
  16514. nullpo_retv( sd );
  16515. if( !clif_session_isValid( sd ) ){
  16516. return;
  16517. }
  16518. fd = sd->fd;
  16519. WFIFOHEAD(fd,2);
  16520. WFIFOW(fd,0) = 0x989;
  16521. WFIFOSET(fd,2);
  16522. #endif
  16523. }
  16524. /**
  16525. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16526. * 0A2F <result>.B <title_id>.L
  16527. */
  16528. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16529. {
  16530. #if PACKETVER >= 20150513
  16531. int fd;
  16532. nullpo_retv(sd);
  16533. if (!clif_session_isValid(sd))
  16534. return;
  16535. fd = sd->fd;
  16536. WFIFOHEAD(fd, packet_len(0xa2f));
  16537. WFIFOW(fd, 0) = 0xa2f;
  16538. WFIFOB(fd, 2) = result;
  16539. WFIFOL(fd, 3) = title_id;
  16540. WFIFOSET(fd, packet_len(0xa2f));
  16541. #endif
  16542. }
  16543. /**
  16544. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16545. * 0A2E <title_id>.L
  16546. */
  16547. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16548. {
  16549. int title_id;
  16550. nullpo_retv(sd);
  16551. title_id = RFIFOL(fd, 2);
  16552. if( title_id == sd->status.title_id ){
  16553. // It is exactly the same as the old one
  16554. return;
  16555. }else if( title_id <= 0 ){
  16556. sd->status.title_id = 0;
  16557. }else{
  16558. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16559. clif_change_title_ack(sd, 1, title_id);
  16560. return;
  16561. }
  16562. sd->status.title_id = title_id;
  16563. }
  16564. clif_name_area(&sd->bl);
  16565. clif_change_title_ack(sd, 0, title_id);
  16566. }
  16567. #ifdef DUMP_UNKNOWN_PACKET
  16568. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16569. {
  16570. const char* packet_txt = "save/packet.txt";
  16571. FILE* fp;
  16572. time_t time_server;
  16573. struct tm *datetime;
  16574. char datestr[512];
  16575. time(&time_server); // get time in seconds since 1/1/1970
  16576. datetime = localtime(&time_server); // convert seconds in structure
  16577. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16578. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16579. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16580. if( sd ) {
  16581. 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);
  16582. } else {
  16583. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16584. }
  16585. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16586. fprintf(fp, "\n");
  16587. fclose(fp);
  16588. } else {
  16589. ShowError("Failed to write '%s'.\n", packet_txt);
  16590. // Dump on console instead
  16591. if( sd ) {
  16592. 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);
  16593. } else {
  16594. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16595. }
  16596. ShowDump(RFIFOP(fd,0), packet_len);
  16597. }
  16598. }
  16599. #endif
  16600. /// Roulette System
  16601. /// Author: Yommy
  16602. /// Opens the roulette window
  16603. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16604. void clif_roulette_open( struct map_session_data* sd ){
  16605. nullpo_retv( sd );
  16606. struct packet_roulette_open_ack p;
  16607. p.PacketType = 0xa1a;
  16608. p.Result = 0; // result
  16609. p.Serial = 0; // serial
  16610. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16611. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16612. p.AdditionItemID = -1; //! TODO: Display bonus item
  16613. p.GoldPoint = sd->roulette_point.gold;
  16614. p.SilverPoint = sd->roulette_point.silver;
  16615. p.BronzePoint = sd->roulette_point.bronze;
  16616. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16617. }
  16618. /// Request to open the roulette window
  16619. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16620. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16621. nullpo_retv(sd);
  16622. if (!battle_config.feature_roulette) {
  16623. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16624. return;
  16625. }
  16626. clif_roulette_open(sd);
  16627. }
  16628. /// Sends the info about the available roulette rewards to the client
  16629. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16630. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16631. void clif_roulette_info( struct map_session_data* sd ){
  16632. nullpo_retv(sd);
  16633. struct packet_roulette_info_ack p;
  16634. p.PacketType = rouletteinfoackType;
  16635. p.PacketLength = sizeof(p);
  16636. p.RouletteSerial = 1;
  16637. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16638. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16639. p.ItemInfo[count].Row = i;
  16640. p.ItemInfo[count].Position = j;
  16641. p.ItemInfo[count].ItemId = rd.nameid[i][j];
  16642. p.ItemInfo[count].Count = rd.qty[i][j];
  16643. #if PACKETVER >= 20180511
  16644. p.ItemInfo[count].unused = 0;
  16645. #endif
  16646. count++;
  16647. }
  16648. }
  16649. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16650. }
  16651. /// Request the roulette reward data
  16652. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16653. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16654. nullpo_retv(sd);
  16655. if (!battle_config.feature_roulette) {
  16656. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16657. return;
  16658. }
  16659. clif_roulette_info(sd);
  16660. }
  16661. /// Notification of the client that the roulette window was closed
  16662. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16663. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16664. nullpo_retv(sd);
  16665. if (!battle_config.feature_roulette) {
  16666. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16667. return;
  16668. }
  16669. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16670. }
  16671. /// Response to a item reward request
  16672. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16673. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16674. #if PACKETVER >= 20141016
  16675. nullpo_retv(sd);
  16676. struct packet_roulette_itemrecv_ack p;
  16677. p.PacketType = roulettercvitemackType;
  16678. p.Result = type;
  16679. p.AdditionItemID = 0; //! TODO: Additional item
  16680. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16681. #endif
  16682. }
  16683. /**
  16684. * Claim roulette reward
  16685. * @param sd Player
  16686. * @return 0:Success
  16687. **/
  16688. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16689. struct item it;
  16690. uint8 res = 1;
  16691. nullpo_retr(1, sd);
  16692. if (sd->roulette.prizeIdx < 0)
  16693. return RECV_ITEM_FAILED;
  16694. memset(&it, 0, sizeof(it));
  16695. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16696. it.identify = 1;
  16697. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16698. ; // onSuccess
  16699. }
  16700. sd->roulette.claimPrize = false;
  16701. sd->roulette.prizeStage = 0;
  16702. sd->roulette.prizeIdx = -1;
  16703. sd->roulette.stage = 0;
  16704. return res;
  16705. }
  16706. /// Update Roulette window with current stats
  16707. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16708. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16709. nullpo_retv( sd );
  16710. struct packet_roulette_generate_ack p;
  16711. p.PacketType = roulettgenerateackType;
  16712. p.Result = result;
  16713. p.Step = stage;
  16714. p.Idx = prizeIdx;
  16715. p.AdditionItemID = bonusItemID;
  16716. p.RemainGold = sd->roulette_point.gold;
  16717. p.RemainSilver = sd->roulette_point.silver;
  16718. p.RemainBronze = sd->roulette_point.bronze;
  16719. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16720. }
  16721. /// Request to start the roulette
  16722. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16723. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16724. enum GENERATE_ROULETTE_ACK result;
  16725. nullpo_retv(sd);
  16726. if (!battle_config.feature_roulette) {
  16727. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16728. return;
  16729. }
  16730. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16731. return;
  16732. }
  16733. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16734. sd->roulette.stage = 0;
  16735. sd->roulette.claimPrize = false;
  16736. sd->roulette.prizeStage = 0;
  16737. sd->roulette.prizeIdx = -1;
  16738. }
  16739. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16740. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16741. }else{
  16742. if (!sd->roulette.stage) {
  16743. if (sd->roulette_point.bronze > 0) {
  16744. sd->roulette_point.bronze -= 1;
  16745. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16746. } else if (sd->roulette_point.silver > 9) {
  16747. sd->roulette_point.silver -= 10;
  16748. sd->roulette.stage = 2;
  16749. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16750. } else if (sd->roulette_point.gold > 9) {
  16751. sd->roulette_point.gold -= 10;
  16752. sd->roulette.stage = 4;
  16753. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16754. }
  16755. }
  16756. sd->roulette.prizeStage = sd->roulette.stage;
  16757. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16758. sd->roulette.claimPrize = true;
  16759. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16760. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16761. result = GENERATE_ROULETTE_LOSING;
  16762. sd->roulette.stage = 0;
  16763. }else{
  16764. result = GENERATE_ROULETTE_SUCCESS;
  16765. sd->roulette.stage++;
  16766. }
  16767. }
  16768. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16769. }
  16770. /// Request to claim a prize
  16771. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16772. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16773. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16774. nullpo_retv(sd);
  16775. if (!battle_config.feature_roulette) {
  16776. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16777. return;
  16778. }
  16779. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16780. return;
  16781. }
  16782. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16783. switch (clif_roulette_getitem(sd)) {
  16784. case ADDITEM_SUCCESS:
  16785. type = RECV_ITEM_SUCCESS;
  16786. break;
  16787. case ADDITEM_INVALID:
  16788. case ADDITEM_OVERITEM:
  16789. case ADDITEM_OVERAMOUNT:
  16790. type = RECV_ITEM_OVERCOUNT;
  16791. break;
  16792. case ADDITEM_OVERWEIGHT:
  16793. type = RECV_ITEM_OVERWEIGHT;
  16794. break;
  16795. case ADDITEM_STACKLIMIT:
  16796. default:
  16797. type = RECV_ITEM_FAILED;
  16798. break;
  16799. }
  16800. }
  16801. clif_roulette_recvitem_ack(sd,type);
  16802. }
  16803. /// MERGE ITEM
  16804. /**
  16805. * Acknowledge the client about item merger result
  16806. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16807. * @param fd
  16808. * @param sd
  16809. **/
  16810. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16811. unsigned char buf[9];
  16812. struct s_packet_db *info = NULL;
  16813. short cmd = 0;
  16814. nullpo_retv(sd);
  16815. if (!clif_session_isValid(sd))
  16816. return;
  16817. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16818. return;
  16819. if (!(info = &packet_db[cmd]) || info->len == 0)
  16820. return;
  16821. WBUFW(buf, 0) = cmd;
  16822. WBUFW(buf, info->pos[0]) = index;
  16823. WBUFW(buf, info->pos[1]) = count;
  16824. WBUFB(buf, info->pos[2]) = type;
  16825. clif_send(buf, info->len, &sd->bl, SELF);
  16826. }
  16827. /**
  16828. * Check if item has the pair to be merged
  16829. * @param sd
  16830. * @param it Item
  16831. * @return True if has pair, False if not
  16832. **/
  16833. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16834. struct item *it_;
  16835. unsigned short i;
  16836. nullpo_retr(false, sd);
  16837. 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);
  16838. if (i < MAX_INVENTORY)
  16839. return true;
  16840. return false;
  16841. }
  16842. /**
  16843. * Check if item can be merged
  16844. * @param id Item Data
  16845. * @param it Item
  16846. * @return True if can be merged, False if not
  16847. **/
  16848. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16849. if (!id || !it)
  16850. return false;
  16851. if (id->type == IT_CASH)
  16852. return false;
  16853. if (!itemdb_isstackable2(id))
  16854. return false;
  16855. if (itemdb_isspecial(it->card[0]))
  16856. return false;
  16857. if (!it->unique_id)
  16858. return false;
  16859. return true;
  16860. }
  16861. /**
  16862. * Open available item to be merged.
  16863. * Only show 1 item in 1 process.
  16864. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16865. * @param sd
  16866. **/
  16867. void clif_merge_item_open(struct map_session_data *sd) {
  16868. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16869. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16870. int len = 0;
  16871. struct s_packet_db *info = NULL;
  16872. struct item *it;
  16873. nullpo_retv(sd);
  16874. if (!clif_session_isValid(sd))
  16875. return;
  16876. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16877. return;
  16878. if (!(info = &packet_db[cmd]) || info->len == 0)
  16879. return;
  16880. // Get entries
  16881. for (i = 0; i < MAX_INVENTORY; i++) {
  16882. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16883. continue;
  16884. if (clif_merge_item_has_pair(sd, it))
  16885. indexes[n++] = i;
  16886. }
  16887. if (n < 2) { // No item need to be merged
  16888. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16889. return;
  16890. }
  16891. WBUFW(buf, 0) = cmd;
  16892. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16893. for (i = 0; i < n; i++) {
  16894. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16895. }
  16896. clif_send(buf, len, &sd->bl, SELF);
  16897. }
  16898. /**
  16899. * Process item merger
  16900. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16901. * @param fd
  16902. * @param sd
  16903. **/
  16904. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16905. struct s_packet_db *info = NULL;
  16906. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16907. unsigned int count = 0;
  16908. struct item_data *id = NULL;
  16909. nullpo_retv(sd);
  16910. if (!clif_session_isValid(sd))
  16911. return;
  16912. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16913. return;
  16914. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16915. if (n < 2) { // No item need to be merged
  16916. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16917. return;
  16918. }
  16919. for (i = 0, j = 0; i < n; i++) {
  16920. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16921. if( idx < 0 || idx >= MAX_INVENTORY ){
  16922. return;
  16923. }
  16924. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16925. continue;
  16926. indexes[j] = idx;
  16927. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16928. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16929. return;
  16930. }
  16931. count += sd->inventory.u.items_inventory[idx].amount;
  16932. j++;
  16933. }
  16934. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16935. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16936. return;
  16937. }
  16938. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16939. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16940. return;
  16941. }
  16942. // Merrrrge!!!!
  16943. for (i = 1; i < n; i++) {
  16944. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16945. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16946. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16947. sd->inventory_data[idx] = NULL;
  16948. clif_delitem(sd, idx, amt, 0);
  16949. }
  16950. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16951. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16952. }
  16953. /**
  16954. * Cancel item merge
  16955. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16956. * @param fd
  16957. * @param sd
  16958. **/
  16959. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16960. return; // Nothing todo yet
  16961. }
  16962. /**
  16963. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16964. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16965. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16966. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16967. **/
  16968. void clif_broadcast_obtain_special_item( const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  16969. char name[NAME_LENGTH];
  16970. if( battle_config.broadcast_hide_name ){
  16971. std::string dispname = std::string( char_name );
  16972. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  16973. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  16974. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  16975. }else{
  16976. safestrncpy( name, char_name, sizeof( name ) );
  16977. }
  16978. switch( type ){
  16979. case ITEMOBTAIN_TYPE_BOXITEM:
  16980. {
  16981. struct packet_package_item_announce p;
  16982. p.PacketType = package_item_announceType;
  16983. p.type = type;
  16984. p.ItemID = client_nameid( nameid );
  16985. p.len = NAME_LENGTH;
  16986. safestrncpy( p.Name, name, sizeof( p.Name ) );
  16987. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  16988. p.BoxItemID = client_nameid( container );
  16989. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  16990. p.PacketLength = 15 + p.len;
  16991. #else
  16992. p.PacketLength = 11 + p.len;
  16993. #endif
  16994. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  16995. }
  16996. break;
  16997. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16998. case ITEMOBTAIN_TYPE_NPC:
  16999. {
  17000. struct packet_item_drop_announce p;
  17001. p.PacketType = item_drop_announceType;
  17002. p.type = type;
  17003. p.ItemID = client_nameid( nameid );
  17004. p.len = NAME_LENGTH;
  17005. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17006. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17007. struct mob_db *db = mob_db( container );
  17008. p.monsterNameLen = NAME_LENGTH;
  17009. safestrncpy( p.monsterName, db->name, NAME_LENGTH );
  17010. }else{
  17011. p.monsterNameLen = 0;
  17012. p.monsterName[0] = '\0';
  17013. }
  17014. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17015. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17016. #else
  17017. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17018. #endif
  17019. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17020. }
  17021. break;
  17022. }
  17023. }
  17024. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17025. /// 0A02 <view>.W
  17026. /// Value <flag> has the following effects:
  17027. /// 1: Open a Dress Room window.
  17028. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17029. #if PACKETVER >= 20150513
  17030. int fd = sd->fd;
  17031. nullpo_retv(sd);
  17032. WFIFOHEAD(fd, packet_len(0xa02));
  17033. WFIFOW(fd,0) = 0xa02;
  17034. WFIFOW(fd,2) = flag;
  17035. WFIFOSET(fd, packet_len(0xa02));
  17036. #endif
  17037. }
  17038. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17039. /// 0A35 <result>.W
  17040. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17041. #if PACKETVER >= 20150513
  17042. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17043. // Ignore the request
  17044. // - Invalid item index
  17045. // - Invalid item ID or item doesn't exist
  17046. // - Item is already identified
  17047. if (idx < 0 || idx >= MAX_INVENTORY ||
  17048. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  17049. sd->inventory.u.items_inventory[idx].identify)
  17050. return;
  17051. // Ignore the request - No magnifiers in inventory
  17052. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17053. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17054. return;
  17055. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17056. return;
  17057. skill_identify(sd, idx);
  17058. #endif
  17059. }
  17060. /// Starts navigation to the given target on client side
  17061. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17062. #if PACKETVER >= 20111010
  17063. int fd = sd->fd;
  17064. WFIFOHEAD(fd,27);
  17065. WFIFOW(fd,0) = 0x08e2;
  17066. // How detailed will our navigation be?
  17067. if( mob_id > 0 ){
  17068. x = 0;
  17069. y = 0;
  17070. WFIFOB(fd,2) = 3; // monster with destination field
  17071. }else if( x > 0 && y > 0 ){
  17072. WFIFOB(fd,2) = 0; // with coordinates
  17073. }else{
  17074. x = 0;
  17075. y = 0;
  17076. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17077. }
  17078. // Which services can be used for transportation?
  17079. WFIFOB(fd,3) = flag;
  17080. // If this flag is set, the navigation window will not be opened up
  17081. WFIFOB(fd,4) = hideWindow;
  17082. // Target map
  17083. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17084. // Target x
  17085. WFIFOW(fd,21) = x;
  17086. // Target y
  17087. WFIFOW(fd,23) = y;
  17088. // Target monster ID
  17089. WFIFOW(fd,25) = mob_id;
  17090. WFIFOSET(fd,27);
  17091. #endif
  17092. }
  17093. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17094. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17095. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17096. #if PACKETVER >= 20150513
  17097. unsigned char* buf;
  17098. int len,i;
  17099. struct map_session_data *tsd;
  17100. struct block_list* tbl;
  17101. if( target == SELF ){
  17102. tsd = BL_CAST(BL_PC,bl);
  17103. tbl = &sd->bl;
  17104. }else{
  17105. tsd = sd;
  17106. tbl = bl;
  17107. }
  17108. if( !tsd->hatEffectCount )
  17109. return;
  17110. len = 9 + tsd->hatEffectCount * 2;
  17111. buf = (unsigned char*)aMalloc( len );
  17112. WBUFW(buf,0) = 0xa3b;
  17113. WBUFW(buf,2) = len;
  17114. WBUFL(buf,4) = tsd->bl.id;
  17115. WBUFB(buf,8) = 1;
  17116. for( i = 0; i < tsd->hatEffectCount; i++ ){
  17117. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  17118. }
  17119. clif_send(buf, len,tbl,target);
  17120. aFree(buf);
  17121. #endif
  17122. }
  17123. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17124. #if PACKETVER >= 20150513
  17125. unsigned char buf[13];
  17126. WBUFW(buf,0) = 0xa3b;
  17127. WBUFW(buf,2) = 13;
  17128. WBUFL(buf,4) = sd->bl.id;
  17129. WBUFB(buf,8) = enable;
  17130. WBUFL(buf,9) = effectId;
  17131. clif_send(buf,13,&sd->bl,AREA);
  17132. #endif
  17133. }
  17134. /// Notify the client that a sale has started
  17135. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17136. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17137. #if PACKETVER_SUPPORTS_SALES
  17138. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17139. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17140. p.itemId = client_nameid( sale_item->nameid );
  17141. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17142. clif_send( &p, sizeof( p ), bl, target );
  17143. #endif
  17144. }
  17145. /// Notify the clien that a sale has ended
  17146. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17147. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17148. #if PACKETVER_SUPPORTS_SALES
  17149. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17150. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17151. p.itemId = client_nameid( sale_item->nameid );
  17152. clif_send( &p, sizeof( p ), bl, target );
  17153. #endif
  17154. }
  17155. /// Update the remaining amount of a sale item.
  17156. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17157. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17158. #if PACKETVER_SUPPORTS_SALES
  17159. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17160. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17161. p.itemId = client_nameid( sale_item->nameid );
  17162. p.amount = sale_item->amount;
  17163. clif_send( &p, sizeof( p ), bl, target );
  17164. #endif
  17165. }
  17166. /// The client requested a refresh of the current remaining count of a sale item
  17167. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17168. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17169. #if PACKETVER_SUPPORTS_SALES
  17170. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17171. struct sale_item_data* sale;
  17172. if( p->AID != sd->status.account_id ){
  17173. return;
  17174. }
  17175. sale = sale_find_item( p->itemId, true );
  17176. if( sale == NULL ){
  17177. return;
  17178. }
  17179. clif_sale_amount(sale, &sd->bl, SELF);
  17180. #endif
  17181. }
  17182. /// Opens the sale administration window on the client
  17183. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17184. void clif_sale_open( struct map_session_data* sd ){
  17185. #if PACKETVER_SUPPORTS_SALES
  17186. nullpo_retv(sd);
  17187. if( sd->state.sale_open ){
  17188. return;
  17189. }
  17190. sd->state.sale_open = true;
  17191. int fd = sd->fd;
  17192. WFIFOHEAD(fd, 2);
  17193. WFIFOW(fd, 0) = 0x9b5;
  17194. WFIFOSET(fd, 2);
  17195. #endif
  17196. }
  17197. /// Client request to open the sale administration window.
  17198. /// This is sent by /limitedsale
  17199. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17200. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17201. #if PACKETVER_SUPPORTS_SALES
  17202. nullpo_retv(sd);
  17203. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17204. return;
  17205. }
  17206. char command[CHAT_SIZE_MAX];
  17207. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17208. is_atcommand(fd, sd, command, 1);
  17209. #endif
  17210. }
  17211. /// Closes the sale administration window on the client.
  17212. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17213. void clif_sale_close(struct map_session_data* sd) {
  17214. #if PACKETVER_SUPPORTS_SALES
  17215. nullpo_retv(sd);
  17216. if( !sd->state.sale_open ){
  17217. return;
  17218. }
  17219. sd->state.sale_open = false;
  17220. int fd = sd->fd;
  17221. WFIFOHEAD(fd, 2);
  17222. WFIFOW(fd, 0) = 0x9bd;
  17223. WFIFOSET(fd, 2);
  17224. #endif
  17225. }
  17226. /// Client request to close the sale administration window.
  17227. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17228. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17229. #if PACKETVER_SUPPORTS_SALES
  17230. nullpo_retv(sd);
  17231. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17232. return;
  17233. }
  17234. clif_sale_close(sd);
  17235. #endif
  17236. }
  17237. /// Reply to a item search request for item sale administration.
  17238. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17239. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17240. #if PACKETVER_SUPPORTS_SALES
  17241. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17242. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17243. if( item != NULL ){
  17244. p.result = 0;
  17245. p.itemId = client_nameid( item->nameid );
  17246. p.price = item->price;
  17247. }else{
  17248. p.result = 1;
  17249. p.itemId = 0;
  17250. p.price = 0;
  17251. }
  17252. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17253. #endif
  17254. }
  17255. /// Search request for an item sale administration.
  17256. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17257. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17258. #if PACKETVER_SUPPORTS_SALES
  17259. char item_name[ITEM_NAME_LENGTH];
  17260. struct item_data *id = NULL;
  17261. nullpo_retv(sd);
  17262. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17263. return;
  17264. }
  17265. if( !sd->state.sale_open ){
  17266. return;
  17267. }
  17268. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17269. id = itemdb_searchname(item_name);
  17270. if( id ){
  17271. int i;
  17272. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17273. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17274. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17275. return;
  17276. }
  17277. }
  17278. }
  17279. // not found
  17280. clif_sale_search_reply( sd, NULL );
  17281. #endif
  17282. }
  17283. /// Reply if an item was successfully put on sale or not.
  17284. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17285. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17286. #if PACKETVER_SUPPORTS_SALES
  17287. int fd = sd->fd;
  17288. WFIFOHEAD(fd, 4);
  17289. WFIFOW(fd, 0) = 0x9af;
  17290. WFIFOW(fd, 2) = (uint16)result;
  17291. WFIFOSET(fd, 4);
  17292. #endif
  17293. }
  17294. /// A client request to put an item on sale.
  17295. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17296. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17297. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17298. #if PACKETVER_SUPPORTS_SALES
  17299. nullpo_retv( sd );
  17300. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17301. if( p->AID != sd->status.account_id ){
  17302. return;
  17303. }
  17304. if( !sd->state.sale_open ){
  17305. return;
  17306. }
  17307. time_t endTime = p->startTime + p->hours * 60 * 60;
  17308. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17309. #endif
  17310. }
  17311. /// Reply to an item removal from sale.
  17312. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17313. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17314. #if PACKETVER_SUPPORTS_SALES
  17315. int fd = sd->fd;
  17316. WFIFOHEAD(fd, 4);
  17317. WFIFOW(fd, 0) = 0x9b1;
  17318. WFIFOW(fd, 2) = failed;
  17319. WFIFOSET(fd, 4);
  17320. #endif
  17321. }
  17322. /// Request to remove an item from sale.
  17323. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17324. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17325. #if PACKETVER_SUPPORTS_SALES
  17326. nullpo_retv( sd );
  17327. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17328. if( p->AID != sd->status.account_id ){
  17329. return;
  17330. }
  17331. if( !sd->state.sale_open ){
  17332. return;
  17333. }
  17334. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17335. #endif
  17336. }
  17337. /// Achievement System
  17338. /// Author: Luxuri, Aleos
  17339. /**
  17340. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17341. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17342. */
  17343. void clif_achievement_list_all(struct map_session_data *sd)
  17344. {
  17345. nullpo_retv(sd);
  17346. if (!battle_config.feature_achievement) {
  17347. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17348. return;
  17349. }
  17350. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17351. if (count == 0)
  17352. return;
  17353. int len = (50 * count) + 22;
  17354. int fd = sd->fd;
  17355. int *info = achievement_level(sd, true);
  17356. WFIFOHEAD(fd,len);
  17357. WFIFOW(fd, 0) = 0xa23;
  17358. WFIFOW(fd, 2) = len;
  17359. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17360. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17361. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17362. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17363. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17364. for (int i = 0; i < count; i++) {
  17365. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17366. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17367. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17368. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17369. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17370. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17371. }
  17372. WFIFOSET(fd, len);
  17373. }
  17374. /**
  17375. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17376. * 0a24 <packetType>.W <ACHPoint>.L
  17377. */
  17378. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17379. {
  17380. nullpo_retv(sd);
  17381. if (!battle_config.feature_achievement) {
  17382. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17383. return;
  17384. }
  17385. int fd = sd->fd;
  17386. int *info = achievement_level(sd, true);
  17387. WFIFOHEAD(fd, packet_len(0xa24));
  17388. WFIFOW(fd, 0) = 0xa24;
  17389. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17390. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17391. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17392. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17393. if (ach) {
  17394. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17395. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17396. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17397. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17398. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17399. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17400. } else
  17401. memset(WFIFOP(fd, 16), 0, 40);
  17402. WFIFOSET(fd, packet_len(0xa24));
  17403. }
  17404. /**
  17405. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17406. * 0a25 <packetType>.W <achievementID>.L
  17407. */
  17408. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17409. {
  17410. nullpo_retv(sd);
  17411. if( sd->achievement_data.save )
  17412. intif_achievement_save(sd);
  17413. achievement_check_reward(sd, RFIFOL(fd,2));
  17414. }
  17415. /**
  17416. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17417. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17418. */
  17419. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17420. {
  17421. WFIFOHEAD(fd, packet_len(0xa26));
  17422. WFIFOW(fd, 0) = 0xa26;
  17423. WFIFOB(fd, 2) = result;
  17424. WFIFOL(fd, 3) = achievement_id;
  17425. WFIFOSET(fd, packet_len(0xa26));
  17426. }
  17427. /// Process the pet evolution request
  17428. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17429. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17430. #if PACKETVER >= 20141008
  17431. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17432. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17433. if (!pet) {
  17434. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17435. return;
  17436. }
  17437. pet_evolution(sd, pet->class_);
  17438. #endif
  17439. }
  17440. /// Sends the result of the evolution to the client.
  17441. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17442. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17443. #if PACKETVER >= 20141008
  17444. int fd = sd->fd;
  17445. WFIFOHEAD(fd, packet_len(0x9fc));
  17446. WFIFOW(fd, 0) = 0x9fc;
  17447. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17448. WFIFOSET(fd, packet_len(0x9fc));
  17449. #endif
  17450. }
  17451. /*
  17452. * This packet is sent by /changedress or /nocosplay
  17453. *
  17454. * 0ae8
  17455. */
  17456. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17457. #if PACKETVER >= 20180103
  17458. char command[CHAT_SIZE_MAX];
  17459. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17460. is_atcommand( fd, sd, command, 1 );
  17461. #endif
  17462. }
  17463. /// Opens an UI window of the given type and initializes it with the given data
  17464. /// 0AE2 <type>.B <data>.L
  17465. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17466. nullpo_retv(sd);
  17467. int fd = sd->fd;
  17468. WFIFOHEAD(fd,packet_len(0xae2));
  17469. WFIFOW(fd,0) = 0xae2;
  17470. WFIFOB(fd,2) = ui_type;
  17471. WFIFOL(fd,3) = data;
  17472. WFIFOSET(fd,packet_len(0xae2));
  17473. }
  17474. /// Request to open an UI window of the given type
  17475. /// 0A68 <type>.B
  17476. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17477. switch( RFIFOB(fd,2) ){
  17478. case IN_UI_ATTENDANCE:
  17479. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17480. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17481. }else if( pc_attendance_enabled() ){
  17482. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17483. }else{
  17484. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17485. }
  17486. break;
  17487. }
  17488. }
  17489. /// Response for attedance request
  17490. /// 0AF0 <unknown>.L <data>.L
  17491. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17492. nullpo_retv(sd);
  17493. int fd = sd->fd;
  17494. WFIFOHEAD(fd,packet_len(0xAF0));
  17495. WFIFOW(fd,0) = 0xAF0;
  17496. WFIFOL(fd,2) = 0;
  17497. WFIFOL(fd,6) = data;
  17498. WFIFOSET(fd,packet_len(0xAF0));
  17499. }
  17500. /// Request from the client to retrieve today's attendance reward
  17501. /// 0AEF
  17502. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17503. pc_attendance_claim_reward(sd);
  17504. }
  17505. /// Send out the percentage of weight that causes it to be displayed in red.
  17506. /// 0ADE <percentage>.L
  17507. void clif_weight_limit( struct map_session_data* sd ){
  17508. #if PACKETVER >= 20171025
  17509. nullpo_retv(sd);
  17510. int fd = sd->fd;
  17511. WFIFOHEAD(fd, packet_len(0xADE));
  17512. WFIFOW(fd, 0) = 0xADE;
  17513. #ifdef RENEWAL
  17514. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17515. #else
  17516. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17517. #endif
  17518. WFIFOSET(fd, packet_len(0xADE));
  17519. #endif
  17520. }
  17521. enum e_private_airship_response : uint32{
  17522. PRIVATEAIRSHIP_OK,
  17523. PRIVATEAIRSHIP_RETRY,
  17524. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17525. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17526. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17527. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17528. };
  17529. /// Send out the response to a private airship request
  17530. /// 0A4A <response>.L
  17531. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17532. #if PACKETVER >= 20180321
  17533. nullpo_retv( sd );
  17534. int fd = sd->fd;
  17535. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17536. WFIFOW( fd, 0 ) = 0xA4A;
  17537. WFIFOL( fd, 2 ) = response;
  17538. WFIFOSET( fd, packet_len( 0xA4A ) );
  17539. #endif
  17540. }
  17541. /// Parses a request for a private airship
  17542. /// 0A49 <mapname>.16B <itemid>.W
  17543. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17544. #if PACKETVER >= 20180321
  17545. // Check if the feature is enabled
  17546. if( !battle_config.feature_privateairship ){
  17547. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17548. return;
  17549. }
  17550. // Check if the player is allowed to warp from the source map
  17551. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17552. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17553. return;
  17554. }
  17555. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17556. char mapname[MAP_NAME_LENGTH_EXT];
  17557. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17558. int16 mapindex = mapindex_name2id( mapname );
  17559. // Check if we know the mapname
  17560. if( mapindex < 0 ){
  17561. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17562. return;
  17563. }
  17564. int16 mapid = map_mapindex2mapid( mapindex );
  17565. // Check if the map is available on this server
  17566. if( mapid < 0 ){
  17567. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17568. return;
  17569. }
  17570. // Check if the player tried to warp to the map he is on
  17571. if( sd->bl.m == mapid ){
  17572. // This is blocked by the client, but just to be sure
  17573. return;
  17574. }
  17575. // This can only be a hack, so we prevent it
  17576. if( map_getmapdata( mapid )->instance_id ){
  17577. // Ignore requests to warp directly into a running instance
  17578. return;
  17579. }
  17580. // Check if the player is allowed to warp to the target map
  17581. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17582. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17583. return;
  17584. }
  17585. uint16 item_id = p->ItemID;
  17586. // Check if the item sent by the client is known to us
  17587. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17588. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17589. return;
  17590. }
  17591. int idx = pc_search_inventory( sd, item_id );
  17592. // Check if the player has the item at all
  17593. if( idx < 0 ){
  17594. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17595. return;
  17596. }
  17597. // Delete the chosen item
  17598. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17599. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17600. return;
  17601. }
  17602. // Warp the player to a random spot on the destination map
  17603. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17604. #endif
  17605. }
  17606. /// Sends out the usage history of the guild storage
  17607. /// 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
  17608. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17609. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17610. #if PACKETVER >= 20140205
  17611. nullpo_retv( sd );
  17612. int fd = sd->fd;
  17613. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17614. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17615. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17616. }else{
  17617. log.clear();
  17618. }
  17619. WFIFOHEAD( fd, size );
  17620. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17621. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17622. p->PacketLength = size;
  17623. p->result = result;
  17624. p->amount = (uint16)log.size();
  17625. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17626. for( int i = 0; i < log.size(); i++ ){
  17627. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  17628. struct guild_log_entry& entry = log[i];
  17629. item->id = entry.id;
  17630. item->itemId = client_nameid( entry.item.nameid );
  17631. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17632. item->action = entry.amount > 0; // action = true(put), false(get)
  17633. item->refine = entry.item.refine;
  17634. item->uniqueId = entry.item.unique_id;
  17635. item->IsIdentified = entry.item.identify;
  17636. item->itemType = itemtype( entry.item.nameid );
  17637. clif_addcards( &item->slot, &entry.item );
  17638. safestrncpy( item->name, entry.name, NAME_LENGTH );
  17639. safestrncpy( item->time, entry.time, NAME_LENGTH );
  17640. item->attribute = entry.item.attribute;
  17641. }
  17642. }
  17643. WFIFOSET( fd, p->PacketLength );
  17644. #endif
  17645. }
  17646. /// Activates the client camera info or updates the client camera with the given values.
  17647. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17648. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17649. #if PACKETVER >= 20160525
  17650. int fd = sd->fd;
  17651. WFIFOHEAD(fd, packet_len(0xa78));
  17652. WFIFOW(fd, 0) = 0xa78;
  17653. WFIFOB(fd, 2) = show;
  17654. WFIFOF(fd, 3) = range;
  17655. WFIFOF(fd, 7) = rotation;
  17656. WFIFOF(fd, 11) = latitude;
  17657. WFIFOSET(fd, packet_len(0xa78));
  17658. #endif
  17659. }
  17660. /// Activates or deactives the client camera info or updates the camera settings.
  17661. /// This packet is triggered by /viewpointvalue or /setcamera
  17662. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17663. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17664. char command[CHAT_SIZE_MAX];
  17665. // /viewpointvalue
  17666. if( RFIFOB( fd, 2 ) == 1 ){
  17667. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17668. // /setcamera
  17669. }else{
  17670. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17671. }
  17672. is_atcommand( fd, sd, command, 1 );
  17673. }
  17674. /// Send the full list of items in the equip switch window
  17675. /// 0a9b <length>.W { <index>.W <position>.L }*
  17676. void clif_equipswitch_list( struct map_session_data* sd ){
  17677. #if PACKETVER >= 20170208
  17678. int fd = sd->fd;
  17679. int offset, i, position;
  17680. WFIFOW(fd, 0) = 0xa9b;
  17681. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17682. short index = sd->equip_switch_index[i];
  17683. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17684. WFIFOW(fd, offset) = index + 2;
  17685. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17686. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17687. offset += 6;
  17688. }
  17689. }
  17690. WFIFOW(fd, 2) = offset;
  17691. WFIFOSET(fd, offset);
  17692. #endif
  17693. }
  17694. /// Acknowledgement for removing an equip to the equip switch window
  17695. /// 0a9a <index>.W <position.>.L <failure>.W
  17696. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17697. #if PACKETVER >= 20170208
  17698. int fd = sd->fd;
  17699. WFIFOHEAD(fd, packet_len(0xa9a));
  17700. WFIFOW(fd, 0) = 0xa9a;
  17701. WFIFOW(fd, 2) = index + 2;
  17702. WFIFOL(fd, 4) = pos;
  17703. WFIFOW(fd, 8) = failed;
  17704. WFIFOSET(fd, packet_len(0xa9a));
  17705. #endif
  17706. }
  17707. /// Request to remove an equip from the equip switch window
  17708. /// 0a99 <index>.W <position>.L <= 20170502
  17709. /// 0a99 <index>.W
  17710. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17711. #if PACKETVER >= 20170208
  17712. uint16 index = RFIFOW(fd, 2) - 2;
  17713. bool removed = false;
  17714. if( !battle_config.feature_equipswitch ){
  17715. return;
  17716. }
  17717. // Check if the index is valid
  17718. if( index >= MAX_INVENTORY ){
  17719. return;
  17720. }
  17721. pc_equipswitch_remove( sd, index );
  17722. #endif
  17723. }
  17724. /// Acknowledgement for adding an equip to the equip switch window
  17725. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17726. /// 0a98 <index>.W <position.>.L <flag>.W
  17727. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17728. #if PACKETVER >= 20170208
  17729. int fd = sd->fd;
  17730. WFIFOHEAD(fd, packet_len(0xa98));
  17731. WFIFOW(fd, 0) = 0xa98;
  17732. WFIFOW(fd, 2) = index + 2;
  17733. WFIFOL(fd, 4) = pos;
  17734. #if PACKETVER <= 20170502
  17735. WFIFOL(fd, 8) = flag;
  17736. #else
  17737. WFIFOW(fd, 8) = flag;
  17738. #endif
  17739. WFIFOSET(fd,packet_len(0xa98));
  17740. #endif
  17741. }
  17742. /// Request to add an equip to the equip switch window
  17743. /// 0a97 <index>.W <position>.L
  17744. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17745. #if PACKETVER >= 20170208
  17746. uint16 index = RFIFOW(fd, 2) - 2;
  17747. uint32 position = RFIFOL(fd, 4);
  17748. if( !battle_config.feature_equipswitch ){
  17749. return;
  17750. }
  17751. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17752. return;
  17753. }
  17754. if( sd->state.trading || sd->npc_shopid ){
  17755. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17756. return;
  17757. }
  17758. if( sd->inventory_data[index]->type == IT_AMMO ){
  17759. position = EQP_AMMO;
  17760. }
  17761. pc_equipitem( sd, index, position, true );
  17762. #endif
  17763. }
  17764. /// Acknowledgement packet for the full equip switch
  17765. /// 0a9d <failed>.W
  17766. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17767. #if PACKETVER >= 20170208
  17768. int fd = sd->fd;
  17769. WFIFOHEAD(fd, packet_len(0xa9d));
  17770. WFIFOW(fd, 0) = 0xa9d;
  17771. WFIFOW(fd, 2) = failed;
  17772. WFIFOSET(fd, packet_len(0xa9d));
  17773. #endif
  17774. }
  17775. /// Request to do a full equip switch
  17776. /// 0a9c
  17777. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17778. #if PACKETVER >= 20170208
  17779. int i;
  17780. t_tick tick = gettick();
  17781. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17782. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17783. // Client will not let you send a request
  17784. return;
  17785. }
  17786. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17787. if( !battle_config.feature_equipswitch ){
  17788. return;
  17789. }
  17790. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17791. if( i == EQI_MAX ){
  17792. // client will show: "There is no item to replace." and should not even come here
  17793. clif_equipswitch_reply( sd, false );
  17794. return;
  17795. }
  17796. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17797. return;
  17798. }
  17799. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17800. #endif
  17801. }
  17802. /// Request to do a single equip switch
  17803. /// 0ace <index>.W
  17804. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17805. #if PACKETVER >= 20170502
  17806. uint16 index = RFIFOW(fd, 2) - 2;
  17807. if( !battle_config.feature_equipswitch ){
  17808. return;
  17809. }
  17810. // Check if the index is valid
  17811. if( index >= MAX_INVENTORY ){
  17812. return;
  17813. }
  17814. // Check if the item exists
  17815. if (sd->inventory_data[index] == nullptr)
  17816. return;
  17817. // Check if the item was already added to equip switch
  17818. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17819. if( sd->npc_id ){
  17820. #ifdef RENEWAL
  17821. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17822. clif_msg( sd, WORK_IN_PROGRESS );
  17823. return;
  17824. }
  17825. #endif
  17826. if( !sd->npc_item_flag ){
  17827. return;
  17828. }
  17829. }
  17830. pc_equipswitch( sd, index );
  17831. return;
  17832. }
  17833. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  17834. #endif
  17835. }
  17836. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  17837. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  17838. const struct PACKET_CZ_START_USE_SKILL *p = (struct PACKET_CZ_START_USE_SKILL *)RFIFOP( fd, 0 );
  17839. // Only rolling cutter is supported for now
  17840. if( p->skillId != GC_ROLLINGCUTTER ){
  17841. return;
  17842. }
  17843. // Already running - cant happen on officials, since only one skill is supported
  17844. if( sd->skill_keep_using.skill_id != 0 ){
  17845. return;
  17846. }
  17847. sd->skill_keep_using.tid = INVALID_TIMER;
  17848. sd->skill_keep_using.skill_id = p->skillId;
  17849. sd->skill_keep_using.level = p->skillLv;
  17850. sd->skill_keep_using.target = p->targetId;
  17851. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  17852. #endif
  17853. }
  17854. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  17855. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  17856. const struct PACKET_CZ_STOP_USE_SKILL *p = (struct PACKET_CZ_STOP_USE_SKILL *)RFIFOP( fd, 0 );
  17857. // Not running
  17858. if( sd->skill_keep_using.skill_id == 0 ){
  17859. return;
  17860. }
  17861. #if 0
  17862. // Hack
  17863. if( p->skillId != sd->skill_keep_using.skill_id ){
  17864. return;
  17865. }
  17866. #endif
  17867. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  17868. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  17869. sd->skill_keep_using.tid = INVALID_TIMER;
  17870. }
  17871. sd->skill_keep_using.skill_id = 0;
  17872. sd->skill_keep_using.level = 0;
  17873. sd->skill_keep_using.target = 0;
  17874. #endif
  17875. }
  17876. void clif_ping( struct map_session_data* sd ){
  17877. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  17878. nullpo_retv( sd );
  17879. int fd = sd->fd;
  17880. if( !session_isActive( fd ) ){
  17881. return;
  17882. }
  17883. struct PACKET_ZC_PING p;
  17884. p.packetType = HEADER_ZC_PING;
  17885. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17886. #endif
  17887. }
  17888. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  17889. nullpo_ret( sd );
  17890. int fd = sd->fd;
  17891. if( !session_isActive( fd ) ){
  17892. return 0;
  17893. }
  17894. t_tick tick = va_arg( ap, t_tick );
  17895. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  17896. clif_ping( sd );
  17897. }
  17898. return 0;
  17899. }
  17900. TIMER_FUNC( clif_ping_timer ){
  17901. map_foreachpc( clif_ping_timer_sub, gettick() );
  17902. return 0;
  17903. }
  17904. /*==========================================
  17905. * Main client packet processing function
  17906. *------------------------------------------*/
  17907. static int clif_parse(int fd)
  17908. {
  17909. int cmd, packet_len;
  17910. TBL_PC* sd;
  17911. int pnum;
  17912. #ifdef PACKET_OBFUSCATION
  17913. int cmd2;
  17914. #endif
  17915. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17916. // Note: "click masters" can do 80+ clicks in 10 seconds
  17917. 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]
  17918. { // begin main client packet processing loop
  17919. sd = (TBL_PC *)session[fd]->session_data;
  17920. if (session[fd]->flag.eof) {
  17921. if (sd) {
  17922. if (sd->state.autotrade) {
  17923. //Disassociate character from the socket connection.
  17924. session[fd]->session_data = NULL;
  17925. sd->fd = 0;
  17926. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17927. } else
  17928. if (sd->state.active) {
  17929. // Player logout display [Valaris]
  17930. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17931. clif_quitsave(fd, sd);
  17932. } else {
  17933. //Unusual logout (during log on/off/map-changer procedure)
  17934. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17935. map_quit(sd);
  17936. }
  17937. } else {
  17938. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17939. }
  17940. do_close(fd);
  17941. return 0;
  17942. }
  17943. if (RFIFOREST(fd) < 2)
  17944. return 0;
  17945. cmd = RFIFOW(fd, 0);
  17946. #ifdef PACKET_OBFUSCATION
  17947. // Check if it is a player that tries to connect to the map server.
  17948. if( sd ){
  17949. // Decrypt the current packet ID with the last key stored in the session.
  17950. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17951. }else{
  17952. // Store the original value for checking
  17953. cmd2 = cmd;
  17954. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17955. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17956. }
  17957. #endif
  17958. // filter out invalid / unsupported packets
  17959. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17960. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17961. #ifdef DUMP_INVALID_PACKET
  17962. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17963. #endif
  17964. #ifdef PACKET_OBFUSCATION_WARN
  17965. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17966. if( !sd ){
  17967. #ifdef PACKET_OBFUSCATION
  17968. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17969. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17970. }
  17971. #else
  17972. // Try to use the initial keys for the decryption of the packet ID.
  17973. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17974. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17975. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17976. }
  17977. #endif
  17978. }
  17979. #endif
  17980. set_eof(fd);
  17981. return 0;
  17982. }
  17983. // determine real packet length
  17984. packet_len = packet_db[cmd].len;
  17985. if (packet_len == -1) { // variable-length packet
  17986. if (RFIFOREST(fd) < 4)
  17987. return 0;
  17988. packet_len = RFIFOW(fd,2);
  17989. if (packet_len < 4 || packet_len > 32768) {
  17990. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17991. #ifdef DUMP_INVALID_PACKET
  17992. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17993. #endif
  17994. set_eof(fd);
  17995. return 0;
  17996. }
  17997. }
  17998. if ((int)RFIFOREST(fd) < packet_len){
  17999. 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 );
  18000. #ifdef DUMP_INVALID_PACKET
  18001. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  18002. #endif
  18003. set_eof( fd );
  18004. return 0; // not enough data received to form the packet
  18005. }
  18006. #ifdef PACKET_OBFUSCATION
  18007. RFIFOW(fd, 0) = cmd;
  18008. if (sd)
  18009. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  18010. #endif
  18011. if( packet_db[cmd].func == clif_parse_debug )
  18012. packet_db[cmd].func(fd, sd);
  18013. else if( packet_db[cmd].func != NULL ) {
  18014. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  18015. ; //Only valid packet when there is no session
  18016. else
  18017. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  18018. ; //Only valid packet when player is not on a map
  18019. else
  18020. packet_db[cmd].func(fd, sd);
  18021. }
  18022. #ifdef DUMP_UNKNOWN_PACKET
  18023. else DumpUnknown(fd,sd,cmd,packet_len);
  18024. #endif
  18025. RFIFOSKIP(fd, packet_len);
  18026. }; // main loop end
  18027. return 0;
  18028. }
  18029. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  18030. va_list argp;
  18031. int i;
  18032. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  18033. return;
  18034. packet_db[cmd].len = length;
  18035. packet_db[cmd].func = func;
  18036. va_start(argp, func);
  18037. for( i = 0; i < MAX_PACKET_POS; i++ ){
  18038. int offset = va_arg(argp, int);
  18039. if( offset == 0 ){
  18040. break;
  18041. }
  18042. packet_db[cmd].pos[i] = offset;
  18043. }
  18044. if( i == MAX_PACKET_POS ){
  18045. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  18046. }
  18047. va_end(argp);
  18048. }
  18049. /*==========================================
  18050. * Reads packets and setups its array reference
  18051. *------------------------------------------*/
  18052. void packetdb_readdb(){
  18053. memset(packet_db,0,sizeof(packet_db));
  18054. memset(packet_db_ack,0,sizeof(packet_db_ack));
  18055. #include "clif_packetdb.hpp"
  18056. #include "clif_shuffle.hpp"
  18057. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  18058. #ifdef PACKET_OBFUSCATION
  18059. 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]);
  18060. #else
  18061. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  18062. #endif
  18063. }
  18064. /*==========================================
  18065. *
  18066. *------------------------------------------*/
  18067. void do_init_clif(void) {
  18068. const char* colors[COLOR_MAX] = {
  18069. "0x00FF00",
  18070. "0xFF0000",
  18071. "0xFFFFFF",
  18072. "0xFFFF00",
  18073. "0x00FFFF",
  18074. "0xB5FFB5",
  18075. };
  18076. int i;
  18077. /**
  18078. * Setup Color Table (saves unnecessary load of strtoul on every call)
  18079. **/
  18080. for(i = 0; i < COLOR_MAX; i++) {
  18081. color_table[i] = strtoul(colors[i],NULL,0);
  18082. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  18083. }
  18084. packetdb_readdb();
  18085. set_defaultparse(clif_parse);
  18086. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  18087. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  18088. exit(EXIT_FAILURE);
  18089. }
  18090. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  18091. add_timer_func_list(clif_delayquit, "clif_delayquit");
  18092. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  18093. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  18094. if( battle_config.ping_timer_interval > 0 ){
  18095. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  18096. }
  18097. #endif
  18098. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  18099. }
  18100. void do_final_clif(void) {
  18101. ers_destroy(delay_clearunit_ers);
  18102. }