clif.cpp 622 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590
  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. fd = sd->fd;
  318. if (!fd) //Don't send to disconnected clients.
  319. return 0;
  320. buf = va_arg(ap,unsigned char*);
  321. len = va_arg(ap,int);
  322. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  323. type = va_arg(ap,int);
  324. switch(type) {
  325. case AREA_WOS:
  326. if (bl == src_bl)
  327. return 0;
  328. break;
  329. case AREA_WOC:
  330. if (sd->chatID || bl == src_bl)
  331. return 0;
  332. break;
  333. case AREA_WOSC:
  334. {
  335. if(src_bl->type == BL_PC) {
  336. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  337. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  338. return 0;
  339. }
  340. else if(src_bl->type == BL_NPC) {
  341. struct npc_data *nd = (struct npc_data *)src_bl;
  342. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  343. return 0;
  344. }
  345. }
  346. break;
  347. }
  348. if (session[fd] == NULL)
  349. return 0;
  350. /* unless visible, hold it here */
  351. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  352. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  353. return 0;
  354. WFIFOHEAD(fd, len);
  355. if (WFIFOP(fd,0) == buf) {
  356. ShowError("WARNING: Invalid use of clif_send function\n");
  357. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  358. ShowError(" Please correct your code.\n");
  359. // don't send to not move the pointer of the packet for next sessions in the loop
  360. //WFIFOSET(fd,0);//## TODO is this ok?
  361. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  362. return 0;
  363. }
  364. memcpy(WFIFOP(fd,0), buf, len);
  365. WFIFOSET(fd,len);
  366. return 0;
  367. }
  368. /*==========================================
  369. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  370. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  371. *------------------------------------------*/
  372. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  373. {
  374. int i;
  375. struct map_session_data *sd, *tsd;
  376. struct party_data *p = NULL;
  377. struct guild *g = NULL;
  378. std::shared_ptr<s_battleground_data> bg;
  379. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  380. struct s_mapiterator* iter;
  381. if( type != ALL_CLIENT )
  382. nullpo_ret(bl);
  383. sd = BL_CAST(BL_PC, bl);
  384. switch(type) {
  385. case ALL_CLIENT: //All player clients.
  386. iter = mapit_getallusers();
  387. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ){
  388. WFIFOHEAD(tsd->fd, len);
  389. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  390. WFIFOSET(tsd->fd, len);
  391. }
  392. mapit_free(iter);
  393. break;
  394. case ALL_SAMEMAP: //All players on the same map
  395. iter = mapit_getallusers();
  396. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  397. {
  398. if( bl->m == tsd->bl.m ){
  399. WFIFOHEAD(tsd->fd, len);
  400. memcpy(WFIFOP(tsd->fd,0), buf, len);
  401. WFIFOSET(tsd->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 ((fd=cd->usersd[i]->fd) >0 && session[fd]){ // Added check to see if session exists [PoW]
  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( !(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 = (TBL_PC*)mapit_next(iter)) != NULL )
  473. {
  474. if( tsd->partyspy == p->party.party_id ){
  475. WFIFOHEAD(tsd->fd, len);
  476. memcpy(WFIFOP(tsd->fd,0), buf, len);
  477. WFIFOSET(tsd->fd,len);
  478. }
  479. }
  480. mapit_free(iter);
  481. }
  482. break;
  483. case DUEL:
  484. case DUEL_WOS:
  485. if (!sd || !sd->duel_group) break; //Invalid usage.
  486. iter = mapit_getallusers();
  487. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  488. {
  489. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  490. continue;
  491. if( sd->duel_group == tsd->duel_group ){
  492. WFIFOHEAD(tsd->fd, len);
  493. memcpy(WFIFOP(tsd->fd,0), buf, len);
  494. WFIFOSET(tsd->fd,len);
  495. }
  496. }
  497. mapit_free(iter);
  498. break;
  499. case SELF:
  500. if (sd && (fd=sd->fd)) {
  501. WFIFOHEAD(fd,len);
  502. memcpy(WFIFOP(fd,0), buf, len);
  503. WFIFOSET(fd,len);
  504. }
  505. break;
  506. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  507. case GUILD_AREA:
  508. case GUILD_AREA_WOS:
  509. x0 = bl->x - AREA_SIZE;
  510. y0 = bl->y - AREA_SIZE;
  511. x1 = bl->x + AREA_SIZE;
  512. y1 = bl->y + AREA_SIZE;
  513. case GUILD_SAMEMAP:
  514. case GUILD_SAMEMAP_WOS:
  515. case GUILD:
  516. case GUILD_WOS:
  517. case GUILD_NOBG:
  518. if (sd && sd->status.guild_id)
  519. g = sd->guild;
  520. if (g) {
  521. for(i = 0; i < g->max_member; i++) {
  522. if( (sd = g->member[i].sd) != NULL )
  523. {
  524. if( !(fd=sd->fd) )
  525. continue;
  526. if( type == GUILD_NOBG && sd->bg_id )
  527. continue;
  528. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  529. continue;
  530. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  531. continue;
  532. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  533. continue;
  534. WFIFOHEAD(fd,len);
  535. memcpy(WFIFOP(fd,0), buf, len);
  536. WFIFOSET(fd,len);
  537. }
  538. }
  539. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  540. break;
  541. iter = mapit_getallusers();
  542. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  543. {
  544. if( tsd->guildspy == g->guild_id ){
  545. WFIFOHEAD(tsd->fd, len);
  546. memcpy(WFIFOP(tsd->fd,0), buf, len);
  547. WFIFOSET(tsd->fd,len);
  548. }
  549. }
  550. mapit_free(iter);
  551. }
  552. break;
  553. case BG_AREA:
  554. case BG_AREA_WOS:
  555. x0 = bl->x - AREA_SIZE;
  556. y0 = bl->y - AREA_SIZE;
  557. x1 = bl->x + AREA_SIZE;
  558. y1 = bl->y + AREA_SIZE;
  559. case BG_SAMEMAP:
  560. case BG_SAMEMAP_WOS:
  561. case BG:
  562. case BG_WOS:
  563. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  564. {
  565. for (const auto &member : bg->members) {
  566. if((sd = member.sd) == nullptr || (fd = sd->fd) == 0)
  567. continue;
  568. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  569. continue;
  570. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  571. continue;
  572. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  573. continue;
  574. WFIFOHEAD(fd,len);
  575. memcpy(WFIFOP(fd,0), buf, len);
  576. WFIFOSET(fd,len);
  577. }
  578. }
  579. break;
  580. case CLAN:
  581. if( sd && sd->clan ){
  582. struct clan* clan = sd->clan;
  583. for( i = 0; i < clan->max_member; i++ ){
  584. if( ( sd = clan->members[i] ) == NULL || !(fd = sd->fd) ){
  585. continue;
  586. }
  587. WFIFOHEAD(fd,len);
  588. memcpy(WFIFOP(fd,0), buf, len);
  589. WFIFOSET(fd,len);
  590. }
  591. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  592. break;
  593. iter = mapit_getallusers();
  594. while ((tsd = (TBL_PC*)mapit_next(iter)) != NULL){
  595. if (tsd->clanspy == clan->id){
  596. WFIFOHEAD(tsd->fd, len);
  597. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  598. WFIFOSET(tsd->fd, len);
  599. }
  600. }
  601. mapit_free(iter);
  602. }
  603. break;
  604. default:
  605. ShowError("clif_send: Unrecognized type %d\n",type);
  606. return -1;
  607. }
  608. return 0;
  609. }
  610. /// Notifies the client, that it's connection attempt was accepted.
  611. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  612. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  613. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  614. void clif_authok(struct map_session_data *sd)
  615. {
  616. #if PACKETVER < 20080102
  617. const int cmd = 0x73;
  618. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  619. const int cmd = 0x2eb;
  620. #else
  621. const int cmd = 0xa18;
  622. #endif
  623. int fd = sd->fd;
  624. WFIFOHEAD(fd,packet_len(cmd));
  625. WFIFOW(fd, 0) = cmd;
  626. WFIFOL(fd, 2) = client_tick(gettick());
  627. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  628. WFIFOB(fd, 9) = 5; // ignored
  629. WFIFOB(fd,10) = 5; // ignored
  630. #if PACKETVER >= 20080102
  631. WFIFOW(fd,11) = sd->status.font;
  632. #endif
  633. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  634. WFIFOB(fd,13) = sd->status.sex;
  635. #endif
  636. WFIFOSET(fd,packet_len(cmd));
  637. }
  638. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  639. /// 0074 <error code>.B
  640. /// error code:
  641. /// 0 = client type mismatch
  642. /// 1 = ID mismatch
  643. /// 2 = mobile - out of available time
  644. /// 3 = mobile - already logged in
  645. /// 4 = mobile - waiting state
  646. void clif_authrefuse(int fd, uint8 error_code)
  647. {
  648. WFIFOHEAD(fd,packet_len(0x74));
  649. WFIFOW(fd,0) = 0x74;
  650. WFIFOB(fd,2) = error_code;
  651. WFIFOSET(fd,packet_len(0x74));
  652. }
  653. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  654. /// 0081 <error code>.B
  655. /// error code:
  656. /// 0 = BAN_UNFAIR
  657. /// 1 = server closed -> MsgStringTable[4]
  658. /// 2 = ID already logged in -> MsgStringTable[5]
  659. /// 3 = timeout/too much lag -> MsgStringTable[241]
  660. /// 4 = server full -> MsgStringTable[264]
  661. /// 5 = underaged -> MsgStringTable[305]
  662. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  663. /// 9 = too many connections from this ip -> MsgStringTable[529]
  664. /// 10 = out of available time paid for -> MsgStringTable[530]
  665. /// 11 = BAN_PAY_SUSPEND
  666. /// 12 = BAN_PAY_CHANGE
  667. /// 13 = BAN_PAY_WRONGIP
  668. /// 14 = BAN_PAY_PNGAMEROOM
  669. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  670. /// 16 = BAN_JAPAN_REFUSE1
  671. /// 17 = BAN_JAPAN_REFUSE2
  672. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  673. /// 100 = BAN_PC_IP_UNFAIR
  674. /// 101 = BAN_PC_IP_COUNT_ALL
  675. /// 102 = BAN_PC_IP_COUNT
  676. /// 103 = BAN_GRAVITY_MEM_AGREE
  677. /// 104 = BAN_GAME_MEM_AGREE
  678. /// 105 = BAN_HAN_VALID
  679. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  680. /// 107 = BAN_OVER_CHARACTER_LIST
  681. /// 108 = BAN_IP_BLOCK
  682. /// 109 = BAN_INVALID_PWD_CNT
  683. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  684. /// ? = disconnected -> MsgStringTable[3]
  685. void clif_authfail_fd(int fd, int type)
  686. {
  687. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  688. return;
  689. WFIFOHEAD(fd, packet_len(0x81));
  690. WFIFOW(fd,0) = 0x81;
  691. WFIFOB(fd,2) = type;
  692. WFIFOSET(fd,packet_len(0x81));
  693. set_eof(fd);
  694. }
  695. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  696. /// 00b3 <type>.B
  697. /// type:
  698. /// 1 = disconnect, char-select
  699. /// ? = nothing
  700. void clif_charselectok(int id, uint8 ok)
  701. {
  702. struct map_session_data* sd;
  703. int fd;
  704. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  705. return;
  706. fd = sd->fd;
  707. WFIFOHEAD(fd,packet_len(0xb3));
  708. WFIFOW(fd,0) = 0xb3;
  709. WFIFOB(fd,2) = ok;
  710. WFIFOSET(fd,packet_len(0xb3));
  711. }
  712. /// Makes an item appear on the ground.
  713. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  714. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  715. /// 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)
  716. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  717. nullpo_retv(fitem);
  718. if( fitem->item.nameid <= 0 ){
  719. return;
  720. }
  721. int view = itemdb_viewid( fitem->item.nameid );
  722. struct packet_dropflooritem p;
  723. p.PacketType = dropflooritemType;
  724. p.ITAID = fitem->bl.id;
  725. p.ITID = ( view > 0 ) ? view : fitem->item.nameid;
  726. #if PACKETVER >= 20130000 /* not sure date */
  727. p.type = itemtype( fitem->item.nameid );
  728. #endif
  729. p.IsIdentified = fitem->item.identify ? 1 : 0;
  730. p.xPos = fitem->bl.x;
  731. p.yPos = fitem->bl.y;
  732. p.subX = fitem->subx;
  733. p.subY = fitem->suby;
  734. p.count = fitem->item.amount;
  735. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  736. if( canShowEffect ){
  737. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  738. if( dropEffect > 0 ){
  739. p.showdropeffect = 1;
  740. p.dropeffectmode = dropEffect - 1;
  741. }else{
  742. p.showdropeffect = 0;
  743. p.dropeffectmode = 0;
  744. }
  745. }else{
  746. p.showdropeffect = 0;
  747. p.dropeffectmode = 0;
  748. }
  749. #endif
  750. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  751. }
  752. /// Makes an item disappear from the ground.
  753. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  754. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  755. {
  756. unsigned char buf[16];
  757. nullpo_retv(fitem);
  758. WBUFW(buf,0) = 0xa1;
  759. WBUFL(buf,2) = fitem->bl.id;
  760. if (fd == 0) {
  761. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  762. } else {
  763. WFIFOHEAD(fd,packet_len(0xa1));
  764. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  765. WFIFOSET(fd,packet_len(0xa1));
  766. }
  767. }
  768. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  769. /// 0080 <id>.L <type>.B
  770. /// type:
  771. /// 0 = out of sight
  772. /// 1 = died
  773. /// 2 = logged out
  774. /// 3 = teleport
  775. /// 4 = trickdead
  776. void clif_clearunit_single(int id, clr_type type, int fd)
  777. {
  778. WFIFOHEAD(fd, packet_len(0x80));
  779. WFIFOW(fd,0) = 0x80;
  780. WFIFOL(fd,2) = id;
  781. WFIFOB(fd,6) = type;
  782. WFIFOSET(fd, packet_len(0x80));
  783. }
  784. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  785. /// 0080 <id>.L <type>.B
  786. /// type:
  787. /// 0 = out of sight
  788. /// 1 = died
  789. /// 2 = logged out
  790. /// 3 = teleport
  791. /// 4 = trickdead
  792. void clif_clearunit_area(struct block_list* bl, clr_type type)
  793. {
  794. unsigned char buf[8];
  795. nullpo_retv(bl);
  796. WBUFW(buf,0) = 0x80;
  797. WBUFL(buf,2) = bl->id;
  798. WBUFB(buf,6) = type;
  799. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  800. if(disguised(bl)) {
  801. WBUFL(buf,2) = disguised_bl_id( bl->id );
  802. clif_send(buf, packet_len(0x80), bl, SELF);
  803. }
  804. }
  805. /// Used to make monsters with player-sprites disappear after dying
  806. /// like normal monsters, because the client does not remove those
  807. /// automatically.
  808. static TIMER_FUNC(clif_clearunit_delayed_sub){
  809. struct block_list *bl = (struct block_list *)data;
  810. clif_clearunit_area(bl, (clr_type) id);
  811. ers_free(delay_clearunit_ers,bl);
  812. return 0;
  813. }
  814. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  815. {
  816. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  817. memcpy (tbl, bl, sizeof (struct block_list));
  818. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  819. }
  820. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  821. {
  822. if(sd->sc.option&OPTION_COSTUME)
  823. {
  824. *rhand = *lhand = 0;
  825. return;
  826. }
  827. #if PACKETVER < 4
  828. *rhand = sd->status.weapon;
  829. *lhand = sd->status.shield;
  830. #else
  831. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  832. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  833. {
  834. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  835. if (id->view_id > 0)
  836. *rhand = id->view_id;
  837. else
  838. *rhand = id->nameid;
  839. } else
  840. *rhand = 0;
  841. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  842. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  843. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  844. {
  845. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  846. if (id->view_id > 0)
  847. *lhand = id->view_id;
  848. else
  849. *lhand = id->nameid;
  850. } else
  851. *lhand = 0;
  852. #endif
  853. }
  854. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  855. static int clif_setlevel_sub(int lv) {
  856. if( lv < battle_config.max_lv ) {
  857. ;
  858. } else if( lv < battle_config.aura_lv ) {
  859. lv = battle_config.max_lv - 1;
  860. } else {
  861. lv = battle_config.max_lv;
  862. }
  863. return lv;
  864. }
  865. static int clif_setlevel(struct block_list* bl) {
  866. int lv = status_get_lv(bl);
  867. if( battle_config.client_limit_unit_lv&bl->type )
  868. return clif_setlevel_sub(lv);
  869. switch( bl->type ) {
  870. case BL_NPC:
  871. case BL_PET:
  872. // npcs and pets do not have level
  873. return 0;
  874. }
  875. return lv;
  876. }
  877. /*==========================================
  878. * Prepares 'unit standing/spawning' packet
  879. *------------------------------------------*/
  880. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  881. nullpo_retv( bl );
  882. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  883. struct status_change* sc = status_get_sc( bl );
  884. struct view_data* vd = status_get_viewdata( bl );
  885. int g_id = status_get_guild_id( bl );
  886. #if PACKETVER < 20091103
  887. if( !pcdb_checkid( vd->class_ ) ){
  888. struct packet_idle_unit2 p;
  889. p.PacketType = idle_unit2Type;
  890. #if PACKETVER >= 20071106
  891. p.objecttype = clif_bl_type( bl, walking );
  892. #endif
  893. p.GID = bl->id;
  894. p.speed = status_get_speed( bl );
  895. p.bodyState = ( sc ) ? sc->opt1 : 0;
  896. p.healthState = ( sc ) ? sc->opt2 : 0;
  897. p.effectState = ( sc ) ? sc->option : 0;
  898. p.job = vd->class_;
  899. p.head = vd->hair_style;
  900. p.weapon = vd->weapon;
  901. p.accessory = vd->head_bottom;
  902. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  903. // The hell, why flags work like this?
  904. p.shield = status_get_emblem_id( bl );
  905. p.accessory2 = GetWord( g_id, 1 );
  906. p.accessory3 = GetWord( g_id, 0 );
  907. }else{
  908. p.shield = vd->shield;
  909. p.accessory2 = vd->head_top;
  910. p.accessory3 = vd->head_mid;
  911. }
  912. p.headpalette = vd->hair_color;
  913. p.bodypalette = vd->cloth_color;
  914. p.headDir = ( sd )? sd->head_dir : 0;
  915. p.GUID = g_id;
  916. p.GEmblemVer = status_get_emblem_id( bl );
  917. p.honor = ( sd ) ? sd->status.manner : 0;
  918. p.virtue = ( sc ) ? sc->opt3 : 0;
  919. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  920. p.sex = vd->sex;
  921. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  922. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  923. p.state = vd->dead_sit;
  924. p.clevel = clif_setlevel( bl );
  925. clif_send( &p, sizeof( p ), tbl, target );
  926. return;
  927. }
  928. #endif
  929. struct packet_idle_unit p;
  930. p.PacketType = idle_unitType;
  931. #if PACKETVER >= 20091103
  932. p.PacketLength = sizeof(p);
  933. p.objecttype = clif_bl_type( bl, walking );
  934. #endif
  935. #if PACKETVER >= 20131223
  936. p.AID = bl->id;
  937. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  938. #else
  939. p.GID = bl->id;
  940. #endif
  941. p.speed = status_get_speed(bl);
  942. p.bodyState = (sc) ? sc->opt1 : 0;
  943. p.healthState = (sc) ? sc->opt2 : 0;
  944. // npc option changed?
  945. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  946. struct map_session_data* sd = (struct map_session_data*)tbl;
  947. struct npc_data* nd = (struct npc_data*)bl;
  948. int option = (sc) ? sc->option : 0;
  949. if( !nd->vd.dead_sit ){
  950. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  951. option ^= OPTION_CLOAK;
  952. }
  953. }
  954. p.effectState = option;
  955. }else{
  956. p.effectState = (sc) ? sc->option : 0;
  957. }
  958. p.job = vd->class_;
  959. p.head = vd->hair_style;
  960. p.weapon = vd->weapon;
  961. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  962. p.shield = vd->shield;
  963. #endif
  964. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  965. // The hell, why flags work like this?
  966. p.accessory = status_get_emblem_id( bl );
  967. p.accessory2 = GetWord( g_id, 1 );
  968. p.accessory3 = GetWord( g_id, 0 );
  969. }else{
  970. p.accessory = vd->head_bottom;
  971. p.accessory2 = vd->head_top;
  972. p.accessory3 = vd->head_mid;
  973. }
  974. p.headpalette = vd->hair_color;
  975. p.bodypalette = vd->cloth_color;
  976. p.headDir = (sd)? sd->head_dir : 0;
  977. #if PACKETVER >= 20101124
  978. p.robe = vd->robe;
  979. #endif
  980. p.GUID = g_id;
  981. p.GEmblemVer = status_get_emblem_id( bl );
  982. p.honor = (sd) ? sd->status.manner : 0;
  983. p.virtue = (sc) ? sc->opt3 : 0;
  984. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  985. p.sex = vd->sex;
  986. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  987. p.xSize = p.ySize = (sd) ? 5 : 0;
  988. p.state = vd->dead_sit;
  989. p.clevel = clif_setlevel( bl );
  990. #if PACKETVER >= 20080102
  991. p.font = (sd) ? sd->status.font : 0;
  992. #endif
  993. #if PACKETVER >= 20120221
  994. 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 ) ) ){
  995. p.maxHP = status_get_max_hp(bl);
  996. p.HP = status_get_hp(bl);
  997. }else{
  998. p.maxHP = -1;
  999. p.HP = -1;
  1000. }
  1001. p.isBoss = ( bl->type == BL_MOB && ( ( ( TBL_MOB *)bl )->db->mexp > 0 ) ) ? 1 : 0;
  1002. #endif
  1003. #if PACKETVER >= 20150513
  1004. p.body = vd->body_style;
  1005. #endif
  1006. /* Might be earlier, this is when the named item bug began */
  1007. #if PACKETVER >= 20131223
  1008. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1009. #endif
  1010. if( disguised( bl ) ){
  1011. #if PACKETVER >= 20091103
  1012. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1013. #if PACKETVER >= 20131223
  1014. p.AID = disguised_bl_id( bl->id );
  1015. #else
  1016. p.GID = disguised_bl_id( bl->id );
  1017. #endif
  1018. #else
  1019. p.GID = disguised_bl_id( bl->id );
  1020. #endif
  1021. }
  1022. clif_send( &p, sizeof( p ), tbl, target );
  1023. }
  1024. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1025. nullpo_retv( bl );
  1026. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1027. struct status_change* sc = status_get_sc( bl );
  1028. struct view_data* vd = status_get_viewdata( bl );
  1029. int g_id = status_get_guild_id( bl );
  1030. #if PACKETVER < 20091103
  1031. if( !pcdb_checkid( vd->class_ ) ){
  1032. struct packet_spawn_unit2 p;
  1033. p.PacketType = spawn_unit2Type;
  1034. #if PACKETVER >= 20071106
  1035. p.objecttype = clif_bl_type( bl, false );
  1036. #endif
  1037. p.GID = bl->id;
  1038. p.speed = status_get_speed( bl );
  1039. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1040. p.healthState = ( sc ) ? sc->opt2 : 0;
  1041. p.effectState = ( sc ) ? sc->option : 0;
  1042. p.head = vd->hair_style;
  1043. p.weapon = vd->weapon;
  1044. p.accessory = vd->head_bottom;
  1045. p.job = vd->class_;
  1046. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1047. // The hell, why flags work like this?
  1048. p.shield = status_get_emblem_id( bl );
  1049. p.accessory2 = GetWord( g_id, 1 );
  1050. p.accessory3 = GetWord( g_id, 0 );
  1051. }else{
  1052. p.shield = vd->shield;
  1053. p.accessory2 = vd->head_top;
  1054. p.accessory3 = vd->head_mid;
  1055. }
  1056. p.headpalette = vd->hair_color;
  1057. p.bodypalette = vd->cloth_color;
  1058. p.headDir = ( sd ) ? sd->head_dir : 0;
  1059. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1060. p.sex = vd->sex;
  1061. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1062. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1063. clif_send( &p, sizeof( p ), bl, target );
  1064. return;
  1065. }
  1066. #endif
  1067. struct packet_spawn_unit p;
  1068. p.PacketType = spawn_unitType;
  1069. #if PACKETVER >= 20091103
  1070. p.PacketLength = sizeof(p);
  1071. p.objecttype = clif_bl_type( bl, false );
  1072. #endif
  1073. #if PACKETVER >= 20131223
  1074. p.AID = bl->id;
  1075. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1076. #else
  1077. p.GID = bl->id;
  1078. #endif
  1079. p.speed = status_get_speed( bl );
  1080. p.bodyState = (sc) ? sc->opt1 : 0;
  1081. p.healthState = (sc) ? sc->opt2 : 0;
  1082. p.effectState = (sc) ? sc->option : 0;
  1083. p.job = vd->class_;
  1084. p.head = vd->hair_style;
  1085. p.weapon = vd->weapon;
  1086. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1087. p.shield = vd->shield;
  1088. #endif
  1089. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1090. // The hell, why flags work like this?
  1091. p.accessory = status_get_emblem_id( bl );
  1092. p.accessory2 = GetWord( g_id, 1 );
  1093. p.accessory3 = GetWord( g_id, 0 );
  1094. }else{
  1095. p.accessory = vd->head_bottom;
  1096. p.accessory2 = vd->head_top;
  1097. p.accessory3 = vd->head_mid;
  1098. }
  1099. p.headpalette = vd->hair_color;
  1100. p.bodypalette = vd->cloth_color;
  1101. p.headDir = (sd)? sd->head_dir : 0;
  1102. #if PACKETVER >= 20101124
  1103. p.robe = vd->robe;
  1104. #endif
  1105. p.GUID = g_id;
  1106. p.GEmblemVer = status_get_emblem_id( bl );
  1107. p.honor = (sd) ? sd->status.manner : 0;
  1108. p.virtue = (sc) ? sc->opt3 : 0;
  1109. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1110. p.sex = vd->sex;
  1111. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1112. p.xSize = p.ySize = (sd) ? 5 : 0;
  1113. p.clevel = clif_setlevel( bl );
  1114. #if PACKETVER >= 20080102
  1115. p.font = (sd) ? sd->status.font : 0;
  1116. #endif
  1117. #if PACKETVER >= 20120221
  1118. 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 ) ) ){
  1119. p.maxHP = status_get_max_hp( bl );
  1120. p.HP = status_get_hp( bl );
  1121. }else{
  1122. p.maxHP = -1;
  1123. p.HP = -1;
  1124. }
  1125. p.isBoss = ( bl->type == BL_MOB && ( ( ( TBL_MOB *)bl)->db->mexp > 0 ) ) ? 1 : 0;
  1126. #endif
  1127. #if PACKETVER >= 20150513
  1128. p.body = vd->body_style;
  1129. #endif
  1130. /* Might be earlier, this is when the named item bug began */
  1131. #if PACKETVER >= 20131223
  1132. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1133. #endif
  1134. if( disguised( bl ) ){
  1135. nullpo_retv( sd );
  1136. if( sd->status.class_ != sd->disguise ){
  1137. clif_send( &p, sizeof( p ), bl, target );
  1138. }
  1139. #if PACKETVER >= 20091103
  1140. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1141. #if PACKETVER >= 20131223
  1142. p.AID = disguised_bl_id( bl->id );
  1143. #else
  1144. p.GID = disguised_bl_id( bl->id );
  1145. #endif
  1146. #else
  1147. p.GID = disguised_bl_id( bl->id );
  1148. #endif
  1149. clif_send( &p, sizeof( p ), bl, SELF );
  1150. }else{
  1151. clif_send( &p, sizeof( p ), bl, target );
  1152. }
  1153. }
  1154. /*==========================================
  1155. * Prepares 'unit walking' packet
  1156. *------------------------------------------*/
  1157. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1158. nullpo_retv( bl );
  1159. nullpo_retv( ud );
  1160. struct map_session_data* sd;
  1161. struct status_change* sc = status_get_sc( bl );
  1162. struct view_data* vd = status_get_viewdata( bl );
  1163. struct packet_unit_walking p;
  1164. int g_id = status_get_guild_id(bl);
  1165. sd = BL_CAST(BL_PC, bl);
  1166. p.PacketType = unit_walkingType;
  1167. #if PACKETVER >= 20091103
  1168. p.PacketLength = sizeof(p);
  1169. #endif
  1170. #if PACKETVER >= 20071106
  1171. p.objecttype = clif_bl_type( bl, true );
  1172. #endif
  1173. #if PACKETVER >= 20131223
  1174. p.AID = bl->id;
  1175. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1176. #else
  1177. p.GID = bl->id;
  1178. #endif
  1179. p.speed = status_get_speed(bl);
  1180. p.bodyState = (sc) ? sc->opt1 : 0;
  1181. p.healthState = (sc) ? sc->opt2 : 0;
  1182. p.effectState = (sc) ? sc->option : 0;
  1183. p.job = vd->class_;
  1184. p.head = vd->hair_style;
  1185. p.weapon = vd->weapon;
  1186. p.accessory = vd->head_bottom;
  1187. p.moveStartTime = client_tick(gettick());
  1188. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1189. p.shield = vd->shield;
  1190. #endif
  1191. p.accessory2 = vd->head_top;
  1192. p.accessory3 = vd->head_mid;
  1193. p.headpalette = vd->hair_color;
  1194. p.bodypalette = vd->cloth_color;
  1195. p.headDir = (sd) ? sd->head_dir : 0;
  1196. #if PACKETVER >= 20101124
  1197. p.robe = vd->robe;
  1198. #endif
  1199. p.GUID = g_id;
  1200. p.GEmblemVer = status_get_emblem_id(bl);
  1201. p.honor = (sd) ? sd->status.manner : 0;
  1202. p.virtue = (sc) ? sc->opt3 : 0;
  1203. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1204. p.sex = vd->sex;
  1205. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1206. p.xSize = p.ySize = (sd) ? 5 : 0;
  1207. p.clevel = clif_setlevel(bl);
  1208. #if PACKETVER >= 20080102
  1209. p.font = (sd) ? sd->status.font : 0;
  1210. #endif
  1211. #if PACKETVER >= 20120221
  1212. 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 ) ) ){
  1213. p.maxHP = status_get_max_hp(bl);
  1214. p.HP = status_get_hp(bl);
  1215. } else {
  1216. p.maxHP = -1;
  1217. p.HP = -1;
  1218. }
  1219. p.isBoss = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0;
  1220. #endif
  1221. #if PACKETVER >= 20150513
  1222. p.body = vd->body_style;
  1223. #endif
  1224. /* Might be earlier, this is when the named item bug began */
  1225. #if PACKETVER >= 20131223
  1226. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1227. #endif
  1228. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1229. if( disguised( bl ) ){
  1230. #if PACKETVER >= 20091103
  1231. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1232. #if PACKETVER >= 20131223
  1233. p.AID = disguised_bl_id( bl->id );
  1234. #else
  1235. p.GID = disguised_bl_id( bl->id );
  1236. #endif
  1237. #else
  1238. p.GID = disguised_bl_id( bl->id );
  1239. #endif
  1240. clif_send(&p,sizeof(p),bl,SELF);
  1241. }
  1242. }
  1243. //Modifies the buffer for disguise characters and sends it to self.
  1244. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1245. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1246. {
  1247. #if PACKETVER >= 20091103
  1248. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1249. WBUFL(buf,5)=-bl->id;
  1250. #elif PACKETVER >= 20071106
  1251. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1252. WBUFL(buf,3)=-bl->id;
  1253. #else
  1254. WBUFL(buf,2)=-bl->id;
  1255. #endif
  1256. clif_send(buf, len, bl, SELF);
  1257. }
  1258. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1259. /// 01b0 <id>.L <type>.B <value>.L
  1260. /// type:
  1261. /// unused
  1262. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1263. {
  1264. nullpo_retv(bl);
  1265. if(!pcdb_checkid(class_))
  1266. {// player classes yield missing sprites
  1267. unsigned char buf[16];
  1268. WBUFW(buf,0)=0x1b0;
  1269. WBUFL(buf,2)=bl->id;
  1270. WBUFB(buf,6)=type;
  1271. WBUFL(buf,7)=class_;
  1272. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1273. }
  1274. }
  1275. /// Notifies the client of an object's spirits.
  1276. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1277. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1278. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1279. {
  1280. WFIFOHEAD(fd, packet_len(0x1e1));
  1281. WFIFOW(fd,0)=0x1e1;
  1282. WFIFOL(fd,2)=sd->bl.id;
  1283. WFIFOW(fd,6)=sd->spiritball;
  1284. WFIFOSET(fd, packet_len(0x1e1));
  1285. }
  1286. /*==========================================
  1287. * Kagerou/Oboro amulet spirit
  1288. *------------------------------------------*/
  1289. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1290. {
  1291. WFIFOHEAD(fd, packet_len(0x08cf));
  1292. WFIFOW(fd,0)=0x08cf;
  1293. WFIFOL(fd,2)=sd->bl.id;
  1294. WFIFOW(fd,6)=sd->spiritcharm_type;
  1295. WFIFOW(fd,8)=sd->spiritcharm;
  1296. WFIFOSET(fd, packet_len(0x08cf));
  1297. }
  1298. /// Notifies the client of an object's souls.
  1299. /// Note: Spirit spheres and Soul spheres work on
  1300. /// seprate systems officially, but both send out
  1301. /// the same packet which leads to confusion on how
  1302. /// much soul energy a Soul Reaper acturally has
  1303. /// should the player also have spirit spheres.
  1304. /// They will likely create a new packet for this soon
  1305. /// to seprate the animations for spirit and soul spheres.
  1306. /// For now well use this and replace it later when possible. [Rytech]
  1307. ///
  1308. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1309. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1310. static void clif_soulball_single(int fd, struct map_session_data *sd)
  1311. {
  1312. WFIFOHEAD(fd, packet_len(0x1d0));
  1313. WFIFOW(fd,0)=0x1d0;
  1314. WFIFOL(fd,2)=sd->bl.id;
  1315. WFIFOW(fd,6)=sd->soulball;
  1316. WFIFOSET(fd, packet_len(0x1d0));
  1317. }
  1318. /*==========================================
  1319. * Run when player changes map / refreshes
  1320. * Tells its client to display all weather settings being used by this map
  1321. *------------------------------------------*/
  1322. static void clif_weather_check(struct map_session_data *sd)
  1323. {
  1324. int16 m = sd->bl.m;
  1325. int fd = sd->fd;
  1326. if (map_getmapflag(m, MF_SNOW)
  1327. || map_getmapflag(m, MF_CLOUDS)
  1328. || map_getmapflag(m, MF_FOG)
  1329. || map_getmapflag(m, MF_FIREWORKS)
  1330. || map_getmapflag(m, MF_SAKURA)
  1331. || map_getmapflag(m, MF_LEAVES)
  1332. || map_getmapflag(m, MF_CLOUDS2))
  1333. {
  1334. if (map_getmapflag(m, MF_SNOW))
  1335. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1336. if (map_getmapflag(m, MF_CLOUDS))
  1337. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1338. if (map_getmapflag(m, MF_CLOUDS2))
  1339. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1340. if (map_getmapflag(m, MF_FOG))
  1341. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1342. if (map_getmapflag(m, MF_FIREWORKS)) {
  1343. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1344. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1345. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1346. }
  1347. if (map_getmapflag(m, MF_SAKURA))
  1348. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1349. if (map_getmapflag(m, MF_LEAVES))
  1350. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1351. }
  1352. }
  1353. /**
  1354. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1355. **/
  1356. void clif_weather(int16 m)
  1357. {
  1358. struct s_mapiterator* iter;
  1359. struct map_session_data *sd=NULL;
  1360. iter = mapit_getallusers();
  1361. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1362. {
  1363. if( sd->bl.m == m )
  1364. clif_weather_check(sd);
  1365. }
  1366. mapit_free(iter);
  1367. }
  1368. /**
  1369. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1370. **/
  1371. int clif_spawn( struct block_list *bl, bool walking ){
  1372. struct view_data *vd;
  1373. vd = status_get_viewdata(bl);
  1374. if( !vd || vd->class_ == JT_INVISIBLE )
  1375. return 0;
  1376. /**
  1377. * Hide NPC from maya purple card.
  1378. **/
  1379. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1380. return 0;
  1381. if( bl->type == BL_NPC && !vd->dead_sit ){
  1382. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1383. }else{
  1384. clif_spawn_unit( bl, AREA_WOS );
  1385. }
  1386. if (vd->cloth_color)
  1387. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1388. if (vd->body_style)
  1389. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1390. switch (bl->type)
  1391. {
  1392. case BL_PC:
  1393. {
  1394. TBL_PC *sd = ((TBL_PC*)bl);
  1395. if (sd->spiritball > 0)
  1396. clif_spiritball(&sd->bl);
  1397. if (sd->soulball > 0)
  1398. clif_soulball(sd);
  1399. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1400. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1401. else if(sd->state.size==SZ_MEDIUM)
  1402. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1403. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1404. clif_sendbgemblem_area(sd);
  1405. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1406. clif_spiritcharm(sd);
  1407. if (sd->status.robe)
  1408. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1409. clif_efst_status_change_sub(bl, bl, AREA);
  1410. clif_hat_effects(sd,bl,AREA);
  1411. }
  1412. break;
  1413. case BL_MOB:
  1414. {
  1415. TBL_MOB *md = ((TBL_MOB*)bl);
  1416. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1417. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1418. else if(md->special_state.size==SZ_MEDIUM)
  1419. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1420. }
  1421. break;
  1422. case BL_NPC:
  1423. {
  1424. TBL_NPC *nd = ((TBL_NPC*)bl);
  1425. if( nd->size == SZ_BIG )
  1426. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1427. else if( nd->size == SZ_MEDIUM )
  1428. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1429. clif_efst_status_change_sub(bl, bl, AREA);
  1430. clif_progressbar_npc_area(nd);
  1431. }
  1432. break;
  1433. case BL_PET:
  1434. if (vd->head_bottom)
  1435. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1436. break;
  1437. }
  1438. return 0;
  1439. }
  1440. /// Sends information about owned homunculus to the client . [orn]
  1441. /// 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)
  1442. /// 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)
  1443. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1444. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1445. nullpo_retv( sd );
  1446. nullpo_retv( hd );
  1447. struct status_data *status = &hd->battle_status;
  1448. struct PACKET_ZC_PROPERTY_HOMUN p;
  1449. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1450. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1451. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1452. 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 );
  1453. p.level = hd->homunculus.level;
  1454. p.hunger = hd->homunculus.hunger;
  1455. p.intimacy = hd->homunculus.intimacy / 100;
  1456. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1457. p.itemId = 0; // equip id
  1458. #endif
  1459. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1460. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1461. p.hit = status->hit;
  1462. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1463. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1464. }else{
  1465. p.crit = status->cri / 10;
  1466. }
  1467. #ifdef RENEWAL
  1468. p.def = status->def + status->def2;
  1469. p.mdef = status->mdef + status->mdef2;
  1470. #else
  1471. p.def = status->def + status->vit;
  1472. p.mdef = status->mdef;
  1473. #endif
  1474. p.flee = status->flee;
  1475. p.amotion = (flag) ? 0 : status->amotion;
  1476. #if PACKETVER >= 20141016
  1477. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1478. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1479. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1480. p.hp = status->hp / ( status->max_hp / 100 );
  1481. p.maxHp = 100;
  1482. }else{
  1483. p.hp = status->hp;
  1484. p.maxHp = status->max_hp;
  1485. }
  1486. #else
  1487. if( status->max_hp > INT16_MAX ){
  1488. p.hp = status->hp / ( status->max_hp / 100 );
  1489. p.maxHp = 100;
  1490. }else{
  1491. p.hp = status->hp;
  1492. p.maxHp = status->max_hp;
  1493. }
  1494. #endif
  1495. if( status->max_sp > INT16_MAX ){
  1496. p.sp = status->sp / ( status->max_sp / 100 );
  1497. p.maxSp = 100;
  1498. }else{
  1499. p.sp = status->sp;
  1500. p.maxSp = status->max_sp;
  1501. }
  1502. p.exp = hd->homunculus.exp;
  1503. p.expNext = hd->exp_next;
  1504. switch( hom_class2type( hd->homunculus.class_ ) ){
  1505. case HT_REG:
  1506. case HT_EVO:
  1507. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1508. p.expNext = 0;
  1509. }
  1510. break;
  1511. case HT_S:
  1512. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1513. p.expNext = 0;
  1514. }
  1515. break;
  1516. }
  1517. p.skillPoints = hd->homunculus.skillpts;
  1518. p.range = status_get_range( &hd->bl );
  1519. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1520. #endif
  1521. }
  1522. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1523. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1524. /// type:
  1525. /// unused
  1526. /// state:
  1527. /// 0 = pre-init
  1528. /// 1 = intimacy
  1529. /// 2 = hunger
  1530. /// 3 = accessory?
  1531. /// ? = ignored
  1532. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1533. { //[orn]
  1534. int fd = sd->fd;
  1535. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1536. hom_calc_skilltree(sd->hd, 0);
  1537. WFIFOHEAD(fd, packet_len(0x230));
  1538. WFIFOW(fd,0)=0x230;
  1539. WFIFOB(fd,2)=0;
  1540. WFIFOB(fd,3)=state;
  1541. WFIFOL(fd,4)=sd->hd->bl.id;
  1542. WFIFOL(fd,8)=param;
  1543. WFIFOSET(fd,packet_len(0x230));
  1544. }
  1545. int clif_homskillinfoblock(struct map_session_data *sd)
  1546. { //[orn]
  1547. struct homun_data *hd;
  1548. int fd = sd->fd;
  1549. int i, len=4;
  1550. nullpo_ret(sd);
  1551. hd = sd->hd;
  1552. if ( !hd )
  1553. return 0 ;
  1554. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1555. WFIFOW(fd,0)=0x235;
  1556. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1557. int id = hd->homunculus.hskill[i].id;
  1558. if( id != 0 ){
  1559. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1560. short idx = hom_skill_get_index(id);
  1561. if (idx == -1)
  1562. continue;
  1563. WFIFOW(fd,len ) = id;
  1564. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1565. WFIFOW(fd,len+4) = 0;
  1566. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1567. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1568. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1569. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1570. 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;
  1571. len+=37;
  1572. }
  1573. }
  1574. WFIFOW(fd,2)=len;
  1575. WFIFOSET(fd,len);
  1576. return 0;
  1577. }
  1578. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1579. { //[orn]
  1580. struct homun_data *hd;
  1581. int fd;
  1582. short idx = -1;
  1583. nullpo_retv(sd);
  1584. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1585. return;
  1586. fd = sd->fd;
  1587. hd = sd->hd;
  1588. WFIFOHEAD(fd, packet_len(0x239));
  1589. WFIFOW(fd,0) = 0x239;
  1590. WFIFOW(fd,2) = skill_id;
  1591. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1592. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1593. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1594. 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;
  1595. WFIFOSET(fd,packet_len(0x239));
  1596. }
  1597. /// Result of request to feed a homun/merc.
  1598. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1599. /// result:
  1600. /// 0 = failure
  1601. /// 1 = success
  1602. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1603. nullpo_retv( sd );
  1604. struct PACKET_ZC_FEED_MER p;
  1605. p.packetType = 0x22f;
  1606. p.result = fail;
  1607. p.itemId = client_nameid( foodid );
  1608. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1609. }
  1610. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1611. /// 0087 <walk start time>.L <walk data>.6B
  1612. void clif_walkok(struct map_session_data *sd)
  1613. {
  1614. int fd=sd->fd;
  1615. WFIFOHEAD(fd, packet_len(0x87));
  1616. WFIFOW(fd,0)=0x87;
  1617. WFIFOL(fd,2)=client_tick(gettick());
  1618. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1619. WFIFOSET(fd,packet_len(0x87));
  1620. }
  1621. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1622. struct status_change *sc = NULL;
  1623. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1624. clif_ally_only = true;
  1625. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1626. if(vd->cloth_color)
  1627. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1628. if(vd->body_style)
  1629. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1630. switch(bl->type) {
  1631. case BL_PC:
  1632. {
  1633. TBL_PC *sd = ((TBL_PC*)bl);
  1634. // clif_movepc(sd);
  1635. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1636. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1637. else if(sd->state.size==SZ_MEDIUM)
  1638. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1639. if (sd->status.robe)
  1640. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1641. }
  1642. break;
  1643. case BL_MOB:
  1644. {
  1645. TBL_MOB *md = ((TBL_MOB*)bl);
  1646. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1647. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1648. else if(md->special_state.size==SZ_MEDIUM)
  1649. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1650. }
  1651. break;
  1652. case BL_PET:
  1653. if(vd->head_bottom) // needed to display pet equip properly
  1654. clif_pet_equip_area((TBL_PET*)bl);
  1655. break;
  1656. }
  1657. clif_ally_only = false;
  1658. }
  1659. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1660. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1661. /// Note: unit must not be self
  1662. void clif_move(struct unit_data *ud)
  1663. {
  1664. unsigned char buf[16];
  1665. struct view_data* vd;
  1666. struct block_list* bl = ud->bl;
  1667. struct status_change *sc = NULL;
  1668. vd = status_get_viewdata(bl);
  1669. if (!vd )
  1670. return;
  1671. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1672. else if( vd->class_ == JT_INVISIBLE ){
  1673. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1674. if(disguised(bl)) {
  1675. WBUFW(buf,0)=0x86;
  1676. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1677. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1678. WBUFL(buf,12)=client_tick(gettick());
  1679. clif_send(buf, packet_len(0x86), bl, SELF);
  1680. }
  1681. return;
  1682. }
  1683. /**
  1684. * Hide NPC from maya purple card.
  1685. **/
  1686. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1687. return;
  1688. if (ud->state.speed_changed) {
  1689. // Since we don't know how to update the speed of other objects,
  1690. // use the old walk packet to update the data.
  1691. ud->state.speed_changed = 0;
  1692. clif_move2(bl, vd, ud);
  1693. return;
  1694. }
  1695. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1696. clif_ally_only = true;
  1697. WBUFW(buf,0)=0x86;
  1698. WBUFL(buf,2)=bl->id;
  1699. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1700. WBUFL(buf,12)=client_tick(gettick());
  1701. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1702. if (disguised(bl)) {
  1703. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1704. clif_send(buf, packet_len(0x86), bl, SELF);
  1705. }
  1706. clif_ally_only = false;
  1707. }
  1708. /*==========================================
  1709. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1710. *------------------------------------------*/
  1711. static TIMER_FUNC(clif_delayquit){
  1712. struct map_session_data *sd = NULL;
  1713. //Remove player from map server
  1714. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1715. map_quit(sd);
  1716. return 0;
  1717. }
  1718. /*==========================================
  1719. *
  1720. *------------------------------------------*/
  1721. void clif_quitsave(int fd,struct map_session_data *sd) {
  1722. if (!battle_config.prevent_logout ||
  1723. sd->canlog_tick == 0 ||
  1724. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1725. map_quit(sd);
  1726. else if (sd->fd) {
  1727. //Disassociate session from player (session is deleted after this function was called)
  1728. //And set a timer to make him quit later.
  1729. session[sd->fd]->session_data = NULL;
  1730. sd->fd = 0;
  1731. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1732. }
  1733. }
  1734. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1735. /// 0091 <map name>.16B <x>.W <y>.W
  1736. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1737. {
  1738. int fd;
  1739. nullpo_retv(sd);
  1740. fd = sd->fd;
  1741. WFIFOHEAD(fd,packet_len(0x91));
  1742. WFIFOW(fd,0) = 0x91;
  1743. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1744. WFIFOW(fd,18) = x;
  1745. WFIFOW(fd,20) = y;
  1746. WFIFOSET(fd,packet_len(0x91));
  1747. }
  1748. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1749. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1750. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1751. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1752. {
  1753. int fd;
  1754. #if PACKETVER >= 20170315
  1755. int cmd = 0xac7;
  1756. #else
  1757. int cmd = 0x92;
  1758. #endif
  1759. nullpo_retv(sd);
  1760. fd = sd->fd;
  1761. WFIFOHEAD(fd,packet_len(cmd));
  1762. WFIFOW(fd,0) = cmd;
  1763. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1764. WFIFOW(fd,18) = x;
  1765. WFIFOW(fd,20) = y;
  1766. WFIFOL(fd,22) = htonl(ip);
  1767. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1768. #if PACKETVER >= 20170315
  1769. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1770. #endif
  1771. WFIFOSET(fd,packet_len(cmd));
  1772. }
  1773. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1774. /// This function combines both calls and allows to simplify the calling code
  1775. void clif_blown(struct block_list *bl)
  1776. {
  1777. clif_slide(bl, bl->x, bl->y);
  1778. clif_fixpos(bl);
  1779. }
  1780. /// Visually moves(slides) a character to x,y. If the target cell
  1781. /// isn't walkable, the char doesn't move at all. If the char is
  1782. /// sitting it will stand up (ZC_STOPMOVE).
  1783. /// 0088 <id>.L <x>.W <y>.W
  1784. void clif_fixpos(struct block_list *bl)
  1785. {
  1786. unsigned char buf[10];
  1787. nullpo_retv(bl);
  1788. WBUFW(buf,0) = 0x88;
  1789. WBUFL(buf,2) = bl->id;
  1790. WBUFW(buf,6) = bl->x;
  1791. WBUFW(buf,8) = bl->y;
  1792. clif_send(buf, packet_len(0x88), bl, AREA);
  1793. if( disguised(bl) ) {
  1794. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1795. clif_send(buf, packet_len(0x88), bl, SELF);
  1796. }
  1797. }
  1798. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1799. /// 00c4 <shop id>.L
  1800. void clif_npcbuysell(struct map_session_data* sd, int id)
  1801. {
  1802. int fd;
  1803. nullpo_retv(sd);
  1804. fd=sd->fd;
  1805. WFIFOHEAD(fd, packet_len(0xc4));
  1806. WFIFOW(fd,0)=0xc4;
  1807. WFIFOL(fd,2)=id;
  1808. WFIFOSET(fd,packet_len(0xc4));
  1809. }
  1810. /// Presents list of items, that can be bought in an NPC shop.
  1811. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1812. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1813. nullpo_retv( sd );
  1814. nullpo_retv( nd );
  1815. int fd = sd->fd;
  1816. if( !session_isActive( fd ) ){
  1817. return;
  1818. }
  1819. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1820. WFIFOHEAD( fd, len );
  1821. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1822. p->packetType = 0xc6;
  1823. int count = 0;
  1824. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1825. int val = nd->u.shop.shop_item[i].value;
  1826. p->items[count].price = val;
  1827. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1828. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1829. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1830. count++;
  1831. }
  1832. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1833. WFIFOSET( fd, p->packetLength );
  1834. }
  1835. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1836. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1837. void clif_selllist(struct map_session_data *sd)
  1838. {
  1839. int fd,i,c=0,val;
  1840. struct npc_data *nd;
  1841. nullpo_retv(sd);
  1842. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1843. return;
  1844. fd=sd->fd;
  1845. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1846. WFIFOW(fd,0)=0xc7;
  1847. for( i = 0; i < MAX_INVENTORY; i++ )
  1848. {
  1849. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1850. {
  1851. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1852. continue;
  1853. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1854. val = 0;
  1855. else {
  1856. val = sd->inventory_data[i]->value_sell;
  1857. if( val < 0 )
  1858. continue;
  1859. }
  1860. WFIFOW(fd,4+c*10)=i+2;
  1861. WFIFOL(fd,6+c*10)=val;
  1862. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1863. c++;
  1864. }
  1865. }
  1866. WFIFOW(fd,2)=c*10+4;
  1867. WFIFOSET(fd,WFIFOW(fd,2));
  1868. }
  1869. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1870. /// 09d4
  1871. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1872. // TODO: State tracking?
  1873. sd->npc_shopid = 0;
  1874. }
  1875. /**
  1876. * Presents list of items, that can be sold to a Market shop.
  1877. * @author: Ind and Yommy
  1878. **/
  1879. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1880. #if PACKETVER >= 20131223
  1881. nullpo_retv( sd );
  1882. nullpo_retv( nd );
  1883. if( sd->state.trading ){
  1884. return;
  1885. }
  1886. int fd = sd->fd;
  1887. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1888. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1889. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1890. int count = 0;
  1891. for( int i = 0; i < nd->u.shop.count; i++ ){
  1892. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1893. if( !item->nameid ){
  1894. continue;
  1895. }
  1896. struct item_data *id = itemdb_exists( item->nameid );
  1897. if( !id ){
  1898. continue;
  1899. }
  1900. p->list[count].nameid = client_nameid( item->nameid );
  1901. p->list[count].type = itemtype( item->nameid );
  1902. p->list[count].price = item->value;
  1903. p->list[count].qty = item->qty;
  1904. p->list[count].weight = id->weight;
  1905. count++;
  1906. }
  1907. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  1908. WFIFOSET( fd, p->packetLength );
  1909. sd->state.trading = 1;
  1910. #endif
  1911. }
  1912. /// Closes the Market shop window.
  1913. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1914. nullpo_retv(sd);
  1915. sd->npc_shopid = 0;
  1916. sd->state.trading = 0;
  1917. }
  1918. /// Purchase item from Market shop.
  1919. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1920. #if PACKETVER >= 20131223
  1921. nullpo_retv( sd );
  1922. nullpo_retv( list );
  1923. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  1924. nullpo_retv( nd );
  1925. int fd = sd->fd;
  1926. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + n * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub ) );
  1927. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)WFIFOP( fd, 0 );
  1928. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  1929. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  1930. p->result = ( res == 0 ? 0 : -1 );
  1931. #else
  1932. p->result = ( res == 0 ? 1 : 0 );
  1933. #endif
  1934. int count = 0;
  1935. if( p->result ){
  1936. for( int i = 0, j; i < n; i++ ){
  1937. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  1938. // Not found
  1939. if( j == nd->u.shop.count ){
  1940. continue;
  1941. }
  1942. p->list[count].ITID = client_nameid( list[i].nameid );
  1943. p->list[count].qty = list[i].qty;
  1944. p->list[count].price = nd->u.shop.shop_item[j].value;
  1945. count++;
  1946. }
  1947. }
  1948. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  1949. WFIFOSET( fd, p->PacketLength );
  1950. #endif
  1951. }
  1952. /// Purchase item from Market shop.
  1953. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1954. #if PACKETVER >= 20131223
  1955. nullpo_retv( sd );
  1956. if( !sd->npc_shopid ){
  1957. return;
  1958. }
  1959. const struct packet_npc_market_purchase *p = (struct packet_npc_market_purchase *)RFIFOP( fd, 0 );
  1960. int count = ( p->PacketLength - sizeof( struct packet_npc_market_purchase ) ) / sizeof( struct packet_npc_market_purchase_sub );
  1961. struct s_npc_buy_list *list;
  1962. CREATE( list, struct s_npc_buy_list, count );
  1963. // Sadly order is reverse
  1964. for( int i = 0; i < count; i++ ){
  1965. list[i].nameid = p->list[i].ITID;
  1966. list[i].qty = p->list[i].qty;
  1967. }
  1968. uint8 res = npc_buylist( sd, count, list );
  1969. clif_npc_market_purchase_ack( sd, res, count, list );
  1970. aFree( list );
  1971. #endif
  1972. }
  1973. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1974. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1975. /// Client behavior (dialog window):
  1976. /// - disable mouse targeting
  1977. /// - open the dialog window
  1978. /// - set npcid of dialog window (0 by default)
  1979. /// - if set to clear on next mes, clear contents
  1980. /// - append this text
  1981. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1982. {
  1983. int fd = sd->fd;
  1984. int slen = strlen(mes) + 9;
  1985. WFIFOHEAD(fd, slen);
  1986. WFIFOW(fd,0)=0xb4;
  1987. WFIFOW(fd,2)=slen;
  1988. WFIFOL(fd,4)=npcid;
  1989. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1990. WFIFOSET(fd,WFIFOW(fd,2));
  1991. }
  1992. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1993. /// 00b5 <npc id>.L
  1994. /// Client behavior (dialog window):
  1995. /// - disable mouse targeting
  1996. /// - open the dialog window
  1997. /// - add 'next' button
  1998. /// When 'next' is pressed:
  1999. /// - 00B9 <npcid of dialog window>.L
  2000. /// - set to clear on next mes
  2001. /// - remove 'next' button
  2002. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2003. {
  2004. int fd;
  2005. nullpo_retv(sd);
  2006. fd=sd->fd;
  2007. WFIFOHEAD(fd, packet_len(0xb5));
  2008. WFIFOW(fd,0)=0xb5;
  2009. WFIFOL(fd,2)=npcid;
  2010. WFIFOSET(fd,packet_len(0xb5));
  2011. }
  2012. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2013. /// 00b6 <npc id>.L
  2014. /// Client behavior:
  2015. /// - if dialog window is open:
  2016. /// - remove 'next' button
  2017. /// - add 'close' button
  2018. /// - else:
  2019. /// - enable mouse targeting
  2020. /// - close the dialog window
  2021. /// - close the menu window
  2022. /// When 'close' is pressed:
  2023. /// - enable mouse targeting
  2024. /// - close the dialog window
  2025. /// - close the menu window
  2026. /// - 0146 <npcid of dialog window>.L
  2027. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2028. {
  2029. int fd;
  2030. nullpo_retv(sd);
  2031. fd=sd->fd;
  2032. WFIFOHEAD(fd, packet_len(0xb6));
  2033. WFIFOW(fd,0)=0xb6;
  2034. WFIFOL(fd,2)=npcid;
  2035. WFIFOSET(fd,packet_len(0xb6));
  2036. }
  2037. /**
  2038. * Close script when player is idle
  2039. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2040. * @author [Ind/Hercules]
  2041. * @param sd : player pointer
  2042. * @param npcid : npc gid to close
  2043. */
  2044. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2045. {
  2046. struct s_packet_db* info;
  2047. int16 len;
  2048. int cmd = 0;
  2049. int fd;
  2050. nullpo_retv(sd);
  2051. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2052. if(!cmd) cmd = 0x8d6; //default
  2053. info = &packet_db[cmd];
  2054. len = info->len;
  2055. fd = sd->fd;
  2056. WFIFOHEAD(fd, len);
  2057. WFIFOW(fd,0)=0x8d6;
  2058. WFIFOL(fd,info->pos[0])=npcid;
  2059. WFIFOSET(fd,len);
  2060. }
  2061. /*==========================================
  2062. *
  2063. *------------------------------------------*/
  2064. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2065. unsigned char *buf;
  2066. int fd = sd->fd;
  2067. sd->state.using_fake_npc = 1;
  2068. WFIFOHEAD(fd, packet_len(0x78));
  2069. buf = WFIFOP(fd,0);
  2070. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2071. WBUFW(buf,0)=0x78;
  2072. #if PACKETVER >= 20071106
  2073. WBUFB(buf,2) = 0; // object type
  2074. buf = WFIFOP(fd,1);
  2075. #endif
  2076. WBUFL(buf,2)=npcid;
  2077. WBUFW(buf,14)=111;
  2078. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2079. WBUFB(buf,49)=5;
  2080. WBUFB(buf,50)=5;
  2081. WFIFOSET(fd, packet_len(0x78));
  2082. }
  2083. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2084. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2085. /// Client behavior:
  2086. /// - disable mouse targeting
  2087. /// - close the menu window
  2088. /// - open the menu window
  2089. /// - add options to the menu (separated in the text by ":")
  2090. /// - set npcid of menu window
  2091. /// - if dialog window is open:
  2092. /// - remove 'next' button
  2093. /// When 'ok' is pressed:
  2094. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2095. /// - close the menu window
  2096. /// When 'cancel' is pressed:
  2097. /// - 00B8 <npcid of menu window>.L <-1>.B
  2098. /// - enable mouse targeting
  2099. /// - close a bunch of windows...
  2100. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2101. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2102. /// TODO investigate behavior of other windows [FlavioJS]
  2103. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2104. {
  2105. int fd = sd->fd;
  2106. int slen = strlen(mes) + 9;
  2107. struct block_list *bl = NULL;
  2108. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2109. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2110. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2111. clif_sendfakenpc(sd, npcid);
  2112. WFIFOHEAD(fd, slen);
  2113. WFIFOW(fd,0)=0xb7;
  2114. WFIFOW(fd,2)=slen;
  2115. WFIFOL(fd,4)=npcid;
  2116. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2117. WFIFOSET(fd,WFIFOW(fd,2));
  2118. }
  2119. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2120. /// 0142 <npc id>.L
  2121. /// Client behavior (inputnum window):
  2122. /// - if npcid exists in the client:
  2123. /// - open the inputnum window
  2124. /// - set npcid of inputnum window
  2125. /// When 'ok' is pressed:
  2126. /// - if inputnum window has text:
  2127. /// - if npcid exists in the client:
  2128. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2129. /// - close inputnum window
  2130. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2131. {
  2132. int fd;
  2133. struct block_list *bl = NULL;
  2134. nullpo_retv(sd);
  2135. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2136. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2137. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2138. clif_sendfakenpc(sd, npcid);
  2139. fd=sd->fd;
  2140. WFIFOHEAD(fd, packet_len(0x142));
  2141. WFIFOW(fd,0)=0x142;
  2142. WFIFOL(fd,2)=npcid;
  2143. WFIFOSET(fd,packet_len(0x142));
  2144. }
  2145. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2146. /// 01d4 <npc id>.L
  2147. /// Client behavior (inputstr window):
  2148. /// - if npcid is 0 or npcid exists in the client:
  2149. /// - open the inputstr window
  2150. /// - set npcid of inputstr window
  2151. /// When 'ok' is pressed:
  2152. /// - if inputstr window has text and isn't an insult(manner.txt):
  2153. /// - if npcid is 0 or npcid exists in the client:
  2154. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2155. /// - close inputstr window
  2156. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2157. {
  2158. int fd;
  2159. struct block_list *bl = NULL;
  2160. nullpo_retv(sd);
  2161. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2162. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2163. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2164. clif_sendfakenpc(sd, npcid);
  2165. fd=sd->fd;
  2166. WFIFOHEAD(fd, packet_len(0x1d4));
  2167. WFIFOW(fd,0)=0x1d4;
  2168. WFIFOL(fd,2)=npcid;
  2169. WFIFOSET(fd,packet_len(0x1d4));
  2170. }
  2171. /// Marks a position on client's minimap (ZC_COMPASS).
  2172. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2173. /// npc id:
  2174. /// is ignored in the client
  2175. /// type:
  2176. /// 0 = display mark for 15 seconds
  2177. /// 1 = display mark until dead or teleported
  2178. /// 2 = remove mark
  2179. /// color:
  2180. /// 0x00RRGGBB
  2181. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2182. {
  2183. int fd;
  2184. nullpo_retv(sd);
  2185. fd=sd->fd;
  2186. WFIFOHEAD(fd, packet_len(0x144));
  2187. WFIFOW(fd,0)=0x144;
  2188. WFIFOL(fd,2)=npc_id;
  2189. WFIFOL(fd,6)=type;
  2190. WFIFOL(fd,10)=x;
  2191. WFIFOL(fd,14)=y;
  2192. WFIFOB(fd,18)=id;
  2193. WFIFOL(fd,19)=color;
  2194. WFIFOSET(fd,packet_len(0x144));
  2195. }
  2196. /// Displays an illustration image.
  2197. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2198. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2199. /// type:
  2200. /// 0 = bottom left corner
  2201. /// 1 = bottom middle
  2202. /// 2 = bottom right corner
  2203. /// 3 = middle of screen, inside a movable window
  2204. /// 4 = middle of screen, movable with a close button, chrome-less
  2205. /// 255 = clear all displayed cutins
  2206. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2207. {
  2208. int fd;
  2209. nullpo_retv(sd);
  2210. fd=sd->fd;
  2211. WFIFOHEAD(fd, packet_len(0x1b3));
  2212. WFIFOW(fd,0)=0x1b3;
  2213. strncpy(WFIFOCP(fd,2),image,64);
  2214. WFIFOB(fd,66)=type;
  2215. WFIFOSET(fd,packet_len(0x1b3));
  2216. }
  2217. /*==========================================
  2218. * Fills in card data from the given item and into the buffer. [Skotlex]
  2219. *------------------------------------------*/
  2220. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2221. nullpo_retv( buf );
  2222. // Blank data
  2223. if( item == nullptr ){
  2224. buf->card[0] = 0;
  2225. buf->card[1] = 0;
  2226. buf->card[2] = 0;
  2227. buf->card[3] = 0;
  2228. return;
  2229. }
  2230. // Pet eggs
  2231. if( item->card[0] == CARD0_PET ){
  2232. buf->card[0] = 0;
  2233. buf->card[1] = 0;
  2234. buf->card[2] = 0;
  2235. buf->card[3] = item->card[3]; //Pet renamed flag.
  2236. return;
  2237. }
  2238. // Forged/created items
  2239. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2240. buf->card[0] = item->card[0];
  2241. buf->card[1] = item->card[1];
  2242. buf->card[2] = item->card[2];
  2243. buf->card[3] = item->card[3];
  2244. return;
  2245. }
  2246. int i = 0, j;
  2247. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2248. if( MAX_SLOTS > 4 && ( j = itemdb_slot( item->nameid ) ) > 4 ){
  2249. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2250. }
  2251. // Normal items.
  2252. if( item->card[i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2253. buf->card[0] = j;
  2254. }else{
  2255. buf->card[0] = item->card[i];
  2256. }
  2257. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2258. buf->card[1] = j;
  2259. }else{
  2260. buf->card[1] = item->card[i];
  2261. }
  2262. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2263. buf->card[2] = j;
  2264. }else{
  2265. buf->card[2] = item->card[i];
  2266. }
  2267. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2268. buf->card[3] = j;
  2269. }else{
  2270. buf->card[3] = item->card[i];
  2271. }
  2272. }
  2273. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2274. /// A maximum of 5 random options can be supported.
  2275. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2276. nullpo_retr( 0, it );
  2277. uint8 count = 0;
  2278. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2279. if( it->option[i].id ){
  2280. buf[i].index = it->option[i].id; // OptIndex
  2281. buf[i].value = it->option[i].value; // Value
  2282. buf[i].param = it->option[i].param; // Param1
  2283. count++;
  2284. }else{
  2285. buf[i].index = 0;
  2286. buf[i].value = 0;
  2287. buf[i].param = 0;
  2288. }
  2289. }
  2290. #if MAX_ITEM_RDM_OPT < 5
  2291. for( ; i < 5; i++ ){
  2292. buf[i].index = 0; // OptIndex
  2293. buf[i].value = 0; // Value
  2294. buf[i].param = 0; // Param1
  2295. }
  2296. #endif
  2297. return count;
  2298. }
  2299. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2300. /// 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)
  2301. /// 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)
  2302. /// 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)
  2303. /// 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)
  2304. /// 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)
  2305. /// 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)
  2306. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2307. nullpo_retv( sd );
  2308. int fd = sd->fd;
  2309. if( !session_isActive( fd ) ){
  2310. return;
  2311. }
  2312. struct packet_additem p;
  2313. if( fail ){
  2314. p = {};
  2315. }else{
  2316. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <= 0 || sd->inventory_data[n] == nullptr ){
  2317. return;
  2318. }
  2319. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2320. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2321. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2322. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2323. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2324. p.location = pc_equippoint(sd,n);
  2325. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2326. #if PACKETVER >= 20061218
  2327. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2328. #endif
  2329. #if PACKETVER >= 20071002
  2330. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2331. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2332. */
  2333. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2334. #endif
  2335. #if PACKETVER >= 20150226
  2336. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2337. #endif
  2338. #if PACKETVER >= 20160921
  2339. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2340. p.look = sd->inventory_data[n]->look;
  2341. #endif
  2342. }
  2343. p.PacketType = additemType;
  2344. p.Index = client_index( n );
  2345. p.count = amount;
  2346. p.result = fail;
  2347. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2348. }
  2349. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2350. /// 00af <index>.W <amount>.W
  2351. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2352. {
  2353. int fd;
  2354. nullpo_retv(sd);
  2355. fd=sd->fd;
  2356. WFIFOHEAD(fd, packet_len(0xaf));
  2357. WFIFOW(fd,0)=0xaf;
  2358. WFIFOW(fd,2)=n+2;
  2359. WFIFOW(fd,4)=amount;
  2360. WFIFOSET(fd,packet_len(0xaf));
  2361. }
  2362. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2363. /// 07fa <delete type>.W <index>.W <amount>.W
  2364. /// delete type:
  2365. /// 0 = Normal
  2366. /// 1 = Item used for a skill
  2367. /// 2 = Refine failed
  2368. /// 3 = Material changed
  2369. /// 4 = Moved to storage
  2370. /// 5 = Moved to cart
  2371. /// 6 = Item sold
  2372. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2373. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2374. {
  2375. #if PACKETVER < 20091117
  2376. clif_dropitem(sd,n,amount);
  2377. #else
  2378. int fd;
  2379. nullpo_retv(sd);
  2380. fd=sd->fd;
  2381. WFIFOHEAD(fd, packet_len(0x7fa));
  2382. WFIFOW(fd,0)=0x7fa;
  2383. WFIFOW(fd,2)=reason;
  2384. WFIFOW(fd,4)=n+2;
  2385. WFIFOW(fd,6)=amount;
  2386. WFIFOSET(fd,packet_len(0x7fa));
  2387. #endif
  2388. }
  2389. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2390. nullpo_retv( p );
  2391. nullpo_retv( it );
  2392. nullpo_retv( id );
  2393. p->index = idx;
  2394. p->ITID = client_nameid( it->nameid );
  2395. p->type = itemtype( it->nameid );
  2396. #if PACKETVER < 20120925
  2397. p->IsIdentified = it->identify ? 1 : 0;
  2398. #endif
  2399. p->location = eqp_pos;
  2400. p->WearState = it->equip;
  2401. #if PACKETVER < 20120925
  2402. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2403. #endif
  2404. p->RefiningLevel = it->refine;
  2405. clif_addcards( &p->slot, it );
  2406. #if PACKETVER >= 20071002
  2407. p->HireExpireDate = it->expire_time;
  2408. #endif
  2409. #if PACKETVER >= 20080102
  2410. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2411. #endif
  2412. #if PACKETVER >= 20100629
  2413. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2414. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2415. #endif
  2416. #if PACKETVER >= 20120925
  2417. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2418. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2419. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2420. p->Flag.SpareBits = 0;
  2421. #endif
  2422. #if PACKETVER >= 20150226
  2423. p->option_count = clif_add_random_options( p->option_data, it );
  2424. #endif
  2425. }
  2426. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2427. nullpo_retv(p);
  2428. nullpo_retv(i);
  2429. nullpo_retv(id);
  2430. p->index = idx;
  2431. p->ITID = client_nameid( i->nameid );
  2432. p->type = itemtype( i->nameid );
  2433. #if PACKETVER < 20120925
  2434. p->IsIdentified = i->identify ? 1 : 0;
  2435. #endif
  2436. p->count = i->amount;
  2437. p->WearState = id->equip;
  2438. #if PACKETVER >= 5
  2439. clif_addcards( &p->slot, i );
  2440. #endif
  2441. #if PACKETVER >= 20080102
  2442. p->HireExpireDate = i->expire_time;
  2443. #endif
  2444. #if PACKETVER >= 20120925
  2445. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2446. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2447. p->Flag.SpareBits = 0;
  2448. #endif
  2449. }
  2450. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2451. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2452. nullpo_retv(sd);
  2453. nullpo_retv(name);
  2454. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2455. memset(buf, 0, sizeof(buf));
  2456. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2457. p->packetType = HEADER_ZC_INVENTORY_START;
  2458. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2459. p->invType = type;
  2460. #endif
  2461. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2462. int strLen = (int)safestrnlen(name, 24) + 1;
  2463. if (strLen > 24)
  2464. strLen = 24;
  2465. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2466. p->packetLength = len;
  2467. safestrncpy(p->name, name, strLen);
  2468. #else
  2469. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2470. safestrncpy(p->name, name, NAME_LENGTH);
  2471. #endif
  2472. clif_send( p, len, &sd->bl, SELF );
  2473. #endif
  2474. }
  2475. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2476. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2477. nullpo_retv(sd);
  2478. struct PACKET_ZC_INVENTORY_END p;
  2479. p.packetType = HEADER_ZC_INVENTORY_END;
  2480. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2481. p.invType = type;
  2482. #endif
  2483. p.flag = 0;
  2484. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2485. #endif
  2486. }
  2487. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2488. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2489. void clif_inventorylist( struct map_session_data *sd ){
  2490. nullpo_retv( sd );
  2491. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2492. e_inventory_type type = INVTYPE_INVENTORY;
  2493. clif_inventoryStart( sd, type, "" );
  2494. #endif
  2495. static struct packet_itemlist_normal itemlist_normal;
  2496. static struct packet_itemlist_equip itemlist_equip;
  2497. int equip = 0;
  2498. int normal = 0;
  2499. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2500. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == nullptr ){
  2501. continue;
  2502. }
  2503. // Non-stackable (Equippable)
  2504. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2505. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2506. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2507. itemlist_equip.PacketType = inventorylistequipType;
  2508. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2509. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2510. itemlist_equip.invType = type;
  2511. #endif
  2512. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2513. equip = 0;
  2514. }
  2515. // Stackable (Normal)
  2516. }else{
  2517. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2518. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2519. itemlist_normal.PacketType = inventorylistnormalType;
  2520. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2521. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2522. itemlist_normal.invType = type;
  2523. #endif
  2524. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2525. normal = 0;
  2526. }
  2527. }
  2528. }
  2529. if( normal ){
  2530. itemlist_normal.PacketType = inventorylistnormalType;
  2531. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2532. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2533. itemlist_normal.invType = type;
  2534. #endif
  2535. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2536. }
  2537. if( sd->equip_index[EQI_AMMO] >= 0 )
  2538. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2539. if( equip ) {
  2540. itemlist_equip.PacketType = inventorylistequipType;
  2541. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2542. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2543. itemlist_equip.invType = type;
  2544. #endif
  2545. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2546. }
  2547. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2548. clif_inventoryEnd( sd, type );
  2549. #endif
  2550. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2551. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2552. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2553. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2554. continue;
  2555. if ( sd->inventory.u.items_inventory[i].favorite )
  2556. clif_favorite_item(sd, i);
  2557. }
  2558. #endif
  2559. }
  2560. //Required when items break/get-repaired. Only sends equippable item list.
  2561. void clif_equiplist( struct map_session_data *sd ){
  2562. // TODO: implement again => only send equip part
  2563. clif_inventorylist( sd );
  2564. }
  2565. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2566. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2567. e_inventory_type type = INVTYPE_STORAGE;
  2568. clif_inventoryStart( sd, type, storename );
  2569. #endif
  2570. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2571. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2572. int equip = 0;
  2573. int normal = 0;
  2574. for( int i = 0; i < items_length; i++ ){
  2575. if( items[i].nameid <= 0 ){
  2576. continue;
  2577. }
  2578. struct item_data* id = itemdb_search( items[i].nameid );
  2579. // Non-stackable (Equippable)
  2580. if( !itemdb_isstackable2( id ) ){
  2581. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2582. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2583. storage_itemlist_equip.PacketType = storageListEquipType;
  2584. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2585. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2586. storage_itemlist_equip.invType = type;
  2587. #elif PACKETVER >= 20120925
  2588. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2589. #endif
  2590. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2591. equip = 0;
  2592. }
  2593. // Stackable (Normal)
  2594. }else{
  2595. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2596. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2597. storage_itemlist_normal.PacketType = storageListNormalType;
  2598. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2599. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2600. storage_itemlist_normal.invType = type;
  2601. #elif PACKETVER >= 20120925
  2602. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2603. #endif
  2604. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2605. normal = 0;
  2606. }
  2607. }
  2608. }
  2609. if( normal ){
  2610. storage_itemlist_normal.PacketType = storageListNormalType;
  2611. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2612. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2613. storage_itemlist_normal.invType = type;
  2614. #elif PACKETVER >= 20120925
  2615. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2616. #endif
  2617. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2618. }
  2619. if( equip ) {
  2620. storage_itemlist_equip.PacketType = storageListEquipType;
  2621. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2622. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2623. storage_itemlist_equip.invType = type;
  2624. #elif PACKETVER >= 20120925
  2625. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2626. #endif
  2627. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2628. }
  2629. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2630. clif_inventoryEnd( sd, type );
  2631. #endif
  2632. }
  2633. void clif_cartlist( struct map_session_data *sd ){
  2634. nullpo_retv( sd );
  2635. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2636. e_inventory_type type = INVTYPE_CART;
  2637. clif_inventoryStart( sd, type, "" );
  2638. #endif
  2639. static struct packet_itemlist_normal itemlist_normal;
  2640. static struct packet_itemlist_equip itemlist_equip;
  2641. int normal = 0;
  2642. int equip = 0;
  2643. for( int i = 0; i < MAX_CART; i++ ){
  2644. if( sd->cart.u.items_cart[i].nameid <= 0 ){
  2645. continue;
  2646. }
  2647. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2648. // Non-stackable (Equippable)
  2649. if( !itemdb_isstackable2(id) ){
  2650. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2651. // Stackable (Normal)
  2652. }else{
  2653. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2654. }
  2655. }
  2656. if( normal ){
  2657. itemlist_normal.PacketType = cartlistnormalType;
  2658. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2659. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2660. itemlist_normal.invType = type;
  2661. #endif
  2662. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2663. }
  2664. if( equip ){
  2665. itemlist_equip.PacketType = cartlistequipType;
  2666. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2667. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2668. itemlist_equip.invType = type;
  2669. #endif
  2670. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2671. }
  2672. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2673. clif_inventoryEnd( sd, type );
  2674. #endif
  2675. }
  2676. /// Removes cart (ZC_CARTOFF).
  2677. /// 012b
  2678. /// Client behaviour:
  2679. /// Closes the cart storage and removes all it's items from memory.
  2680. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2681. void clif_clearcart(int fd)
  2682. {
  2683. WFIFOHEAD(fd, packet_len(0x12b));
  2684. WFIFOW(fd,0) = 0x12b;
  2685. WFIFOSET(fd, packet_len(0x12b));
  2686. }
  2687. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2688. /// 01eb <account id>.L <x>.W <y>.W
  2689. void clif_guild_xy(struct map_session_data *sd)
  2690. {
  2691. unsigned char buf[10];
  2692. nullpo_retv(sd);
  2693. WBUFW(buf,0)=0x1eb;
  2694. WBUFL(buf,2)=sd->status.account_id;
  2695. WBUFW(buf,6)=sd->bl.x;
  2696. WBUFW(buf,8)=sd->bl.y;
  2697. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2698. }
  2699. /*==========================================
  2700. * Sends x/y dot to a single fd. [Skotlex]
  2701. *------------------------------------------*/
  2702. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2703. {
  2704. if( sd->bg_id )
  2705. return;
  2706. WFIFOHEAD(fd,packet_len(0x1eb));
  2707. WFIFOW(fd,0)=0x1eb;
  2708. WFIFOL(fd,2)=sd->status.account_id;
  2709. WFIFOW(fd,6)=sd->bl.x;
  2710. WFIFOW(fd,8)=sd->bl.y;
  2711. WFIFOSET(fd,packet_len(0x1eb));
  2712. }
  2713. // Guild XY locators [Valaris]
  2714. void clif_guild_xy_remove(struct map_session_data *sd)
  2715. {
  2716. unsigned char buf[10];
  2717. nullpo_retv(sd);
  2718. WBUFW(buf,0)=0x1eb;
  2719. WBUFL(buf,2)=sd->status.account_id;
  2720. WBUFW(buf,6)=-1;
  2721. WBUFW(buf,8)=-1;
  2722. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2723. }
  2724. /*==========================================
  2725. *
  2726. *------------------------------------------*/
  2727. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2728. {
  2729. struct map_session_data *sd, *tsd;
  2730. #if PACKETVER < 20100126
  2731. const int cmd = 0x106;
  2732. #else
  2733. const int cmd = 0x80e;
  2734. #endif
  2735. sd = va_arg(ap, struct map_session_data *);
  2736. tsd = (TBL_PC *)bl;
  2737. nullpo_ret(sd);
  2738. nullpo_ret(tsd);
  2739. if( !tsd->fd || tsd == sd )
  2740. return 0;
  2741. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2742. return 0;
  2743. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2744. WFIFOW(tsd->fd,0) = cmd;
  2745. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2746. #if PACKETVER < 20100126
  2747. if( sd->battle_status.max_hp > INT16_MAX )
  2748. { //To correctly display the %hp bar. [Skotlex]
  2749. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2750. WFIFOW(tsd->fd,8) = 100;
  2751. } else {
  2752. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2753. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2754. }
  2755. #else
  2756. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2757. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2758. #endif
  2759. WFIFOSET(tsd->fd,packet_len(cmd));
  2760. return 0;
  2761. }
  2762. /*==========================================
  2763. * Server tells all players that are allowed to view HP bars
  2764. * and are nearby 'sd' that 'sd' hp bar was updated.
  2765. *------------------------------------------*/
  2766. static int clif_hpmeter(struct map_session_data *sd)
  2767. {
  2768. nullpo_ret(sd);
  2769. 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);
  2770. return 0;
  2771. }
  2772. /// Notifies client of a character parameter change.
  2773. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2774. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2775. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2776. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2777. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2778. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2779. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2780. /// TODO: Extract individual packets.
  2781. /// FIXME: Packet lengths from packet_len(cmd)
  2782. void clif_updatestatus(struct map_session_data *sd,int type)
  2783. {
  2784. int fd,len=8;
  2785. nullpo_retv(sd);
  2786. fd=sd->fd;
  2787. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2788. return;
  2789. WFIFOHEAD(fd, 14);
  2790. WFIFOW(fd,0)=0xb0;
  2791. WFIFOW(fd,2)=type;
  2792. switch(type){
  2793. // 00b0
  2794. case SP_WEIGHT:
  2795. pc_updateweightstatus(sd);
  2796. WFIFOHEAD(fd,14);
  2797. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2798. WFIFOW(fd,2)=type;
  2799. WFIFOL(fd,4)=sd->weight;
  2800. break;
  2801. case SP_MAXWEIGHT:
  2802. WFIFOL(fd,4)=sd->max_weight;
  2803. break;
  2804. case SP_SPEED:
  2805. WFIFOL(fd,4)=sd->battle_status.speed;
  2806. break;
  2807. case SP_BASELEVEL:
  2808. WFIFOL(fd,4)=sd->status.base_level;
  2809. break;
  2810. case SP_JOBLEVEL:
  2811. WFIFOL(fd,4)=sd->status.job_level;
  2812. break;
  2813. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2814. WFIFOL(fd,4)=sd->status.karma;
  2815. break;
  2816. case SP_MANNER:
  2817. WFIFOL(fd,4)=sd->status.manner;
  2818. break;
  2819. case SP_STATUSPOINT:
  2820. WFIFOL(fd,4)=sd->status.status_point;
  2821. break;
  2822. case SP_SKILLPOINT:
  2823. WFIFOL(fd,4)=sd->status.skill_point;
  2824. break;
  2825. case SP_HIT:
  2826. WFIFOL(fd,4)=sd->battle_status.hit;
  2827. break;
  2828. case SP_FLEE1:
  2829. WFIFOL(fd,4)=sd->battle_status.flee;
  2830. break;
  2831. case SP_FLEE2:
  2832. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2833. break;
  2834. case SP_MAXHP:
  2835. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2836. break;
  2837. case SP_MAXSP:
  2838. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2839. break;
  2840. case SP_HP:
  2841. // On officials the HP never go below 1, even if you die [Lemongrass]
  2842. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2843. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2844. break;
  2845. case SP_SP:
  2846. WFIFOL(fd,4)=sd->battle_status.sp;
  2847. break;
  2848. case SP_ASPD:
  2849. WFIFOL(fd,4)=sd->battle_status.amotion;
  2850. break;
  2851. case SP_ATK1:
  2852. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2853. break;
  2854. case SP_DEF1:
  2855. WFIFOL(fd,4)=pc_leftside_def(sd);
  2856. break;
  2857. case SP_MDEF1:
  2858. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2859. break;
  2860. case SP_ATK2:
  2861. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2862. break;
  2863. case SP_DEF2:
  2864. WFIFOL(fd,4)=pc_rightside_def(sd);
  2865. break;
  2866. case SP_MDEF2: {
  2867. //negative check (in case you have something like Berserk active)
  2868. int mdef2 = pc_rightside_mdef(sd);
  2869. WFIFOL(fd,4)=
  2870. #ifndef RENEWAL
  2871. ( mdef2 < 0 ) ? 0 :
  2872. #endif
  2873. mdef2;
  2874. }
  2875. break;
  2876. case SP_CRITICAL:
  2877. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2878. break;
  2879. case SP_MATK1:
  2880. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2881. break;
  2882. case SP_MATK2:
  2883. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2884. break;
  2885. case SP_ZENY:
  2886. WFIFOW(fd,0)=0xb1;
  2887. WFIFOL(fd,4)=sd->status.zeny;
  2888. break;
  2889. #if PACKETVER >= 20170830
  2890. case SP_BASEEXP:
  2891. WFIFOW(fd,0)=0xacb;
  2892. WFIFOQ(fd,4)=sd->status.base_exp;
  2893. len = packet_len(0xacb);
  2894. break;
  2895. case SP_JOBEXP:
  2896. WFIFOW(fd,0)=0xacb;
  2897. WFIFOQ(fd,4)=sd->status.job_exp;
  2898. len = packet_len(0xacb);
  2899. break;
  2900. case SP_NEXTBASEEXP:
  2901. WFIFOW(fd,0)=0xacb;
  2902. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2903. len = packet_len(0xacb);
  2904. break;
  2905. case SP_NEXTJOBEXP:
  2906. WFIFOW(fd,0)=0xacb;
  2907. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2908. len = packet_len(0xacb);
  2909. break;
  2910. #else
  2911. case SP_BASEEXP:
  2912. WFIFOW(fd,0)=0xb1;
  2913. WFIFOL(fd,4)=sd->status.base_exp;
  2914. break;
  2915. case SP_JOBEXP:
  2916. WFIFOW(fd,0)=0xb1;
  2917. WFIFOL(fd,4)=sd->status.job_exp;
  2918. break;
  2919. case SP_NEXTBASEEXP:
  2920. WFIFOW(fd,0)=0xb1;
  2921. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2922. break;
  2923. case SP_NEXTJOBEXP:
  2924. WFIFOW(fd,0)=0xb1;
  2925. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2926. break;
  2927. #endif
  2928. /**
  2929. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2930. **/
  2931. case SP_USTR:
  2932. case SP_UAGI:
  2933. case SP_UVIT:
  2934. case SP_UINT:
  2935. case SP_UDEX:
  2936. case SP_ULUK:
  2937. WFIFOW(fd,0)=0xbe;
  2938. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2939. len=5;
  2940. break;
  2941. /**
  2942. * Tells the client how far it is allowed to attack (weapon range)
  2943. **/
  2944. case SP_ATTACKRANGE:
  2945. WFIFOW(fd,0)=0x13a;
  2946. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2947. len=4;
  2948. break;
  2949. case SP_STR:
  2950. WFIFOW(fd,0)=0x141;
  2951. WFIFOL(fd,2)=type;
  2952. WFIFOL(fd,6)=sd->status.str;
  2953. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2954. len=14;
  2955. break;
  2956. case SP_AGI:
  2957. WFIFOW(fd,0)=0x141;
  2958. WFIFOL(fd,2)=type;
  2959. WFIFOL(fd,6)=sd->status.agi;
  2960. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2961. len=14;
  2962. break;
  2963. case SP_VIT:
  2964. WFIFOW(fd,0)=0x141;
  2965. WFIFOL(fd,2)=type;
  2966. WFIFOL(fd,6)=sd->status.vit;
  2967. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2968. len=14;
  2969. break;
  2970. case SP_INT:
  2971. WFIFOW(fd,0)=0x141;
  2972. WFIFOL(fd,2)=type;
  2973. WFIFOL(fd,6)=sd->status.int_;
  2974. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2975. len=14;
  2976. break;
  2977. case SP_DEX:
  2978. WFIFOW(fd,0)=0x141;
  2979. WFIFOL(fd,2)=type;
  2980. WFIFOL(fd,6)=sd->status.dex;
  2981. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2982. len=14;
  2983. break;
  2984. case SP_LUK:
  2985. WFIFOW(fd,0)=0x141;
  2986. WFIFOL(fd,2)=type;
  2987. WFIFOL(fd,6)=sd->status.luk;
  2988. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2989. len=14;
  2990. break;
  2991. case SP_CARTINFO:
  2992. WFIFOW(fd,0)=0x121;
  2993. WFIFOW(fd,2)=sd->cart_num;
  2994. WFIFOW(fd,4)=MAX_CART;
  2995. WFIFOL(fd,6)=sd->cart_weight;
  2996. WFIFOL(fd,10)=sd->cart_weight_max;
  2997. len=14;
  2998. break;
  2999. default:
  3000. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3001. return;
  3002. }
  3003. WFIFOSET(fd,len);
  3004. // Additional update packets that should be sent right after
  3005. switch( type ){
  3006. case SP_BASELEVEL:
  3007. if( sd->status.party_id ){
  3008. struct party_data* p;
  3009. int i;
  3010. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3011. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3012. if( i < MAX_PARTY ){
  3013. p->party.member[i].lv = sd->status.base_level;
  3014. clif_party_job_and_level(sd);
  3015. }
  3016. }
  3017. }
  3018. break;
  3019. case SP_HP:
  3020. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3021. clif_hpmeter(sd);
  3022. }
  3023. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3024. clif_party_hp(sd);
  3025. }
  3026. if( sd->bg_id ){
  3027. clif_bg_hp(sd);
  3028. }
  3029. break;
  3030. }
  3031. }
  3032. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3033. /// 01ab <account id>.L <var id>.W <value>.L
  3034. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3035. {
  3036. unsigned char buf[12];
  3037. nullpo_retv(sd);
  3038. WBUFW(buf,0)=0x1ab;
  3039. WBUFL(buf,2)=sd->bl.id;
  3040. WBUFW(buf,6)=type;
  3041. switch(type)
  3042. {
  3043. case SP_MANNER:
  3044. WBUFL(buf,8)=val;
  3045. break;
  3046. default:
  3047. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3048. return;
  3049. }
  3050. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3051. }
  3052. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3053. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3054. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3055. struct PACKET_ZC_SPRITE_CHANGE p;
  3056. p.packetType = sendLookType;
  3057. p.AID = id;
  3058. p.type = type;
  3059. p.val = val;
  3060. #if PACKETVER >= 4
  3061. p.val2 = val2;
  3062. #endif
  3063. clif_send( &p, sizeof( p ), bl, target );
  3064. }
  3065. /// Updates sprite/style properties of an object.
  3066. void clif_changelook(struct block_list *bl, int type, int val) {
  3067. struct map_session_data* sd;
  3068. struct status_change* sc;
  3069. struct view_data* vd;
  3070. enum send_target target = AREA;
  3071. int val2 = 0;
  3072. nullpo_retv(bl);
  3073. sd = BL_CAST(BL_PC, bl);
  3074. sc = status_get_sc(bl);
  3075. vd = status_get_viewdata(bl);
  3076. if( vd ) //temp hack to let Warp Portal change appearance
  3077. switch(type) {
  3078. case LOOK_WEAPON:
  3079. if (sd) {
  3080. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3081. val = vd->weapon;
  3082. }
  3083. else
  3084. vd->weapon = val;
  3085. break;
  3086. case LOOK_SHIELD:
  3087. if (sd) {
  3088. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3089. val = vd->shield;
  3090. }
  3091. else
  3092. vd->shield = val;
  3093. break;
  3094. case LOOK_BASE:
  3095. if (!sd)
  3096. break;
  3097. if ( val == JT_INVISIBLE )
  3098. return;
  3099. if (sd->sc.option&OPTION_COSTUME)
  3100. vd->weapon = vd->shield = 0;
  3101. if (!vd->cloth_color)
  3102. break;
  3103. if (sd) {
  3104. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3105. vd->cloth_color = 0;
  3106. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3107. vd->cloth_color = 0;
  3108. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3109. vd->cloth_color = 0;
  3110. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3111. vd->cloth_color = 0;
  3112. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3113. vd->cloth_color = 0;
  3114. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3115. vd->body_style = 0;
  3116. }
  3117. break;
  3118. case LOOK_HAIR:
  3119. vd->hair_style = val;
  3120. break;
  3121. case LOOK_HEAD_BOTTOM:
  3122. vd->head_bottom = val;
  3123. break;
  3124. case LOOK_HEAD_TOP:
  3125. vd->head_top = val;
  3126. break;
  3127. case LOOK_HEAD_MID:
  3128. vd->head_mid = val;
  3129. break;
  3130. case LOOK_HAIR_COLOR:
  3131. vd->hair_color = val;
  3132. break;
  3133. case LOOK_CLOTHES_COLOR:
  3134. if (val && sd) {
  3135. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3136. val = 0;
  3137. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3138. val = 0;
  3139. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3140. val = 0;
  3141. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3142. val = 0;
  3143. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3144. val = 0;
  3145. }
  3146. vd->cloth_color = val;
  3147. break;
  3148. case LOOK_SHOES:
  3149. #if PACKETVER > 3
  3150. if (sd) {
  3151. int n;
  3152. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3153. if(sd->inventory_data[n]->view_id > 0)
  3154. val = sd->inventory_data[n]->view_id;
  3155. else
  3156. val = sd->inventory.u.items_inventory[n].nameid;
  3157. } else
  3158. val = 0;
  3159. }
  3160. #endif
  3161. //Shoes? No packet uses this....
  3162. break;
  3163. case LOOK_BODY:
  3164. // unknown purpose
  3165. break;
  3166. case LOOK_ROBE:
  3167. #if PACKETVER < 20110111
  3168. return;
  3169. #else
  3170. vd->robe = val;
  3171. #endif
  3172. break;
  3173. case LOOK_BODY2:
  3174. #if PACKETVER < 20150513
  3175. return;
  3176. #else
  3177. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3178. val = 0;
  3179. vd->body_style = val;
  3180. #endif
  3181. break;
  3182. }
  3183. // prevent leaking the presence of GM-hidden objects
  3184. if( sc && sc->option&OPTION_INVISIBLE )
  3185. target = SELF;
  3186. #if PACKETVER < 4
  3187. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3188. #else
  3189. if (bl->type != BL_NPC) {
  3190. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3191. type = LOOK_WEAPON;
  3192. val = (vd ? vd->weapon : 0);
  3193. val2 = (vd ? vd->shield : 0);
  3194. }
  3195. if (disguised(bl)) {
  3196. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3197. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3198. } else
  3199. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3200. } else
  3201. unit_refresh(bl);
  3202. #endif
  3203. }
  3204. //Sends a change-base-look packet required for traps as they are triggered.
  3205. void clif_changetraplook(struct block_list *bl,int val) {
  3206. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3207. }
  3208. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3209. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3210. clif_sprite_change(bl, id, type, val, 0, target);
  3211. }
  3212. /// Character status (ZC_STATUS).
  3213. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3214. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3215. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3216. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3217. void clif_initialstatus(struct map_session_data *sd) {
  3218. int fd, mdef2;
  3219. unsigned char *buf;
  3220. nullpo_retv(sd);
  3221. fd=sd->fd;
  3222. WFIFOHEAD(fd, packet_len(0xbd));
  3223. buf = WFIFOP(fd,0);
  3224. WBUFW(buf,0) = 0xbd;
  3225. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3226. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3227. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3228. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3229. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3230. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3231. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3232. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3233. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3234. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3235. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3236. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3237. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3238. WBUFW(buf,16) = pc_leftside_atk(sd);
  3239. WBUFW(buf,18) = pc_rightside_atk(sd);
  3240. WBUFW(buf,20) = pc_rightside_matk(sd);
  3241. WBUFW(buf,22) = pc_leftside_matk(sd);
  3242. WBUFW(buf,24) = pc_leftside_def(sd);
  3243. WBUFW(buf,26) = pc_rightside_def(sd);
  3244. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3245. mdef2 = pc_rightside_mdef(sd);
  3246. WBUFW(buf,30) =
  3247. #ifndef RENEWAL
  3248. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3249. #endif
  3250. mdef2;
  3251. WBUFW(buf,32) = sd->battle_status.hit;
  3252. WBUFW(buf,34) = sd->battle_status.flee;
  3253. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3254. WBUFW(buf,38) = sd->battle_status.cri/10;
  3255. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3256. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3257. WFIFOSET(fd, packet_len(0xbd));
  3258. clif_updatestatus(sd, SP_STR);
  3259. clif_updatestatus(sd, SP_AGI);
  3260. clif_updatestatus(sd, SP_VIT);
  3261. clif_updatestatus(sd, SP_INT);
  3262. clif_updatestatus(sd, SP_DEX);
  3263. clif_updatestatus(sd, SP_LUK);
  3264. clif_updatestatus(sd, SP_ATTACKRANGE);
  3265. clif_updatestatus(sd, SP_ASPD);
  3266. }
  3267. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3268. /// 013c <index>.W
  3269. void clif_arrowequip(struct map_session_data *sd,int val) {
  3270. int fd;
  3271. nullpo_retv(sd);
  3272. #if PACKETVER >= 20121128
  3273. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3274. #endif
  3275. fd=sd->fd;
  3276. WFIFOHEAD(fd, packet_len(0x013c));
  3277. WFIFOW(fd,0) = 0x013c;
  3278. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3279. WFIFOSET(fd, packet_len(0x013c));
  3280. }
  3281. /// Ammunition action message (ZC_ACTION_FAILURE).
  3282. /// 013b <type>.W
  3283. /// type:
  3284. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3285. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3286. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3287. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3288. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3289. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3290. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3291. int fd;
  3292. nullpo_retv(sd);
  3293. fd=sd->fd;
  3294. WFIFOHEAD(fd, packet_len(0x013b));
  3295. WFIFOW(fd,0) = 0x013b;
  3296. WFIFOW(fd,2) = type;
  3297. WFIFOSET(fd, packet_len(0x013b));
  3298. }
  3299. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3300. /// 01ad <packet len>.W { <name id>.W }*
  3301. void clif_arrow_create_list( struct map_session_data *sd ){
  3302. nullpo_retv( sd );
  3303. int fd = sd->fd;
  3304. if( !session_isActive( fd ) ){
  3305. return;
  3306. }
  3307. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  3308. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  3309. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3310. int count = 0;
  3311. for( int i = 0; i < MAX_SKILL_ARROW_DB; i++ ){
  3312. short nameid = skill_arrow_db[i].nameid;
  3313. if( !itemdb_exists( nameid ) ){
  3314. continue;
  3315. }
  3316. int index = pc_search_inventory( sd, nameid );
  3317. if( index < 0 ){
  3318. continue;
  3319. }
  3320. if( sd->inventory.u.items_inventory[index].equip ){
  3321. continue;
  3322. }
  3323. if( !sd->inventory.u.items_inventory[index].identify ){
  3324. continue;
  3325. }
  3326. p->items[count].itemId = client_nameid( nameid );
  3327. count++;
  3328. }
  3329. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3330. WFIFOSET( fd, p->packetLength );
  3331. if( count > 0 ){
  3332. sd->menuskill_id = AC_MAKINGARROW;
  3333. sd->menuskill_val = count;
  3334. }
  3335. }
  3336. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3337. /// 00bc <status id>.W <result>.B <value>.B
  3338. /// status id:
  3339. /// SP_STR ~ SP_LUK
  3340. /// result:
  3341. /// 0 = failure
  3342. /// 1 = success
  3343. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3344. int fd;
  3345. nullpo_retv(sd);
  3346. fd=sd->fd;
  3347. WFIFOHEAD(fd, packet_len(0xbc));
  3348. WFIFOW(fd,0) = 0xbc;
  3349. WFIFOW(fd,2) = type;
  3350. WFIFOB(fd,4) = ok;
  3351. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3352. WFIFOSET(fd, packet_len(0xbc));
  3353. }
  3354. /// Notifies the client about the result of a request to equip an item.
  3355. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3356. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3357. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3358. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3359. /// @ok: //inversed forv2 v5
  3360. /// 0 = failure
  3361. /// 1 = success
  3362. /// 2 = failure due to low level
  3363. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3364. {
  3365. int fd = 0, cmd = 0, look = 0;
  3366. struct s_packet_db *info = NULL;
  3367. nullpo_retv(sd);
  3368. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3369. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3370. return;
  3371. fd = sd->fd;
  3372. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3373. look = sd->inventory_data[n]->look;
  3374. WFIFOHEAD(fd, info->len);
  3375. WFIFOW(fd, 0) = cmd;
  3376. WFIFOW(fd, info->pos[0]) = n+2;
  3377. switch (cmd) {
  3378. case 0xaa:
  3379. WFIFOW(fd, info->pos[1]) = pos;
  3380. #if PACKETVER < 20100629
  3381. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3382. #else
  3383. WFIFOL(fd, info->pos[2]) = look;
  3384. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3385. #endif
  3386. break;
  3387. case 0x8d0:
  3388. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3389. flag = 1;
  3390. case 0x999:
  3391. if (cmd == 0x999)
  3392. WFIFOL(fd, info->pos[1]) = pos;
  3393. else
  3394. WFIFOW(fd, info->pos[1]) = pos;
  3395. WFIFOL(fd, info->pos[2]) = look;
  3396. WFIFOW(fd, info->pos[3]) = flag;
  3397. break;
  3398. }
  3399. WFIFOSET(fd, info->len);
  3400. }
  3401. /// Notifies the client about the result of a request to take off an item.
  3402. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3403. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3404. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3405. /// @ok : //inversed for v2 v5
  3406. /// 0 = failure
  3407. /// 1 = success
  3408. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3409. {
  3410. int fd, header, offs = 0;
  3411. #if PACKETVER >= 20130000
  3412. header = 0x99a;
  3413. ok = ok ? 0 : 1;
  3414. #elif PACKETVER >= 20110824
  3415. header = 0x8d1;
  3416. ok = ok ? 0 : 1;
  3417. #else
  3418. header = 0xac;
  3419. #endif
  3420. nullpo_retv(sd);
  3421. fd=sd->fd;
  3422. WFIFOHEAD(fd, packet_len(header));
  3423. WFIFOW(fd,offs+0) = header;
  3424. WFIFOW(fd,offs+2) = n+2;
  3425. #if PACKETVER >= 20130000
  3426. WFIFOL(fd,offs+4) = pos;
  3427. offs += 2;
  3428. #else
  3429. WFIFOW(fd,offs+4) = pos;
  3430. #endif
  3431. WFIFOB(fd,offs+6) = ok;
  3432. WFIFOSET(fd, packet_len(header));
  3433. }
  3434. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3435. /// 019b <id>.L <effect id>.L
  3436. /// effect id:
  3437. /// 0 = base level up
  3438. /// 1 = job level up
  3439. /// 2 = refine failure
  3440. /// 3 = refine success
  3441. /// 4 = game over
  3442. /// 5 = pharmacy success
  3443. /// 6 = pharmacy failure
  3444. /// 7 = base level up (super novice)
  3445. /// 8 = job level up (super novice)
  3446. /// 9 = base level up (taekwon)
  3447. void clif_misceffect(struct block_list* bl,int type)
  3448. {
  3449. unsigned char buf[32];
  3450. nullpo_retv(bl);
  3451. WBUFW(buf,0) = 0x19b;
  3452. WBUFL(buf,2) = bl->id;
  3453. WBUFL(buf,6) = type;
  3454. clif_send(buf,packet_len(0x19b),bl,AREA);
  3455. }
  3456. /// Notifies clients in the area of a state change.
  3457. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3458. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3459. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3460. nullpo_retv( bl );
  3461. struct status_change* sc = status_get_sc( bl );
  3462. //How can an option change if there's no sc?
  3463. if( sc == nullptr ){
  3464. return;
  3465. }
  3466. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3467. struct PACKET_ZC_STATE_CHANGE p;
  3468. p.packetType = HEADER_ZC_STATE_CHANGE;
  3469. p.AID = bl->id;
  3470. p.bodyState = sc->opt1;
  3471. p.healthState = sc->opt2;
  3472. p.effectState = sc->option;
  3473. p.isPKModeON = sd ? sd->status.karma : false;
  3474. if( target == nullptr ){
  3475. if( disguised( bl ) ){
  3476. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3477. p.AID = disguised_bl_id( p.AID );
  3478. clif_send( &p, sizeof( p ), bl, SELF );
  3479. p.AID = disguised_bl_id( p.AID );
  3480. p.effectState = OPTION_INVISIBLE;
  3481. clif_send( &p, sizeof( p ), bl, SELF );
  3482. }else{
  3483. clif_send( &p, sizeof( p ), bl, AREA );
  3484. }
  3485. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3486. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3487. if( sc->data[SC_PROVOKE] ){
  3488. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3489. clif_status_change( bl, StatusIconChangeTable[SC_PROVOKE], 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3490. }
  3491. }else{
  3492. if( disguised( bl ) ){
  3493. p.AID = disguised_bl_id( p.AID );
  3494. clif_send( &p, sizeof( p ), target, SELF );
  3495. p.AID = disguised_bl_id( p.AID );
  3496. p.effectState = OPTION_INVISIBLE;
  3497. clif_send( &p, sizeof( p ), target, SELF );
  3498. }else{
  3499. clif_send( &p, sizeof( p ), target, SELF );
  3500. }
  3501. }
  3502. }
  3503. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3504. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3505. void clif_changeoption2(struct block_list* bl)
  3506. {
  3507. unsigned char buf[20];
  3508. struct status_change *sc;
  3509. sc = status_get_sc(bl);
  3510. if (!sc) return; //How can an option change if there's no sc?
  3511. WBUFW(buf,0) = 0x28a;
  3512. WBUFL(buf,2) = bl->id;
  3513. WBUFL(buf,6) = sc->option;
  3514. WBUFL(buf,10) = clif_setlevel(bl);
  3515. WBUFL(buf,14) = sc->opt3;
  3516. if(disguised(bl)) {
  3517. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3518. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3519. clif_send(buf,packet_len(0x28a),bl,SELF);
  3520. WBUFL(buf,2) = bl->id;
  3521. WBUFL(buf,6) = OPTION_INVISIBLE;
  3522. clif_send(buf,packet_len(0x28a),bl,SELF);
  3523. } else
  3524. clif_send(buf,packet_len(0x28a),bl,AREA);
  3525. }
  3526. /// Notifies the client about the result of an item use request.
  3527. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3528. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3529. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3530. nullpo_retv( sd );
  3531. int fd = sd->fd;
  3532. if( !session_isActive( fd ) ){
  3533. return;
  3534. }
  3535. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid <= 0 || sd->inventory_data[index] == nullptr ){
  3536. return;
  3537. }
  3538. struct PACKET_ZC_USE_ITEM_ACK p;
  3539. p.packetType = useItemAckType;
  3540. p.index = index + 2;
  3541. #if PACKETVER > 3
  3542. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3543. p.AID = sd->bl.id;
  3544. #endif
  3545. p.amount = amount;
  3546. p.result = ok;
  3547. if( !ok ){
  3548. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3549. }else{
  3550. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3551. }
  3552. }
  3553. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3554. /// 00d6 <flag>.B
  3555. /// flag:
  3556. /// 0 = Room has been successfully created (opens chat room)
  3557. /// 1 = Room limit exceeded
  3558. /// 2 = Same room already exists
  3559. void clif_createchat(struct map_session_data* sd, int flag)
  3560. {
  3561. int fd;
  3562. nullpo_retv(sd);
  3563. fd = sd->fd;
  3564. WFIFOHEAD(fd,packet_len(0xd6));
  3565. WFIFOW(fd,0) = 0xd6;
  3566. WFIFOB(fd,2) = flag;
  3567. WFIFOSET(fd,packet_len(0xd6));
  3568. }
  3569. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3570. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3571. /// type:
  3572. /// 0 = private (password protected)
  3573. /// 1 = public
  3574. /// 2 = arena (npc waiting room)
  3575. /// 3 = PK zone (non-clickable)
  3576. void clif_dispchat(struct chat_data* cd, int fd)
  3577. {
  3578. unsigned char buf[128];
  3579. uint8 type;
  3580. if( cd == NULL || cd->owner == NULL )
  3581. return;
  3582. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3583. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3584. : 1;
  3585. WBUFW(buf, 0) = 0xd7;
  3586. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3587. WBUFL(buf, 4) = cd->owner->id;
  3588. WBUFL(buf, 8) = cd->bl.id;
  3589. WBUFW(buf,12) = cd->limit;
  3590. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3591. WBUFB(buf,16) = type;
  3592. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3593. if( fd ) {
  3594. WFIFOHEAD(fd,WBUFW(buf,2));
  3595. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3596. WFIFOSET(fd,WBUFW(buf,2));
  3597. } else {
  3598. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3599. }
  3600. }
  3601. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3602. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3603. /// type:
  3604. /// 0 = private (password protected)
  3605. /// 1 = public
  3606. /// 2 = arena (npc waiting room)
  3607. /// 3 = PK zone (non-clickable)
  3608. void clif_changechatstatus(struct chat_data* cd)
  3609. {
  3610. unsigned char buf[128];
  3611. uint8 type;
  3612. if( cd == NULL || cd->usersd[0] == NULL )
  3613. return;
  3614. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3615. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3616. : 1;
  3617. WBUFW(buf, 0) = 0xdf;
  3618. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3619. WBUFL(buf, 4) = cd->owner->id;
  3620. WBUFL(buf, 8) = cd->bl.id;
  3621. WBUFW(buf,12) = cd->limit;
  3622. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3623. WBUFB(buf,16) = type;
  3624. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3625. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3626. }
  3627. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3628. /// 00d8 <chat id>.L
  3629. void clif_clearchat(struct chat_data *cd,int fd)
  3630. {
  3631. unsigned char buf[32];
  3632. nullpo_retv(cd);
  3633. WBUFW(buf,0) = 0xd8;
  3634. WBUFL(buf,2) = cd->bl.id;
  3635. if( fd ) {
  3636. WFIFOHEAD(fd,packet_len(0xd8));
  3637. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3638. WFIFOSET(fd,packet_len(0xd8));
  3639. } else {
  3640. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3641. }
  3642. }
  3643. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3644. /// 00da <result>.B
  3645. /// result:
  3646. /// 0 = room full
  3647. /// 1 = wrong password
  3648. /// 2 = kicked
  3649. /// 3 = success (no message)
  3650. /// 4 = no enough zeny
  3651. /// 5 = too low level
  3652. /// 6 = too high level
  3653. /// 7 = unsuitable job class
  3654. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3655. {
  3656. int fd;
  3657. nullpo_retv(sd);
  3658. fd = sd->fd;
  3659. WFIFOHEAD(fd,packet_len(0xda));
  3660. WFIFOW(fd,0) = 0xda;
  3661. WFIFOB(fd,2) = flag;
  3662. WFIFOSET(fd,packet_len(0xda));
  3663. }
  3664. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3665. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3666. /// role:
  3667. /// 0 = owner (menu)
  3668. /// 1 = normal
  3669. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3670. {
  3671. int fd;
  3672. int i,t;
  3673. nullpo_retv(sd);
  3674. nullpo_retv(cd);
  3675. fd = sd->fd;
  3676. if (!session_isActive(fd))
  3677. return;
  3678. t = (int)(cd->owner->type == BL_NPC);
  3679. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3680. WFIFOW(fd, 0) = 0xdb;
  3681. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3682. WFIFOL(fd, 4) = cd->bl.id;
  3683. if(cd->owner->type == BL_NPC){
  3684. WFIFOL(fd, 30) = 1;
  3685. WFIFOL(fd, 8) = 0;
  3686. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3687. for (i = 0; i < cd->users; i++) {
  3688. WFIFOL(fd, 8+(i+1)*28) = 1;
  3689. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3690. }
  3691. }else{
  3692. for (i = 0; i < cd->users; i++) {
  3693. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3694. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3695. }
  3696. }
  3697. WFIFOSET(fd, WFIFOW(fd, 2));
  3698. }
  3699. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3700. /// 00dc <users>.W <name>.24B
  3701. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3702. {
  3703. unsigned char buf[29];
  3704. nullpo_retv(sd);
  3705. nullpo_retv(cd);
  3706. WBUFW(buf, 0) = 0xdc;
  3707. WBUFW(buf, 2) = cd->users;
  3708. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3709. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3710. }
  3711. /// Announce the new owner (ZC_ROLE_CHANGE).
  3712. /// 00e1 <role>.L <nick>.24B
  3713. /// role:
  3714. /// 0 = owner (menu)
  3715. /// 1 = normal
  3716. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3717. {
  3718. unsigned char buf[64];
  3719. nullpo_retv(sd);
  3720. nullpo_retv(cd);
  3721. WBUFW(buf, 0) = 0xe1;
  3722. WBUFL(buf, 2) = 1;
  3723. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3724. WBUFW(buf,30) = 0xe1;
  3725. WBUFL(buf,32) = 0;
  3726. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3727. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3728. }
  3729. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3730. /// 00dd <users>.W <nick>.24B <flag>.B
  3731. /// flag:
  3732. /// 0 = left
  3733. /// 1 = kicked
  3734. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3735. {
  3736. unsigned char buf[32];
  3737. nullpo_retv(sd);
  3738. nullpo_retv(cd);
  3739. WBUFW(buf, 0) = 0xdd;
  3740. WBUFW(buf, 2) = cd->users-1;
  3741. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3742. WBUFB(buf,28) = flag;
  3743. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3744. }
  3745. /// Opens a trade request window from char 'name'.
  3746. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3747. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3748. void clif_traderequest(struct map_session_data* sd, const char* name)
  3749. {
  3750. int fd = sd->fd;
  3751. #if PACKETVER < 6
  3752. WFIFOHEAD(fd,packet_len(0xe5));
  3753. WFIFOW(fd,0) = 0xe5;
  3754. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3755. WFIFOSET(fd,packet_len(0xe5));
  3756. #else
  3757. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3758. if( !tsd ) return;
  3759. WFIFOHEAD(fd,packet_len(0x1f4));
  3760. WFIFOW(fd,0) = 0x1f4;
  3761. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3762. WFIFOL(fd,26) = tsd->status.char_id;
  3763. WFIFOW(fd,30) = tsd->status.base_level;
  3764. WFIFOSET(fd,packet_len(0x1f4));
  3765. #endif
  3766. }
  3767. /// Reply to a trade-request.
  3768. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3769. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3770. /// result:
  3771. /// 0 = Char is too far
  3772. /// 1 = Character does not exist
  3773. /// 2 = Trade failed
  3774. /// 3 = Accept
  3775. /// 4 = Cancel
  3776. /// 5 = Busy
  3777. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3778. {
  3779. int fd = sd->fd;
  3780. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3781. if( PACKETVER < 6 || !tsd ) {
  3782. WFIFOHEAD(fd,packet_len(0xe7));
  3783. WFIFOW(fd,0) = 0xe7;
  3784. WFIFOB(fd,2) = type;
  3785. WFIFOSET(fd,packet_len(0xe7));
  3786. } else {
  3787. WFIFOHEAD(fd,packet_len(0x1f5));
  3788. WFIFOW(fd,0) = 0x1f5;
  3789. WFIFOB(fd,2) = type;
  3790. WFIFOL(fd,3) = tsd->status.char_id;
  3791. WFIFOW(fd,7) = tsd->status.base_level;
  3792. WFIFOSET(fd,packet_len(0x1f5));
  3793. }
  3794. }
  3795. /// Notifies the client about an item from other player in current trade.
  3796. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3797. /// 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)
  3798. /// 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)
  3799. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3800. nullpo_retv( sd );
  3801. nullpo_retv( tsd );
  3802. int fd = tsd->fd;
  3803. if( !session_isActive( fd ) ){
  3804. return;
  3805. }
  3806. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3807. if( index ){
  3808. index = server_index( index );
  3809. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid <= 0 || sd->inventory_data[index] == nullptr ){
  3810. return;
  3811. }
  3812. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3813. #if PACKETVER >= 20100223
  3814. p.itemType = sd->inventory_data[index]->type;
  3815. #endif
  3816. p.identified = sd->inventory.u.items_inventory[index].identify;
  3817. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3818. p.refine = sd->inventory.u.items_inventory[index].refine;
  3819. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3820. #if PACKETVER >= 20150226
  3821. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3822. #endif
  3823. }else{
  3824. p = {};
  3825. }
  3826. p.packetType = tradeaddType;
  3827. p.amount = amount;
  3828. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  3829. }
  3830. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3831. /// 00ea <index>.W <result>.B
  3832. /// result:
  3833. /// 0 = success
  3834. /// 1 = overweight
  3835. /// 2 = trade canceled
  3836. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3837. {
  3838. int fd;
  3839. nullpo_retv(sd);
  3840. fd = sd->fd;
  3841. WFIFOHEAD(fd,packet_len(0xea));
  3842. WFIFOW(fd,0) = 0xea;
  3843. WFIFOW(fd,2) = index;
  3844. WFIFOB(fd,4) = fail;
  3845. WFIFOSET(fd,packet_len(0xea));
  3846. }
  3847. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3848. /// 00ec <who>.B
  3849. /// who:
  3850. /// 0 = self
  3851. /// 1 = other player
  3852. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3853. {
  3854. int fd;
  3855. nullpo_retv(sd);
  3856. fd = sd->fd;
  3857. WFIFOHEAD(fd,packet_len(0xec));
  3858. WFIFOW(fd,0) = 0xec;
  3859. WFIFOB(fd,2) = fail;
  3860. WFIFOSET(fd,packet_len(0xec));
  3861. }
  3862. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3863. /// 00ee
  3864. void clif_tradecancelled(struct map_session_data* sd)
  3865. {
  3866. int fd;
  3867. nullpo_retv(sd);
  3868. fd = sd->fd;
  3869. WFIFOHEAD(fd,packet_len(0xee));
  3870. WFIFOW(fd,0) = 0xee;
  3871. WFIFOSET(fd,packet_len(0xee));
  3872. }
  3873. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3874. /// 00f0 <result>.B
  3875. /// result:
  3876. /// 0 = success
  3877. /// 1 = failure
  3878. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3879. {
  3880. int fd;
  3881. nullpo_retv(sd);
  3882. fd = sd->fd;
  3883. WFIFOHEAD(fd,packet_len(0xf0));
  3884. WFIFOW(fd,0) = 0xf0;
  3885. WFIFOB(fd,2) = fail;
  3886. WFIFOSET(fd,packet_len(0xf0));
  3887. }
  3888. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3889. /// 00f1
  3890. /// NOTE: Unknown purpose. Items are not removed until the window is
  3891. /// refreshed (ex. by putting another item in there).
  3892. void clif_tradeundo(struct map_session_data* sd)
  3893. {
  3894. int fd = sd->fd;
  3895. WFIFOHEAD(fd,packet_len(0xf1));
  3896. WFIFOW(fd,0) = 0xf1;
  3897. WFIFOSET(fd,packet_len(0xf1));
  3898. }
  3899. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3900. /// 00f2 <current count>.W <max count>.W
  3901. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3902. {
  3903. int fd;
  3904. nullpo_retv(sd);
  3905. fd=sd->fd;
  3906. WFIFOHEAD(fd,packet_len(0xf2));
  3907. WFIFOW(fd,0) = 0xf2;
  3908. WFIFOW(fd,2) = amount;
  3909. WFIFOW(fd,4) = max_amount;
  3910. WFIFOSET(fd,packet_len(0xf2));
  3911. }
  3912. /// Notifies the client of an item being added to the storage.
  3913. /// 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)
  3914. /// 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)
  3915. /// 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)
  3916. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  3917. nullpo_retv( sd );
  3918. nullpo_retv( i );
  3919. int fd = sd->fd;
  3920. if( !session_isActive( fd ) ){
  3921. return;
  3922. }
  3923. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  3924. p.packetType = storageaddType; // Storage item added
  3925. p.index = client_storage_index( index ); // index
  3926. p.amount = amount; // amount
  3927. p.itemId = client_nameid( i->nameid ); // id
  3928. #if PACKETVER >= 5
  3929. p.itemType = itemtype( i->nameid ); //type
  3930. #endif
  3931. p.identified = i->identify; //identify flag
  3932. p.damaged = i->attribute; // attribute
  3933. p.refine = i->refine; //refine
  3934. clif_addcards( &p.slot, i );
  3935. #if PACKETVER >= 20150226
  3936. clif_add_random_options( p.option_data, i );
  3937. #endif
  3938. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  3939. }
  3940. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3941. /// 00f6 <index>.W <amount>.L
  3942. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3943. {
  3944. int fd;
  3945. nullpo_retv(sd);
  3946. fd=sd->fd;
  3947. WFIFOHEAD(fd,packet_len(0xf6));
  3948. WFIFOW(fd,0)=0xf6; // Storage item removed
  3949. WFIFOW(fd,2)=client_storage_index(index);
  3950. WFIFOL(fd,4)=amount;
  3951. WFIFOSET(fd,packet_len(0xf6));
  3952. }
  3953. /// Closes storage (ZC_CLOSE_STORE).
  3954. /// 00f8
  3955. void clif_storageclose(struct map_session_data* sd)
  3956. {
  3957. int fd;
  3958. nullpo_retv(sd);
  3959. fd=sd->fd;
  3960. WFIFOHEAD(fd,packet_len(0xf8));
  3961. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3962. WFIFOSET(fd,packet_len(0xf8));
  3963. }
  3964. /// Notifies clients in an area of an object's souls.
  3965. /// Note: Spirit spheres and Soul spheres work on
  3966. /// seprate systems officially, but both send out
  3967. /// the same packet which leads to confusion on how
  3968. /// much soul energy a Soul Reaper acturally has
  3969. /// should the player also have spirit spheres.
  3970. /// They will likely create a new packet for this soon
  3971. /// to seprate the animations for spirit and soul spheres.
  3972. /// For now well use this and replace it later when possible. [Rytech]
  3973. ///
  3974. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  3975. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  3976. void clif_soulball(struct map_session_data *sd)
  3977. {
  3978. unsigned char buf[8];
  3979. nullpo_retv(sd);
  3980. WBUFW(buf,0)=0x1d0;
  3981. WBUFL(buf,2)=sd->bl.id;
  3982. WBUFW(buf,6)=sd->soulball;
  3983. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  3984. return;
  3985. }
  3986. /*==========================================
  3987. * Server tells 'sd' player client the abouts of 'dstsd' player
  3988. *------------------------------------------*/
  3989. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3990. {
  3991. struct block_list *d_bl;
  3992. int i;
  3993. if( dstsd->chatID ) {
  3994. struct chat_data *cd = NULL;
  3995. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3996. clif_dispchat(cd,sd->fd);
  3997. } else if( dstsd->state.vending )
  3998. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3999. else if( dstsd->state.buyingstore )
  4000. clif_buyingstore_entry_single(sd, dstsd);
  4001. if(dstsd->spiritball > 0)
  4002. clif_spiritball_single(sd->fd, dstsd);
  4003. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4004. clif_spiritcharm_single(sd->fd, dstsd);
  4005. if (dstsd->soulball > 0)
  4006. clif_soulball_single(sd->fd, dstsd);
  4007. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4008. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4009. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4010. )
  4011. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4012. // display link (sd - dstsd) to sd
  4013. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4014. if( i < MAX_DEVOTION )
  4015. clif_devotion(&sd->bl, sd);
  4016. // display links (dstsd - devotees) to sd
  4017. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4018. if( i < MAX_DEVOTION )
  4019. clif_devotion(&dstsd->bl, sd);
  4020. // display link (dstsd - crusader) to sd
  4021. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4022. clif_devotion(d_bl, sd);
  4023. }
  4024. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4025. struct unit_data *ud;
  4026. struct view_data *vd;
  4027. bool option = false;
  4028. unsigned int option_val = 0;
  4029. vd = status_get_viewdata(bl);
  4030. if (!vd || vd->class_ == JT_INVISIBLE)
  4031. return;
  4032. /**
  4033. * Hide NPC from maya purple card.
  4034. **/
  4035. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4036. return;
  4037. ud = unit_bl2ud(bl);
  4038. if( ud && ud->walktimer != INVALID_TIMER ){
  4039. clif_set_unit_walking( bl, sd, ud, SELF );
  4040. }else{
  4041. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4042. }
  4043. if (vd->cloth_color)
  4044. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4045. if (vd->body_style)
  4046. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4047. switch (bl->type)
  4048. {
  4049. case BL_PC:
  4050. {
  4051. TBL_PC* tsd = (TBL_PC*)bl;
  4052. clif_getareachar_pc(sd, tsd);
  4053. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4054. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4055. else if(tsd->state.size==SZ_MEDIUM)
  4056. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4057. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4058. clif_sendbgemblem_single(sd->fd,tsd);
  4059. if ( tsd->status.robe )
  4060. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4061. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4062. clif_hat_effects(sd,bl,SELF);
  4063. }
  4064. break;
  4065. case BL_MER: // Devotion Effects
  4066. if( ((TBL_MER*)bl)->devotion_flag )
  4067. clif_devotion(bl, sd);
  4068. break;
  4069. case BL_NPC:
  4070. {
  4071. TBL_NPC* nd = (TBL_NPC*)bl;
  4072. if( nd->chat_id )
  4073. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4074. if( nd->size == SZ_BIG )
  4075. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4076. else if( nd->size == SZ_MEDIUM )
  4077. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4078. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4079. clif_progressbar_npc(nd, sd);
  4080. }
  4081. break;
  4082. case BL_MOB:
  4083. {
  4084. TBL_MOB* md = (TBL_MOB*)bl;
  4085. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4086. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4087. else if(md->special_state.size==SZ_MEDIUM)
  4088. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4089. #if PACKETVER >= 20120404
  4090. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4091. int i;
  4092. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4093. if( md->dmglog[i].id == sd->status.char_id )
  4094. clif_monster_hp_bar(md, sd->fd);
  4095. }
  4096. #endif
  4097. }
  4098. break;
  4099. case BL_PET:
  4100. if (vd->head_bottom)
  4101. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4102. break;
  4103. }
  4104. }
  4105. //Modifies the type of damage according to status changes [Skotlex]
  4106. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4107. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4108. {
  4109. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4110. }
  4111. /*==========================================
  4112. * Estimates walk delay based on the damage criteria. [Skotlex]
  4113. *------------------------------------------*/
  4114. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4115. {
  4116. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4117. return 0;
  4118. if (bl->type == BL_PC) {
  4119. if (battle_config.pc_walk_delay_rate != 100)
  4120. delay = delay*battle_config.pc_walk_delay_rate/100;
  4121. } else
  4122. if (battle_config.walk_delay_rate != 100)
  4123. delay = delay*battle_config.walk_delay_rate/100;
  4124. if (div_ > 1) //Multi-hit skills mean higher delays.
  4125. delay += battle_config.multihit_delay*(div_-1);
  4126. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4127. }
  4128. /*========================================== [Playtester]
  4129. * Returns hallucination damage the client displays
  4130. *------------------------------------------*/
  4131. static int clif_hallucination_damage()
  4132. {
  4133. int digit = rnd() % 5 + 1;
  4134. switch (digit)
  4135. {
  4136. case 1:
  4137. return (rnd() % 10);
  4138. case 2:
  4139. return (rnd() % 100);
  4140. case 3:
  4141. return (rnd() % 1000);
  4142. case 4:
  4143. return (rnd() % 10000);
  4144. }
  4145. return (rnd() % 32767);
  4146. }
  4147. /// Sends a 'damage' packet (src performs action on dst)
  4148. /// 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)
  4149. /// 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)
  4150. /// 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)
  4151. /// type:
  4152. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4153. /// 1 = pick up item
  4154. /// 2 = sit down
  4155. /// 3 = stand up
  4156. /// 4 = damage (endure)
  4157. /// 5 = (splash?)
  4158. /// 6 = (skill?)
  4159. /// 7 = (repeat damage?)
  4160. /// 8 = multi-hit damage
  4161. /// 9 = multi-hit damage (endure)
  4162. /// 10 = critical hit
  4163. /// 11 = lucky dodge
  4164. /// 12 = (touch skill?)
  4165. /// 13 = multi-hit critical
  4166. 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)
  4167. {
  4168. unsigned char buf[34];
  4169. struct status_change *sc;
  4170. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4171. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4172. #if PACKETVER < 20071113
  4173. const int cmd = 0x8a;
  4174. int offset = 0;
  4175. #elif PACKETVER < 20131223
  4176. const int cmd = 0x2e1;
  4177. int offset = 2;
  4178. #else
  4179. const int cmd = 0x8c8;
  4180. int offset = 3;
  4181. #endif
  4182. nullpo_ret(src);
  4183. nullpo_ret(dst);
  4184. if (type != DMG_MULTI_HIT_CRITICAL)
  4185. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4186. sc = status_get_sc(dst);
  4187. if(sc && sc->count) {
  4188. if(sc->data[SC_HALLUCINATION]) {
  4189. if(damage) damage = clif_hallucination_damage();
  4190. if(damage2) damage2 = clif_hallucination_damage();
  4191. }
  4192. }
  4193. WBUFW(buf,0) = cmd;
  4194. WBUFL(buf,2) = src->id;
  4195. WBUFL(buf,6) = dst->id;
  4196. WBUFL(buf,10) = client_tick(tick);
  4197. WBUFL(buf,14) = sdelay;
  4198. WBUFL(buf,18) = ddelay;
  4199. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4200. #if PACKETVER < 20071113
  4201. WBUFW(buf,22) = damage ? div : 0;
  4202. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4203. #else
  4204. WBUFL(buf, 22) = damage ? div : 0;
  4205. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4206. #endif
  4207. } else {
  4208. #if PACKETVER < 20071113
  4209. WBUFW(buf,22) = min(damage, INT16_MAX);
  4210. WBUFW(buf,27+offset) = damage2;
  4211. #else
  4212. WBUFL(buf,22) = damage;
  4213. WBUFL(buf,27+offset) = damage2;
  4214. #endif
  4215. }
  4216. #if PACKETVER >= 20131223
  4217. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4218. #endif
  4219. WBUFW(buf,24+offset) = div;
  4220. WBUFB(buf,26+offset) = type;
  4221. if(disguised(dst)) {
  4222. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4223. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4224. clif_send(buf, packet_len(cmd), dst, SELF);
  4225. } else
  4226. clif_send(buf, packet_len(cmd), dst, AREA);
  4227. if(disguised(src)) {
  4228. WBUFL(buf,2) = disguised_bl_id( src->id );
  4229. if (disguised(dst))
  4230. WBUFL(buf,6) = dst->id;
  4231. #if PACKETVER < 20071113
  4232. if(damage > 0) WBUFW(buf,22) = -1;
  4233. if(damage2 > 0) WBUFW(buf,27) = -1;
  4234. #else
  4235. if(damage > 0) WBUFL(buf,22) = -1;
  4236. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4237. #endif
  4238. clif_send(buf,packet_len(cmd),src,SELF);
  4239. }
  4240. if(src == dst) {
  4241. unit_setdir(src, unit_getdir(src));
  4242. }
  4243. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4244. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4245. //Return adjusted can't walk delay for further processing.
  4246. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4247. }
  4248. /*==========================================
  4249. * src picks up dst
  4250. *------------------------------------------*/
  4251. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4252. {
  4253. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4254. unsigned char buf[32];
  4255. nullpo_retv(src);
  4256. nullpo_retv(dst);
  4257. WBUFW(buf, 0) = 0x8a;
  4258. WBUFL(buf, 2) = src->id;
  4259. WBUFL(buf, 6) = dst->id;
  4260. WBUFB(buf,26) = 1;
  4261. clif_send(buf, packet_len(0x8a), src, AREA);
  4262. }
  4263. /*==========================================
  4264. * inform clients in area that `bl` is sitting
  4265. *------------------------------------------*/
  4266. void clif_sitting(struct block_list* bl)
  4267. {
  4268. unsigned char buf[32];
  4269. nullpo_retv(bl);
  4270. WBUFW(buf, 0) = 0x8a;
  4271. WBUFL(buf, 2) = bl->id;
  4272. WBUFB(buf,26) = 2;
  4273. clif_send(buf, packet_len(0x8a), bl, AREA);
  4274. if(disguised(bl)) {
  4275. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4276. clif_send(buf, packet_len(0x8a), bl, SELF);
  4277. }
  4278. }
  4279. /*==========================================
  4280. * inform clients in area that `bl` is standing
  4281. *------------------------------------------*/
  4282. void clif_standing(struct block_list* bl)
  4283. {
  4284. unsigned char buf[32];
  4285. nullpo_retv(bl);
  4286. WBUFW(buf, 0) = 0x8a;
  4287. WBUFL(buf, 2) = bl->id;
  4288. WBUFB(buf,26) = 3;
  4289. clif_send(buf, packet_len(0x8a), bl, AREA);
  4290. if(disguised(bl)) {
  4291. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4292. clif_send(buf, packet_len(0x8a), bl, SELF);
  4293. }
  4294. }
  4295. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4296. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4297. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4298. {
  4299. unsigned char buf[32];
  4300. WBUFW(buf,0) = 0x192;
  4301. WBUFW(buf,2) = x;
  4302. WBUFW(buf,4) = y;
  4303. WBUFW(buf,6) = type;
  4304. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4305. if( fd )
  4306. {
  4307. WFIFOHEAD(fd,packet_len(0x192));
  4308. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4309. WFIFOSET(fd,packet_len(0x192));
  4310. }
  4311. else
  4312. {
  4313. struct block_list dummy_bl;
  4314. dummy_bl.type = BL_NUL;
  4315. dummy_bl.x = x;
  4316. dummy_bl.y = y;
  4317. dummy_bl.m = m;
  4318. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4319. }
  4320. }
  4321. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4322. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4323. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4324. nullpo_retv( sd );
  4325. nullpo_retv( fitem );
  4326. struct PACKET_ZC_ITEM_ENTRY p;
  4327. int view = itemdb_viewid( fitem->item.nameid );
  4328. p.packetType = 0x9d;
  4329. p.AID = fitem->bl.id;
  4330. p.itemId = view > 0 ? view : fitem->item.nameid;
  4331. p.identify = fitem->item.identify;
  4332. p.x = fitem->bl.x;
  4333. p.y = fitem->bl.y;
  4334. p.amount = fitem->item.amount;
  4335. p.subX = fitem->subx;
  4336. p.subY = fitem->suby;
  4337. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4338. }
  4339. /// Notifes client about Graffiti
  4340. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4341. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4342. unsigned char buf[128];
  4343. nullpo_retv(bl);
  4344. nullpo_retv(unit);
  4345. WBUFW(buf, 0) = 0x1c9;
  4346. WBUFL(buf, 2) = unit->bl.id;
  4347. WBUFL(buf, 6) = unit->group->src_id;
  4348. WBUFW(buf,10) = unit->bl.x;
  4349. WBUFW(buf,12) = unit->bl.y;
  4350. WBUFB(buf,14) = unit->group->unit_id;
  4351. WBUFB(buf,15) = 1;
  4352. WBUFB(buf,16) = 1;
  4353. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4354. clif_send(buf,packet_len(0x1c9),bl,target);
  4355. }
  4356. /// Notifies the client of a skill unit.
  4357. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4358. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4359. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4360. /// 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)
  4361. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4362. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4363. unsigned char buf[128];
  4364. nullpo_retv(bl);
  4365. nullpo_retv(unit);
  4366. if (bl->type == BL_PC)
  4367. fd = ((TBL_PC*)bl)->fd;
  4368. if (unit->group->state.guildaura)
  4369. return;
  4370. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4371. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4372. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4373. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4374. else
  4375. unit_id = unit->group->unit_id;
  4376. if (!visible)
  4377. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4378. #if PACKETVER >= 3
  4379. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4380. clif_graffiti(bl, unit, target);
  4381. return;
  4382. }
  4383. #endif
  4384. #if PACKETVER <= 20120702
  4385. header = 0x011f;
  4386. //#if PACKETVER < 20110718
  4387. // header = 0x011f;
  4388. //#elif PACKETVER < 20121212
  4389. // header = 0x08c7;
  4390. #elif PACKETVER < 20130731
  4391. header = 0x099f;
  4392. #else
  4393. header = 0x09ca;
  4394. #endif
  4395. len = packet_len(header);
  4396. WBUFW(buf,pos) = header;
  4397. if (header != 0x011f) {
  4398. WBUFW(buf, pos+2) = len;
  4399. pos += 2;
  4400. }
  4401. WBUFL(buf,pos+2) = unit->bl.id;
  4402. WBUFL(buf,pos+6) = unit->group->src_id;
  4403. WBUFW(buf,pos+10) = unit->bl.x;
  4404. WBUFW(buf,pos+12) = unit->bl.y;
  4405. switch (header) {
  4406. case 0x011f:
  4407. WBUFB(buf,pos+14) = unit_id;
  4408. WBUFB(buf,pos+15) = visible;
  4409. break;
  4410. case 0x08c7:
  4411. WBUFB(buf,pos+14) = unit_id;
  4412. WBUFW(buf,pos+15) = unit->range;
  4413. WBUFB(buf,pos+17) = visible;
  4414. break;
  4415. case 0x099f:
  4416. WBUFL(buf,pos+14) = unit_id;
  4417. WBUFW(buf,pos+18) = unit->range;
  4418. WBUFB(buf,pos+20) = visible;
  4419. break;
  4420. case 0x09ca:
  4421. WBUFL(buf,pos+14) = unit_id;
  4422. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4423. WBUFB(buf,pos+19) = visible;
  4424. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4425. break;
  4426. }
  4427. clif_send(buf, len, bl, target);
  4428. if (unit->group->skill_id == WZ_ICEWALL)
  4429. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4430. }
  4431. /*==========================================
  4432. * Server tells client to remove unit of id 'unit->bl.id'
  4433. *------------------------------------------*/
  4434. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4435. {
  4436. nullpo_retv(unit);
  4437. WFIFOHEAD(fd,packet_len(0x120));
  4438. WFIFOW(fd, 0)=0x120;
  4439. WFIFOL(fd, 2)=unit->bl.id;
  4440. WFIFOSET(fd,packet_len(0x120));
  4441. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4442. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4443. }
  4444. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4445. /// 0120 <id>.L
  4446. void clif_skill_delunit(struct skill_unit *unit)
  4447. {
  4448. unsigned char buf[16];
  4449. nullpo_retv(unit);
  4450. WBUFW(buf, 0)=0x120;
  4451. WBUFL(buf, 2)=unit->bl.id;
  4452. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4453. }
  4454. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4455. /// 01ac <id>.L
  4456. /// Only affects units with class [139,153] client-side.
  4457. void clif_skillunit_update(struct block_list* bl)
  4458. {
  4459. unsigned char buf[6];
  4460. nullpo_retv(bl);
  4461. WBUFW(buf,0) = 0x1ac;
  4462. WBUFL(buf,2) = bl->id;
  4463. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4464. }
  4465. /*==========================================
  4466. *
  4467. *------------------------------------------*/
  4468. static int clif_getareachar(struct block_list* bl,va_list ap)
  4469. {
  4470. struct map_session_data *sd;
  4471. nullpo_ret(bl);
  4472. sd=va_arg(ap,struct map_session_data*);
  4473. if (sd == NULL || !sd->fd)
  4474. return 0;
  4475. switch(bl->type){
  4476. case BL_ITEM:
  4477. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4478. break;
  4479. case BL_SKILL:
  4480. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4481. break;
  4482. default:
  4483. if(&sd->bl == bl)
  4484. break;
  4485. clif_getareachar_unit(sd,bl);
  4486. break;
  4487. }
  4488. return 0;
  4489. }
  4490. /*==========================================
  4491. * tbl has gone out of view-size of bl
  4492. *------------------------------------------*/
  4493. int clif_outsight(struct block_list *bl,va_list ap)
  4494. {
  4495. struct block_list *tbl;
  4496. struct view_data *vd;
  4497. TBL_PC *sd, *tsd;
  4498. tbl=va_arg(ap,struct block_list*);
  4499. if(bl == tbl) return 0;
  4500. sd = BL_CAST(BL_PC, bl);
  4501. tsd = BL_CAST(BL_PC, tbl);
  4502. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4503. nullpo_ret(bl);
  4504. switch(bl->type){
  4505. case BL_PC:
  4506. if(sd->vd.class_ != JT_INVISIBLE)
  4507. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4508. if(sd->chatID){
  4509. struct chat_data *cd;
  4510. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4511. if(cd->usersd[0]==sd)
  4512. clif_dispchat(cd,tsd->fd);
  4513. }
  4514. if(sd->state.vending)
  4515. clif_closevendingboard(bl,tsd->fd);
  4516. if(sd->state.buyingstore)
  4517. clif_buyingstore_disappear_entry_single(tsd, sd);
  4518. break;
  4519. case BL_ITEM:
  4520. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4521. break;
  4522. case BL_SKILL:
  4523. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4524. break;
  4525. case BL_NPC:
  4526. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4527. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4528. break;
  4529. default:
  4530. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4531. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4532. break;
  4533. }
  4534. }
  4535. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4536. nullpo_ret(tbl);
  4537. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4538. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4539. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4540. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4541. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4542. }
  4543. return 0;
  4544. }
  4545. /*==========================================
  4546. * tbl has come into view of bl
  4547. *------------------------------------------*/
  4548. int clif_insight(struct block_list *bl,va_list ap)
  4549. {
  4550. struct block_list *tbl;
  4551. TBL_PC *sd, *tsd;
  4552. tbl=va_arg(ap,struct block_list*);
  4553. if (bl == tbl) return 0;
  4554. sd = BL_CAST(BL_PC, bl);
  4555. tsd = BL_CAST(BL_PC, tbl);
  4556. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4557. switch(bl->type){
  4558. case BL_ITEM:
  4559. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4560. break;
  4561. case BL_SKILL:
  4562. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4563. break;
  4564. default:
  4565. clif_getareachar_unit(tsd,bl);
  4566. break;
  4567. }
  4568. }
  4569. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4570. clif_getareachar_unit(sd,tbl);
  4571. }
  4572. return 0;
  4573. }
  4574. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4575. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4576. void clif_skillinfoblock(struct map_session_data *sd)
  4577. {
  4578. int fd;
  4579. int i,len,id;
  4580. nullpo_retv(sd);
  4581. fd = sd->fd;
  4582. if (!fd)
  4583. return;
  4584. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4585. WFIFOW(fd,0) = 0x10f;
  4586. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4587. {
  4588. if( (id = sd->status.skill[i].id) != 0 )
  4589. {
  4590. // workaround for bugreport:5348
  4591. if (len + 37 > 8192)
  4592. break;
  4593. WFIFOW(fd,len) = id;
  4594. WFIFOL(fd,len+2) = skill_get_inf(id);
  4595. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4596. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4597. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4598. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4599. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4600. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4601. else
  4602. WFIFOB(fd,len+36) = 0;
  4603. len += 37;
  4604. }
  4605. }
  4606. WFIFOW(fd,2)=len;
  4607. WFIFOSET(fd,len);
  4608. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4609. for ( ; i < MAX_SKILL; i++)
  4610. {
  4611. if( (id = sd->status.skill[i].id) != 0 )
  4612. {
  4613. clif_addskill(sd, id);
  4614. clif_skillinfo(sd, id, 0);
  4615. }
  4616. }
  4617. }
  4618. /**
  4619. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4620. **/
  4621. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4622. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4623. void clif_addskill(struct map_session_data *sd, int skill_id)
  4624. {
  4625. int fd;
  4626. uint16 idx = 0;
  4627. nullpo_retv(sd);
  4628. fd = sd->fd;
  4629. if (!fd || !(idx = skill_get_index(skill_id)))
  4630. return;
  4631. if( sd->status.skill[idx].id <= 0 )
  4632. return;
  4633. WFIFOHEAD(fd, packet_len(0x111));
  4634. WFIFOW(fd,0) = 0x111;
  4635. WFIFOW(fd,2) = skill_id;
  4636. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4637. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4638. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4639. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4640. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4641. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4642. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4643. else
  4644. WFIFOB(fd,38) = 0;
  4645. WFIFOSET(fd,packet_len(0x111));
  4646. }
  4647. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4648. /// 0441 <skill id>.W
  4649. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4650. {
  4651. #if PACKETVER >= 20081217
  4652. int fd;
  4653. uint16 idx = 0;
  4654. nullpo_retv(sd);
  4655. fd = sd->fd;
  4656. if (!fd || !(idx = skill_get_index(skill_id)))
  4657. return;
  4658. WFIFOHEAD(fd,packet_len(0x441));
  4659. WFIFOW(fd,0) = 0x441;
  4660. WFIFOW(fd,2) = skill_id;
  4661. WFIFOSET(fd,packet_len(0x441));
  4662. #endif
  4663. clif_skillinfoblock(sd);
  4664. }
  4665. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4666. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4667. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4668. int fd;
  4669. nullpo_retv(sd);
  4670. fd = sd->fd;
  4671. WFIFOHEAD(fd, packet_len(0x10e));
  4672. WFIFOW(fd, 0) = 0x10e;
  4673. WFIFOW(fd, 2) = skill_id;
  4674. WFIFOW(fd, 4) = lv;
  4675. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4676. WFIFOW(fd, 8) = range;
  4677. WFIFOB(fd, 10) = upgradable;
  4678. WFIFOSET(fd, packet_len(0x10e));
  4679. }
  4680. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4681. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4682. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4683. {
  4684. const int fd = sd->fd;
  4685. uint16 idx = skill_get_index(skill_id);
  4686. if (!idx)
  4687. return;
  4688. WFIFOHEAD(fd,packet_len(0x7e1));
  4689. WFIFOW(fd,0) = 0x7e1;
  4690. WFIFOW(fd,2) = skill_id;
  4691. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4692. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4693. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4694. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4695. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4696. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4697. else
  4698. WFIFOB(fd,14) = 0;
  4699. WFIFOSET(fd,packet_len(0x7e1));
  4700. }
  4701. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4702. #if PACKETVER >= 20151223
  4703. if( !battle_config.show_skill_scale ){
  4704. return;
  4705. }
  4706. struct PACKET_ZC_SKILL_SCALE p;
  4707. p.PacketType = skillscale;
  4708. p.AID = src_id;
  4709. p.skill_id = skill_id;
  4710. p.skill_lv = skill_lv;
  4711. p.x = x;
  4712. p.y = y;
  4713. p.casttime = casttime;
  4714. if( disguised( bl ) ){
  4715. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4716. p.AID = disguised_bl_id( bl->id );
  4717. clif_send( &p, sizeof( p ), bl, SELF );
  4718. }else{
  4719. clif_send( &p, sizeof( p ), bl, AREA );
  4720. }
  4721. #endif
  4722. }
  4723. /// Notifies clients in area, that an object is about to use a skill.
  4724. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4725. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4726. /// property:
  4727. /// 0 = Yellow cast aura
  4728. /// 1 = Water elemental cast aura
  4729. /// 2 = Earth elemental cast aura
  4730. /// 3 = Fire elemental cast aura
  4731. /// 4 = Wind elemental cast aura
  4732. /// 5 = Poison elemental cast aura
  4733. /// 6 = Holy elemental cast aura
  4734. /// ? = like 0
  4735. /// is disposable:
  4736. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4737. /// 1 = no text
  4738. 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)
  4739. {
  4740. #if PACKETVER < 20091124
  4741. const int cmd = 0x13e;
  4742. #else
  4743. const int cmd = 0x7fb;
  4744. #endif
  4745. unsigned char buf[32];
  4746. WBUFW(buf,0) = cmd;
  4747. WBUFL(buf,2) = src_id;
  4748. WBUFL(buf,6) = dst_id;
  4749. WBUFW(buf,10) = dst_x;
  4750. WBUFW(buf,12) = dst_y;
  4751. WBUFW(buf,14) = skill_id;
  4752. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4753. WBUFL(buf,20) = casttime;
  4754. #if PACKETVER >= 20091124
  4755. WBUFB(buf,24) = 0; // isDisposable
  4756. #endif
  4757. if (disguised(bl)) {
  4758. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4759. WBUFL(buf,2) = disguised_bl_id( src_id );
  4760. clif_send(buf,packet_len(cmd), bl, SELF);
  4761. } else
  4762. clif_send(buf,packet_len(cmd), bl, AREA);
  4763. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4764. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4765. }
  4766. }
  4767. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4768. /// 01b9 <id>.L
  4769. void clif_skillcastcancel(struct block_list* bl)
  4770. {
  4771. unsigned char buf[16];
  4772. nullpo_retv(bl);
  4773. WBUFW(buf,0) = 0x1b9;
  4774. WBUFL(buf,2) = bl->id;
  4775. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4776. }
  4777. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4778. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4779. /// num (only used when skill id = NV_BASIC and cause = 0):
  4780. /// 0 = "skill failed" MsgStringTable[159]
  4781. /// 1 = "no emotions" MsgStringTable[160]
  4782. /// 2 = "no sit" MsgStringTable[161]
  4783. /// 3 = "no chat" MsgStringTable[162]
  4784. /// 4 = "no party" MsgStringTable[163]
  4785. /// 5 = "no shout" MsgStringTable[164]
  4786. /// 6 = "no PKing" MsgStringTable[165]
  4787. /// 7 = "no alligning" MsgStringTable[383]
  4788. /// ? = ignored
  4789. /// cause:
  4790. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4791. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4792. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4793. /// "skill failed" MsgStringTable[204] (otherwise)
  4794. /// ... = @see enum useskill_fail_cause
  4795. /// ? = ignored
  4796. ///
  4797. /// if(result!=0) doesn't display any of the previous messages
  4798. /// Note: when this packet is received an unknown flag is always set to 0,
  4799. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4800. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, int itemId ){
  4801. nullpo_retv( sd );
  4802. int fd = sd->fd;
  4803. if( !session_isActive( fd ) ){
  4804. return;
  4805. }
  4806. if(battle_config.display_skill_fail&1)
  4807. return; //Disable all skill failed messages
  4808. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4809. return; //Disable delay failed messages
  4810. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4811. return;
  4812. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4813. return;
  4814. struct PACKET_ZC_ACK_TOUSESKILL p;
  4815. p.packetType = 0x110;
  4816. p.skillId = skill_id;
  4817. p.btype = btype;
  4818. p.itemId = itemId;
  4819. p.flag = 0; // 0 - failed
  4820. p.cause = cause;
  4821. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4822. }
  4823. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4824. /// 043d <skill ID>.W <tick>.L
  4825. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4826. {
  4827. #if PACKETVER>=20081112
  4828. int fd;
  4829. nullpo_retv(sd);
  4830. fd=sd->fd;
  4831. WFIFOHEAD(fd,packet_len(0x43d));
  4832. WFIFOW(fd,0) = 0x43d;
  4833. WFIFOW(fd,2) = skill_id;
  4834. WFIFOL(fd,4) = client_tick(tick);
  4835. WFIFOSET(fd,packet_len(0x43d));
  4836. #endif
  4837. }
  4838. /// Skill attack effect and damage.
  4839. /// 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)
  4840. /// 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)
  4841. 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)
  4842. {
  4843. unsigned char buf[64];
  4844. struct status_change *sc;
  4845. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4846. nullpo_ret(src);
  4847. nullpo_ret(dst);
  4848. type = clif_calc_delay(type,div,damage,ddelay);
  4849. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4850. if(sc->data[SC_HALLUCINATION] && damage)
  4851. damage = clif_hallucination_damage();
  4852. }
  4853. #if PACKETVER < 3
  4854. WBUFW(buf,0)=0x114;
  4855. WBUFW(buf,2)=skill_id;
  4856. WBUFL(buf,4)=src->id;
  4857. WBUFL(buf,8)=dst->id;
  4858. WBUFL(buf,12)=client_tick(tick);
  4859. WBUFL(buf,16)=sdelay;
  4860. WBUFL(buf,20)=ddelay;
  4861. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4862. WBUFW(buf,24)=damage?div:0;
  4863. } else {
  4864. WBUFW(buf,24)=damage;
  4865. }
  4866. WBUFW(buf,26)=skill_lv;
  4867. WBUFW(buf,28)=div;
  4868. WBUFB(buf,30)=type;
  4869. if (disguised(dst)) {
  4870. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4871. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4872. clif_send(buf,packet_len(0x114),dst,SELF);
  4873. } else
  4874. clif_send(buf,packet_len(0x114),dst,AREA);
  4875. if(disguised(src)) {
  4876. WBUFL(buf,4)=disguised_bl_id(src->id);
  4877. if (disguised(dst))
  4878. WBUFL(buf,8)=dst->id;
  4879. if(damage > 0)
  4880. WBUFW(buf,24)=-1;
  4881. clif_send(buf,packet_len(0x114),src,SELF);
  4882. }
  4883. #else
  4884. WBUFW(buf,0)=0x1de;
  4885. WBUFW(buf,2)=skill_id;
  4886. WBUFL(buf,4)=src->id;
  4887. WBUFL(buf,8)=dst->id;
  4888. WBUFL(buf,12)=client_tick(tick);
  4889. WBUFL(buf,16)=sdelay;
  4890. WBUFL(buf,20)=ddelay;
  4891. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4892. WBUFL(buf,24)=damage?div:0;
  4893. } else {
  4894. WBUFL(buf,24)=damage;
  4895. }
  4896. WBUFW(buf,28)=skill_lv;
  4897. WBUFW(buf,30)=div;
  4898. // For some reason, late 2013 and newer clients have
  4899. // a issue that causes players and monsters to endure
  4900. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4901. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4902. #if PACKETVER < 20131223
  4903. WBUFB(buf,32)=type;
  4904. #else
  4905. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  4906. #endif
  4907. if (disguised(dst)) {
  4908. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4909. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4910. clif_send(buf,packet_len(0x1de),dst,SELF);
  4911. } else
  4912. clif_send(buf,packet_len(0x1de),dst,AREA);
  4913. if(disguised(src)) {
  4914. WBUFL(buf,4)=disguised_bl_id(src->id);
  4915. if (disguised(dst))
  4916. WBUFL(buf,8)=dst->id;
  4917. if(damage > 0)
  4918. WBUFL(buf,24)=-1;
  4919. clif_send(buf,packet_len(0x1de),src,SELF);
  4920. }
  4921. #endif
  4922. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4923. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4924. }
  4925. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4926. /// 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
  4927. /*
  4928. 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)
  4929. {
  4930. unsigned char buf[64];
  4931. struct status_change *sc;
  4932. nullpo_ret(src);
  4933. nullpo_ret(dst);
  4934. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4935. type = clif_calc_delay(type,div,damage,ddelay);
  4936. sc = status_get_sc(dst);
  4937. if(sc && sc->count) {
  4938. if(sc->data[SC_HALLUCINATION] && damage)
  4939. damage = clif_hallucination_damage();
  4940. }
  4941. WBUFW(buf,0)=0x115;
  4942. WBUFW(buf,2)=skill_id;
  4943. WBUFL(buf,4)=src->id;
  4944. WBUFL(buf,8)=dst->id;
  4945. WBUFL(buf,12)=client_tick(tick);
  4946. WBUFL(buf,16)=sdelay;
  4947. WBUFL(buf,20)=ddelay;
  4948. WBUFW(buf,24)=dst->x;
  4949. WBUFW(buf,26)=dst->y;
  4950. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4951. WBUFW(buf,28)=damage?div:0;
  4952. } else {
  4953. WBUFW(buf,28)=damage;
  4954. }
  4955. WBUFW(buf,30)=skill_lv;
  4956. WBUFW(buf,32)=div;
  4957. WBUFB(buf,34)=type;
  4958. clif_send(buf,packet_len(0x115),src,AREA);
  4959. if(disguised(src)) {
  4960. WBUFL(buf,4)=disguised_bl_id(src->id);
  4961. if(damage > 0)
  4962. WBUFW(buf,28)=-1;
  4963. clif_send(buf,packet_len(0x115),src,SELF);
  4964. }
  4965. if (disguised(dst)) {
  4966. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4967. if (disguised(src))
  4968. WBUFL(buf,4)=src->id;
  4969. else if(damage > 0)
  4970. WBUFW(buf,28)=-1;
  4971. clif_send(buf,packet_len(0x115),dst,SELF);
  4972. }
  4973. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4974. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4975. }
  4976. */
  4977. /// Non-damaging skill effect
  4978. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4979. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4980. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  4981. {
  4982. unsigned char buf[17];
  4983. #if PACKETVER < 20130731
  4984. const int cmd = 0x11a;
  4985. #else
  4986. const int cmd = 0x9cb;
  4987. #endif
  4988. int offset = 0;
  4989. bool success = ( tick != 0 );
  4990. nullpo_ret(dst);
  4991. WBUFW(buf,0) = cmd;
  4992. WBUFW(buf,2) = skill_id;
  4993. #if PACKETVER < 20130731
  4994. WBUFW(buf,4) = min(heal, INT16_MAX);
  4995. #else
  4996. WBUFL(buf,4) = min(heal, INT32_MAX);
  4997. offset += 2;
  4998. #endif
  4999. WBUFL(buf,6+offset) = dst->id;
  5000. WBUFL(buf,10+offset) = src ? src->id : 0;
  5001. WBUFB(buf,14+offset) = success;
  5002. if (disguised(dst)) {
  5003. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5004. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5005. clif_send(buf, packet_len(cmd), dst, SELF);
  5006. } else
  5007. clif_send(buf, packet_len(cmd), dst, AREA);
  5008. if(src && disguised(src)) {
  5009. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5010. if (disguised(dst))
  5011. WBUFL(buf,6+offset) = dst->id;
  5012. clif_send(buf, packet_len(cmd), src, SELF);
  5013. }
  5014. return success;
  5015. }
  5016. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5017. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5018. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5019. {
  5020. unsigned char buf[32];
  5021. nullpo_retv(src);
  5022. WBUFW(buf,0)=0x117;
  5023. WBUFW(buf,2)=skill_id;
  5024. WBUFL(buf,4)=src->id;
  5025. WBUFW(buf,8)=val;
  5026. WBUFW(buf,10)=x;
  5027. WBUFW(buf,12)=y;
  5028. WBUFL(buf,14)=client_tick(tick);
  5029. if(disguised(src)) {
  5030. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5031. WBUFL(buf,4)=disguised_bl_id(src->id);
  5032. clif_send(buf,packet_len(0x117),src,SELF);
  5033. } else
  5034. clif_send(buf,packet_len(0x117),src,AREA);
  5035. }
  5036. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5037. /// 011c <skill id>.W { <map name>.16B }*4
  5038. 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)
  5039. {
  5040. int fd;
  5041. nullpo_retv(sd);
  5042. fd = sd->fd;
  5043. WFIFOHEAD(fd,packet_len(0x11c));
  5044. WFIFOW(fd,0) = 0x11c;
  5045. WFIFOW(fd,2) = skill_id;
  5046. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5047. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5048. else // normal map name
  5049. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5050. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5051. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5052. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5053. WFIFOSET(fd,packet_len(0x11c));
  5054. sd->menuskill_id = skill_id;
  5055. if (skill_id == AL_WARP) {
  5056. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5057. sd->state.workinprogress = WIP_DISABLE_ALL;
  5058. } else
  5059. sd->menuskill_val = skill_lv;
  5060. }
  5061. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5062. /// 011e <type>.B
  5063. /// type:
  5064. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5065. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5066. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5067. ///
  5068. /// @param sd Who receives the message
  5069. /// @param type What message
  5070. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5071. {
  5072. int fd;
  5073. nullpo_retv(sd);
  5074. fd=sd->fd;
  5075. WFIFOHEAD(fd,packet_len(0x11e));
  5076. WFIFOW(fd,0)=0x11e;
  5077. WFIFOB(fd,2)=type;
  5078. WFIFOSET(fd,packet_len(0x11e));
  5079. }
  5080. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5081. /// 0189 <type>.W
  5082. /// type:
  5083. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5084. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5085. ///
  5086. /// @param sd Who receives the message
  5087. /// @param type What message
  5088. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5089. {
  5090. int fd;
  5091. nullpo_retv(sd);
  5092. fd=sd->fd;
  5093. WFIFOHEAD(fd,packet_len(0x189));
  5094. WFIFOW(fd,0)=0x189;
  5095. WFIFOW(fd,2)=type;
  5096. WFIFOSET(fd,packet_len(0x189));
  5097. }
  5098. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5099. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5100. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5101. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5102. {
  5103. struct status_data *status;
  5104. unsigned char buf[64];
  5105. int i, fix;
  5106. nullpo_retv(sd);
  5107. nullpo_retv(dst);
  5108. if( dst->type != BL_MOB )
  5109. return;
  5110. status = status_get_status_data(dst);
  5111. WBUFW(buf, 0)=0x18c;
  5112. WBUFW(buf, 2)=status_get_class(dst);
  5113. WBUFW(buf, 4)=status_get_lv(dst);
  5114. WBUFW(buf, 6)=status->size;
  5115. WBUFL(buf, 8)=status->hp;
  5116. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5117. +(battle_config.estimation_type&2?status->def2:0);
  5118. WBUFW(buf,14)=status->race;
  5119. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5120. +(battle_config.estimation_type&2?status->mdef2:0);
  5121. WBUFW(buf,18)= status->def_ele;
  5122. for(i=0;i<9;i++)
  5123. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5124. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5125. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5126. }
  5127. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5128. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5129. /// material id:
  5130. /// unused by the client
  5131. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5132. nullpo_retv(sd);
  5133. int fd = sd->fd;
  5134. if( !session_isActive( fd ) ){
  5135. return;
  5136. }
  5137. if (sd->menuskill_id == skill_id)
  5138. return; //Avoid resending the menu twice or more times...
  5139. if (skill_id == GC_CREATENEWPOISON)
  5140. skill_id = GC_RESEARCHNEWPOISON;
  5141. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5142. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5143. p->packetType = 0x18d;
  5144. int count = 0;
  5145. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5146. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5147. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5148. )
  5149. {
  5150. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5151. p->items[count].material[0] = 0;
  5152. p->items[count].material[1] = 0;
  5153. p->items[count].material[2] = 0;
  5154. count++;
  5155. }
  5156. }
  5157. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5158. WFIFOSET( fd, p->packetLength );
  5159. if( count > 0 ){
  5160. sd->menuskill_id = skill_id;
  5161. sd->menuskill_val = trigger;
  5162. return;
  5163. }
  5164. }
  5165. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5166. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5167. /// mk type:
  5168. /// 1 = cooking
  5169. /// 2 = arrow
  5170. /// 3 = elemental
  5171. /// 4 = GN_MIX_COOKING
  5172. /// 5 = GN_MAKEBOMB
  5173. /// 6 = GN_S_PHARMACY
  5174. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5175. nullpo_retv( sd );
  5176. // Avoid resending the menu twice or more times...
  5177. if( sd->menuskill_id == skill_id ){
  5178. return;
  5179. }
  5180. int fd = sd->fd;
  5181. if( !session_isActive( fd ) ){
  5182. return;
  5183. }
  5184. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5185. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5186. p->packetType = 0x25a;
  5187. p->makeItem = list_type; // list type
  5188. int count = 0;
  5189. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5190. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5191. continue;
  5192. }
  5193. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5194. count++;
  5195. }
  5196. if( count > 0 || skill_id == AM_PHARMACY ){
  5197. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5198. WFIFOSET( fd, p->packetLength );
  5199. sd->menuskill_id = skill_id;
  5200. sd->menuskill_val = trigger;
  5201. sd->menuskill_val2 = qty; // amount.
  5202. }else{
  5203. clif_menuskill_clear(sd);
  5204. #if PACKETVER >= 20090922
  5205. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5206. #else
  5207. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5208. WFIFOSET( fd, p->packetLength );
  5209. #endif
  5210. }
  5211. }
  5212. /// Notifies clients of a status change.
  5213. /// 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)]
  5214. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5215. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5216. /// @param bl Sends packet to clients around this object
  5217. /// @param id ID of object that has this effect
  5218. /// @param type Status icon see enum efst_types
  5219. /// @param flag 1:Active, 0:Deactive
  5220. /// @param tick Duration in ms
  5221. /// @param val1
  5222. /// @param val2
  5223. /// @param val3
  5224. 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)
  5225. {
  5226. unsigned char buf[32];
  5227. if (type == EFST_BLANK) //It shows nothing on the client...
  5228. return;
  5229. if (type == EFST_POSTDELAY && tick == 0)
  5230. return;
  5231. nullpo_retv(bl);
  5232. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5233. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5234. tick = 200;
  5235. #if PACKETVER >= 20120618
  5236. if (flag && battle_config.display_status_timers)
  5237. WBUFW(buf,0) = 0x983;
  5238. else
  5239. #elif PACKETVER >= 20090121
  5240. if (flag && battle_config.display_status_timers)
  5241. WBUFW(buf,0) = 0x43f;
  5242. else
  5243. #endif
  5244. WBUFW(buf,0) = 0x196;
  5245. WBUFW(buf,2) = type;
  5246. WBUFL(buf,4) = id;
  5247. WBUFB(buf,8) = flag;
  5248. #if PACKETVER >= 20120618
  5249. if (flag && battle_config.display_status_timers) {
  5250. if (tick <= 0)
  5251. tick = 9999; // this is indeed what official servers do
  5252. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5253. WBUFL(buf,13) = client_tick(tick);
  5254. WBUFL(buf,17) = val1;
  5255. WBUFL(buf,21) = val2;
  5256. WBUFL(buf,25) = val3;
  5257. }
  5258. #elif PACKETVER >= 20090121
  5259. if (flag && battle_config.display_status_timers) {
  5260. if (tick <= 0)
  5261. tick = 9999; // this is indeed what official servers do
  5262. WBUFL(buf,9) = client_tick(tick);
  5263. WBUFL(buf,13) = val1;
  5264. WBUFL(buf,17) = val2;
  5265. WBUFL(buf,21) = val3;
  5266. }
  5267. #endif
  5268. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5269. }
  5270. /* Sends status effect to clients around the bl
  5271. * @param bl Object that has the effect
  5272. * @param type Status icon see enum efst_types
  5273. * @param flag 1:Active, 0:Deactive
  5274. * @param tick Duration in ms
  5275. * @param val1
  5276. * @param val2
  5277. * @param val3
  5278. */
  5279. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5280. struct map_session_data *sd = NULL;
  5281. if (type == EFST_BLANK) //It shows nothing on the client...
  5282. return;
  5283. if (type == EFST_POSTDELAY && tick == 0)
  5284. return;
  5285. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5286. return;
  5287. nullpo_retv(bl);
  5288. sd = BL_CAST(BL_PC, bl);
  5289. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5290. return;
  5291. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5292. }
  5293. /**
  5294. * Send any active EFST to those around.
  5295. * @param tbl: Unit to send the packet to
  5296. * @param bl: Objects walking into view
  5297. * @param target: Client send type
  5298. */
  5299. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5300. unsigned char i;
  5301. struct sc_display_entry **sc_display;
  5302. unsigned char sc_display_count;
  5303. bool spheres_sent;
  5304. nullpo_retv(bl);
  5305. switch( bl->type ){
  5306. case BL_PC: {
  5307. struct map_session_data* sd = (struct map_session_data*)bl;
  5308. sc_display = sd->sc_display;
  5309. sc_display_count = sd->sc_display_count;
  5310. spheres_sent = !sd->state.connect_new;
  5311. }
  5312. break;
  5313. case BL_NPC: {
  5314. struct npc_data* nd = (struct npc_data*)bl;
  5315. sc_display = nd->sc_display;
  5316. sc_display_count = nd->sc_display_count;
  5317. spheres_sent = true;
  5318. }
  5319. break;
  5320. default:
  5321. return;
  5322. }
  5323. for (i = 0; i < sc_display_count; i++) {
  5324. enum sc_type type = sc_display[i]->type;
  5325. struct status_change *sc = status_get_sc(bl);
  5326. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5327. t_tick tick = 0;
  5328. if (td)
  5329. tick = DIFF_TICK(td->tick, gettick());
  5330. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5331. #if PACKETVER > 20120418
  5332. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5333. #else
  5334. 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);
  5335. #endif
  5336. }else{
  5337. #if PACKETVER > 20120418
  5338. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5339. #else
  5340. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5341. #endif
  5342. }
  5343. }
  5344. }
  5345. /// Notifies the client when a player enters the screen with an active EFST.
  5346. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5347. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5348. 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) {
  5349. #if PACKETVER >= 20111108
  5350. unsigned char buf[32];
  5351. #if PACKETVER >= 20120618
  5352. const int cmd = 0x984;
  5353. #elif PACKETVER >= 20111108
  5354. const int cmd = 0x8ff;
  5355. #endif
  5356. int offset = 0;
  5357. if (type == EFST_BLANK)
  5358. return;
  5359. nullpo_retv(bl);
  5360. if (tick <= 0)
  5361. tick = 9999;
  5362. WBUFW(buf,offset + 0) = cmd;
  5363. WBUFL(buf,offset + 2) = tid;
  5364. WBUFW(buf,offset + 6) = type;
  5365. #if PACKETVER >= 20111108
  5366. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5367. #if PACKETVER >= 20120618
  5368. WBUFL(buf,offset + 12) = client_tick(tick);
  5369. offset += 4;
  5370. #endif
  5371. WBUFL(buf,offset + 12) = val1;
  5372. WBUFL(buf,offset + 16) = val2;
  5373. WBUFL(buf,offset + 20) = val3;
  5374. #endif
  5375. clif_send(buf,packet_len(cmd),bl,target);
  5376. #endif
  5377. }
  5378. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5379. /// 008e <packet len>.W <message>.?B
  5380. void clif_displaymessage(const int fd, const char* mes)
  5381. {
  5382. nullpo_retv(mes);
  5383. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5384. if (fd == 0)
  5385. ;
  5386. else {
  5387. char *message, *line;
  5388. message = aStrdup(mes);
  5389. line = strtok(message, "\n");
  5390. while(line != NULL) {
  5391. #if PACKETVER == 20141022
  5392. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5393. /** so we redirect to ZC_NPC_CHAT **/
  5394. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5395. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5396. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5397. if (len > 0) {
  5398. WFIFOHEAD(fd, 13 + len);
  5399. WFIFOW(fd, 0) = 0x2C1;
  5400. WFIFOW(fd, 2) = 13 + len;
  5401. WFIFOL(fd, 4) = 0;
  5402. WFIFOL(fd, 8) = color;
  5403. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5404. WFIFOSET(fd, WFIFOW(fd, 2));
  5405. }
  5406. #else
  5407. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5408. int len = strnlen(line, CHAT_SIZE_MAX);
  5409. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5410. WFIFOHEAD(fd, 5 + len);
  5411. WFIFOW(fd,0) = 0x8e;
  5412. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5413. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5414. WFIFOSET(fd, 5 + len);
  5415. }
  5416. #endif
  5417. line = strtok(NULL, "\n");
  5418. }
  5419. aFree(message);
  5420. }
  5421. }
  5422. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5423. /// 009a <packet len>.W <message>.?B
  5424. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5425. {
  5426. nullpo_retv(mes);
  5427. if (len < 2)
  5428. return;
  5429. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5430. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5431. WBUFW(buf.get(),0) = 0x9a;
  5432. WBUFW(buf.get(),2) = 4 + lp + len;
  5433. if (type&BC_BLUE)
  5434. 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.
  5435. else if (type&BC_WOE)
  5436. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5437. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5438. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5439. }
  5440. /*==========================================
  5441. * Displays a message on a 'bl' to all it's nearby clients
  5442. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5443. *------------------------------------------*/
  5444. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5445. size_t len;
  5446. nullpo_retv(bl);
  5447. if(!message)
  5448. return;
  5449. len = strlen(message)+1;
  5450. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5451. if( len > CHAT_SIZE_MAX ) {
  5452. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  5453. len = CHAT_SIZE_MAX;
  5454. }
  5455. std::unique_ptr<char> buf(new char[8+len]);
  5456. WBUFW(buf.get(),0)=0x8d;
  5457. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5458. WBUFL(buf.get(),4)=bl->id;
  5459. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5460. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5461. }
  5462. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5463. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5464. 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)
  5465. {
  5466. nullpo_retv(mes);
  5467. if (len < 2)
  5468. return;
  5469. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5470. WBUFW(buf.get(),0) = 0x1c3;
  5471. WBUFW(buf.get(),2) = len + 16;
  5472. WBUFL(buf.get(),4) = fontColor;
  5473. WBUFW(buf.get(),8) = fontType;
  5474. WBUFW(buf.get(),10) = fontSize;
  5475. WBUFW(buf.get(),12) = fontAlign;
  5476. WBUFW(buf.get(),14) = fontY;
  5477. memcpy(WBUFP(buf.get(),16), mes, len);
  5478. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5479. }
  5480. /*
  5481. * Display *msg to all *users in channel
  5482. */
  5483. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5484. DBIterator *iter;
  5485. struct map_session_data *user;
  5486. unsigned short msg_len = 0, len = 0;
  5487. unsigned char buf[CHAT_SIZE_MAX];
  5488. if (!channel || !msg)
  5489. return;
  5490. msg_len = (unsigned short)(strlen(msg) + 1);
  5491. if( msg_len > sizeof(buf)-12 ) {
  5492. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5493. msg_len = sizeof(buf)-12;
  5494. }
  5495. WBUFW(buf,0) = 0x2C1;
  5496. WBUFW(buf,2) = (len = msg_len + 12);
  5497. WBUFL(buf,4) = 0;
  5498. WBUFL(buf,8) = color;
  5499. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5500. iter = db_iterator(channel->users);
  5501. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5502. clif_send(buf, len, &user->bl, SELF);
  5503. }
  5504. dbi_destroy(iter);
  5505. }
  5506. /// Displays heal effect.
  5507. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5508. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5509. /// var id:
  5510. /// 5 = HP (SP_HP)
  5511. /// 7 = SP (SP_SP)
  5512. /// ? = ignored
  5513. void clif_heal(int fd,int type,int val) {
  5514. #if PACKETVER < 20141022
  5515. const int cmd = 0x13d;
  5516. #else
  5517. const int cmd = 0xa27;
  5518. #endif
  5519. WFIFOHEAD(fd, packet_len(cmd));
  5520. WFIFOW(fd,0) = cmd;
  5521. WFIFOW(fd,2) = type;
  5522. #if PACKETVER < 20141022
  5523. WFIFOW(fd,4) = min(val, INT16_MAX);
  5524. #else
  5525. WFIFOL(fd,4) = min(val, INT32_MAX);
  5526. #endif
  5527. WFIFOSET(fd, packet_len(cmd));
  5528. }
  5529. /// Displays resurrection effect (ZC_RESURRECTION).
  5530. /// 0148 <id>.L <type>.W
  5531. /// type:
  5532. /// ignored
  5533. void clif_resurrection(struct block_list *bl,int type)
  5534. {
  5535. unsigned char buf[16];
  5536. nullpo_retv(bl);
  5537. WBUFW(buf,0)=0x148;
  5538. WBUFL(buf,2)=bl->id;
  5539. WBUFW(buf,6)=0;
  5540. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5541. if (disguised(bl))
  5542. clif_spawn(bl);
  5543. }
  5544. /// Sets the map property
  5545. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5546. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5547. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5548. {
  5549. #if PACKETVER >= 20121010
  5550. short cmd = 0x99b;
  5551. unsigned char buf[8];
  5552. #else
  5553. short cmd = 0x199;
  5554. unsigned char buf[4];
  5555. #endif
  5556. WBUFW(buf,0)=cmd;
  5557. WBUFW(buf,2)=property;
  5558. #if PACKETVER >= 20121010
  5559. struct map_data *mapdata = map_getmapdata(bl->m);
  5560. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5561. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5562. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5563. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5564. ((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
  5565. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5566. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5567. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5568. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5569. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5570. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5571. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5572. #endif
  5573. clif_send(buf,packet_len(cmd),bl,t);
  5574. }
  5575. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5576. /// 01d6 <type>.W
  5577. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5578. {
  5579. int fd;
  5580. nullpo_retv(sd);
  5581. fd=sd->fd;
  5582. WFIFOHEAD(fd,packet_len(0x1D6));
  5583. WFIFOW(fd,0)=0x1D6;
  5584. WFIFOW(fd,2)=type;
  5585. WFIFOSET(fd,packet_len(0x1D6));
  5586. }
  5587. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5588. /// 019a <id>.L <ranking>.L <total>.L
  5589. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5590. {
  5591. if(type == 2) {
  5592. int fd = sd->fd;
  5593. WFIFOHEAD(fd,packet_len(0x19a));
  5594. WFIFOW(fd,0) = 0x19a;
  5595. WFIFOL(fd,2) = sd->bl.id;
  5596. WFIFOL(fd,6) = pvprank;
  5597. WFIFOL(fd,10) = pvpnum;
  5598. WFIFOSET(fd,packet_len(0x19a));
  5599. } else {
  5600. unsigned char buf[32];
  5601. WBUFW(buf,0) = 0x19a;
  5602. WBUFL(buf,2) = sd->bl.id;
  5603. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5604. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5605. else
  5606. WBUFL(buf,6) = pvprank;
  5607. WBUFL(buf,10) = pvpnum;
  5608. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5609. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5610. else if(!type)
  5611. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5612. else
  5613. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5614. }
  5615. }
  5616. /*==========================================
  5617. *
  5618. *------------------------------------------*/
  5619. void clif_map_property_mapall(int map_idx, enum map_property property)
  5620. {
  5621. struct block_list bl;
  5622. bl.id = 0;
  5623. bl.type = BL_NUL;
  5624. bl.m = map_idx;
  5625. clif_map_property( &bl, property, ALL_SAMEMAP );
  5626. }
  5627. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5628. /// 0188 <result>.W <index>.W <refine>.W
  5629. /// result:
  5630. /// 0 = success
  5631. /// 1 = failure
  5632. /// 2 = downgrade
  5633. void clif_refine(int fd, int fail, int index, int val)
  5634. {
  5635. WFIFOHEAD(fd,packet_len(0x188));
  5636. WFIFOW(fd,0)=0x188;
  5637. WFIFOW(fd,2)=fail;
  5638. WFIFOW(fd,4)=index+2;
  5639. WFIFOW(fd,6)=val;
  5640. WFIFOSET(fd,packet_len(0x188));
  5641. }
  5642. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5643. /// 0223 <result>.L <nameid>.W
  5644. /// result:
  5645. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5646. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5647. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5648. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5649. void clif_upgrademessage( struct map_session_data* sd, int result, unsigned short item_id ){
  5650. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5651. p.packetType = 0x223;
  5652. p.result = result;
  5653. p.itemId = client_nameid( item_id );
  5654. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5655. }
  5656. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5657. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5658. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5659. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5660. int fd;
  5661. nullpo_retv(sd);
  5662. fd = sd->fd;
  5663. #if PACKETVER < 20091104
  5664. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5665. WFIFOW(fd,0) = 0x97;
  5666. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5667. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5668. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5669. WFIFOSET(fd,WFIFOW(fd,2));
  5670. #else
  5671. struct map_session_data *ssd = map_nick2sd(nick,false);
  5672. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5673. WFIFOW(fd,0) = 0x97;
  5674. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5675. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5676. // If it is not a message from the server or a player from another map-server
  5677. if( ssd ){
  5678. gmlvl = pc_get_group_level(ssd);
  5679. }
  5680. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5681. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5682. WFIFOSET(fd,WFIFOW(fd,2));
  5683. #endif
  5684. }
  5685. /// Inform the player about the result of his whisper action
  5686. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5687. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5688. /// result:
  5689. /// 0 = success to send wisper
  5690. /// 1 = target character is not loged in
  5691. /// 2 = ignored by target
  5692. /// 3 = everyone ignored by target
  5693. void clif_wis_end(int fd, int result)
  5694. {
  5695. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5696. #if PACKETVER < 20131223
  5697. const int cmd = 0x98;
  5698. #else
  5699. const int cmd = 0x9df;
  5700. #endif
  5701. if (!sd)
  5702. return;
  5703. WFIFOHEAD(fd,packet_len(cmd));
  5704. WFIFOW(fd,0) = cmd;
  5705. WFIFOB(fd,2) = (char)result;
  5706. #if PACKETVER >= 20131223
  5707. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5708. #endif
  5709. WFIFOSET(fd,packet_len(cmd));
  5710. }
  5711. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5712. /// 0194 <char id>.L <name>.24B
  5713. /// 0af7 <flag>.W <char id>.L <name>.24B
  5714. void clif_solved_charname(int fd, int charid, const char* name)
  5715. {
  5716. #if PACKETVER >= 20180221
  5717. WFIFOHEAD(fd,packet_len(0xaf7));
  5718. WFIFOW(fd,0) = 0xaf7;
  5719. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5720. WFIFOL(fd,4) = charid;
  5721. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5722. WFIFOSET(fd,packet_len(0x0af7));
  5723. #else
  5724. WFIFOHEAD(fd,packet_len(0x194));
  5725. WFIFOW(fd,0)=0x194;
  5726. WFIFOL(fd,2)=charid;
  5727. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5728. WFIFOSET(fd,packet_len(0x194));
  5729. #endif
  5730. }
  5731. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5732. /// 017b <packet len>.W { <name id>.W }*
  5733. void clif_use_card(struct map_session_data *sd,int idx)
  5734. {
  5735. int i,c,ep;
  5736. int fd=sd->fd;
  5737. nullpo_retv(sd);
  5738. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5739. return;
  5740. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5741. return; //Avoid parsing invalid item indexes (no card/no item)
  5742. ep=sd->inventory_data[idx]->equip;
  5743. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5744. WFIFOW(fd,0)=0x17b;
  5745. for(i=c=0;i<MAX_INVENTORY;i++){
  5746. int j;
  5747. if(sd->inventory_data[i] == NULL)
  5748. continue;
  5749. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5750. continue;
  5751. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5752. continue;
  5753. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5754. continue;
  5755. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5756. continue;
  5757. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5758. continue;
  5759. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5760. if( j == sd->inventory_data[i]->slot ) // No room
  5761. continue;
  5762. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5763. continue;
  5764. WFIFOW(fd,4+c*2)=i+2;
  5765. c++;
  5766. }
  5767. if( !c ) return; // no item is available for card insertion
  5768. WFIFOW(fd,2)=4+c*2;
  5769. WFIFOSET(fd,WFIFOW(fd,2));
  5770. }
  5771. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5772. /// 017d <equip index>.W <card index>.W <result>.B
  5773. /// result:
  5774. /// 0 = success
  5775. /// 1 = failure
  5776. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5777. {
  5778. int fd;
  5779. nullpo_retv(sd);
  5780. fd=sd->fd;
  5781. WFIFOHEAD(fd,packet_len(0x17d));
  5782. WFIFOW(fd,0)=0x17d;
  5783. WFIFOW(fd,2)=idx_equip+2;
  5784. WFIFOW(fd,4)=idx_card+2;
  5785. WFIFOB(fd,6)=flag;
  5786. WFIFOSET(fd,packet_len(0x17d));
  5787. }
  5788. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5789. /// 0177 <packet len>.W { <index>.W }*
  5790. void clif_item_identify_list(struct map_session_data *sd)
  5791. {
  5792. int i,c;
  5793. int fd;
  5794. nullpo_retv(sd);
  5795. fd=sd->fd;
  5796. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5797. WFIFOW(fd,0)=0x177;
  5798. for(i=c=0;i<MAX_INVENTORY;i++){
  5799. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5800. WFIFOW(fd,c*2+4)=i+2;
  5801. c++;
  5802. }
  5803. }
  5804. if(c > 0) {
  5805. WFIFOW(fd,2)=c*2+4;
  5806. WFIFOSET(fd,WFIFOW(fd,2));
  5807. sd->menuskill_id = MC_IDENTIFY;
  5808. sd->menuskill_val = c;
  5809. sd->state.workinprogress = WIP_DISABLE_ALL;
  5810. }
  5811. }
  5812. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5813. /// 0179 <index>.W <result>.B
  5814. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5815. {
  5816. int fd;
  5817. nullpo_retv(sd);
  5818. fd=sd->fd;
  5819. WFIFOHEAD(fd,packet_len(0x179));
  5820. WFIFOW(fd, 0)=0x179;
  5821. WFIFOW(fd, 2)=idx+2;
  5822. WFIFOB(fd, 4)=flag;
  5823. WFIFOSET(fd,packet_len(0x179));
  5824. }
  5825. /// Presents a list of items that can be repaired.
  5826. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  5827. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  5828. nullpo_retv( sd );
  5829. nullpo_retv( dstsd );
  5830. int fd = sd->fd;
  5831. if( !session_isActive( fd ) ){
  5832. return;
  5833. }
  5834. int len = MAX_INVENTORY * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5835. // Preallocate the maximum size
  5836. WFIFOHEAD( fd, len );
  5837. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  5838. int c = 0;
  5839. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5840. 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)){
  5841. p->items[c].index = i;
  5842. p->items[c].itemId = dstsd->inventory.u.items_inventory[i].nameid;
  5843. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  5844. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  5845. c++;
  5846. }
  5847. }
  5848. if( c > 0 ){
  5849. p->packetType = 0x1fc;
  5850. // Recalculate real length
  5851. len = c * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5852. p->packetLength = len;
  5853. WFIFOSET( fd, len );
  5854. sd->menuskill_id = BS_REPAIRWEAPON;
  5855. sd->menuskill_val = dstsd->bl.id;
  5856. sd->menuskill_val2 = lv;
  5857. }else{
  5858. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  5859. }
  5860. }
  5861. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5862. /// 01fe <index>.W <result>.B
  5863. /// index:
  5864. /// ignored (inventory index)
  5865. /// result:
  5866. /// 0 = Item repair success.
  5867. /// 1 = Item repair failure.
  5868. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5869. {
  5870. int fd;
  5871. nullpo_retv(sd);
  5872. fd = sd->fd;
  5873. WFIFOHEAD(fd,packet_len(0x1fe));
  5874. WFIFOW(fd, 0)=0x1fe;
  5875. WFIFOW(fd, 2)=idx+2;
  5876. WFIFOB(fd, 4)=flag;
  5877. WFIFOSET(fd,packet_len(0x1fe));
  5878. }
  5879. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5880. /// 02bb <equip location>.W <account id>.L
  5881. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5882. {
  5883. int fd = sd->fd;
  5884. WFIFOHEAD(fd,packet_len(0x2bb));
  5885. WFIFOW(fd,0) = 0x2bb;
  5886. WFIFOW(fd,2) = position;
  5887. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5888. WFIFOSET(fd,packet_len(0x2bb));
  5889. }
  5890. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5891. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5892. void clif_item_refine_list( struct map_session_data *sd ){
  5893. nullpo_retv( sd );
  5894. int fd = sd->fd;
  5895. if( !session_isActive( fd ) ){
  5896. return;
  5897. }
  5898. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * MAX_INVENTORY );
  5899. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)WFIFOP( fd, 0 );
  5900. p->packetType = 0x221;
  5901. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  5902. int refine_item[5];
  5903. refine_item[0] = -1;
  5904. refine_item[1] = pc_search_inventory( sd, ITEMID_PHRACON );
  5905. refine_item[2] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  5906. refine_item[3] = refine_item[4] = pc_search_inventory( sd, ITEMID_ORIDECON );
  5907. int count = 0;
  5908. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5909. unsigned char wlv;
  5910. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5911. sd->inventory.u.items_inventory[i].identify && ( wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid ) ) >= 1 &&
  5912. refine_item[wlv] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  5913. p->items[count].index = client_index( i );
  5914. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  5915. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  5916. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  5917. count++;
  5918. }
  5919. }
  5920. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  5921. WFIFOSET( fd, p->packetLength );
  5922. if( count > 0 ){
  5923. sd->menuskill_id = WS_WEAPONREFINE;
  5924. sd->menuskill_val = skill_lv;
  5925. }
  5926. }
  5927. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5928. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5929. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  5930. nullpo_retv( sd );
  5931. struct PACKET_ZC_AUTORUN_SKILL p;
  5932. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  5933. p.skill_id = skill_id;
  5934. p.skill_type = skill_get_inf( skill_id );
  5935. p.skill_lv = skill_lv;
  5936. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  5937. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  5938. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  5939. p.up_flag = false;
  5940. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5941. }
  5942. /// Adds an item to character's cart.
  5943. /// 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)
  5944. /// 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)
  5945. /// 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)
  5946. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  5947. nullpo_retv( sd );
  5948. int fd = sd->fd;
  5949. if( !session_isActive( fd ) ){
  5950. return;
  5951. }
  5952. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0 ){
  5953. return;
  5954. }
  5955. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  5956. p.packetType = cartaddType;
  5957. p.index = client_index( n );
  5958. p.amount = amount;
  5959. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  5960. #if PACKETVER >= 5
  5961. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  5962. #endif
  5963. p.identified = sd->cart.u.items_cart[n].identify;
  5964. p.damaged = sd->cart.u.items_cart[n].attribute;
  5965. p.refine = sd->cart.u.items_cart[n].refine;
  5966. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  5967. #if PACKETVER >= 20150226
  5968. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  5969. #endif
  5970. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5971. }
  5972. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5973. /* Acknowledge an item have been added to cart
  5974. * 012c <result>B
  5975. * result :
  5976. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5977. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5978. */
  5979. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5980. {
  5981. int fd;
  5982. unsigned char *buf;
  5983. nullpo_retv(sd);
  5984. fd = sd->fd;
  5985. buf = WFIFOP(fd,0);
  5986. WBUFW(buf,0) = 0x12c;
  5987. WBUFB(buf,2) = flag;
  5988. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5989. }
  5990. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5991. void clif_bank_open(struct map_session_data *sd){
  5992. int fd;
  5993. nullpo_retv(sd);
  5994. fd = sd->fd;
  5995. WFIFOHEAD(fd,4);
  5996. WFIFOW(fd,0) = 0x09b7;
  5997. WFIFOW(fd,2) = 0;
  5998. WFIFOSET(fd,4);
  5999. }
  6000. /*
  6001. * Request to Open the banking system
  6002. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6003. */
  6004. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6005. //TODO check if preventing trade or stuff like that
  6006. //also mark something in case char ain't available for saving, should we check now ?
  6007. nullpo_retv(sd);
  6008. if( !battle_config.feature_banking ) {
  6009. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6010. return;
  6011. }
  6012. else {
  6013. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6014. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6015. if(sd->status.account_id == aid){
  6016. sd->state.banking = 1;
  6017. //request save ?
  6018. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6019. //on succes open bank ?
  6020. clif_bank_open(sd);
  6021. }
  6022. }
  6023. }
  6024. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6025. void clif_bank_close(struct map_session_data *sd){
  6026. int fd;
  6027. nullpo_retv(sd);
  6028. fd = sd->fd;
  6029. WFIFOHEAD(fd,4);
  6030. WFIFOW(fd,0) = 0x09B9;
  6031. WFIFOW(fd,2) = 0;
  6032. WFIFOSET(fd,4);
  6033. }
  6034. /*
  6035. * Request to close the banking system
  6036. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6037. */
  6038. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6039. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6040. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6041. nullpo_retv(sd);
  6042. if( !battle_config.feature_banking ) {
  6043. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6044. //still allow to go trough to not stuck player if we have disable it while they was in
  6045. }
  6046. if(sd->status.account_id == aid){
  6047. sd->state.banking = 0;
  6048. clif_bank_close(sd);
  6049. }
  6050. }
  6051. /*
  6052. * Display how much we got in bank (I suppose)
  6053. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6054. */
  6055. void clif_Bank_Check(struct map_session_data* sd) {
  6056. unsigned char buf[13];
  6057. struct s_packet_db* info;
  6058. int16 len;
  6059. int cmd = 0;
  6060. nullpo_retv(sd);
  6061. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6062. if(!cmd) cmd = 0x09A6; //default
  6063. info = &packet_db[cmd];
  6064. len = info->len;
  6065. if(!len) return; //version as packet disable
  6066. // sd->state.banking = 1; //mark opening and closing
  6067. WBUFW(buf,0) = cmd;
  6068. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6069. WBUFW(buf,info->pos[1]) = 0; //reason
  6070. clif_send(buf,len,&sd->bl,SELF);
  6071. }
  6072. /*
  6073. * Requesting the data in bank
  6074. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6075. */
  6076. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6077. nullpo_retv(sd);
  6078. if( !battle_config.feature_banking ) {
  6079. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6080. return;
  6081. }
  6082. else {
  6083. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6084. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6085. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6086. clif_Bank_Check(sd);
  6087. }
  6088. }
  6089. /*
  6090. * Acknowledge of deposit some money in bank
  6091. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6092. */
  6093. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6094. unsigned char buf[17];
  6095. struct s_packet_db* info;
  6096. int16 len;
  6097. int cmd =0;
  6098. nullpo_retv(sd);
  6099. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6100. if(!cmd) cmd = 0x09A8;
  6101. info = &packet_db[cmd];
  6102. len = info->len;
  6103. if(!len) return; //version as packet disable
  6104. WBUFW(buf,0) = cmd;
  6105. WBUFW(buf,info->pos[0]) = (short)reason;
  6106. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6107. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6108. clif_send(buf,len,&sd->bl,SELF);
  6109. }
  6110. /*
  6111. * Request saving some money in bank
  6112. * @author : original [Yommy/Hercules]
  6113. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6114. */
  6115. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6116. nullpo_retv(sd);
  6117. if( !battle_config.feature_banking ) {
  6118. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6119. return;
  6120. }
  6121. else {
  6122. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6123. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6124. int money = RFIFOL(fd,info->pos[1]);
  6125. if(sd->status.account_id == aid){
  6126. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6127. clif_bank_deposit(sd,reason);
  6128. }
  6129. }
  6130. }
  6131. /*
  6132. * Acknowledge of withdrawing some money from bank
  6133. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6134. */
  6135. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6136. unsigned char buf[17];
  6137. struct s_packet_db* info;
  6138. int16 len;
  6139. int cmd;
  6140. nullpo_retv(sd);
  6141. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6142. if(!cmd) cmd = 0x09AA;
  6143. info = &packet_db[cmd];
  6144. len = info->len;
  6145. if(!len) return; //version as packet disable
  6146. WBUFW(buf,0) = cmd;
  6147. WBUFW(buf,info->pos[0]) = (short)reason;
  6148. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6149. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6150. clif_send(buf,len,&sd->bl,SELF);
  6151. }
  6152. /*
  6153. * Request Withdrawing some money from bank
  6154. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6155. */
  6156. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6157. nullpo_retv(sd);
  6158. if( !battle_config.feature_banking ) {
  6159. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6160. return;
  6161. }
  6162. else {
  6163. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6164. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6165. int money = RFIFOL(fd,info->pos[1]);
  6166. if(sd->status.account_id == aid){
  6167. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6168. clif_bank_withdraw(sd,reason);
  6169. }
  6170. }
  6171. }
  6172. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6173. /// 0125 <index>.W <amount>.L
  6174. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6175. {
  6176. int fd;
  6177. nullpo_retv(sd);
  6178. fd=sd->fd;
  6179. WFIFOHEAD(fd,packet_len(0x125));
  6180. WFIFOW(fd,0)=0x125;
  6181. WFIFOW(fd,2)=n+2;
  6182. WFIFOL(fd,4)=amount;
  6183. WFIFOSET(fd,packet_len(0x125));
  6184. }
  6185. /// Opens the shop creation menu (ZC_OPENSTORE).
  6186. /// 012d <num>.W
  6187. /// num:
  6188. /// number of allowed item slots
  6189. void clif_openvendingreq(struct map_session_data* sd, int num)
  6190. {
  6191. int fd;
  6192. nullpo_retv(sd);
  6193. fd = sd->fd;
  6194. WFIFOHEAD(fd,packet_len(0x12d));
  6195. WFIFOW(fd,0) = 0x12d;
  6196. WFIFOW(fd,2) = num;
  6197. WFIFOSET(fd,packet_len(0x12d));
  6198. }
  6199. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6200. /// 0131 <owner id>.L <message>.80B
  6201. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6202. {
  6203. unsigned char buf[128];
  6204. nullpo_retv(bl);
  6205. WBUFW(buf,0) = 0x131;
  6206. WBUFL(buf,2) = bl->id;
  6207. safestrncpy(WBUFCP(buf,6), message, 80);
  6208. if( fd ) {
  6209. WFIFOHEAD(fd,packet_len(0x131));
  6210. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6211. WFIFOSET(fd,packet_len(0x131));
  6212. } else {
  6213. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6214. }
  6215. }
  6216. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6217. /// 0132 <owner id>.L
  6218. void clif_closevendingboard(struct block_list* bl, int fd)
  6219. {
  6220. unsigned char buf[16];
  6221. nullpo_retv(bl);
  6222. WBUFW(buf,0) = 0x132;
  6223. WBUFL(buf,2) = bl->id;
  6224. if( fd ) {
  6225. WFIFOHEAD(fd,packet_len(0x132));
  6226. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6227. WFIFOSET(fd,packet_len(0x132));
  6228. } else {
  6229. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6230. }
  6231. }
  6232. /// Sends a list of items in a shop.
  6233. /// 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)
  6234. /// 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)
  6235. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6236. nullpo_retv( sd );
  6237. nullpo_retv( vsd );
  6238. nullpo_retv( vsd->vending );
  6239. int fd = sd->fd;
  6240. if( !session_isActive( fd ) ){
  6241. return;
  6242. }
  6243. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6244. WFIFOHEAD( fd, len );
  6245. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6246. p->packetType = vendinglistType;
  6247. p->packetLength = len;
  6248. p->AID = vsd->status.account_id;
  6249. #if PACKETVER >= 20100105
  6250. p->venderId = vsd->vender_id;
  6251. #endif
  6252. for( int i = 0; i < vsd->vend_num; i++ ){
  6253. int index = vsd->vending[i].index;
  6254. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6255. p->items[i].price = vsd->vending[i].value;
  6256. p->items[i].amount = vsd->vending[i].amount;
  6257. p->items[i].index = client_index( index );
  6258. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6259. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6260. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6261. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6262. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6263. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6264. #if PACKETVER >= 20150226
  6265. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6266. #if PACKETVER >= 20160921
  6267. p->items[i].location = pc_equippoint_sub( sd, data );
  6268. p->items[i].viewSprite = data->look;
  6269. #endif
  6270. #endif
  6271. }
  6272. WFIFOSET( fd, len );
  6273. }
  6274. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6275. /// 0135 <index>.W <amount>.W <result>.B
  6276. /// result:
  6277. /// 0 = success
  6278. /// 1 = not enough zeny
  6279. /// 2 = overweight
  6280. /// 4 = out of stock
  6281. /// 5 = "cannot use an npc shop while in a trade"
  6282. /// 6 = Because the store information was incorrect the item was not purchased.
  6283. /// 7 = No sales information.
  6284. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6285. {
  6286. int fd;
  6287. nullpo_retv(sd);
  6288. fd = sd->fd;
  6289. WFIFOHEAD(fd,packet_len(0x135));
  6290. WFIFOW(fd,0) = 0x135;
  6291. WFIFOW(fd,2) = index+2;
  6292. WFIFOW(fd,4) = amount;
  6293. WFIFOB(fd,6) = fail;
  6294. WFIFOSET(fd,packet_len(0x135));
  6295. }
  6296. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6297. /// 0a28 <Result>.B
  6298. /// result:
  6299. /// 0 = Successed
  6300. /// 1 = Failed
  6301. void clif_openvending_ack(struct map_session_data* sd, int result)
  6302. {
  6303. int fd;
  6304. nullpo_retv(sd);
  6305. fd = sd->fd;
  6306. WFIFOHEAD(fd, 3);
  6307. WFIFOW(fd,0) = 0xa28;
  6308. WFIFOB(fd,2) = result;
  6309. WFIFOSET(fd, 3);
  6310. }
  6311. /// Shop creation success.
  6312. /// 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)
  6313. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6314. nullpo_retv( sd );
  6315. nullpo_retv( vending );
  6316. int fd = sd->fd;
  6317. if( !session_isActive( fd ) ){
  6318. return;
  6319. }
  6320. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6321. WFIFOHEAD( fd, len );
  6322. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6323. p->packetType = 0x136;
  6324. p->packetLength = len;
  6325. p->AID = id;
  6326. for( int i = 0; i < sd->vend_num; i++ ) {
  6327. int index = vending[i].index;
  6328. p->items[i].price = vending[i].value;
  6329. p->items[i].index = client_index( index );
  6330. p->items[i].amount = vending[i].amount;
  6331. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6332. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6333. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6334. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6335. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6336. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6337. #if PACKETVER >= 20150226
  6338. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6339. #endif
  6340. }
  6341. WFIFOSET( fd, len );
  6342. #if PACKETVER >= 20141022
  6343. /// 0 = Successed
  6344. /// 1 = Failed
  6345. clif_openvending_ack( sd, 0 );
  6346. #endif
  6347. }
  6348. /// Inform merchant that someone has bought an item.
  6349. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6350. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6351. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6352. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6353. const int cmd = 0x137;
  6354. #else
  6355. const int cmd = 0x9e5;
  6356. #endif
  6357. int fd = sd->fd;
  6358. nullpo_retv(sd);
  6359. WFIFOHEAD(fd,packet_len(cmd));
  6360. WFIFOW(fd,0) = cmd;
  6361. WFIFOW(fd,2) = index+2;
  6362. WFIFOW(fd,4) = amount;
  6363. #if PACKETVER >= 20141016
  6364. WFIFOL(fd,6) = char_id; // GID
  6365. WFIFOL(fd,10) = (int)time(NULL); // Date
  6366. WFIFOL(fd,14) = zeny; // zeny
  6367. #endif
  6368. WFIFOSET(fd,packet_len(cmd));
  6369. }
  6370. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6371. /// 00fa <result>.B
  6372. /// result:
  6373. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6374. /// 1 = MsgStringTable[78]="party name already exists"
  6375. /// 2 = MsgStringTable[79]="already in a party"
  6376. /// 3 = cannot organize parties on this map
  6377. /// ? = nothing
  6378. void clif_party_created(struct map_session_data *sd,int result)
  6379. {
  6380. int fd;
  6381. nullpo_retv(sd);
  6382. fd=sd->fd;
  6383. WFIFOHEAD(fd,packet_len(0xfa));
  6384. WFIFOW(fd,0)=0xfa;
  6385. WFIFOB(fd,2)=result;
  6386. WFIFOSET(fd,packet_len(0xfa));
  6387. }
  6388. /// Adds new member to a party.
  6389. /// 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)
  6390. /// 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)
  6391. /// 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)
  6392. /// role:
  6393. /// 0 = leader
  6394. /// 1 = normal
  6395. /// state:
  6396. /// 0 = connected
  6397. /// 1 = disconnected
  6398. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6399. {
  6400. int i;
  6401. #if PACKETVER < 20170502
  6402. unsigned char buf[81];
  6403. int cmd = 0x1e9;
  6404. int offset = 0;
  6405. #else
  6406. unsigned char buf[85];
  6407. int cmd = 0xa43;
  6408. int offset = 4;
  6409. #endif
  6410. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6411. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6412. } else {
  6413. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6414. }
  6415. if (i >= MAX_PARTY) return; //Should never happen...
  6416. sd = p->data[i].sd;
  6417. WBUFW(buf, 0) = cmd;
  6418. WBUFL(buf, 2) = sd->status.account_id;
  6419. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6420. #if PACKETVER >= 20170502
  6421. WBUFW(buf,10) = sd->status.class_;
  6422. WBUFW(buf,12) = sd->status.base_level;
  6423. #endif
  6424. WBUFW(buf,offset+10) = sd->bl.x;
  6425. WBUFW(buf,offset+12) = sd->bl.y;
  6426. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6427. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6428. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6429. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6430. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6431. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6432. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6433. }
  6434. /// Sends party information (ZC_GROUP_LIST).
  6435. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6436. /// role:
  6437. /// 0 = leader
  6438. /// 1 = normal
  6439. /// state:
  6440. /// 0 = connected
  6441. /// 1 = disconnected
  6442. /// 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
  6443. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6444. {
  6445. struct map_session_data* party_sd = NULL;
  6446. int i, c;
  6447. #if PACKETVER < 20170502
  6448. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6449. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6450. int cmd = 0xfb;
  6451. #else
  6452. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6453. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6454. int cmd = 0xa44;
  6455. #endif
  6456. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6457. nullpo_retv(p);
  6458. WBUFW(buf,0) = cmd;
  6459. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6460. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6461. {
  6462. struct party_member* m = &p->party.member[i];
  6463. if(!m->account_id) continue;
  6464. if(party_sd == NULL) party_sd = p->data[i].sd;
  6465. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6466. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6467. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6468. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6469. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6470. #if PACKETVER >= 20170502
  6471. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6472. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6473. #endif
  6474. c++;
  6475. }
  6476. #if PACKETVER < 20170502
  6477. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6478. #else
  6479. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6480. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6481. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6482. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6483. #endif
  6484. if(sd) { // send only to self
  6485. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6486. } else if (party_sd) { // send to whole party
  6487. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6488. }
  6489. }
  6490. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6491. /// 02c9 <flag>.B
  6492. /// flag:
  6493. /// 0 = allow party invites
  6494. /// 1 = auto-deny party invites
  6495. void clif_partyinvitationstate(struct map_session_data* sd)
  6496. {
  6497. int fd;
  6498. nullpo_retv(sd);
  6499. fd = sd->fd;
  6500. WFIFOHEAD(fd, packet_len(0x2c9));
  6501. WFIFOW(fd, 0) = 0x2c9;
  6502. WFIFOB(fd, 2) = 0; // not implemented
  6503. WFIFOSET(fd, packet_len(0x2c9));
  6504. }
  6505. /// Party invitation request.
  6506. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6507. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6508. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6509. {
  6510. #if PACKETVER < 20070821
  6511. const int cmd = 0xfe;
  6512. #else
  6513. const int cmd = 0x2c6;
  6514. #endif
  6515. int fd;
  6516. struct party_data *p;
  6517. nullpo_retv(sd);
  6518. nullpo_retv(tsd);
  6519. fd=tsd->fd;
  6520. if( (p=party_search(sd->status.party_id))==NULL )
  6521. return;
  6522. WFIFOHEAD(fd,packet_len(cmd));
  6523. WFIFOW(fd,0)=cmd;
  6524. WFIFOL(fd,2)=sd->status.party_id;
  6525. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6526. WFIFOSET(fd,packet_len(cmd));
  6527. }
  6528. /// Party invite result.
  6529. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6530. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6531. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6532. {
  6533. int fd;
  6534. nullpo_retv(sd);
  6535. fd=sd->fd;
  6536. #if PACKETVER < 20070904
  6537. if( reply == PARTY_REPLY_OFFLINE ) {
  6538. clif_displaymessage(fd, msg_txt(sd,3));
  6539. return;
  6540. }
  6541. #endif
  6542. #if PACKETVER < 20070821
  6543. WFIFOHEAD(fd,packet_len(0xfd));
  6544. WFIFOW(fd,0) = 0xfd;
  6545. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6546. WFIFOB(fd,26) = reply;
  6547. WFIFOSET(fd,packet_len(0xfd));
  6548. #else
  6549. WFIFOHEAD(fd,packet_len(0x2c5));
  6550. WFIFOW(fd,0) = 0x2c5;
  6551. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6552. WFIFOL(fd,26) = reply;
  6553. WFIFOSET(fd,packet_len(0x2c5));
  6554. #endif
  6555. }
  6556. /// Updates party settings.
  6557. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6558. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6559. /// exp option:
  6560. /// 0 = exp sharing disabled
  6561. /// 1 = exp sharing enabled
  6562. /// 2 = cannot change exp sharing
  6563. ///
  6564. /// flag:
  6565. /// 0 = send to party
  6566. /// 1 = send to sd
  6567. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6568. {
  6569. unsigned char buf[16];
  6570. #if PACKETVER < 20090603
  6571. const int cmd = 0x101;
  6572. #else
  6573. const int cmd = 0x7d8;
  6574. #endif
  6575. nullpo_retv(p);
  6576. if(!sd && flag==0){
  6577. int i;
  6578. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6579. if (i < MAX_PARTY)
  6580. sd = p->data[i].sd;
  6581. }
  6582. if(!sd) return;
  6583. WBUFW(buf,0)=cmd;
  6584. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6585. #if PACKETVER >= 20090603
  6586. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6587. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6588. #endif
  6589. if(flag==0)
  6590. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6591. else
  6592. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6593. }
  6594. /**
  6595. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6596. * @param sd Send the notification for this player
  6597. * @param account_id Account ID of kicked member
  6598. * @param name Name of kicked member
  6599. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6600. * @param target Send target
  6601. **/
  6602. 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) {
  6603. unsigned char buf[2+4+NAME_LENGTH+1];
  6604. if (!sd)
  6605. return;
  6606. WBUFW(buf,0) = 0x0105;
  6607. WBUFL(buf,2) = account_id;
  6608. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6609. WBUFB(buf,6+NAME_LENGTH) = result;
  6610. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6611. }
  6612. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6613. /// 0109 <packet len>.W <account id>.L <message>.?B
  6614. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6615. {
  6616. struct map_session_data *sd;
  6617. int i;
  6618. nullpo_retv(p);
  6619. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6620. if(i < MAX_PARTY){
  6621. unsigned char buf[1024];
  6622. if( len > sizeof(buf)-8 )
  6623. {
  6624. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6625. len = sizeof(buf)-8;
  6626. }
  6627. sd = p->data[i].sd;
  6628. WBUFW(buf,0)=0x109;
  6629. WBUFW(buf,2)=len+8;
  6630. WBUFL(buf,4)=account_id;
  6631. safestrncpy(WBUFCP(buf,8), mes, len);
  6632. clif_send(buf,len+8,&sd->bl,PARTY);
  6633. }
  6634. }
  6635. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6636. /// 0107 <account id>.L <x>.W <y>.W
  6637. void clif_party_xy(struct map_session_data *sd)
  6638. {
  6639. unsigned char buf[16];
  6640. nullpo_retv(sd);
  6641. WBUFW(buf,0)=0x107;
  6642. WBUFL(buf,2)=sd->status.account_id;
  6643. WBUFW(buf,6)=sd->bl.x;
  6644. WBUFW(buf,8)=sd->bl.y;
  6645. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6646. }
  6647. /*==========================================
  6648. * Sends x/y dot to a single fd. [Skotlex]
  6649. *------------------------------------------*/
  6650. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6651. {
  6652. WFIFOHEAD(fd,packet_len(0x107));
  6653. WFIFOW(fd,0)=0x107;
  6654. WFIFOL(fd,2)=sd->status.account_id;
  6655. WFIFOW(fd,6)=sd->bl.x;
  6656. WFIFOW(fd,8)=sd->bl.y;
  6657. WFIFOSET(fd,packet_len(0x107));
  6658. }
  6659. /// Updates HP bar of a party member.
  6660. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6661. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6662. void clif_party_hp(struct map_session_data *sd)
  6663. {
  6664. unsigned char buf[16];
  6665. #if PACKETVER < 20100126
  6666. const int cmd = 0x106;
  6667. #else
  6668. const int cmd = 0x80e;
  6669. #endif
  6670. nullpo_retv(sd);
  6671. WBUFW(buf,0)=cmd;
  6672. WBUFL(buf,2)=sd->status.account_id;
  6673. #if PACKETVER < 20100126
  6674. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6675. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6676. WBUFW(buf,8) = 100;
  6677. } else {
  6678. WBUFW(buf,6) = sd->battle_status.hp;
  6679. WBUFW(buf,8) = sd->battle_status.max_hp;
  6680. }
  6681. #else
  6682. WBUFL(buf,6) = sd->battle_status.hp;
  6683. WBUFL(buf,10) = sd->battle_status.max_hp;
  6684. #endif
  6685. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6686. }
  6687. /// Notifies the party members of a character's death or revival.
  6688. /// 0AB2 <GID>.L <dead>.B
  6689. void clif_party_dead( struct map_session_data *sd ){
  6690. #if PACKETVER >= 20170502
  6691. unsigned char buf[7];
  6692. nullpo_retv(sd);
  6693. WBUFW(buf, 0) = 0xab2;
  6694. WBUFL(buf, 2) = sd->status.account_id;
  6695. WBUFB(buf, 6) = pc_isdead(sd);
  6696. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6697. #endif
  6698. }
  6699. /// Updates the job and level of a party member
  6700. /// 0abd <account id>.L <job>.W <level>.W
  6701. void clif_party_job_and_level(struct map_session_data *sd){
  6702. #if PACKETVER >= 20170502
  6703. unsigned char buf[10];
  6704. nullpo_retv(sd);
  6705. WBUFW(buf, 0) = 0xabd;
  6706. WBUFL(buf, 2) = sd->status.account_id;
  6707. WBUFW(buf, 6) = sd->status.class_;
  6708. WBUFW(buf, 8) = sd->status.base_level;
  6709. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6710. #endif
  6711. }
  6712. /*==========================================
  6713. * Sends HP bar to a single fd. [Skotlex]
  6714. *------------------------------------------*/
  6715. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6716. {
  6717. #if PACKETVER < 20100126
  6718. const int cmd = 0x106;
  6719. #else
  6720. const int cmd = 0x80e;
  6721. #endif
  6722. WFIFOHEAD(fd,packet_len(cmd));
  6723. WFIFOW(fd,0) = cmd;
  6724. WFIFOL(fd,2) = id;
  6725. #if PACKETVER < 20100126
  6726. if( maxhp > INT16_MAX )
  6727. {// To correctly display the %hp bar. [Skotlex]
  6728. WFIFOW(fd,6) = hp/(maxhp/100);
  6729. WFIFOW(fd,8) = 100;
  6730. } else {
  6731. WFIFOW(fd,6) = hp;
  6732. WFIFOW(fd,8) = maxhp;
  6733. }
  6734. #else
  6735. WFIFOL(fd,6) = hp;
  6736. WFIFOL(fd,10) = maxhp;
  6737. #endif
  6738. WFIFOSET(fd, packet_len(cmd));
  6739. }
  6740. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6741. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6742. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6743. {
  6744. int fd;
  6745. nullpo_retv(sd);
  6746. nullpo_retv(bl);
  6747. fd=sd->fd;
  6748. WFIFOHEAD(fd,packet_len(0x139));
  6749. WFIFOW(fd, 0)=0x139;
  6750. WFIFOL(fd, 2)=bl->id;
  6751. WFIFOW(fd, 6)=bl->x;
  6752. WFIFOW(fd, 8)=bl->y;
  6753. WFIFOW(fd,10)=sd->bl.x;
  6754. WFIFOW(fd,12)=sd->bl.y;
  6755. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6756. WFIFOSET(fd,packet_len(0x139));
  6757. }
  6758. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6759. /// 018f <result>.W <name id>.W
  6760. /// result:
  6761. /// 0 = success
  6762. /// 1 = failure
  6763. /// 2 = success (alchemist)
  6764. /// 3 = failure (alchemist)
  6765. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid){
  6766. nullpo_retv( sd );
  6767. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6768. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6769. p.packetType = 0x18f;
  6770. p.result = flag;
  6771. p.itemId = client_nameid( nameid );
  6772. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6773. }
  6774. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6775. /// 019e
  6776. void clif_catch_process(struct map_session_data *sd)
  6777. {
  6778. int fd;
  6779. nullpo_retv(sd);
  6780. fd=sd->fd;
  6781. WFIFOHEAD(fd,packet_len(0x19e));
  6782. WFIFOW(fd,0)=0x19e;
  6783. WFIFOSET(fd,packet_len(0x19e));
  6784. }
  6785. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6786. /// 01a0 <result>.B
  6787. /// 0 = failure
  6788. /// 1 = success
  6789. void clif_pet_roulette(struct map_session_data *sd,int data)
  6790. {
  6791. int fd;
  6792. nullpo_retv(sd);
  6793. fd=sd->fd;
  6794. WFIFOHEAD(fd,packet_len(0x1a0));
  6795. WFIFOW(fd,0)=0x1a0;
  6796. WFIFOB(fd,2)=data;
  6797. WFIFOSET(fd,packet_len(0x1a0));
  6798. }
  6799. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6800. /// 01a6 <packet len>.W { <index>.W }*
  6801. void clif_sendegg(struct map_session_data *sd)
  6802. {
  6803. int i,n=0,fd;
  6804. nullpo_retv(sd);
  6805. fd=sd->fd;
  6806. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6807. clif_displaymessage(fd, msg_txt(sd,666));
  6808. return;
  6809. }
  6810. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6811. WFIFOW(fd,0)=0x1a6;
  6812. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6813. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6814. sd->inventory_data[i]->type != IT_PETEGG ||
  6815. sd->inventory.u.items_inventory[i].amount <= 0)
  6816. continue;
  6817. WFIFOW(fd,n*2+4)=i+2;
  6818. n++;
  6819. }
  6820. WFIFOW(fd,2)=4+n*2;
  6821. WFIFOSET(fd,WFIFOW(fd,2));
  6822. sd->menuskill_id = SA_TAMINGMONSTER;
  6823. sd->menuskill_val = -1;
  6824. }
  6825. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6826. /// 01a4 <type>.B <id>.L <data>.L
  6827. /// type:
  6828. /// 0 = pre-init (data = 0)
  6829. /// 1 = intimacy (data = 0~4)
  6830. /// 2 = hunger (data = 0~4)
  6831. /// 3 = accessory
  6832. /// 4 = performance (data = 1~3: normal, 4: special)
  6833. /// 5 = hairstyle
  6834. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6835. ///
  6836. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6837. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6838. {
  6839. uint8 buf[16];
  6840. nullpo_retv(pd);
  6841. WBUFW(buf,0) = 0x1a4;
  6842. WBUFB(buf,2) = type;
  6843. WBUFL(buf,3) = pd->bl.id;
  6844. WBUFL(buf,7) = param;
  6845. if (sd)
  6846. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6847. else
  6848. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6849. }
  6850. /// Pet's base data (ZC_PROPERTY_PET).
  6851. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6852. void clif_send_petstatus(struct map_session_data *sd)
  6853. {
  6854. int fd;
  6855. struct s_pet *pet;
  6856. nullpo_retv(sd);
  6857. nullpo_retv(sd->pd);
  6858. fd=sd->fd;
  6859. pet = &sd->pd->pet;
  6860. WFIFOHEAD(fd,packet_len(0x1a2));
  6861. WFIFOW(fd,0)=0x1a2;
  6862. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6863. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6864. WFIFOW(fd,27)=pet->level;
  6865. WFIFOW(fd,29)=pet->hungry;
  6866. WFIFOW(fd,31)=pet->intimate;
  6867. WFIFOW(fd,33)=pet->equip;
  6868. #if PACKETVER >= 20081126
  6869. WFIFOW(fd,35)=pet->class_;
  6870. #endif
  6871. WFIFOSET(fd,packet_len(0x1a2));
  6872. }
  6873. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6874. /// 01aa <id>.L <data>.L
  6875. /// data:
  6876. /// @see CZ_PET_ACT.
  6877. void clif_pet_emotion(struct pet_data *pd,int param)
  6878. {
  6879. unsigned char buf[16];
  6880. nullpo_retv(pd);
  6881. memset(buf,0,packet_len(0x1aa));
  6882. WBUFW(buf,0)=0x1aa;
  6883. WBUFL(buf,2)=pd->bl.id;
  6884. WBUFL(buf,6)=param;
  6885. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6886. }
  6887. /// Result of request to feed a pet (ZC_FEED_PET).
  6888. /// 01a3 <result>.B <name id>.W
  6889. /// result:
  6890. /// 0 = failure
  6891. /// 1 = success
  6892. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  6893. nullpo_retv( sd );
  6894. struct PACKET_ZC_FEED_PET p;
  6895. p.packetType = 0x1a3;
  6896. p.result = fail;
  6897. p.itemId = client_nameid( foodid );
  6898. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6899. }
  6900. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6901. /// 01cd { <skill id>.L }*7
  6902. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6903. {
  6904. nullpo_retv(sd);
  6905. int fd = sd->fd;
  6906. #ifdef RENEWAL
  6907. uint16 autospell_skill[][2] = {
  6908. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  6909. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  6910. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  6911. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  6912. };
  6913. int count = 0;
  6914. WFIFOHEAD(fd, 2 * 6 + 4);
  6915. WFIFOW(fd, 0) = 0x442;
  6916. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  6917. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  6918. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  6919. count++;
  6920. }
  6921. }
  6922. WFIFOW(fd, 2) = 8 + count * 2;
  6923. WFIFOL(fd, 4) = count;
  6924. WFIFOSET(fd, WFIFOW(fd, 2));
  6925. #else
  6926. WFIFOHEAD(fd,packet_len(0x1cd));
  6927. WFIFOW(fd, 0)=0x1cd;
  6928. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6929. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6930. else
  6931. WFIFOL(fd,2)= 0x00000000;
  6932. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6933. WFIFOL(fd,6)= MG_COLDBOLT;
  6934. else
  6935. WFIFOL(fd,6)= 0x00000000;
  6936. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6937. WFIFOL(fd,10)= MG_FIREBOLT;
  6938. else
  6939. WFIFOL(fd,10)= 0x00000000;
  6940. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6941. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6942. else
  6943. WFIFOL(fd,14)= 0x00000000;
  6944. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6945. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6946. else
  6947. WFIFOL(fd,18)= 0x00000000;
  6948. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6949. WFIFOL(fd,22)= MG_FIREBALL;
  6950. else
  6951. WFIFOL(fd,22)= 0x00000000;
  6952. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6953. WFIFOL(fd,26)= MG_FROSTDIVER;
  6954. else
  6955. WFIFOL(fd,26)= 0x00000000;
  6956. WFIFOSET(fd,packet_len(0x1cd));
  6957. #endif
  6958. sd->menuskill_id = SA_AUTOSPELL;
  6959. sd->menuskill_val = skill_lv;
  6960. }
  6961. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6962. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6963. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6964. {
  6965. unsigned char buf[56];
  6966. nullpo_retv(src);
  6967. memset(buf,0,packet_len(0x1cf));
  6968. WBUFW(buf,0) = 0x1cf;
  6969. WBUFL(buf,2) = src->id;
  6970. if( src->type == BL_MER )
  6971. {
  6972. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6973. if( md && md->master && md->devotion_flag )
  6974. WBUFL(buf,6) = md->master->bl.id;
  6975. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  6976. }
  6977. else
  6978. {
  6979. int i;
  6980. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6981. if( sd == NULL )
  6982. return;
  6983. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6984. WBUFL(buf,6+4*i) = sd->devotion[i];
  6985. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  6986. }
  6987. if( tsd )
  6988. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6989. else
  6990. clif_send(buf, packet_len(0x1cf), src, AREA);
  6991. }
  6992. /*==========================================
  6993. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6994. * Notifies clients in an area of an object's spirits.
  6995. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6996. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6997. *------------------------------------------*/
  6998. void clif_spiritball(struct block_list *bl) {
  6999. unsigned char buf[16];
  7000. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7001. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7002. nullpo_retv(bl);
  7003. WBUFW(buf, 0) = 0x1d0;
  7004. WBUFL(buf, 2) = bl->id;
  7005. WBUFW(buf, 6) = 0; //init to 0
  7006. switch(bl->type){
  7007. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7008. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7009. }
  7010. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7011. }
  7012. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7013. /// 01d2 <account id>.L <delay>.L
  7014. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7015. {
  7016. unsigned char buf[32];
  7017. nullpo_retv(bl);
  7018. WBUFW(buf,0)=0x1d2;
  7019. WBUFL(buf,2)=bl->id;
  7020. WBUFL(buf,6)=client_tick(wait);
  7021. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7022. }
  7023. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7024. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7025. /// flag:
  7026. /// 0 = inactive
  7027. /// 1 = active
  7028. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7029. {
  7030. unsigned char buf[32];
  7031. nullpo_retv(src);
  7032. WBUFW(buf,0)=0x1d1;
  7033. WBUFL(buf,2)=src->id;
  7034. WBUFL(buf,6)=dst_id;
  7035. WBUFL(buf,10)=active;
  7036. clif_send(buf,packet_len(0x1d1),src,AREA);
  7037. }
  7038. /// MVP effect (ZC_MVP).
  7039. /// 010c <account id>.L
  7040. void clif_mvp_effect(struct map_session_data *sd)
  7041. {
  7042. unsigned char buf[16];
  7043. nullpo_retv(sd);
  7044. WBUFW(buf,0)=0x10c;
  7045. WBUFL(buf,2)=sd->bl.id;
  7046. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7047. }
  7048. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7049. /// 010a <name id>.W
  7050. void clif_mvp_item( struct map_session_data *sd, unsigned short nameid ){
  7051. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7052. p.packetType = 0x10a;
  7053. p.itemId = client_nameid( nameid );
  7054. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7055. }
  7056. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7057. /// 010b <exp>.L
  7058. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7059. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7060. if (battle_config.mvp_exp_reward_message) {
  7061. char e_msg[CHAT_SIZE_MAX];
  7062. sprintf(e_msg, msg_txt(sd, 717), exp);
  7063. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7064. }
  7065. #else
  7066. int fd;
  7067. nullpo_retv(sd);
  7068. fd = sd->fd;
  7069. WFIFOHEAD(fd, packet_len(0x10b));
  7070. WFIFOW(fd,0) = 0x10b;
  7071. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7072. WFIFOSET(fd, packet_len(0x10b));
  7073. #endif
  7074. }
  7075. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7076. /// 010d
  7077. ///
  7078. /// "You are the MVP, but cannot obtain the reward because
  7079. /// you are overweight."
  7080. void clif_mvp_noitem(struct map_session_data* sd)
  7081. {
  7082. int fd = sd->fd;
  7083. WFIFOHEAD(fd,packet_len(0x10d));
  7084. WFIFOW(fd,0) = 0x10d;
  7085. WFIFOSET(fd,packet_len(0x10d));
  7086. }
  7087. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7088. /// 0167 <result>.B
  7089. /// result:
  7090. /// 0 = "Guild has been created."
  7091. /// 1 = "You are already in a Guild."
  7092. /// 2 = "That Guild Name already exists."
  7093. /// 3 = "You need the neccessary item to create a Guild."
  7094. void clif_guild_created(struct map_session_data *sd,int flag)
  7095. {
  7096. int fd;
  7097. nullpo_retv(sd);
  7098. fd=sd->fd;
  7099. WFIFOHEAD(fd,packet_len(0x167));
  7100. WFIFOW(fd,0)=0x167;
  7101. WFIFOB(fd,2)=flag;
  7102. WFIFOSET(fd,packet_len(0x167));
  7103. }
  7104. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7105. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7106. /// mode:
  7107. /// &0x01 = allow invite
  7108. /// &0x10 = allow expel
  7109. void clif_guild_belonginfo(struct map_session_data *sd)
  7110. {
  7111. int ps,fd;
  7112. struct guild* g;
  7113. nullpo_retv(sd);
  7114. nullpo_retv(g = sd->guild);
  7115. fd=sd->fd;
  7116. ps=guild_getposition(sd);
  7117. WFIFOHEAD(fd,packet_len(0x16c));
  7118. WFIFOW(fd,0)=0x16c;
  7119. WFIFOL(fd,2)=g->guild_id;
  7120. WFIFOL(fd,6)=g->emblem_id;
  7121. WFIFOL(fd,10)=g->position[ps].mode;
  7122. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7123. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7124. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7125. WFIFOSET(fd,packet_len(0x16c));
  7126. }
  7127. /// Guild member login notice.
  7128. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7129. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7130. /// status:
  7131. /// 0 = offline
  7132. /// 1 = online
  7133. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7134. {
  7135. unsigned char buf[64];
  7136. struct map_session_data* sd;
  7137. nullpo_retv(g);
  7138. WBUFW(buf, 0)=0x1f2;
  7139. WBUFL(buf, 2)=g->member[idx].account_id;
  7140. WBUFL(buf, 6)=g->member[idx].char_id;
  7141. WBUFL(buf,10)=flag;
  7142. if( ( sd = g->member[idx].sd ) != NULL )
  7143. {
  7144. WBUFW(buf,14) = sd->status.sex;
  7145. WBUFW(buf,16) = sd->status.hair;
  7146. WBUFW(buf,18) = sd->status.hair_color;
  7147. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7148. }
  7149. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7150. {
  7151. WBUFW(buf,14) = 0;
  7152. WBUFW(buf,16) = 0;
  7153. WBUFW(buf,18) = 0;
  7154. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7155. }
  7156. }
  7157. // Function `clif_guild_memberlogin_notice` sends info about
  7158. // logins and logouts of a guild member to the rest members.
  7159. // But at the 1st time (after a player login or map changing)
  7160. // the client won't show the message.
  7161. // So I suggest use this function for sending "first-time-info"
  7162. // to some player on entering the game or changing location.
  7163. // At next time the client would always show the message.
  7164. // The function sends all the statuses in the single packet
  7165. // to economize traffic. [LuzZza]
  7166. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7167. {
  7168. struct guild *g;
  7169. unsigned char buf[14*128];
  7170. int i, count=0, p_len;
  7171. nullpo_retv(sd);
  7172. p_len = packet_len(0x16d);
  7173. if(!(g = sd->guild))
  7174. return;
  7175. for(i=0; i<g->max_member; i++) {
  7176. if(g->member[i].account_id > 0 &&
  7177. g->member[i].account_id != sd->status.account_id) {
  7178. WBUFW(buf,count*p_len) = 0x16d;
  7179. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7180. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7181. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7182. count++;
  7183. }
  7184. }
  7185. clif_send(buf, p_len*count, &sd->bl, SELF);
  7186. }
  7187. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7188. /// 014e <menu flag>.L
  7189. /// menu flag:
  7190. /// 0x00 = Basic Info (always on)
  7191. /// &0x01 = Member manager
  7192. /// &0x02 = Positions
  7193. /// &0x04 = Skills
  7194. /// &0x10 = Expulsion list
  7195. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7196. /// &0x80 = Notice
  7197. void clif_guild_masterormember(struct map_session_data *sd)
  7198. {
  7199. int fd;
  7200. nullpo_retv(sd);
  7201. fd=sd->fd;
  7202. WFIFOHEAD(fd,packet_len(0x14e));
  7203. WFIFOW(fd,0) = 0x14e;
  7204. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7205. WFIFOSET(fd,packet_len(0x14e));
  7206. }
  7207. /// Guild basic information (Territories [Valaris])
  7208. /// 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)
  7209. /// 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)
  7210. /// 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)
  7211. void clif_guild_basicinfo(struct map_session_data *sd) {
  7212. int fd;
  7213. struct guild *g;
  7214. #if PACKETVER < 20160622
  7215. int cmd = 0x1b6;
  7216. int offset = NAME_LENGTH;
  7217. #else
  7218. int cmd = 0xa84;
  7219. int offset = 0;
  7220. #endif
  7221. nullpo_retv(sd);
  7222. fd = sd->fd;
  7223. if( (g = sd->guild) == NULL )
  7224. return;
  7225. WFIFOHEAD(fd,packet_len(cmd));
  7226. WFIFOW(fd, 0)=cmd;
  7227. WFIFOL(fd, 2)=g->guild_id;
  7228. WFIFOL(fd, 6)=g->guild_lv;
  7229. WFIFOL(fd,10)=g->connect_member;
  7230. WFIFOL(fd,14)=g->max_member;
  7231. WFIFOL(fd,18)=g->average_lv;
  7232. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7233. WFIFOL(fd,26)=g->next_exp;
  7234. WFIFOL(fd,30)=0; // Tax Points
  7235. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7236. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7237. WFIFOL(fd,42)=g->emblem_id;
  7238. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7239. #if PACKETVER < 20160622
  7240. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7241. #endif
  7242. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7243. WFIFOL(fd,70+offset+16) = 0; // zeny
  7244. #if PACKETVER >= 20160622
  7245. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7246. #endif
  7247. WFIFOSET(fd,packet_len(cmd));
  7248. }
  7249. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7250. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7251. void clif_guild_allianceinfo(struct map_session_data *sd)
  7252. {
  7253. int fd,i,c;
  7254. struct guild *g;
  7255. nullpo_retv(sd);
  7256. if( (g = sd->guild) == NULL )
  7257. return;
  7258. fd = sd->fd;
  7259. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7260. WFIFOW(fd, 0)=0x14c;
  7261. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7262. struct guild_alliance *a=&g->alliance[i];
  7263. if(a->guild_id>0){
  7264. WFIFOL(fd,c*32+4)=a->opposition;
  7265. WFIFOL(fd,c*32+8)=a->guild_id;
  7266. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7267. c++;
  7268. }
  7269. }
  7270. WFIFOW(fd, 2)=c*32+4;
  7271. WFIFOSET(fd,WFIFOW(fd,2));
  7272. }
  7273. /// Guild member manager information
  7274. /// 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)
  7275. /// state:
  7276. /// 0 = offline
  7277. /// 1 = online
  7278. /// memo:
  7279. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7280. /// 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)
  7281. void clif_guild_memberlist(struct map_session_data *sd)
  7282. {
  7283. int fd;
  7284. int i,c;
  7285. struct guild *g;
  7286. #if PACKETVER < 20161026
  7287. int cmd = 0x154;
  7288. int size = 104;
  7289. #else
  7290. int cmd = 0xaa5;
  7291. int size = 34;
  7292. #endif
  7293. nullpo_retv(sd);
  7294. if( (fd = sd->fd) == 0 )
  7295. return;
  7296. if( (g = sd->guild) == NULL )
  7297. return;
  7298. WFIFOHEAD(fd, g->max_member * size + 4);
  7299. WFIFOW(fd, 0)=cmd;
  7300. for(i=0,c=0;i<g->max_member;i++){
  7301. struct guild_member *m=&g->member[i];
  7302. if(m->account_id==0)
  7303. continue;
  7304. WFIFOL(fd,c*size+ 4)=m->account_id;
  7305. WFIFOL(fd,c*size+ 8)=m->char_id;
  7306. WFIFOW(fd,c*size+12)=m->hair;
  7307. WFIFOW(fd,c*size+14)=m->hair_color;
  7308. WFIFOW(fd,c*size+16)=m->gender;
  7309. WFIFOW(fd,c*size+18)=m->class_;
  7310. WFIFOW(fd,c*size+20)=m->lv;
  7311. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7312. WFIFOL(fd,c*size+26)=m->online;
  7313. WFIFOL(fd,c*size+30)=m->position;
  7314. #if PACKETVER < 20161026
  7315. 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.
  7316. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7317. #else
  7318. WFIFOL(fd,c*size+34)=m->last_login;
  7319. #endif
  7320. c++;
  7321. }
  7322. WFIFOW(fd, 2)=c*size+4;
  7323. WFIFOSET(fd,WFIFOW(fd,2));
  7324. }
  7325. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7326. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7327. void clif_guild_positionnamelist(struct map_session_data *sd)
  7328. {
  7329. int i,fd;
  7330. struct guild *g;
  7331. nullpo_retv(sd);
  7332. if( (g = sd->guild) == NULL )
  7333. return;
  7334. fd = sd->fd;
  7335. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7336. WFIFOW(fd, 0)=0x166;
  7337. for(i=0;i<MAX_GUILDPOSITION;i++){
  7338. WFIFOL(fd,i*28+4)=i;
  7339. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7340. }
  7341. WFIFOW(fd,2)=i*28+4;
  7342. WFIFOSET(fd,WFIFOW(fd,2));
  7343. }
  7344. /// Guild position information (ZC_POSITION_INFO).
  7345. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7346. /// mode:
  7347. /// &0x01 = allow invite
  7348. /// &0x10 = allow expel
  7349. /// ranking:
  7350. /// TODO
  7351. void clif_guild_positioninfolist(struct map_session_data *sd)
  7352. {
  7353. int i,fd;
  7354. struct guild *g;
  7355. nullpo_retv(sd);
  7356. if( (g = sd->guild) == NULL )
  7357. return;
  7358. fd = sd->fd;
  7359. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7360. WFIFOW(fd, 0)=0x160;
  7361. for(i=0;i<MAX_GUILDPOSITION;i++){
  7362. struct guild_position *p=&g->position[i];
  7363. WFIFOL(fd,i*16+ 4)=i;
  7364. WFIFOL(fd,i*16+ 8)=p->mode;
  7365. WFIFOL(fd,i*16+12)=i;
  7366. WFIFOL(fd,i*16+16)=p->exp_mode;
  7367. }
  7368. WFIFOW(fd, 2)=i*16+4;
  7369. WFIFOSET(fd,WFIFOW(fd,2));
  7370. }
  7371. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7372. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7373. /// mode:
  7374. /// &0x01 = allow invite
  7375. /// &0x10 = allow expel
  7376. /// ranking:
  7377. /// TODO
  7378. void clif_guild_positionchanged(struct guild *g,int idx)
  7379. {
  7380. // FIXME: This packet is intended to update the clients after a
  7381. // commit of position info changes, not sending one packet per
  7382. // position.
  7383. struct map_session_data *sd;
  7384. unsigned char buf[128];
  7385. nullpo_retv(g);
  7386. WBUFW(buf, 0)=0x174;
  7387. WBUFW(buf, 2)=44; // packet len
  7388. // GUILD_REG_POSITION_INFO{
  7389. WBUFL(buf, 4)=idx;
  7390. WBUFL(buf, 8)=g->position[idx].mode;
  7391. WBUFL(buf,12)=idx;
  7392. WBUFL(buf,16)=g->position[idx].exp_mode;
  7393. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7394. // }*
  7395. if( (sd=guild_getavailablesd(g))!=NULL )
  7396. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7397. }
  7398. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7399. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7400. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7401. {
  7402. // FIXME: This packet is intended to update the clients after a
  7403. // commit of member position assignment changes, not sending one
  7404. // packet per position.
  7405. struct map_session_data *sd;
  7406. unsigned char buf[64];
  7407. nullpo_retv(g);
  7408. WBUFW(buf, 0)=0x156;
  7409. WBUFW(buf, 2)=16; // packet len
  7410. // MEMBER_POSITION_INFO{
  7411. WBUFL(buf, 4)=g->member[idx].account_id;
  7412. WBUFL(buf, 8)=g->member[idx].char_id;
  7413. WBUFL(buf,12)=g->member[idx].position;
  7414. // }*
  7415. if( (sd=guild_getavailablesd(g))!=NULL )
  7416. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7417. }
  7418. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7419. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7420. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7421. {
  7422. int fd;
  7423. nullpo_retv(sd);
  7424. nullpo_retv(g);
  7425. fd = sd->fd;
  7426. if( g->emblem_len <= 0 )
  7427. return;
  7428. WFIFOHEAD(fd,g->emblem_len+12);
  7429. WFIFOW(fd,0)=0x152;
  7430. WFIFOW(fd,2)=g->emblem_len+12;
  7431. WFIFOL(fd,4)=g->guild_id;
  7432. WFIFOL(fd,8)=g->emblem_id;
  7433. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7434. WFIFOSET(fd,WFIFOW(fd,2));
  7435. }
  7436. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7437. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7438. void clif_guild_emblem_area(struct block_list* bl)
  7439. {
  7440. uint8 buf[12];
  7441. nullpo_retv(bl);
  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. WBUFW(buf,0) = 0x1b4;
  7445. WBUFL(buf,2) = bl->id;
  7446. WBUFL(buf,6) = status_get_guild_id(bl);
  7447. WBUFW(buf,10) = status_get_emblem_id(bl);
  7448. clif_send(buf, 12, bl, AREA_WOS);
  7449. }
  7450. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7451. /// 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 }*
  7452. void clif_guild_skillinfo(struct map_session_data* sd)
  7453. {
  7454. int fd;
  7455. struct guild* g;
  7456. int i,c;
  7457. nullpo_retv(sd);
  7458. if( (g = sd->guild) == NULL )
  7459. return;
  7460. fd = sd->fd;
  7461. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7462. WFIFOW(fd,0) = 0x0162;
  7463. WFIFOW(fd,4) = g->skill_point;
  7464. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7465. {
  7466. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7467. {
  7468. int id = g->skill[i].id;
  7469. int p = 6 + c*37;
  7470. WFIFOW(fd,p+0) = id;
  7471. WFIFOL(fd,p+2) = skill_get_inf(id);
  7472. WFIFOW(fd,p+6) = g->skill[i].lv;
  7473. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7474. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7475. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7476. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7477. c++;
  7478. }
  7479. }
  7480. WFIFOW(fd,2) = 6 + c*37;
  7481. WFIFOSET(fd,WFIFOW(fd,2));
  7482. }
  7483. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7484. /// 016f <subject>.60B <notice>.120B
  7485. void clif_guild_notice(struct map_session_data* sd)
  7486. {
  7487. int fd;
  7488. struct guild* g;
  7489. nullpo_retv(sd);
  7490. nullpo_retv(g = sd->guild);
  7491. fd = sd->fd;
  7492. if ( !session_isActive(fd) )
  7493. return;
  7494. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7495. return;
  7496. WFIFOHEAD(fd,packet_len(0x16f));
  7497. WFIFOW(fd,0) = 0x16f;
  7498. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7499. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7500. WFIFOSET(fd,packet_len(0x16f));
  7501. }
  7502. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7503. /// 016a <guild id>.L <guild name>.24B
  7504. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7505. {
  7506. int fd;
  7507. nullpo_retv(sd);
  7508. nullpo_retv(g);
  7509. fd=sd->fd;
  7510. WFIFOHEAD(fd,packet_len(0x16a));
  7511. WFIFOW(fd,0)=0x16a;
  7512. WFIFOL(fd,2)=g->guild_id;
  7513. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7514. WFIFOSET(fd,packet_len(0x16a));
  7515. }
  7516. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7517. /// 0169 <answer>.B
  7518. /// answer:
  7519. /// 0 = Already in guild.
  7520. /// 1 = Offer rejected.
  7521. /// 2 = Offer accepted.
  7522. /// 3 = Guild full.
  7523. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7524. {
  7525. int fd;
  7526. nullpo_retv(sd);
  7527. fd=sd->fd;
  7528. WFIFOHEAD(fd,packet_len(0x169));
  7529. WFIFOW(fd,0)=0x169;
  7530. WFIFOB(fd,2)=flag;
  7531. WFIFOSET(fd,packet_len(0x169));
  7532. }
  7533. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7534. /// 015a <char name>.24B <reason>.40B
  7535. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7536. {
  7537. unsigned char buf[128];
  7538. nullpo_retv(sd);
  7539. WBUFW(buf, 0)=0x15a;
  7540. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7541. memcpy(WBUFP(buf,26),mes,40);
  7542. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7543. }
  7544. /// Notifies clients of a guild of an expelled member.
  7545. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7546. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7547. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7548. {
  7549. unsigned char buf[128];
  7550. #if PACKETVER < 20100803
  7551. const unsigned short cmd = 0x15c;
  7552. #else
  7553. const unsigned short cmd = 0x839;
  7554. #endif
  7555. nullpo_retv(sd);
  7556. WBUFW(buf,0) = cmd;
  7557. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7558. safestrncpy(WBUFCP(buf,26), mes, 40);
  7559. #if PACKETVER < 20100803
  7560. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7561. #endif
  7562. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7563. }
  7564. /// Guild expulsion list (ZC_BAN_LIST).
  7565. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7566. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7567. void clif_guild_expulsionlist(struct map_session_data* sd)
  7568. {
  7569. #if PACKETVER < 20100803
  7570. const int offset = NAME_LENGTH*2+40;
  7571. #else
  7572. const int offset = NAME_LENGTH+40;
  7573. #endif
  7574. int fd, i, c = 0;
  7575. struct guild* g;
  7576. nullpo_retv(sd);
  7577. if( (g = sd->guild) == NULL )
  7578. return;
  7579. fd = sd->fd;
  7580. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7581. WFIFOW(fd,0) = 0x163;
  7582. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7583. {
  7584. struct guild_expulsion* e = &g->expulsion[i];
  7585. if( e->account_id > 0 )
  7586. {
  7587. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7588. #if PACKETVER < 20100803
  7589. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7590. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7591. #else
  7592. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7593. #endif
  7594. c++;
  7595. }
  7596. }
  7597. WFIFOW(fd,2) = 4 + c*offset;
  7598. WFIFOSET(fd,WFIFOW(fd,2));
  7599. }
  7600. /// Guild chat message (ZC_GUILD_CHAT).
  7601. /// 017f <packet len>.W <message>.?B
  7602. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7603. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7604. struct map_session_data *sd;
  7605. uint8 buf[256];
  7606. if( len == 0 )
  7607. {
  7608. return;
  7609. }
  7610. else if( len > sizeof(buf)-5 )
  7611. {
  7612. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7613. len = sizeof(buf)-5;
  7614. }
  7615. WBUFW(buf, 0) = 0x17f;
  7616. WBUFW(buf, 2) = len + 5;
  7617. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7618. if ((sd = guild_getavailablesd(g)) != NULL)
  7619. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7620. }
  7621. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7622. /// 0171 <inviter account id>.L <guild name>.24B
  7623. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7624. {
  7625. int fd;
  7626. nullpo_retv(sd);
  7627. fd=sd->fd;
  7628. WFIFOHEAD(fd,packet_len(0x171));
  7629. WFIFOW(fd,0)=0x171;
  7630. WFIFOL(fd,2)=account_id;
  7631. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7632. WFIFOSET(fd,packet_len(0x171));
  7633. }
  7634. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7635. /// 0173 <answer>.B
  7636. /// answer:
  7637. /// 0 = Already allied.
  7638. /// 1 = You rejected the offer.
  7639. /// 2 = You accepted the offer.
  7640. /// 3 = They have too any alliances.
  7641. /// 4 = You have too many alliances.
  7642. /// 5 = Alliances are disabled.
  7643. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7644. {
  7645. int fd;
  7646. nullpo_retv(sd);
  7647. fd=sd->fd;
  7648. WFIFOHEAD(fd,packet_len(0x173));
  7649. WFIFOW(fd,0)=0x173;
  7650. WFIFOL(fd,2)=flag;
  7651. WFIFOSET(fd,packet_len(0x173));
  7652. }
  7653. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7654. /// 0184 <other guild id>.L <relation>.L
  7655. /// relation:
  7656. /// 0 = Ally
  7657. /// 1 = Enemy
  7658. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7659. {
  7660. int fd;
  7661. nullpo_retv(sd);
  7662. fd = sd->fd;
  7663. if (fd <= 0)
  7664. return;
  7665. WFIFOHEAD(fd,packet_len(0x184));
  7666. WFIFOW(fd,0)=0x184;
  7667. WFIFOL(fd,2)=guild_id;
  7668. WFIFOL(fd,6)=flag;
  7669. WFIFOSET(fd,packet_len(0x184));
  7670. }
  7671. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7672. /// 0181 <result>.B
  7673. /// result:
  7674. /// 0 = Antagonist has been set.
  7675. /// 1 = Guild has too many Antagonists.
  7676. /// 2 = Already set as an Antagonist.
  7677. /// 3 = Antagonists are disabled.
  7678. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7679. {
  7680. int fd;
  7681. nullpo_retv(sd);
  7682. fd=sd->fd;
  7683. WFIFOHEAD(fd,packet_len(0x181));
  7684. WFIFOW(fd,0)=0x181;
  7685. WFIFOB(fd,2)=flag;
  7686. WFIFOSET(fd,packet_len(0x181));
  7687. }
  7688. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7689. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7690. /*
  7691. void clif_guild_allianceadded(struct guild *g,int idx)
  7692. {
  7693. unsigned char buf[64];
  7694. WBUFW(buf,0)=0x185;
  7695. WBUFL(buf,2)=g->alliance[idx].opposition;
  7696. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7697. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7698. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7699. }
  7700. */
  7701. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7702. /// 015e <reason>.L
  7703. /// 0 = success
  7704. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7705. /// 2 = there are still members in the guild
  7706. void clif_guild_broken(struct map_session_data *sd,int flag)
  7707. {
  7708. int fd;
  7709. nullpo_retv(sd);
  7710. fd=sd->fd;
  7711. WFIFOHEAD(fd,packet_len(0x15e));
  7712. WFIFOW(fd,0)=0x15e;
  7713. WFIFOL(fd,2)=flag;
  7714. WFIFOSET(fd,packet_len(0x15e));
  7715. }
  7716. /// Displays emotion on an object (ZC_EMOTION).
  7717. /// 00c0 <id>.L <type>.B
  7718. /// type:
  7719. /// enum emotion_type
  7720. void clif_emotion(struct block_list *bl,int type)
  7721. {
  7722. unsigned char buf[8];
  7723. nullpo_retv(bl);
  7724. WBUFW(buf,0)=0xc0;
  7725. WBUFL(buf,2)=bl->id;
  7726. WBUFB(buf,6)=type;
  7727. clif_send(buf,packet_len(0xc0),bl,AREA);
  7728. }
  7729. /// Displays the contents of a talkiebox trap.
  7730. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7731. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7732. nullpo_retv( bl );
  7733. nullpo_retv( talkie );
  7734. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7735. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7736. p.aid = bl->id;
  7737. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7738. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7739. }
  7740. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7741. /// 01ea <id>.L
  7742. void clif_wedding_effect(struct block_list *bl)
  7743. {
  7744. unsigned char buf[6];
  7745. nullpo_retv(bl);
  7746. WBUFW(buf,0) = 0x1ea;
  7747. WBUFL(buf,2) = bl->id;
  7748. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7749. }
  7750. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7751. /// 01e6 <partner name>.24B
  7752. void clif_callpartner(struct map_session_data *sd)
  7753. {
  7754. unsigned char buf[26];
  7755. nullpo_retv(sd);
  7756. WBUFW(buf,0) = 0x1e6;
  7757. if( sd->status.partner_id ) {
  7758. const char *p = map_charid2nick(sd->status.partner_id);
  7759. struct map_session_data *p_sd = pc_get_partner(sd);
  7760. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7761. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7762. else
  7763. WBUFB(buf,2) = 0;
  7764. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7765. WBUFB(buf,2) = 0;
  7766. }
  7767. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7768. }
  7769. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7770. /// 01e4
  7771. /// This packet while still implemented by the client is no longer being officially used.
  7772. /*
  7773. void clif_marriage_process(struct map_session_data *sd)
  7774. {
  7775. int fd;
  7776. nullpo_retv(sd);
  7777. fd=sd->fd;
  7778. WFIFOHEAD(fd,packet_len(0x1e4));
  7779. WFIFOW(fd,0)=0x1e4;
  7780. WFIFOSET(fd,packet_len(0x1e4));
  7781. }
  7782. */
  7783. /// Notice of divorce (ZC_DIVORCE).
  7784. /// 0205 <partner name>.24B
  7785. void clif_divorced(struct map_session_data* sd, const char* name)
  7786. {
  7787. int fd;
  7788. nullpo_retv(sd);
  7789. fd=sd->fd;
  7790. WFIFOHEAD(fd,packet_len(0x205));
  7791. WFIFOW(fd,0)=0x205;
  7792. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7793. WFIFOSET(fd, packet_len(0x205));
  7794. }
  7795. /// Marriage proposal (ZC_REQ_COUPLE).
  7796. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7797. /// This packet while still implemented by the client is no longer being officially used.
  7798. /*
  7799. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7800. {
  7801. nullpo_retv(sd);
  7802. WFIFOHEAD(fd,packet_len(0x1e2));
  7803. WFIFOW(fd,0) = 0x1e2;
  7804. WFIFOL(fd,2) = ssd->status.account_id;
  7805. WFIFOL(fd,6) = ssd->status.char_id;
  7806. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7807. WFIFOSET(fd, packet_len(0x1e2));
  7808. }
  7809. */
  7810. /*==========================================
  7811. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7812. *------------------------------------------*/
  7813. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7814. {
  7815. unsigned char buf[256];
  7816. if( len == 0 ) {
  7817. return;
  7818. } else if( len > sizeof(buf)-5 ) {
  7819. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7820. len = sizeof(buf)-5;
  7821. }
  7822. WBUFW(buf, 0) = 0x17f;
  7823. WBUFW(buf, 2) = len + 5;
  7824. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7825. clif_send(buf, WBUFW(buf,2), src, target);
  7826. }
  7827. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7828. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7829. /// 00cd <result>.B
  7830. /// result:
  7831. /// 0 = failure
  7832. /// 1 = success
  7833. void clif_GM_kickack(struct map_session_data *sd, int id)
  7834. {
  7835. int fd;
  7836. nullpo_retv(sd);
  7837. fd = sd->fd;
  7838. WFIFOHEAD(fd,packet_len(0xcd));
  7839. WFIFOW(fd,0) = 0xcd;
  7840. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7841. WFIFOSET(fd, packet_len(0xcd));
  7842. }
  7843. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7844. {
  7845. int fd;
  7846. nullpo_retv(tsd);
  7847. fd = tsd->fd;
  7848. if (sd == NULL)
  7849. tsd->state.keepshop = true;
  7850. if (fd > 0)
  7851. clif_authfail_fd(fd, 15);
  7852. else
  7853. map_quit(tsd);
  7854. if (sd)
  7855. clif_GM_kickack(sd, tsd->status.account_id);
  7856. }
  7857. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7858. /// 014a <result>.L
  7859. /// result:
  7860. /// 0 = "A manner point has been successfully aligned."
  7861. /// 1 = MP_FAILURE_EXHAUST
  7862. /// 2 = MP_FAILURE_ALREADY_GIVING
  7863. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7864. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7865. /// 5 = "You got a good point from %s."
  7866. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7867. {
  7868. int fd;
  7869. nullpo_retv(sd);
  7870. fd = sd->fd;
  7871. WFIFOHEAD(fd,packet_len(0x14a));
  7872. WFIFOW(fd,0) = 0x14a;
  7873. WFIFOL(fd,2) = type;
  7874. WFIFOSET(fd, packet_len(0x14a));
  7875. }
  7876. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7877. /// 014b <type>.B <GM name>.24B
  7878. /// type:
  7879. /// 0 = positive (unmute)
  7880. /// 1 = negative (mute)
  7881. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7882. {
  7883. int fd;
  7884. nullpo_retv(sd);
  7885. nullpo_retv(tsd);
  7886. fd = tsd->fd;
  7887. WFIFOHEAD(fd,packet_len(0x14b));
  7888. WFIFOW(fd,0) = 0x14b;
  7889. WFIFOB(fd,2) = type;
  7890. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7891. WFIFOSET(fd, packet_len(0x14b));
  7892. }
  7893. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7894. /// 00d1 <type>.B <result>.B
  7895. /// type:
  7896. /// 0 = /ex (deny)
  7897. /// 1 = /in (allow)
  7898. /// result:
  7899. /// 0 = success
  7900. /// 1 = failure
  7901. /// 2 = too many blocks
  7902. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7903. {
  7904. int fd;
  7905. nullpo_retv(sd);
  7906. fd=sd->fd;
  7907. WFIFOHEAD(fd,packet_len(0xd1));
  7908. WFIFOW(fd,0)=0xd1;
  7909. WFIFOB(fd,2)=type;
  7910. WFIFOB(fd,3)=flag;
  7911. WFIFOSET(fd,packet_len(0xd1));
  7912. }
  7913. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7914. /// 00d2 <type>.B <result>.B
  7915. /// type:
  7916. /// 0 = /exall (deny)
  7917. /// 1 = /inall (allow)
  7918. /// result:
  7919. /// 0 = success
  7920. /// 1 = failure
  7921. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7922. {
  7923. int fd;
  7924. nullpo_retv(sd);
  7925. fd=sd->fd;
  7926. WFIFOHEAD(fd,packet_len(0xd2));
  7927. WFIFOW(fd,0)=0xd2;
  7928. WFIFOB(fd,2)=type;
  7929. WFIFOB(fd,3)=flag;
  7930. WFIFOSET(fd,packet_len(0xd2));
  7931. }
  7932. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7933. /// 07fe <bgm>.24B
  7934. void clif_playBGM(struct map_session_data* sd, const char* name)
  7935. {
  7936. int fd;
  7937. nullpo_retv(sd);
  7938. fd = sd->fd;
  7939. WFIFOHEAD(fd,packet_len(0x7fe));
  7940. WFIFOW(fd,0) = 0x7fe;
  7941. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7942. WFIFOSET(fd,packet_len(0x7fe));
  7943. }
  7944. /// Plays/stops a wave sound (ZC_SOUND).
  7945. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7946. /// file name:
  7947. /// relative to data\wav
  7948. /// act:
  7949. /// 0 = play (once)
  7950. /// 1 = play (repeat, does not work)
  7951. /// 2 = stops all sound instances of file name (does not work)
  7952. /// term:
  7953. /// unknown purpose, only relevant to act = 1
  7954. /// npc id:
  7955. /// The accustic direction of the sound is determined by the
  7956. /// relative position of the NPC to the player (3D sound).
  7957. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7958. {
  7959. int fd;
  7960. nullpo_retv(sd);
  7961. nullpo_retv(bl);
  7962. fd = sd->fd;
  7963. WFIFOHEAD(fd,packet_len(0x1d3));
  7964. WFIFOW(fd,0) = 0x1d3;
  7965. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7966. WFIFOB(fd,26) = type;
  7967. WFIFOL(fd,27) = 0;
  7968. WFIFOL(fd,31) = bl->id;
  7969. WFIFOSET(fd,packet_len(0x1d3));
  7970. }
  7971. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7972. {
  7973. unsigned char buf[40];
  7974. nullpo_retv(bl);
  7975. WBUFW(buf,0) = 0x1d3;
  7976. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7977. WBUFB(buf,26) = type;
  7978. WBUFL(buf,27) = 0;
  7979. WBUFL(buf,31) = bl->id;
  7980. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7981. }
  7982. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7983. /// 01f3 <id>.L <effect id>.L
  7984. /// effect id:
  7985. /// @see doc/effect_list.txt
  7986. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7987. {
  7988. unsigned char buf[24];
  7989. nullpo_retv(bl);
  7990. memset(buf, 0, packet_len(0x1f3));
  7991. WBUFW(buf,0) = 0x1f3;
  7992. WBUFL(buf,2) = bl->id;
  7993. WBUFL(buf,6) = type;
  7994. clif_send(buf, packet_len(0x1f3), bl, target);
  7995. if (disguised(bl)) {
  7996. WBUFL(buf,2) = disguised_bl_id(bl->id);
  7997. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7998. }
  7999. }
  8000. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8001. {
  8002. WFIFOHEAD(fd,10);
  8003. WFIFOW(fd,0) = 0x1f3;
  8004. WFIFOL(fd,2) = bl->id;
  8005. WFIFOL(fd,6) = type;
  8006. WFIFOSET(fd,10);
  8007. }
  8008. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8009. /// 0284 <id>.L <effect id>.L <num data>.L
  8010. /// effect id:
  8011. /// @see doc/effect_list.txt
  8012. /// num data:
  8013. /// effect-dependent value
  8014. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8015. {
  8016. uint8 buf[14];
  8017. WBUFW(buf,0) = 0x284;
  8018. WBUFL(buf,2) = bl->id;
  8019. WBUFL(buf,6) = effect_id;
  8020. WBUFL(buf,10) = num;
  8021. clif_send(buf, packet_len(0x284), bl, target);
  8022. if( disguised(bl) )
  8023. {
  8024. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8025. clif_send(buf, packet_len(0x284), bl, SELF);
  8026. }
  8027. }
  8028. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8029. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8030. 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) {
  8031. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8032. uint8 buf[CHAT_SIZE_MAX];
  8033. nullpo_retv(bl);
  8034. if (msg_len > sizeof(buf) - 12) {
  8035. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8036. msg_len = sizeof(buf) - 12;
  8037. }
  8038. if (rgb2bgr)
  8039. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8040. WBUFW(buf,0) = 0x2C1;
  8041. WBUFW(buf,2) = msg_len + 12;
  8042. WBUFL(buf,4) = bl->id;
  8043. WBUFL(buf,8) = color;
  8044. memcpy(WBUFCP(buf,12), msg, msg_len);
  8045. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8046. }
  8047. /**
  8048. * Notifies the client that the storage window is still open
  8049. *
  8050. * Should only be used in cases where the client closed the
  8051. * storage window without server's consent
  8052. */
  8053. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8054. // Notify the client that the storage is open
  8055. if( sd->state.storage_flag == 1 ) {
  8056. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8057. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8058. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8059. }
  8060. // Notify the client that the gstorage is open otherwise it will
  8061. // remain locked forever and nobody will be able to access it
  8062. if( sd->state.storage_flag == 2 ) {
  8063. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8064. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8065. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8066. else {
  8067. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8068. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8069. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8070. }
  8071. }
  8072. }
  8073. // refresh the client's screen, getting rid of any effects
  8074. void clif_refresh(struct map_session_data *sd)
  8075. {
  8076. nullpo_retv(sd);
  8077. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8078. clif_inventorylist(sd);
  8079. clif_equipswitch_list(sd);
  8080. if(pc_iscarton(sd)) {
  8081. clif_cartlist(sd);
  8082. clif_updatestatus(sd,SP_CARTINFO);
  8083. }
  8084. clif_updatestatus(sd,SP_WEIGHT);
  8085. clif_updatestatus(sd,SP_MAXWEIGHT);
  8086. clif_updatestatus(sd,SP_STR);
  8087. clif_updatestatus(sd,SP_AGI);
  8088. clif_updatestatus(sd,SP_VIT);
  8089. clif_updatestatus(sd,SP_INT);
  8090. clif_updatestatus(sd,SP_DEX);
  8091. clif_updatestatus(sd,SP_LUK);
  8092. if (sd->spiritball)
  8093. clif_spiritball_single(sd->fd, sd);
  8094. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8095. clif_spiritcharm_single(sd->fd, sd);
  8096. if (sd->soulball)
  8097. clif_soulball_single(sd->fd, sd);
  8098. if (sd->vd.cloth_color)
  8099. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8100. if (sd->vd.body_style)
  8101. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8102. if(hom_is_active(sd->hd))
  8103. clif_send_homdata(sd,SP_ACK,0);
  8104. if( sd->md ) {
  8105. clif_mercenary_info(sd);
  8106. clif_mercenary_skillblock(sd);
  8107. }
  8108. if( sd->ed )
  8109. clif_elemental_info(sd);
  8110. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8111. clif_weather_check(sd);
  8112. if( sd->chatID )
  8113. chat_leavechat(sd,0);
  8114. if( sd->state.vending )
  8115. clif_openvending(sd, sd->bl.id, sd->vending);
  8116. if( pc_issit(sd) )
  8117. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8118. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8119. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8120. else
  8121. clif_changed_dir(&sd->bl, SELF);
  8122. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8123. //Issue #2143
  8124. //Cancel Trading State
  8125. if (sd->state.trading)
  8126. trade_tradecancel(sd);
  8127. //Cancel Buying/Selling State
  8128. if (sd->state.buyingstore)
  8129. buyingstore_close(sd);
  8130. mail_clear(sd);
  8131. clif_loadConfirm( sd );
  8132. if( disguised(&sd->bl) ) {/* refresh-da */
  8133. short disguise = sd->disguise;
  8134. pc_disguise(sd, 0);
  8135. pc_disguise(sd, disguise);
  8136. }
  8137. clif_refresh_storagewindow(sd);
  8138. }
  8139. /// Updates the object's (bl) name on client.
  8140. /// Used to update when a char leaves a party/guild. [Skotlex]
  8141. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8142. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8143. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8144. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8145. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8146. nullpo_retv( src );
  8147. nullpo_retv( bl );
  8148. struct PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8149. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8150. packet.gid = bl->id;
  8151. switch( bl->type ){
  8152. case BL_PC: {
  8153. struct map_session_data *sd = (struct map_session_data *)bl;
  8154. struct party_data *p = NULL;
  8155. //Requesting your own "shadow" name. [Skotlex]
  8156. if( src == bl && target == SELF && sd->disguise ){
  8157. packet.gid = -bl->id;
  8158. }
  8159. if( sd->fakename[0] ) {
  8160. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8161. break;
  8162. }
  8163. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8164. if( sd->status.party_id ){
  8165. p = party_search( sd->status.party_id );
  8166. }
  8167. // do not display party unless the player is also in a guild
  8168. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8169. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8170. }
  8171. if( sd->guild ){
  8172. int position;
  8173. // Will get the position of the guild the player is in
  8174. position = guild_getposition( sd );
  8175. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8176. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8177. }else if( sd->clan ){
  8178. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8179. }
  8180. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8181. packet.title_id = sd->status.title_id; // Title ID
  8182. #endif
  8183. }
  8184. break;
  8185. //[blackhole89]
  8186. case BL_HOM:
  8187. safestrncpy( packet.name, ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH );
  8188. break;
  8189. case BL_MER:
  8190. safestrncpy( packet.name, ((TBL_MER*)bl)->db->name, NAME_LENGTH );
  8191. break;
  8192. case BL_PET:
  8193. safestrncpy( packet.name, ((TBL_PET*)bl)->pet.name, NAME_LENGTH );
  8194. break;
  8195. case BL_NPC:
  8196. safestrncpy( packet.name, ((TBL_NPC*)bl)->name, NAME_LENGTH );
  8197. break;
  8198. case BL_MOB: {
  8199. struct mob_data *md = (struct mob_data *)bl;
  8200. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8201. if( md->guardian_data && md->guardian_data->guild_id ){
  8202. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8203. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8204. }else if( battle_config.show_mob_info ){
  8205. char mobhp[50], *str_p = mobhp;
  8206. if( battle_config.show_mob_info&4 ){
  8207. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8208. }
  8209. if( battle_config.show_mob_info&1 ){
  8210. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8211. }
  8212. if( battle_config.show_mob_info&2 ){
  8213. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8214. }
  8215. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8216. if( str_p != mobhp ){
  8217. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8218. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8219. }
  8220. }
  8221. }
  8222. break;
  8223. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8224. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8225. // break;
  8226. return;
  8227. case BL_ELEM:
  8228. safestrncpy( packet.name, ((TBL_ELEM*)bl)->db->name, NAME_LENGTH );
  8229. break;
  8230. case BL_SKILL:
  8231. // Newer clients request this, but do not need an answer
  8232. return;
  8233. default:
  8234. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8235. return;
  8236. }
  8237. clif_send( &packet, sizeof( packet ), src, target );
  8238. }
  8239. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8240. /// 01ff <id>.L <x>.W <y>.W
  8241. ///
  8242. /// Visually moves(instant) a character to x,y. The char moves even
  8243. /// when the target cell isn't walkable. If the char is sitting it
  8244. /// stays that way.
  8245. void clif_slide(struct block_list *bl, int x, int y)
  8246. {
  8247. unsigned char buf[10];
  8248. nullpo_retv(bl);
  8249. WBUFW(buf, 0) = 0x01ff;
  8250. WBUFL(buf, 2) = bl->id;
  8251. WBUFW(buf, 6) = x;
  8252. WBUFW(buf, 8) = y;
  8253. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8254. if( disguised(bl) )
  8255. {
  8256. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8257. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8258. }
  8259. }
  8260. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8261. /// 008d <packet len>.W <id>.L <message>.?B
  8262. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8263. {
  8264. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8265. int len_mes = strlen(mes)+1; //Account for \0
  8266. if (len_mes > sizeof(buf)-8) {
  8267. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8268. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8269. }
  8270. // send message to others
  8271. if (flag == AREA) {
  8272. WBUFW(buf,0) = 0x8d;
  8273. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8274. WBUFL(buf,4) = bl->id;
  8275. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8276. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8277. }
  8278. // send back message to the speaker
  8279. if( bl->type == BL_PC ) {
  8280. WBUFW(buf,0) = 0x8e;
  8281. WBUFW(buf, 2) = len_mes + 4;
  8282. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8283. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8284. }
  8285. }
  8286. /*==========================
  8287. * Minimap fix [Kevin]
  8288. * Remove dot from minimap
  8289. *--------------------------*/
  8290. void clif_party_xy_remove(struct map_session_data *sd)
  8291. {
  8292. unsigned char buf[16];
  8293. nullpo_retv(sd);
  8294. WBUFW(buf,0)=0x107;
  8295. WBUFL(buf,2)=sd->status.account_id;
  8296. WBUFW(buf,6)=-1;
  8297. WBUFW(buf,8)=-1;
  8298. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8299. }
  8300. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8301. /// 0215 <msg id>.L
  8302. /// msg id:
  8303. /// 0x15 = End all negative status (PA_GOSPEL)
  8304. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8305. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8306. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8307. /// 0x19 = All stats +20 (PA_GOSPEL)
  8308. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8309. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8310. /// 0x1e = DEF +25% (PA_GOSPEL)
  8311. /// 0x1f = ATK +100% (PA_GOSPEL)
  8312. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8313. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8314. /// ? = nothing
  8315. void clif_gospel_info(struct map_session_data *sd, int type)
  8316. {
  8317. int fd=sd->fd;
  8318. WFIFOHEAD(fd,packet_len(0x215));
  8319. WFIFOW(fd,0)=0x215;
  8320. WFIFOL(fd,2)=type;
  8321. WFIFOSET(fd, packet_len(0x215));
  8322. }
  8323. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8324. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8325. /// result:
  8326. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8327. /// star:
  8328. /// 0 = Place of the Sun
  8329. /// 1 = Place of the Moon
  8330. /// 2 = Place of the Stars
  8331. /// 1 = Star Gladiator %s's %s: <mapname>
  8332. /// star:
  8333. /// 0 = Place of the Sun
  8334. /// 1 = Place of the Moon
  8335. /// 2 = Place of the Stars
  8336. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8337. /// star:
  8338. /// 0 = Target of the Sun
  8339. /// 1 = Target of the Moon
  8340. /// 2 = Target of the Stars
  8341. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8342. /// star:
  8343. /// 0 = Monster of the Sun
  8344. /// 1 = Monster of the Moon
  8345. /// 2 = Monster of the Stars
  8346. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8347. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8348. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8349. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8350. /// 40 = Target HP : <monster_id used as HP>
  8351. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8352. {
  8353. int fd = sd->fd;
  8354. WFIFOHEAD(fd,packet_len(0x20e));
  8355. WFIFOW(fd,0) = 0x20e;
  8356. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8357. WFIFOL(fd,26) = monster_id;
  8358. WFIFOB(fd,30) = star;
  8359. WFIFOB(fd,31) = result;
  8360. WFIFOSET(fd,packet_len(0x20e));
  8361. }
  8362. /*==========================================
  8363. * Info about Star Glaldiator save map [Komurka]
  8364. * type: 1: Information, 0: Map registered
  8365. *------------------------------------------*/
  8366. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8367. {
  8368. char mapname[MAP_NAME_LENGTH_EXT];
  8369. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8370. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8371. }
  8372. /*==========================================
  8373. * Info about Star Glaldiator hate mob [Komurka]
  8374. * type: 1: Register mob, 0: Information.
  8375. *------------------------------------------*/
  8376. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8377. {
  8378. if( pcdb_checkid(class_) ) {
  8379. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8380. } else if( mobdb_checkid(class_) ) {
  8381. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8382. } else {
  8383. 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);
  8384. }
  8385. }
  8386. /*==========================================
  8387. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8388. *------------------------------------------*/
  8389. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8390. {
  8391. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8392. }
  8393. /*==========================================
  8394. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8395. *------------------------------------------*/
  8396. void clif_feel_hate_reset(struct map_session_data *sd)
  8397. {
  8398. clif_starskill(sd, "", 0, 0, 30);
  8399. }
  8400. /// Send out reply to configuration change
  8401. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8402. /// type: see enum e_config_type
  8403. /// value:
  8404. /// false = disabled
  8405. /// true = enabled
  8406. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8407. int fd;
  8408. nullpo_retv(sd);
  8409. fd = sd->fd;
  8410. WFIFOHEAD(fd, packet_len(0x2d9));
  8411. WFIFOW(fd, 0) = 0x2d9;
  8412. WFIFOL(fd, 2) = type;
  8413. WFIFOL(fd, 6) = enabled;
  8414. WFIFOSET(fd, packet_len(0x2d9));
  8415. }
  8416. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8417. /// 02da <open equip window>.B
  8418. /// open equip window:
  8419. /// 0 = disabled
  8420. /// 1 = enabled
  8421. void clif_equipcheckbox(struct map_session_data* sd)
  8422. {
  8423. int fd;
  8424. nullpo_retv(sd);
  8425. fd = sd->fd;
  8426. WFIFOHEAD(fd, packet_len(0x2da));
  8427. WFIFOW(fd, 0) = 0x2da;
  8428. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8429. WFIFOSET(fd, packet_len(0x2da));
  8430. }
  8431. /// Sends info about a player's equipped items.
  8432. /// 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)
  8433. /// 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)
  8434. /// 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)
  8435. /// 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)
  8436. /// 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)
  8437. /// 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)
  8438. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8439. nullpo_retv( sd );
  8440. nullpo_retv( tsd );
  8441. struct packet_viewequip_ack packet;
  8442. int equip = 0;
  8443. for( int i = 0; i < EQI_MAX; i++ ){
  8444. int k = tsd->equip_index[i];
  8445. if( k >= 0 ){
  8446. if( tsd->inventory.u.items_inventory[k].nameid <= 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8447. continue;
  8448. }
  8449. if( !tsd->inventory.u.items_inventory[k].equip ){
  8450. continue;
  8451. }
  8452. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8453. continue;
  8454. }
  8455. clif_item_equip( client_index( k ), &packet.list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8456. }
  8457. }
  8458. packet.PacketType = viewequipackType;
  8459. packet.PacketLength = ( sizeof( packet ) - sizeof( packet.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  8460. safestrncpy( packet.characterName, tsd->status.name, NAME_LENGTH );
  8461. packet.job = tsd->status.class_;
  8462. packet.head = tsd->vd.hair_style;
  8463. packet.accessory = tsd->vd.head_bottom;
  8464. packet.accessory2 = tsd->vd.head_mid;
  8465. packet.accessory3 = tsd->vd.head_top;
  8466. #if PACKETVER >= 20110111
  8467. packet.robe = tsd->vd.robe;
  8468. #endif
  8469. packet.headpalette = tsd->vd.hair_color;
  8470. packet.bodypalette = tsd->vd.cloth_color;
  8471. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8472. packet.body2 = tsd->vd.body_style;
  8473. #endif
  8474. packet.sex = tsd->vd.sex;
  8475. clif_send( &packet, packet.PacketLength, &sd->bl, SELF );
  8476. }
  8477. /// Display msgstringtable.txt string (ZC_MSG).
  8478. /// 0291 <message>.W
  8479. void clif_msg(struct map_session_data* sd, unsigned short id)
  8480. {
  8481. int fd;
  8482. nullpo_retv(sd);
  8483. fd = sd->fd;
  8484. WFIFOHEAD(fd, packet_len(0x291));
  8485. WFIFOW(fd, 0) = 0x291;
  8486. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8487. WFIFOSET(fd, packet_len(0x291));
  8488. }
  8489. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8490. /// 0x7e2 <message>.W <value>.L
  8491. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8492. {
  8493. int fd = sd->fd;
  8494. WFIFOHEAD(fd, packet_len(0x7e2));
  8495. WFIFOW(fd,0) = 0x7e2;
  8496. WFIFOW(fd,2) = id;
  8497. WFIFOL(fd,4) = value;
  8498. WFIFOSET(fd, packet_len(0x7e2));
  8499. }
  8500. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8501. /// 07e6 <skill id>.W <msg id>.L
  8502. ///
  8503. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8504. /// "[SkillName] Message"
  8505. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8506. {
  8507. int fd = sd->fd;
  8508. WFIFOHEAD(fd, packet_len(0x7e6));
  8509. WFIFOW(fd,0) = 0x7e6;
  8510. WFIFOW(fd,2) = skill_id;
  8511. WFIFOL(fd,4) = msg_id;
  8512. WFIFOSET(fd, packet_len(0x7e6));
  8513. }
  8514. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8515. /// 09cd <msg id>.W <color>.L
  8516. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8517. nullpo_retv(sd);
  8518. int fd = sd->fd;
  8519. WFIFOHEAD(fd, packet_len(0x9cd));
  8520. WFIFOW(fd, 0) = 0x9cd;
  8521. WFIFOW(fd, 2) = msg_id;
  8522. WFIFOL(fd, 4) = color;
  8523. WFIFOSET(fd, packet_len(0x9cd));
  8524. }
  8525. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8526. /// Returns true if the packet was parsed successfully.
  8527. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8528. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8529. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8530. const char* seperator = " : ";
  8531. int fd;
  8532. struct s_packet_db* info;
  8533. uint16 packetLength, inputLength;
  8534. const char *input, *name, *message;
  8535. size_t nameLength, messageLength;
  8536. fd = sd->fd;
  8537. info = &packet_db[RFIFOW(fd,0)];
  8538. packetLength = RFIFOW(fd,info->pos[0]);
  8539. input = RFIFOCP(fd,info->pos[1]);
  8540. // basic structure check for the 4-byte header
  8541. if( packetLength < 4 ){
  8542. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8543. return false;
  8544. }else{
  8545. inputLength = packetLength - 4;
  8546. }
  8547. // process <name> part of the packet
  8548. if( whisperFormat ) {
  8549. // name has fixed width
  8550. if( inputLength < NAME_LENGTH + 1 ) {
  8551. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8552. return false;
  8553. }
  8554. name = input;
  8555. // validate name
  8556. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8557. // only restriction is that the name must be zero-terminated
  8558. if( name[nameLength] != '\0' ) {
  8559. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8560. return false;
  8561. }
  8562. message = input + NAME_LENGTH;
  8563. messageLength = inputLength - NAME_LENGTH;
  8564. }else{
  8565. // name and message are separated by ' : '
  8566. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8567. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8568. // check if there's enough data provided
  8569. if( inputLength < nameLength + seperatorLength + 1 ){
  8570. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8571. return false;
  8572. }
  8573. name = input;
  8574. // validate name
  8575. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8576. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8577. {
  8578. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8579. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8580. set_eof(sd->fd); // Just kick them out to correct it.
  8581. return false;
  8582. }
  8583. message = input + nameLength + seperatorLength;
  8584. messageLength = inputLength - nameLength - seperatorLength;
  8585. }
  8586. #if PACKETVER < 20151001
  8587. // the declared length must match real length
  8588. if( messageLength != strnlen(message, messageLength)+1 ) {
  8589. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8590. return false;
  8591. }
  8592. // verify <message> part of the packet
  8593. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8594. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8595. return false;
  8596. }
  8597. #else
  8598. // No zero termination anymore
  8599. messageLength += 1;
  8600. #endif
  8601. // messages mustn't be too long
  8602. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8603. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8604. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8605. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8606. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8607. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8608. return false;
  8609. }
  8610. // If it is not a whisper message, set the name to the fakename of the player
  8611. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8612. strcpy( out_name, sd->fakename );
  8613. }else{
  8614. safestrncpy( out_name, name, nameLength + 1 );
  8615. }
  8616. safestrncpy( out_message, message, messageLength );
  8617. if( whisperFormat ){
  8618. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8619. out_full_message[nameLength] = '\0';
  8620. }else{
  8621. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8622. }
  8623. if( is_atcommand( fd, sd, out_message, 1 ) )
  8624. return false;
  8625. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8626. return false; //no "chatting" while muted.
  8627. if( battle_config.min_chat_delay ) { //[Skotlex]
  8628. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8629. return false;
  8630. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8631. }
  8632. if (battle_config.idletime_option&IDLE_CHAT)
  8633. sd->idletime = last_tick;
  8634. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8635. sd->idletime_hom = last_tick;
  8636. return true;
  8637. }
  8638. /**
  8639. * Displays a message if the player enters a PK Zone (during pk_mode)
  8640. * @param sd: Player data
  8641. */
  8642. inline void clif_pk_mode_message(struct map_session_data * sd)
  8643. {
  8644. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8645. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8646. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8647. char output[CHAT_SIZE_MAX];
  8648. // 1504: You've entered a PK Zone (safe until level %d).
  8649. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8650. battle_config.pk_min_level);
  8651. clif_showscript(&sd->bl, output, SELF);
  8652. } else {
  8653. // 1503: You've entered a PK Zone.
  8654. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8655. }
  8656. }
  8657. return;
  8658. }
  8659. // ---------------------
  8660. // clif_parse_wanttoconnect
  8661. // ---------------------
  8662. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8663. // error codes:
  8664. // 0 - Success
  8665. // 1 - Unknown packet_ver
  8666. // 2 - Invalid account_id
  8667. // 3 - Invalid char_id
  8668. // 4 - Invalid login_id1 (reserved)
  8669. // 5 - Invalid client_tick (reserved)
  8670. // 6 - Invalid sex
  8671. // Only the first 'invalid' error that appears is used.
  8672. static int clif_parse_WantToConnection_sub(int fd)
  8673. {
  8674. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8675. unsigned short cmd;
  8676. //By default, start searching on the default one.
  8677. cmd = RFIFOW(fd, 0);
  8678. packet_len = RFIFOREST(fd);
  8679. // FIXME: If the packet is not received at once, this will FAIL.
  8680. // Figure out, when it happens, that only part of the packet is
  8681. // received, or fix the function to be able to deal with that
  8682. // case.
  8683. if( packet_len != packet_db[cmd].len )
  8684. return 1; /* wrong length */
  8685. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8686. return 2; /* invalid account_id */
  8687. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8688. return 3; /* invalid char_id */
  8689. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8690. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8691. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8692. return 6; /* invalid sex */
  8693. else
  8694. return 0;
  8695. }
  8696. /// Request to connect to map-server.
  8697. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8698. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8699. /// There are various variants of this packet, some of them have padding between fields.
  8700. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8701. {
  8702. struct block_list* bl;
  8703. struct auth_node* node;
  8704. int cmd, account_id, char_id, login_id1, sex, err;
  8705. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8706. if (sd) {
  8707. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8708. return;
  8709. }
  8710. cmd = RFIFOW(fd, 0);
  8711. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8712. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8713. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8714. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8715. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8716. err = clif_parse_WantToConnection_sub(fd);
  8717. if( err ){ // connection rejected
  8718. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8719. err == 1 ? "." :
  8720. err == 2 ? ", possibly for having an invalid account_id." :
  8721. err == 3 ? ", possibly for having an invalid char_id." :
  8722. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8723. err == 4 ? ", possibly for having an invalid login_id1." :
  8724. err == 5 ? ", possibly for having an invalid client_tick." :
  8725. */
  8726. err == 6 ? ", possibly for having an invalid sex." :
  8727. ". ERROR invalid error code"));
  8728. WFIFOHEAD(fd,packet_len(0x6a));
  8729. WFIFOW(fd,0) = 0x6a;
  8730. WFIFOB(fd,2) = err;
  8731. WFIFOSET(fd,packet_len(0x6a));
  8732. #ifdef DUMP_INVALID_PACKET
  8733. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8734. #endif
  8735. RFIFOSKIP(fd, RFIFOREST(fd));
  8736. set_eof(fd);
  8737. return;
  8738. }
  8739. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8740. clif_authfail_fd(fd,1);// server closed
  8741. return;
  8742. }
  8743. //Check for double login.
  8744. bl = map_id2bl(account_id);
  8745. if(bl && bl->type != BL_PC) {
  8746. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8747. WFIFOHEAD(fd,packet_len(0x6a));
  8748. WFIFOW(fd,0) = 0x6a;
  8749. WFIFOB(fd,2) = 3; // Rejected by server
  8750. WFIFOSET(fd,packet_len(0x6a));
  8751. set_eof(fd);
  8752. return;
  8753. }
  8754. if (bl ||
  8755. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8756. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8757. {
  8758. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8759. return;
  8760. }
  8761. CREATE(sd, TBL_PC, 1);
  8762. sd->fd = fd;
  8763. #ifdef PACKET_OBFUSCATION
  8764. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8765. #endif
  8766. session[fd]->session_data = sd;
  8767. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8768. #if PACKETVER < 20070521
  8769. WFIFOHEAD(fd,4);
  8770. WFIFOL(fd,0) = sd->bl.id;
  8771. WFIFOSET(fd,4);
  8772. #else
  8773. WFIFOHEAD(fd,packet_len(0x283));
  8774. WFIFOW(fd,0) = 0x283;
  8775. WFIFOL(fd,2) = sd->bl.id;
  8776. WFIFOSET(fd,packet_len(0x283));
  8777. #endif
  8778. chrif_authreq(sd,false);
  8779. }
  8780. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8781. /// 007d
  8782. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8783. {
  8784. bool guild_notice = false;
  8785. if(sd->bl.prev != NULL)
  8786. return;
  8787. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8788. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8789. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8790. sd->state.connect_new = 0;
  8791. return;
  8792. }
  8793. if (sd->state.rewarp) { //Rewarp player.
  8794. sd->state.rewarp = 0;
  8795. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8796. return;
  8797. }
  8798. sd->state.warping = 0;
  8799. // look
  8800. #if PACKETVER < 4
  8801. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8802. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8803. #else
  8804. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8805. #endif
  8806. pc_set_costume_view(sd);
  8807. if(sd->vd.cloth_color)
  8808. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8809. if(sd->vd.body_style)
  8810. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8811. // item
  8812. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8813. pc_checkitem(sd);
  8814. clif_equipswitch_list(sd);
  8815. // cart
  8816. if(pc_iscarton(sd)) {
  8817. clif_cartlist(sd);
  8818. clif_updatestatus(sd,SP_CARTINFO);
  8819. }
  8820. // weight
  8821. clif_updatestatus(sd,SP_WEIGHT);
  8822. clif_updatestatus(sd,SP_MAXWEIGHT);
  8823. // guild
  8824. // (needs to go before clif_spawn() to show guild emblems correctly)
  8825. if(sd->status.guild_id)
  8826. guild_send_memberinfoshort(sd,1);
  8827. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8828. if(battle_config.pc_invincible_time > 0) {
  8829. if(mapdata_flag_gvg(mapdata))
  8830. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8831. else
  8832. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8833. }
  8834. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8835. map_spawnmobs(sd->bl.m);
  8836. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8837. mapdata->users_pvp++;
  8838. }
  8839. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8840. // reset the callshop flag if the player changes map
  8841. sd->state.callshop = 0;
  8842. if(map_addblock(&sd->bl))
  8843. return;
  8844. clif_spawn(&sd->bl);
  8845. // Party
  8846. // (needs to go after clif_spawn() to show hp bars correctly)
  8847. if(sd->status.party_id) {
  8848. party_send_movemap(sd);
  8849. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8850. }
  8851. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8852. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8853. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8854. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8855. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8856. sd->pvp_rank = 0;
  8857. sd->pvp_lastusers = 0;
  8858. sd->pvp_point = 5;
  8859. sd->pvp_won = 0;
  8860. sd->pvp_lost = 0;
  8861. }
  8862. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8863. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8864. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8865. else if (mapdata->flag[MF_GVG_DUNGEON])
  8866. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8867. else if( mapdata_flag_gvg(mapdata) )
  8868. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8869. else
  8870. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8871. // info about nearby objects
  8872. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8873. 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);
  8874. // pet
  8875. if( sd->pd ) {
  8876. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8877. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8878. pet_return_egg( sd, sd->pd );
  8879. } else {
  8880. if(map_addblock(&sd->pd->bl))
  8881. return;
  8882. clif_spawn(&sd->pd->bl);
  8883. clif_send_petdata(sd,sd->pd,0,0);
  8884. clif_send_petstatus(sd);
  8885. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8886. }
  8887. }
  8888. //homunculus [blackhole89]
  8889. if( hom_is_active(sd->hd) ) {
  8890. if(map_addblock(&sd->hd->bl))
  8891. return;
  8892. clif_spawn(&sd->hd->bl);
  8893. clif_send_homdata(sd,SP_ACK,0);
  8894. clif_hominfo(sd,sd->hd,1);
  8895. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8896. clif_homskillinfoblock(sd);
  8897. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8898. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8899. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8900. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8901. }
  8902. if( sd->md ) {
  8903. if(map_addblock(&sd->md->bl))
  8904. return;
  8905. clif_spawn(&sd->md->bl);
  8906. clif_mercenary_info(sd);
  8907. clif_mercenary_skillblock(sd);
  8908. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8909. }
  8910. if( sd->ed ) {
  8911. if (map_addblock(&sd->ed->bl))
  8912. return;
  8913. clif_spawn(&sd->ed->bl);
  8914. clif_elemental_info(sd);
  8915. clif_elemental_updatestatus(sd,SP_HP);
  8916. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8917. clif_elemental_updatestatus(sd,SP_SP);
  8918. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8919. }
  8920. if(sd->state.connect_new) {
  8921. int lv;
  8922. guild_notice = true;
  8923. clif_skillinfoblock(sd);
  8924. clif_hotkeys_send(sd,0);
  8925. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  8926. clif_hotkeys_send(sd,1);
  8927. #endif
  8928. clif_updatestatus(sd,SP_BASEEXP);
  8929. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8930. clif_updatestatus(sd,SP_JOBEXP);
  8931. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8932. clif_updatestatus(sd,SP_SKILLPOINT);
  8933. clif_initialstatus(sd);
  8934. if (sd->sc.option&OPTION_FALCON)
  8935. clif_status_load(&sd->bl, EFST_FALCON, 1);
  8936. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  8937. clif_status_load(&sd->bl, EFST_RIDING, 1);
  8938. else if (sd->sc.option&OPTION_WUGRIDER)
  8939. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  8940. else if (sd->sc.option&OPTION_MADOGEAR)
  8941. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106
  8942. clif_status_load( &sd->bl, EFST_MADOGEAR, 1 );
  8943. #else
  8944. clif_status_load( &sd->bl, EFST_RIDING, 1 );
  8945. #endif
  8946. else if (sd->sc.data[SC_ALL_RIDING])
  8947. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  8948. if(sd->status.manner < 0)
  8949. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8950. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8951. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8952. if(sd->bl.m == sd->feel_map[0].m
  8953. || sd->bl.m == sd->feel_map[1].m
  8954. || sd->bl.m == sd->feel_map[2].m)
  8955. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8956. }
  8957. if(sd->pd && sd->pd->pet.intimate > 900)
  8958. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8959. if(hom_is_active(sd->hd))
  8960. hom_init_timers(sd->hd);
  8961. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  8962. sd->state.night = 1;
  8963. clif_status_load(&sd->bl, EFST_SKE, 1);
  8964. }
  8965. // Notify everyone that this char logged in [Skotlex].
  8966. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8967. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8968. //Login Event
  8969. npc_script_event(sd, NPCE_LOGIN);
  8970. }
  8971. } else {
  8972. //For some reason the client "loses" these on warp/map-change.
  8973. clif_updatestatus(sd,SP_STR);
  8974. clif_updatestatus(sd,SP_AGI);
  8975. clif_updatestatus(sd,SP_VIT);
  8976. clif_updatestatus(sd,SP_INT);
  8977. clif_updatestatus(sd,SP_DEX);
  8978. clif_updatestatus(sd,SP_LUK);
  8979. // abort currently running script
  8980. sd->state.using_fake_npc = 0;
  8981. sd->state.menu_or_input = 0;
  8982. sd->npc_menu = 0;
  8983. if(sd->npc_id)
  8984. npc_event_dequeue(sd);
  8985. }
  8986. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8987. #if PACKETVER >= 20070918
  8988. clif_partyinvitationstate(sd);
  8989. clif_equipcheckbox(sd);
  8990. #endif
  8991. #if PACKETVER >= 20141008
  8992. if( battle_config.pet_autofeed_always ){
  8993. // Always send ON or OFF
  8994. if( sd->pd && battle_config.feature_pet_autofeed ){
  8995. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  8996. }else{
  8997. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  8998. }
  8999. }else{
  9000. // Only send when enabled
  9001. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9002. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9003. }
  9004. }
  9005. #endif
  9006. #if PACKETVER >= 20170920
  9007. if( battle_config.homunculus_autofeed_always ){
  9008. // Always send ON or OFF
  9009. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9010. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9011. }else{
  9012. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9013. }
  9014. }else{
  9015. // Only send when enabled
  9016. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9017. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9018. }
  9019. }
  9020. #endif
  9021. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9022. clif_guild_notice(sd); // Displays after VIP
  9023. guild_notice = false; // Do not display it twice
  9024. }
  9025. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9026. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9027. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9028. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9029. }
  9030. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9031. { //Display night.
  9032. if( !sd->state.night )
  9033. {
  9034. sd->state.night = 1;
  9035. clif_status_load(&sd->bl, EFST_SKE, 1);
  9036. }
  9037. }
  9038. else if( sd->state.night )
  9039. { //Clear night display.
  9040. sd->state.night = 0;
  9041. clif_status_load(&sd->bl, EFST_SKE, 0);
  9042. }
  9043. if( mapdata->flag[MF_BATTLEGROUND] )
  9044. {
  9045. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9046. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9047. clif_bg_updatescore_single(sd);
  9048. }
  9049. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9050. {
  9051. char output[128];
  9052. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9053. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9054. }
  9055. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9056. mapdata->hpmeter_visible++;
  9057. sd->state.hpmeter_visible = 1;
  9058. }
  9059. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9060. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9061. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9062. #ifdef VIP_ENABLE
  9063. if (!sd->state.connect_new &&
  9064. !sd->vip.disableshowrate &&
  9065. sd->state.pmap != sd->bl.m &&
  9066. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9067. )
  9068. {
  9069. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9070. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9071. }
  9072. #endif
  9073. // Instances do not need their own channels
  9074. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9075. channel_mjoin(sd); //join new map
  9076. clif_pk_mode_message(sd);
  9077. }
  9078. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9079. clif_guild_notice(sd); // Displays at end
  9080. }
  9081. mail_clear(sd);
  9082. /* Guild Aura Init */
  9083. if( sd->guild && sd->state.gmaster_flag ) {
  9084. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9085. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9086. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9087. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9088. }
  9089. if( sd->state.vending ) { /* show we have a vending */
  9090. clif_openvending(sd,sd->bl.id,sd->vending);
  9091. clif_showvendingboard(&sd->bl,sd->message,0);
  9092. }
  9093. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9094. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9095. npc_script_event(sd, NPCE_LOADMAP);
  9096. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9097. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9098. if (sd->sc.opt2) //Client loses these on warp.
  9099. clif_changeoption(&sd->bl);
  9100. 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)) {
  9101. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9102. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9103. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9104. }
  9105. clif_weather_check(sd);
  9106. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9107. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9108. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9109. else
  9110. sd->areanpc.clear();
  9111. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9112. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9113. pc_setdead(sd);
  9114. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9115. if(pc_isdead(sd))
  9116. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9117. else {
  9118. skill_usave_trigger(sd);
  9119. if (battle_config.spawn_direction)
  9120. clif_changed_dir(&sd->bl, SELF);
  9121. }
  9122. // Trigger skill effects if you appear standing on them
  9123. if(!battle_config.pc_invincible_time)
  9124. skill_unit_move(&sd->bl,gettick(),1);
  9125. pc_show_questinfo_reinit(sd);
  9126. pc_show_questinfo(sd);
  9127. #if PACKETVER >= 20150513
  9128. if( sd->mail.inbox.unread ){
  9129. clif_Mail_new(sd, 0, NULL, NULL);
  9130. }
  9131. #endif
  9132. sd->state.connect_new = 0;
  9133. sd->state.changemap = false;
  9134. }
  9135. /// Server's tick (ZC_NOTIFY_TIME).
  9136. /// 007f <time>.L
  9137. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9138. {
  9139. int fd = sd->fd;
  9140. WFIFOHEAD(fd,packet_len(0x7f));
  9141. WFIFOW(fd,0) = 0x7f;
  9142. WFIFOL(fd,2) = client_tick(time);
  9143. WFIFOSET(fd,packet_len(0x7f));
  9144. }
  9145. /// Request for server's tick.
  9146. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9147. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9148. /// There are various variants of this packet, some of them have padding between fields.
  9149. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9150. {
  9151. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9152. clif_notify_time(sd, gettick());
  9153. }
  9154. /// Sends hotkey bar.
  9155. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9156. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9157. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9158. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9159. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9160. #ifdef HOTKEY_SAVING
  9161. nullpo_retv( sd );
  9162. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9163. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9164. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9165. if( tab == 0 ){
  9166. p.rotate = sd->status.hotkey_rowshift;
  9167. }else{
  9168. p.rotate = sd->status.hotkey_rowshift2;
  9169. }
  9170. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9171. p.tab = tab;
  9172. #endif
  9173. #endif
  9174. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9175. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9176. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9177. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9178. }
  9179. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9180. #endif
  9181. }
  9182. /// Request to update a position on the hotkey row bar
  9183. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9184. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9185. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9186. if( p->tab == 0 ){
  9187. sd->status.hotkey_rowshift = p->rowshift;
  9188. }else{
  9189. sd->status.hotkey_rowshift2 = p->rowshift;
  9190. }
  9191. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9192. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9193. sd->status.hotkey_rowshift = p->rowshift;
  9194. #endif
  9195. }
  9196. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9197. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9198. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9199. #ifdef HOTKEY_SAVING
  9200. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9201. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9202. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9203. if( idx >= MAX_HOTKEYS_DB ){
  9204. return;
  9205. }
  9206. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9207. sd->status.hotkeys[idx].id = p->hotkey.id;
  9208. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9209. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9210. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9211. const unsigned short idx = p->index;
  9212. if( idx >= MAX_HOTKEYS_DB ){
  9213. return;
  9214. }
  9215. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9216. sd->status.hotkeys[idx].id = p->hotkey.id;
  9217. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9218. #endif
  9219. #endif
  9220. }
  9221. /// Displays cast-like progress bar (ZC_PROGRESS).
  9222. /// 02f0 <color>.L <time>.L
  9223. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9224. {
  9225. int fd = sd->fd;
  9226. WFIFOHEAD(fd,packet_len(0x2f0));
  9227. WFIFOW(fd,0) = 0x2f0;
  9228. WFIFOL(fd,2) = color;
  9229. WFIFOL(fd,6) = second;
  9230. WFIFOSET(fd,packet_len(0x2f0));
  9231. }
  9232. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9233. /// 02f2
  9234. void clif_progressbar_abort(struct map_session_data * sd)
  9235. {
  9236. int fd = sd->fd;
  9237. WFIFOHEAD(fd,packet_len(0x2f2));
  9238. WFIFOW(fd,0) = 0x2f2;
  9239. WFIFOSET(fd,packet_len(0x2f2));
  9240. }
  9241. /// Notification from the client, that the progress bar has reached 100%.
  9242. /// 02f1 (CZ_PROGRESS)
  9243. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9244. // No progressbar active, ignore it
  9245. if( !sd->progressbar.npc_id ){
  9246. return;
  9247. }
  9248. int npc_id = sd->progressbar.npc_id;
  9249. bool closing = false;
  9250. // Check if the progress was canceled
  9251. if( gettick() < sd->progressbar.timeout && sd->st ){
  9252. closing = true;
  9253. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9254. // If a message window was open, offer a close button to the user
  9255. if( sd->st->mes_active ){
  9256. clif_scriptclose( sd, npc_id );
  9257. }
  9258. }
  9259. sd->progressbar.npc_id = 0;
  9260. sd->progressbar.timeout = 0;
  9261. sd->state.workinprogress = WIP_DISABLE_NONE;
  9262. npc_scriptcont(sd, npc_id, closing);
  9263. }
  9264. /// Displays cast-like progress bar on a NPC
  9265. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9266. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9267. #if PACKETVER >= 20130821
  9268. unsigned char buf[14];
  9269. if( nd->progressbar.timeout > 0 ){
  9270. WBUFW(buf,0) = 0x9d1;
  9271. WBUFL(buf,2) = nd->bl.id;
  9272. WBUFL(buf,6) = nd->progressbar.color;
  9273. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9274. if( sd ){
  9275. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9276. }else{
  9277. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9278. }
  9279. }
  9280. #endif
  9281. }
  9282. /// Request to walk to a certain position on the current map.
  9283. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9284. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9285. /// There are various variants of this packet, some of them have padding between fields.
  9286. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9287. {
  9288. short x, y;
  9289. if (pc_isdead(sd)) {
  9290. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9291. return;
  9292. }
  9293. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9294. ; //You CAN walk on this OPT1 value.
  9295. else if (sd->progressbar.npc_id) {
  9296. clif_progressbar_abort(sd);
  9297. return; // First walk attempt cancels the progress bar
  9298. } else if (pc_cant_act(sd))
  9299. return;
  9300. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9301. return;
  9302. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9303. //A move command one cell west is only valid if the target cell is free
  9304. if(battle_config.official_cell_stack_limit > 0
  9305. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9306. return;
  9307. // Cloaking wall check is actually updated when you click to process next movement
  9308. // not when you move each cell. This is official behaviour.
  9309. if (sd->sc.data[SC_CLOAKING])
  9310. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9311. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9312. pc_delinvincibletimer(sd);
  9313. //Set last idle time... [Skotlex]
  9314. if (battle_config.idletime_option&IDLE_WALK)
  9315. sd->idletime = last_tick;
  9316. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9317. sd->idletime_hom = last_tick;
  9318. unit_walktoxy(&sd->bl, x, y, 4);
  9319. }
  9320. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9321. /// 018b <result>.W
  9322. /// result:
  9323. /// 0 = disconnect (quit)
  9324. /// 1 = cannot disconnect (wait 10 seconds)
  9325. /// ? = ignored
  9326. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9327. {
  9328. int fd = sd->fd;
  9329. WFIFOHEAD(fd,packet_len(0x18b));
  9330. WFIFOW(fd,0) = 0x18b;
  9331. WFIFOW(fd,2) = result;
  9332. WFIFOSET(fd,packet_len(0x18b));
  9333. }
  9334. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9335. /// 018a <type>.W
  9336. /// type:
  9337. /// 0 = quit
  9338. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9339. {
  9340. /* Rovert's prevent logout option fixed [Valaris] */
  9341. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9342. 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] &&
  9343. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9344. {
  9345. set_eof(fd);
  9346. pc_damage_log_clear(sd,0);
  9347. clif_disconnect_ack(sd, 0);
  9348. } else {
  9349. clif_disconnect_ack(sd, 1);
  9350. }
  9351. }
  9352. /// Requesting unit's name.
  9353. /// 0094 <id>.L (CZ_REQNAME)
  9354. /// 0368 <id>.L (CZ_REQNAME2)
  9355. /// There are various variants of this packet, some of them have padding between fields.
  9356. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9357. {
  9358. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9359. struct block_list* bl;
  9360. //struct status_change *sc;
  9361. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9362. id = sd->bl.id;
  9363. bl = map_id2bl(id);
  9364. if( bl == NULL )
  9365. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9366. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9367. return; // Block namerequests past view range
  9368. // 'see people in GM hide' cheat detection
  9369. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9370. sc = status_get_sc(bl);
  9371. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9372. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9373. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9374. ) {
  9375. char gm_msg[256];
  9376. 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);
  9377. ShowWarning(gm_msg);
  9378. // information is sent to all online GMs
  9379. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9380. return;
  9381. }
  9382. */
  9383. clif_name(&sd->bl,bl,SELF);
  9384. }
  9385. /// Validates and processes global messages
  9386. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9387. /// There are various variants of this packet.
  9388. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9389. {
  9390. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9391. size_t length;
  9392. // validate packet and retrieve name and message
  9393. if( !clif_process_message(sd, false, name, message, output ) )
  9394. return;
  9395. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9396. channel_send(sd->gcbind,sd,message);
  9397. return;
  9398. }
  9399. // send message to others (using the send buffer for temp. storage)
  9400. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9401. length = strlen(output) + 1;
  9402. // send back message to the speaker
  9403. WFIFOHEAD(fd,4+length);
  9404. WFIFOW(fd,0) = 0x8e;
  9405. WFIFOW(fd,2) = (uint16)(4+length);
  9406. safestrncpy(WFIFOCP(fd,4), output, length );
  9407. WFIFOSET(fd, WFIFOW(fd,2));
  9408. #ifdef PCRE_SUPPORT
  9409. // trigger listening npcs
  9410. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9411. #endif
  9412. // Chat logging type 'O' / Global Chat
  9413. 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);
  9414. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9415. }
  9416. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9417. /// Request to warp to a map on given coordinates.
  9418. /// 0140 <map name>.16B <x>.W <y>.W
  9419. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9420. {
  9421. char command[MAP_NAME_LENGTH_EXT+25];
  9422. char* map_name;
  9423. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9424. map_name = RFIFOCP(fd,info->pos[0]);
  9425. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9426. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9427. RFIFOW(fd,info->pos[1]), //x
  9428. RFIFOW(fd,info->pos[2])); //y
  9429. is_atcommand(fd, sd, command, 1);
  9430. }
  9431. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9432. /// 009c <id>.L <head dir>.W <dir>.B
  9433. /// head dir:
  9434. /// 0 = straight
  9435. /// 1 = turned CW
  9436. /// 2 = turned CCW
  9437. /// dir:
  9438. /// 0 = north
  9439. /// 1 = northwest
  9440. /// 2 = west
  9441. /// 3 = southwest
  9442. /// 4 = south
  9443. /// 5 = southeast
  9444. /// 6 = east
  9445. /// 7 = northeast
  9446. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9447. {
  9448. unsigned char buf[64];
  9449. WBUFW(buf,0) = 0x9c;
  9450. WBUFL(buf,2) = bl->id;
  9451. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9452. WBUFB(buf,8) = unit_getdir(bl);
  9453. clif_send(buf, packet_len(0x9c), bl, target);
  9454. if (disguised(bl)) {
  9455. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9456. WBUFW(buf,6) = 0;
  9457. clif_send(buf, packet_len(0x9c), bl, SELF);
  9458. }
  9459. }
  9460. /// Request to change own body and head direction.
  9461. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9462. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9463. /// There are various variants of this packet, some of them have padding between fields.
  9464. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9465. {
  9466. unsigned char headdir, dir;
  9467. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9468. headdir = RFIFOB(fd,info->pos[0]);
  9469. dir = RFIFOB(fd,info->pos[1]);
  9470. pc_setdir(sd, dir, headdir);
  9471. clif_changed_dir(&sd->bl, AREA_WOS);
  9472. }
  9473. /// Request to show an emotion (CZ_REQ_EMOTION).
  9474. /// 00bf <type>.B
  9475. /// type:
  9476. /// @see enum emotion_type
  9477. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9478. {
  9479. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9480. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9481. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9482. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9483. return;
  9484. }
  9485. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9486. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9487. sd->emotionlasttime = time(NULL);
  9488. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9489. return;
  9490. }
  9491. sd->emotionlasttime = time(NULL);
  9492. if (battle_config.idletime_option&IDLE_EMOTION)
  9493. sd->idletime = last_tick;
  9494. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9495. sd->idletime_hom = last_tick;
  9496. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9497. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9498. return;
  9499. }
  9500. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9501. emoticon = rnd()%6+ET_DICE1;
  9502. }
  9503. clif_emotion(&sd->bl, emoticon);
  9504. } else
  9505. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9506. }
  9507. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9508. /// 00c2 <count>.L
  9509. void clif_user_count(struct map_session_data* sd, int count)
  9510. {
  9511. int fd = sd->fd;
  9512. WFIFOHEAD(fd,packet_len(0xc2));
  9513. WFIFOW(fd,0) = 0xc2;
  9514. WFIFOL(fd,2) = count;
  9515. WFIFOSET(fd,packet_len(0xc2));
  9516. }
  9517. /// /w /who (CZ_REQ_USER_COUNT).
  9518. /// Request to display amount of currently connected players.
  9519. /// 00c1
  9520. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9521. {
  9522. clif_user_count(sd, map_getusers());
  9523. }
  9524. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9525. {
  9526. if (pc_isdead(sd)) {
  9527. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9528. return;
  9529. }
  9530. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9531. // (not all are included in pc_can_attack)
  9532. if (sd->sc.count &&
  9533. (sd->sc.data[SC_TRICKDEAD] ||
  9534. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9535. sd->sc.data[SC_BLADESTOP] ||
  9536. sd->sc.data[SC__MANHOLE] ||
  9537. sd->sc.data[SC_SUHIDE] ||
  9538. sd->sc.data[SC_GRAVITYCONTROL]))
  9539. return;
  9540. if(action_type != 0x00 && action_type != 0x07)
  9541. pc_stop_walking(sd, 1);
  9542. pc_stop_attack(sd);
  9543. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9544. target_id = sd->bl.id;
  9545. switch(action_type)
  9546. {
  9547. case 0x00: // once attack
  9548. case 0x07: // continuous attack
  9549. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9550. return;
  9551. if( sd->sc.option&OPTION_COSTUME )
  9552. return;
  9553. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9554. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9555. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9556. return;
  9557. }
  9558. }
  9559. pc_delinvincibletimer(sd);
  9560. if (battle_config.idletime_option&IDLE_ATTACK)
  9561. sd->idletime = last_tick;
  9562. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9563. sd->idletime_hom = last_tick;
  9564. unit_attack(&sd->bl, target_id, action_type != 0);
  9565. break;
  9566. case 0x02: // sitdown
  9567. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9568. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9569. break;
  9570. }
  9571. if(pc_issit(sd)) {
  9572. //Bugged client? Just refresh them.
  9573. clif_sitting(&sd->bl);
  9574. return;
  9575. }
  9576. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9577. break;
  9578. if (sd->sc.count && (
  9579. sd->sc.data[SC_DANCING] ||
  9580. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9581. )) //No sitting during these states either.
  9582. break;
  9583. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9584. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9585. break;
  9586. }
  9587. if (battle_config.idletime_option&IDLE_SIT)
  9588. sd->idletime = last_tick;
  9589. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9590. sd->idletime_hom = last_tick;
  9591. pc_setsit(sd);
  9592. skill_sit(sd, true);
  9593. clif_sitting(&sd->bl);
  9594. break;
  9595. case 0x03: // standup
  9596. if (!pc_issit(sd)) {
  9597. //Bugged client? Just refresh them.
  9598. clif_standing(&sd->bl);
  9599. return;
  9600. }
  9601. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9602. break;
  9603. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9604. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9605. break;
  9606. }
  9607. if (pc_setstand(sd, false)) {
  9608. if (battle_config.idletime_option&IDLE_SIT)
  9609. sd->idletime = last_tick;
  9610. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9611. sd->idletime_hom = last_tick;
  9612. skill_sit(sd, false);
  9613. clif_standing(&sd->bl);
  9614. }
  9615. break;
  9616. }
  9617. }
  9618. /// Request for an action.
  9619. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9620. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9621. /// action:
  9622. /// 0 = attack
  9623. /// 1 = pick up item
  9624. /// 2 = sit down
  9625. /// 3 = stand up
  9626. /// 7 = continous attack
  9627. /// 12 = (touch skill?)
  9628. /// There are various variants of this packet, some of them have padding between fields.
  9629. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9630. {
  9631. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9632. clif_parse_ActionRequest_sub(sd,
  9633. RFIFOB(fd,info->pos[1]),
  9634. RFIFOL(fd,info->pos[0]),
  9635. gettick()
  9636. );
  9637. }
  9638. /// Response to the death/system menu (CZ_RESTART).
  9639. /// 00b2 <type>.B
  9640. /// type:
  9641. /// 0 = restart (respawn)
  9642. /// 1 = char-select (disconnect)
  9643. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9644. {
  9645. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9646. case 0x00:
  9647. pc_respawn(sd,CLR_OUTSIGHT);
  9648. break;
  9649. case 0x01:
  9650. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9651. 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] &&
  9652. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9653. { //Send to char-server for character selection.
  9654. pc_damage_log_clear(sd,0);
  9655. chrif_charselectreq(sd, session[fd]->client_addr);
  9656. } else {
  9657. clif_disconnect_ack(sd, 1);
  9658. }
  9659. break;
  9660. }
  9661. }
  9662. /// Validates and processes whispered messages (CZ_WHISPER).
  9663. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9664. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9665. {
  9666. struct map_session_data* dstsd;
  9667. int i;
  9668. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9669. // validate packet and retrieve name and message
  9670. if( !clif_process_message( sd, true, target, message, output ) )
  9671. return;
  9672. // Chat logging type 'W' / Whisper
  9673. 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);
  9674. //-------------------------------------------------------//
  9675. // Lordalfa - Paperboy - To whisper NPC commands //
  9676. //-------------------------------------------------------//
  9677. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9678. {
  9679. char* str = target+4; //Skip the NPC: string part.
  9680. struct npc_data* npc;
  9681. if ((npc = npc_name2id(str))) {
  9682. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9683. char *split;
  9684. char event[EVENT_NAME_LENGTH];
  9685. str = message;
  9686. // skip codepage indicator, if detected
  9687. if( str[0] == '|' && strlen(str) >= 4 )
  9688. str += 3;
  9689. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9690. split = strchr(str,'#');
  9691. if( split == NULL ) { // use the remaining string
  9692. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9693. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9694. split_data[i][0] = '\0';
  9695. break;
  9696. }
  9697. *split = '\0';
  9698. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9699. str = split+1;
  9700. }
  9701. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9702. char variablename[CHAT_SIZE_MAX];
  9703. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9704. set_var_str( sd, variablename, split_data[i] );
  9705. }
  9706. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9707. npc_event(sd,event,0); // Calls the NPC label
  9708. return;
  9709. }
  9710. } else if( target[0] == '#' ) {
  9711. struct Channel *channel = NULL;
  9712. char* chname = target;
  9713. channel = channel_name2channel(chname,sd,3);
  9714. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9715. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9716. channel_send(channel,sd,message);
  9717. }
  9718. else if( channel->pass[0] == '\0') { //no pass needed
  9719. if (channel_join(channel,sd)==0)
  9720. channel_send(channel,sd,message); //join success
  9721. }
  9722. else {
  9723. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9724. }
  9725. return;
  9726. }
  9727. }
  9728. // searching destination character
  9729. dstsd = map_nick2sd(target,false);
  9730. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9731. // player is not on this map-server
  9732. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9733. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9734. // and if we ask for 'Test', we must not contact 'test' player
  9735. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9736. intif_wis_message(sd, target, message, strlen(message) + 1);
  9737. return;
  9738. }
  9739. // if player ignores everyone
  9740. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9741. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9742. clif_wis_end(fd, 1); // 1: target character is not logged in
  9743. else
  9744. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9745. return;
  9746. }
  9747. // if player is autotrading
  9748. if (dstsd->state.autotrade == 1){
  9749. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9750. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9751. return;
  9752. }
  9753. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9754. // if player ignores the source character
  9755. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9756. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9757. clif_wis_end(fd, 2); // 2: ignored by target
  9758. return;
  9759. }
  9760. }
  9761. // notify sender of success
  9762. clif_wis_end(fd, 0); // 0: success to send wisper
  9763. // Normal message
  9764. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9765. }
  9766. /// /b /nb (CZ_BROADCAST).
  9767. /// Request to broadcast a message on whole server.
  9768. /// 0099 <packet len>.W <text>.?B 00
  9769. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9770. char command[CHAT_SIZE_MAX+11];
  9771. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9772. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9773. char* msg = RFIFOCP(fd,info->pos[1]);
  9774. // as the length varies depending on the command used, just block unreasonably long strings
  9775. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9776. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9777. is_atcommand(fd, sd, command, 1);
  9778. }
  9779. /// Request to pick up an item.
  9780. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9781. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9782. /// There are various variants of this packet, some of them have padding between fields.
  9783. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9784. {
  9785. struct flooritem_data *fitem;
  9786. int map_object_id;
  9787. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9788. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9789. do {
  9790. if (pc_isdead(sd)) {
  9791. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9792. break;
  9793. }
  9794. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9795. break;
  9796. if (pc_cant_act(sd))
  9797. break;
  9798. if (!pc_takeitem(sd, fitem))
  9799. break;
  9800. return;
  9801. } while (0);
  9802. // Client REQUIRES a fail packet or you can no longer pick items.
  9803. clif_additem(sd,0,0,6);
  9804. }
  9805. /// Request to drop an item.
  9806. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9807. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9808. /// There are various variants of this packet, some of them have padding between fields.
  9809. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9810. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9811. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9812. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9813. for(;;) {
  9814. if (pc_isdead(sd))
  9815. break;
  9816. if (pc_cant_act2(sd) || sd->npc_id)
  9817. break;
  9818. if (sd->sc.count && (
  9819. sd->sc.data[SC_AUTOCOUNTER] ||
  9820. sd->sc.data[SC_BLADESTOP] ||
  9821. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9822. ))
  9823. break;
  9824. if (!pc_dropitem(sd, item_index, item_amount))
  9825. break;
  9826. if (battle_config.idletime_option&IDLE_DROPITEM)
  9827. sd->idletime = last_tick;
  9828. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9829. sd->idletime_hom = last_tick;
  9830. return;
  9831. }
  9832. //Because the client does not like being ignored.
  9833. clif_dropitem(sd, item_index,0);
  9834. }
  9835. /// Request to use an item.
  9836. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9837. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9838. /// There are various variants of this packet, some of them have padding between fields.
  9839. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9840. {
  9841. int n;
  9842. if (pc_isdead(sd)) {
  9843. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9844. return;
  9845. }
  9846. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9847. clif_msg(sd, WORK_IN_PROGRESS);
  9848. return;
  9849. }
  9850. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9851. if (battle_config.idletime_option&IDLE_USEITEM)
  9852. sd->idletime = last_tick;
  9853. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9854. sd->idletime_hom = last_tick;
  9855. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9856. if(n <0 || n >= MAX_INVENTORY)
  9857. return;
  9858. if (!pc_useitem(sd,n))
  9859. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9860. }
  9861. /// Request to equip an item
  9862. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9863. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9864. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9865. {
  9866. int index;
  9867. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9868. if(pc_isdead(sd)) {
  9869. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9870. return;
  9871. }
  9872. index = RFIFOW(fd,info->pos[0])-2;
  9873. if (index < 0 || index >= MAX_INVENTORY)
  9874. return; //Out of bounds check.
  9875. if(sd->npc_id && !sd->npc_item_flag) {
  9876. return;
  9877. } else if (sd->state.storage_flag || sd->sc.opt1)
  9878. ; //You can equip/unequip stuff while storage is open/under status changes
  9879. else if (pc_cant_act2(sd))
  9880. return;
  9881. if(!sd->inventory.u.items_inventory[index].identify) {
  9882. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9883. return;
  9884. }
  9885. if(!sd->inventory_data[index])
  9886. return;
  9887. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9888. pet_equipitem(sd,index);
  9889. return;
  9890. }
  9891. if (battle_config.idletime_option&IDLE_USEITEM)
  9892. sd->idletime = last_tick;
  9893. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9894. sd->idletime_hom = last_tick;
  9895. //Client doesn't send the position for ammo.
  9896. if(sd->inventory_data[index]->type == IT_AMMO)
  9897. pc_equipitem(sd,index,EQP_AMMO);
  9898. else {
  9899. int req_pos;
  9900. #if PACKETVER >= 20120925
  9901. req_pos = RFIFOL(fd,info->pos[1]);
  9902. #else
  9903. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9904. #endif
  9905. pc_equipitem(sd,index,req_pos);
  9906. }
  9907. }
  9908. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9909. /// 00ab <index>.W
  9910. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9911. {
  9912. int index;
  9913. if(pc_isdead(sd)) {
  9914. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9915. return;
  9916. }
  9917. if (sd->npc_id && !sd->npc_item_flag) {
  9918. return;
  9919. } else if (sd->state.storage_flag || sd->sc.opt1)
  9920. ; //You can equip/unequip stuff while storage is open/under status changes
  9921. else if (pc_cant_act2(sd))
  9922. return;
  9923. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9924. if (battle_config.idletime_option&IDLE_USEITEM)
  9925. sd->idletime = last_tick;
  9926. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9927. sd->idletime_hom = last_tick;
  9928. pc_unequipitem(sd,index,1);
  9929. }
  9930. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9931. /// 0090 <id>.L <type>.B
  9932. /// type:
  9933. /// 1 = click
  9934. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9935. {
  9936. struct block_list *bl;
  9937. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9938. if(pc_isdead(sd)) {
  9939. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9940. return;
  9941. }
  9942. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  9943. #ifdef RENEWAL
  9944. clif_msg( sd, WORK_IN_PROGRESS );
  9945. #endif
  9946. return;
  9947. }
  9948. if( sd->state.mail_writing )
  9949. return;
  9950. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9951. //type = RFIFOB(fd,info->pos[1]);
  9952. if (!bl) return;
  9953. switch (bl->type) {
  9954. case BL_MOB:
  9955. case BL_PC:
  9956. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9957. break;
  9958. case BL_NPC:
  9959. #ifdef RENEWAL
  9960. 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
  9961. clif_msg(sd, WORK_IN_PROGRESS);
  9962. break;
  9963. }
  9964. #endif
  9965. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  9966. struct npc_data* nd = (struct npc_data*)bl;
  9967. // Progressbar is running
  9968. if( nd->progressbar.timeout > 0 ){
  9969. return;
  9970. }
  9971. npc_click(sd,nd);
  9972. }
  9973. break;
  9974. }
  9975. }
  9976. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9977. /// 00c5 <id>.L <type>.B
  9978. /// type:
  9979. /// 0 = buy
  9980. /// 1 = sell
  9981. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9982. {
  9983. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9984. if (sd->state.trading)
  9985. return;
  9986. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9987. }
  9988. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9989. /// 00ca <result>.B
  9990. /// result:
  9991. /// 0 = "The deal has successfully completed."
  9992. /// 1 = "You do not have enough zeny."
  9993. /// 2 = "You are over your Weight Limit."
  9994. /// 3 = "Out of the maximum capacity, you have too many items."
  9995. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  9996. /// 10 = "Props open-air store sales will be traded in RODEX"
  9997. /// 11 = "The exchange failed."
  9998. /// 12 = "The exchange was well done."
  9999. /// 13 = "The item is already sold and out of stock."
  10000. /// 14 = "There is not enough goods to exchange."
  10001. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10002. {
  10003. int fd = sd->fd;
  10004. WFIFOHEAD(fd,packet_len(0xca));
  10005. WFIFOW(fd,0) = 0xca;
  10006. WFIFOB(fd,2) = result;
  10007. WFIFOSET(fd,packet_len(0xca));
  10008. }
  10009. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10010. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10011. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10012. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10013. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10014. int result;
  10015. if( sd->state.trading || !sd->npc_shopid )
  10016. result = 1;
  10017. else
  10018. result = npc_buylist( sd, n, (struct s_npc_buy_list*)p->items );
  10019. sd->npc_shopid = 0; //Clear shop data.
  10020. clif_npc_buy_result(sd, result);
  10021. }
  10022. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10023. /// 00cb <result>.B
  10024. /// result:
  10025. /// 0 = "The deal has successfully completed."
  10026. /// 1 = "The deal has failed."
  10027. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10028. {
  10029. int fd = sd->fd;
  10030. WFIFOHEAD(fd,packet_len(0xcb));
  10031. WFIFOW(fd,0) = 0xcb;
  10032. WFIFOB(fd,2) = result;
  10033. WFIFOSET(fd,packet_len(0xcb));
  10034. }
  10035. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10036. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10037. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10038. {
  10039. int fail=0,n;
  10040. unsigned short *item_list;
  10041. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10042. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10043. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10044. if (sd->state.trading || !sd->npc_shopid)
  10045. fail = 1;
  10046. else
  10047. fail = npc_selllist(sd,n,item_list);
  10048. sd->npc_shopid = 0; //Clear shop data.
  10049. clif_npc_sell_result(sd, fail);
  10050. }
  10051. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10052. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10053. /// type:
  10054. /// 0 = private
  10055. /// 1 = public
  10056. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10057. {
  10058. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10059. int len = RFIFOW(fd,info->pos[0])-15;
  10060. int limit = RFIFOW(fd,info->pos[1]);
  10061. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10062. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10063. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10064. char s_password[CHATROOM_PASS_SIZE];
  10065. char s_title[CHATROOM_TITLE_SIZE];
  10066. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10067. return;
  10068. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10069. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10070. return;
  10071. }
  10072. if( npc_isnear(&sd->bl) ) {
  10073. // uncomment to send msg_txt.
  10074. //char output[150];
  10075. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10076. //clif_displaymessage(sd->fd, output);
  10077. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10078. return;
  10079. }
  10080. if( len <= 0 )
  10081. return; // invalid input
  10082. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10083. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10084. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10085. }
  10086. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10087. /// 00d9 <chat ID>.L <passwd>.8B
  10088. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10089. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10090. int chatid = RFIFOL(fd,info->pos[0]);
  10091. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10092. chat_joinchat(sd,chatid,password);
  10093. }
  10094. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10095. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10096. /// type:
  10097. /// 0 = private
  10098. /// 1 = public
  10099. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10100. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10101. int len = RFIFOW(fd,info->pos[0])-15;
  10102. int limit = RFIFOW(fd,info->pos[1]);
  10103. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10104. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10105. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10106. char s_password[CHATROOM_PASS_SIZE];
  10107. char s_title[CHATROOM_TITLE_SIZE];
  10108. if( len <= 0 )
  10109. return; // invalid input
  10110. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10111. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10112. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10113. }
  10114. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10115. /// 00e0 <role>.L <nick>.24B
  10116. /// role:
  10117. /// 0 = owner
  10118. /// 1 = normal
  10119. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10120. {
  10121. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10122. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10123. }
  10124. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10125. /// 00e2 <name>.24B
  10126. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10127. {
  10128. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10129. }
  10130. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10131. /// 00e3
  10132. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10133. {
  10134. chat_leavechat(sd,0);
  10135. }
  10136. //Handles notifying asker and rejecter of what has just ocurred.
  10137. //Type is used to determine the correct msg_txt to use:
  10138. //0:
  10139. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10140. {
  10141. const char* msg;
  10142. char output[256];
  10143. // Your request has been rejected by autoreject option.
  10144. msg = msg_txt(sd,392);
  10145. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10146. //Notice that a request was rejected.
  10147. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10148. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10149. }
  10150. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10151. /// 00e4 <account id>.L
  10152. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10153. {
  10154. struct map_session_data *t_sd;
  10155. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10156. if(!sd->chatID && pc_cant_act(sd))
  10157. return; //You can trade while in a chatroom.
  10158. if(t_sd){
  10159. // @noask [LuzZza]
  10160. if(t_sd->state.noask) {
  10161. clif_noask_sub(sd, t_sd, 0);
  10162. return;
  10163. }
  10164. if (t_sd->state.mail_writing) {
  10165. int old = sd->trade_partner;
  10166. // Fake trading
  10167. sd->trade_partner = t_sd->status.account_id;
  10168. clif_tradestart(sd, 5);
  10169. // Restore old state
  10170. sd->trade_partner = old;
  10171. return;
  10172. }
  10173. }
  10174. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10175. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10176. return;
  10177. }
  10178. trade_traderequest(sd,t_sd);
  10179. }
  10180. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10181. /// 00e6 <result>.B
  10182. /// result:
  10183. /// 3 = accepted
  10184. /// 4 = rejected
  10185. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10186. {
  10187. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10188. }
  10189. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10190. /// 00e8 <index>.W <amount>.L
  10191. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10192. {
  10193. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10194. short index = RFIFOW(fd,info->pos[0]);
  10195. int amount = RFIFOL(fd,info->pos[1]);
  10196. if( index == 0 )
  10197. trade_tradeaddzeny(sd, amount);
  10198. else
  10199. trade_tradeadditem(sd, index, (short)amount);
  10200. }
  10201. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10202. /// 00eb
  10203. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10204. {
  10205. trade_tradeok(sd);
  10206. }
  10207. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10208. /// 00ed
  10209. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10210. {
  10211. trade_tradecancel(sd);
  10212. }
  10213. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10214. /// 00ef
  10215. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10216. {
  10217. trade_tradecommit(sd);
  10218. }
  10219. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10220. /// 0118
  10221. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10222. {
  10223. pc_stop_attack(sd);
  10224. if (sd) sd->ud.state.attack_continue = 0;
  10225. }
  10226. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10227. /// 0126 <index>.W <amount>.L
  10228. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10229. {
  10230. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10231. if (pc_istrading(sd))
  10232. return;
  10233. if (!pc_iscarton(sd))
  10234. return;
  10235. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10236. }
  10237. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10238. /// 0127 <index>.W <amount>.L
  10239. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10240. {
  10241. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10242. if (!pc_iscarton(sd))
  10243. return;
  10244. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10245. }
  10246. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10247. /// 012a
  10248. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10249. {
  10250. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10251. #ifdef NEW_CARTS
  10252. && sd->sc.data[SC_PUSH_CART] )
  10253. pc_setcart(sd,0);
  10254. #else
  10255. )
  10256. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10257. #endif
  10258. else // priority to remove this option before we can clear cart
  10259. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10260. }
  10261. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10262. /// 097f <Length>.W <identity>.L <type>.B
  10263. void clif_SelectCart(struct map_session_data *sd) {
  10264. #if PACKETVER >= 20150826
  10265. int i = 0, carts = 3;
  10266. int fd = sd->fd;
  10267. WFIFOHEAD(fd,8 + carts);
  10268. WFIFOW(fd,0) = 0x97f;
  10269. WFIFOW(fd,2) = 8 + carts;
  10270. WFIFOL(fd,4) = sd->status.account_id;
  10271. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10272. for( i = 0; i < carts; i++ ) {
  10273. WFIFOB(fd,8 + i) = 10 + i;
  10274. }
  10275. WFIFOSET(fd,8 + carts);
  10276. #endif
  10277. }
  10278. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10279. /// 0980 <identity>.L <type>.B
  10280. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10281. #if PACKETVER >= 20150826
  10282. int type;
  10283. // Check identity
  10284. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10285. return;
  10286. type = (int)RFIFOB(fd,6);
  10287. // Check type
  10288. if( type < 10 || type > MAX_CARTS )
  10289. return;
  10290. pc_setcart(sd, type);
  10291. #endif
  10292. }
  10293. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10294. /// 01af <num>.W
  10295. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10296. {// TODO: State tracking?
  10297. int type;
  10298. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10299. return;
  10300. #ifdef RENEWAL
  10301. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10302. clif_msg(sd, WORK_IN_PROGRESS);
  10303. return;
  10304. }
  10305. #endif
  10306. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10307. if(
  10308. #ifdef NEW_CARTS
  10309. (type == 9 && sd->status.base_level > 130) ||
  10310. (type == 8 && sd->status.base_level > 120) ||
  10311. (type == 7 && sd->status.base_level > 110) ||
  10312. (type == 6 && sd->status.base_level > 100) ||
  10313. #endif
  10314. (type == 5 && sd->status.base_level > 90) ||
  10315. (type == 4 && sd->status.base_level > 80) ||
  10316. (type == 3 && sd->status.base_level > 65) ||
  10317. (type == 2 && sd->status.base_level > 40) ||
  10318. (type == 1))
  10319. pc_setcart(sd, type);
  10320. }
  10321. /// Request to increase status (CZ_STATUS_CHANGE).
  10322. /// 00bb <status id>.W <amount>.B
  10323. /// status id:
  10324. /// SP_STR ~ SP_LUK
  10325. /// amount:
  10326. /// Old clients always send 1 for this, even when using /str+ and the like.
  10327. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10328. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10329. {
  10330. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10331. if( increase_amount < 0 ) {
  10332. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10333. fd, increase_amount);
  10334. }
  10335. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10336. }
  10337. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10338. /// 0112 <skill id>.W
  10339. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10340. {
  10341. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10342. }
  10343. 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)
  10344. {
  10345. int lv;
  10346. if( !hd )
  10347. return;
  10348. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10349. clif_emotion(&hd->bl, ET_THINK);
  10350. return;
  10351. }
  10352. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10353. target_id = hd->bl.id;
  10354. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10355. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10356. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10357. clif_emotion(&hd->bl, ET_THINK);
  10358. if (hd->master)
  10359. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10360. return;
  10361. }
  10362. lv = hom_checkskill(hd, skill_id);
  10363. if( skill_lv > lv )
  10364. skill_lv = lv;
  10365. if( skill_lv )
  10366. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10367. }
  10368. 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)
  10369. {
  10370. int lv;
  10371. if( !hd )
  10372. return;
  10373. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10374. clif_emotion(&hd->bl, ET_THINK);
  10375. return;
  10376. }
  10377. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10378. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10379. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10380. clif_emotion(&hd->bl, ET_THINK);
  10381. if (hd->master)
  10382. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10383. return;
  10384. }
  10385. #ifdef RENEWAL
  10386. if (hd->sc.data[SC_BASILICA_CELL])
  10387. #else
  10388. if (hd->sc.data[SC_BASILICA])
  10389. #endif
  10390. return;
  10391. lv = hom_checkskill(hd, skill_id);
  10392. if( skill_lv > lv )
  10393. skill_lv = lv;
  10394. if( skill_lv )
  10395. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10396. }
  10397. 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)
  10398. {
  10399. int lv;
  10400. if( !md )
  10401. return;
  10402. if( skill_isNotOk_mercenary(skill_id, md) )
  10403. return;
  10404. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10405. target_id = md->bl.id;
  10406. if( md->ud.skilltimer != INVALID_TIMER )
  10407. {
  10408. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10409. }
  10410. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10411. return;
  10412. lv = mercenary_checkskill(md, skill_id);
  10413. if( skill_lv > lv )
  10414. skill_lv = lv;
  10415. if( skill_lv )
  10416. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10417. }
  10418. 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)
  10419. {
  10420. int lv;
  10421. if( !md )
  10422. return;
  10423. if( skill_isNotOk_mercenary(skill_id, md) )
  10424. return;
  10425. if( md->ud.skilltimer != INVALID_TIMER )
  10426. return;
  10427. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10428. {
  10429. if (md->master)
  10430. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10431. return;
  10432. }
  10433. #ifdef RENEWAL
  10434. if (md->sc.data[SC_BASILICA_CELL])
  10435. #else
  10436. if (md->sc.data[SC_BASILICA])
  10437. #endif
  10438. return;
  10439. lv = mercenary_checkskill(md, skill_id);
  10440. if( skill_lv > lv )
  10441. skill_lv = lv;
  10442. if( skill_lv )
  10443. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10444. }
  10445. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10446. t_tick tick = gettick();
  10447. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10448. int inf = skill_get_inf(skill_id);
  10449. if (inf&INF_GROUND_SKILL || !inf)
  10450. return; //Using a ground/passive skill on a target? WRONG.
  10451. if (sd->state.block_action & PCBLOCK_SKILL) {
  10452. clif_msg(sd, WORK_IN_PROGRESS);
  10453. return;
  10454. }
  10455. if( SKILL_CHK_HOMUN(skill_id) ) {
  10456. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10457. return;
  10458. }
  10459. if( SKILL_CHK_MERC(skill_id) ) {
  10460. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10461. return;
  10462. }
  10463. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10464. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10465. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10466. sd->idletime = last_tick;
  10467. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10468. sd->idletime_hom = last_tick;
  10469. if( sd->npc_id ){
  10470. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10471. #ifdef RENEWAL
  10472. clif_msg( sd, WORK_IN_PROGRESS );
  10473. #endif
  10474. return;
  10475. }
  10476. }
  10477. if ((pc_cant_act2(sd) || sd->chatID) &&
  10478. skill_id != RK_REFRESH &&
  10479. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10480. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10481. return;
  10482. if( pc_issit(sd) )
  10483. return;
  10484. if( skill_isNotOk(skill_id, sd) )
  10485. return;
  10486. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10487. target_id = sd->bl.id; // never trust the client
  10488. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10489. target_id = sd->bl.id;
  10490. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10491. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10492. return;
  10493. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10494. if( sd->skillitem != skill_id ) {
  10495. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10496. return;
  10497. }
  10498. }
  10499. if( sd->sc.option&OPTION_COSTUME )
  10500. return;
  10501. #ifndef RENEWAL
  10502. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10503. return; // On basilica only caster can use Basilica again to stop it.
  10504. #endif
  10505. if( sd->menuskill_id ) {
  10506. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10507. clif_menuskill_clear(sd); //Cancel pet capture.
  10508. }else if( sd->menuskill_id == SG_FEEL ){
  10509. clif_menuskill_clear( sd ); // Cancel selection
  10510. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10511. return; //Can't use skills while a menu is open.
  10512. }
  10513. if( sd->skillitem == skill_id ) {
  10514. if( skill_lv != sd->skillitemlv )
  10515. skill_lv = sd->skillitemlv;
  10516. if( !(inf&INF_SELF_SKILL) )
  10517. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10518. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10519. return;
  10520. }
  10521. sd->skillitem = sd->skillitemlv = 0;
  10522. if( SKILL_CHK_GUILD(skill_id) ) {
  10523. if( sd->state.gmaster_flag )
  10524. skill_lv = guild_checkskill(sd->guild, skill_id);
  10525. else
  10526. skill_lv = 0;
  10527. } else {
  10528. if( skill_id != ALL_EQSWITCH ){
  10529. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10530. }
  10531. }
  10532. pc_delinvincibletimer(sd);
  10533. if( skill_lv )
  10534. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10535. }
  10536. /// Request to use a targeted skill.
  10537. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10538. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10539. /// There are various variants of this packet, some of them have padding between fields.
  10540. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10541. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10542. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10543. }
  10544. /*==========================================
  10545. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10546. *------------------------------------------*/
  10547. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10548. {
  10549. t_tick tick = gettick();
  10550. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10551. return; //Using a target skill on the ground? WRONG.
  10552. if (sd->state.block_action & PCBLOCK_SKILL) {
  10553. clif_msg(sd, WORK_IN_PROGRESS);
  10554. return;
  10555. }
  10556. if( SKILL_CHK_HOMUN(skill_id) ) {
  10557. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10558. return;
  10559. }
  10560. if( SKILL_CHK_MERC(skill_id) ) {
  10561. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10562. return;
  10563. }
  10564. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10565. #ifdef RENEWAL
  10566. clif_msg( sd, WORK_IN_PROGRESS );
  10567. #endif
  10568. return;
  10569. }
  10570. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10571. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10572. sd->idletime = last_tick;
  10573. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10574. sd->idletime_hom = last_tick;
  10575. if( skill_isNotOk(skill_id, sd) )
  10576. return;
  10577. if( skillmoreinfo != -1 ) {
  10578. if( pc_issit(sd) ) {
  10579. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10580. return;
  10581. }
  10582. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10583. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10584. }
  10585. if( sd->ud.skilltimer != INVALID_TIMER )
  10586. return;
  10587. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10588. if( sd->skillitem != skill_id ) {
  10589. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10590. return;
  10591. }
  10592. }
  10593. if( sd->sc.option&OPTION_COSTUME )
  10594. return;
  10595. #ifndef RENEWAL
  10596. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10597. return; // On basilica only caster can use Basilica again to stop it.
  10598. #endif
  10599. if( sd->menuskill_id ) {
  10600. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10601. clif_menuskill_clear(sd); //Cancel pet capture.
  10602. }else if( sd->menuskill_id == SG_FEEL ){
  10603. clif_menuskill_clear( sd ); // Cancel selection
  10604. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10605. return; //Can't use skills while a menu is open.
  10606. }
  10607. pc_delinvincibletimer(sd);
  10608. if( sd->skillitem == skill_id ) {
  10609. if( skill_lv != sd->skillitemlv )
  10610. skill_lv = sd->skillitemlv;
  10611. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10612. } else {
  10613. int lv;
  10614. sd->skillitem = sd->skillitemlv = 0;
  10615. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10616. if( skill_lv > lv )
  10617. skill_lv = lv;
  10618. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10619. }
  10620. }
  10621. }
  10622. /// Request to use a ground skill.
  10623. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10624. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10625. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10626. /// There are various variants of this packet, some of them have padding between fields.
  10627. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10628. {
  10629. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10630. if (pc_cant_act(sd))
  10631. return;
  10632. if (pc_issit(sd))
  10633. return;
  10634. clif_parse_UseSkillToPosSub(fd, sd,
  10635. RFIFOW(fd,info->pos[0]), //skill lv
  10636. RFIFOW(fd,info->pos[1]), //skill num
  10637. RFIFOW(fd,info->pos[2]), //pos x
  10638. RFIFOW(fd,info->pos[3]), //pos y
  10639. // TODO: find out what this is intended to do
  10640. //RFIFOB(fd, info->pos[4])
  10641. -1 //Skill more info.
  10642. );
  10643. }
  10644. /// Request to use a ground skill with text.
  10645. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10646. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10647. /// There are various variants of this packet, some of them have padding between fields.
  10648. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10649. {
  10650. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10651. if (pc_cant_act(sd))
  10652. return;
  10653. if (pc_issit(sd))
  10654. return;
  10655. clif_parse_UseSkillToPosSub(fd, sd,
  10656. RFIFOW(fd,info->pos[0]), //Skill lv
  10657. RFIFOW(fd,info->pos[1]), //Skill num
  10658. RFIFOW(fd,info->pos[2]), //pos x
  10659. RFIFOW(fd,info->pos[3]), //pos y
  10660. info->pos[4] //skill more info
  10661. );
  10662. }
  10663. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10664. /// 011b <skill id>.W <map name>.16B
  10665. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10666. {
  10667. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10668. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10669. char map_name[MAP_NAME_LENGTH];
  10670. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10671. sd->state.workinprogress = WIP_DISABLE_NONE;
  10672. if(skill_id != sd->menuskill_id)
  10673. return;
  10674. //It is possible to use teleport with the storage window open bugreport:8027
  10675. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10676. clif_menuskill_clear(sd);
  10677. return;
  10678. }
  10679. pc_delinvincibletimer(sd);
  10680. skill_castend_map(sd,skill_id,map_name);
  10681. }
  10682. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10683. /// 011d
  10684. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10685. {
  10686. if (!pc_isdead(sd))
  10687. pc_memo(sd,-1);
  10688. }
  10689. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10690. /// 018e <name id>.W { <material id>.W }*3
  10691. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10692. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10693. switch( sd->menuskill_id ) {
  10694. case -1:
  10695. case AM_PHARMACY:
  10696. case RK_RUNEMASTERY:
  10697. case GC_RESEARCHNEWPOISON:
  10698. break;
  10699. default:
  10700. return;
  10701. }
  10702. if (pc_istrading(sd)) {
  10703. //Make it fail to avoid shop exploits where you sell something different than you see.
  10704. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10705. clif_menuskill_clear(sd);
  10706. return;
  10707. }
  10708. int produce_idx;
  10709. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10710. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10711. clif_menuskill_clear(sd);
  10712. }
  10713. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10714. /// 025b <mk type>.W <name id>.W
  10715. /// mk type:
  10716. /// 1 = cooking
  10717. /// 2 = arrow
  10718. /// 3 = elemental
  10719. /// 4 = GN_MIX_COOKING
  10720. /// 5 = GN_MAKEBOMB
  10721. /// 6 = GN_S_PHARMACY
  10722. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10723. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10724. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10725. short food_idx = -1;
  10726. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10727. return;
  10728. if (pc_istrading(sd)) {
  10729. //Make it fail to avoid shop exploits where you sell something different than you see.
  10730. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10731. clif_menuskill_clear(sd);
  10732. return;
  10733. }
  10734. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10735. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10736. clif_menuskill_clear(sd);
  10737. }
  10738. /// Answer to repair weapon item selection dialog
  10739. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10740. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10741. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  10742. const struct PACKET_CZ_REQ_ITEMREPAIR *p = (struct PACKET_CZ_REQ_ITEMREPAIR *)RFIFOP( fd, 0 );
  10743. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10744. return;
  10745. if (pc_istrading(sd)) {
  10746. //Make it fail to avoid shop exploits where you sell something different than you see.
  10747. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10748. clif_menuskill_clear(sd);
  10749. return;
  10750. }
  10751. skill_repairweapon( sd, p->index );
  10752. clif_menuskill_clear(sd);
  10753. }
  10754. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10755. /// 0222 <index>.L
  10756. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  10757. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10758. return;
  10759. if (pc_istrading(sd)) {
  10760. //Make it fail to avoid shop exploits where you sell something different than you see.
  10761. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10762. clif_menuskill_clear(sd);
  10763. return;
  10764. }
  10765. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  10766. clif_menuskill_clear(sd);
  10767. }
  10768. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10769. /// 00b8 <npc id>.L <choice>.B
  10770. /// choice:
  10771. /// 1~254 = menu item
  10772. /// 255 = cancel
  10773. /// NOTE: If there were more than 254 items in the list, choice
  10774. /// overflows to choice%256.
  10775. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10776. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10777. int npc_id = RFIFOL(fd,info->pos[0]);
  10778. uint8 select = RFIFOB(fd,info->pos[1]);
  10779. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10780. #ifdef SECURE_NPCTIMEOUT
  10781. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10782. #endif
  10783. TBL_NPC* nd = map_id2nd(npc_id);
  10784. 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);
  10785. clif_GM_kick(NULL,sd);
  10786. #ifdef SECURE_NPCTIMEOUT
  10787. }
  10788. #endif
  10789. return;
  10790. }
  10791. sd->npc_menu = select;
  10792. npc_scriptcont(sd,npc_id, false);
  10793. }
  10794. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10795. /// 00b9 <npc id>.L
  10796. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10797. {
  10798. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10799. }
  10800. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10801. /// 0143 <npc id>.L <value>.L
  10802. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10803. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10804. int npcid = RFIFOL(fd,info->pos[0]);
  10805. int amount = (int)RFIFOL(fd,info->pos[1]);
  10806. sd->npc_amount = amount;
  10807. npc_scriptcont(sd, npcid, false);
  10808. }
  10809. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10810. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10811. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10812. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10813. int message_len = RFIFOW(fd,info->pos[0])-8;
  10814. int npcid = RFIFOL(fd,info->pos[1]);
  10815. const char* message = RFIFOCP(fd,info->pos[2]);
  10816. if( message_len <= 0 )
  10817. return; // invalid input
  10818. #if PACKETVER >= 20151001
  10819. message_len++;
  10820. #endif
  10821. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10822. npc_scriptcont(sd, npcid, false);
  10823. }
  10824. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10825. /// 0146 <npc id>.L
  10826. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10827. {
  10828. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10829. return;
  10830. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10831. }
  10832. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10833. /// 0178 <index>.W
  10834. /// index:
  10835. /// -1 = cancel
  10836. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10837. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10838. if (sd->menuskill_id != MC_IDENTIFY)
  10839. return;
  10840. // Ignore the request
  10841. // - Invalid item index
  10842. // - Invalid item ID or item doesn't exist
  10843. // - Item is already identified
  10844. if (idx < 0 || idx >= MAX_INVENTORY ||
  10845. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10846. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10847. sd->state.workinprogress = WIP_DISABLE_NONE;
  10848. clif_menuskill_clear(sd);
  10849. return;
  10850. }
  10851. skill_identify(sd, idx);
  10852. clif_menuskill_clear(sd);
  10853. }
  10854. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10855. /// 01ae <name id>.W
  10856. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10857. if (pc_istrading(sd)) {
  10858. //Make it fail to avoid shop exploits where you sell something different than you see.
  10859. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10860. clif_menuskill_clear(sd);
  10861. return;
  10862. }
  10863. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  10864. switch (sd->menuskill_id) {
  10865. case AC_MAKINGARROW:
  10866. skill_arrow_create(sd,p->itemId);
  10867. break;
  10868. case SA_CREATECON:
  10869. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  10870. break;
  10871. case WL_READING_SB:
  10872. skill_spellbook(sd,p->itemId);
  10873. break;
  10874. case GC_POISONINGWEAPON:
  10875. skill_poisoningweapon(sd,p->itemId);
  10876. break;
  10877. case NC_MAGICDECOY:
  10878. skill_magicdecoy(sd,p->itemId);
  10879. break;
  10880. }
  10881. clif_menuskill_clear(sd);
  10882. }
  10883. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10884. /// 01ce <skill id>.L
  10885. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10886. {
  10887. if (sd->menuskill_id != SA_AUTOSPELL)
  10888. return;
  10889. sd->state.workinprogress = WIP_DISABLE_NONE;
  10890. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10891. clif_menuskill_clear(sd);
  10892. }
  10893. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10894. /// 017a <card index>.W
  10895. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10896. {
  10897. if (sd->state.trading != 0)
  10898. return;
  10899. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10900. }
  10901. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10902. /// 017c <card index>.W <equip index>.W
  10903. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10904. {
  10905. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10906. if (sd->state.trading != 0)
  10907. return;
  10908. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10909. }
  10910. /// Request of character's name by char ID.
  10911. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10912. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10913. /// There are various variants of this packet, some of them have padding between fields.
  10914. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10915. {
  10916. int charid;
  10917. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10918. map_reqnickdb(sd, charid);
  10919. }
  10920. /// /resetskill /resetstate (CZ_RESET).
  10921. /// Request to reset stats or skills.
  10922. /// 0197 <type>.W
  10923. /// type:
  10924. /// 0 = state
  10925. /// 1 = skill
  10926. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10927. char cmd[15];
  10928. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10929. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10930. else
  10931. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10932. is_atcommand(fd, sd, cmd, 1);
  10933. }
  10934. /// /lb /nlb (CZ_LOCALBROADCAST).
  10935. /// Request to broadcast a message on current map.
  10936. /// 019c <packet len>.W <text>.?B
  10937. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10938. {
  10939. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10940. char command[CHAT_SIZE_MAX+16];
  10941. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10942. char* msg = RFIFOCP(fd,info->pos[1]);
  10943. // as the length varies depending on the command used, just block unreasonably long strings
  10944. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10945. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10946. is_atcommand(fd, sd, command, 1);
  10947. }
  10948. /// Request to move an item from inventory to storage.
  10949. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10950. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10951. /// There are various variants of this packet, some of them have padding between fields.
  10952. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10953. {
  10954. int item_index, item_amount;
  10955. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10956. if (pc_istrading(sd))
  10957. return;
  10958. item_index = RFIFOW(fd,info->pos[0])-2;
  10959. item_amount = RFIFOL(fd,info->pos[1]);
  10960. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10961. return;
  10962. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  10963. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  10964. return;
  10965. }
  10966. if (sd->state.storage_flag == 1)
  10967. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  10968. else
  10969. if (sd->state.storage_flag == 2)
  10970. storage_guild_storageadd(sd, item_index, item_amount);
  10971. else if (sd->state.storage_flag == 3)
  10972. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  10973. }
  10974. /// Request to move an item from storage to inventory.
  10975. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10976. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10977. /// There are various variants of this packet, some of them have padding between fields.
  10978. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10979. {
  10980. int item_index, item_amount;
  10981. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10982. item_index = RFIFOW(fd,info->pos[0])-1;
  10983. item_amount = RFIFOL(fd,info->pos[1]);
  10984. if (sd->state.storage_flag == 1)
  10985. storage_storageget(sd, &sd->storage, item_index, item_amount);
  10986. else if(sd->state.storage_flag == 2)
  10987. storage_guild_storageget(sd, item_index, item_amount);
  10988. else if(sd->state.storage_flag == 3)
  10989. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  10990. }
  10991. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10992. /// 0129 <index>.W <amount>.L
  10993. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10994. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10995. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10996. int amount = RFIFOL(fd,info->pos[1]);
  10997. if( sd->state.vending )
  10998. return;
  10999. if (!pc_iscarton(sd))
  11000. return;
  11001. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11002. return;
  11003. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11004. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11005. return;
  11006. }
  11007. if (sd->state.storage_flag == 1)
  11008. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11009. else if (sd->state.storage_flag == 2)
  11010. storage_guild_storageaddfromcart(sd, idx, amount);
  11011. else if (sd->state.storage_flag == 3)
  11012. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11013. }
  11014. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11015. /// 0128 <index>.W <amount>.L
  11016. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11017. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11018. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11019. int amount = RFIFOL(fd,info->pos[1]);
  11020. if( sd->state.vending )
  11021. return;
  11022. if (!pc_iscarton(sd))
  11023. return;
  11024. if (sd->state.storage_flag == 1)
  11025. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11026. else
  11027. if (sd->state.storage_flag == 2)
  11028. storage_guild_storagegettocart(sd, idx, amount);
  11029. else if (sd->state.storage_flag == 3)
  11030. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11031. }
  11032. /// Request to close storage (CZ_CLOSE_STORE).
  11033. /// 00f7
  11034. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11035. {
  11036. if( sd->state.storage_flag == 1 )
  11037. storage_storageclose(sd);
  11038. else
  11039. if( sd->state.storage_flag == 2 )
  11040. storage_guild_storageclose(sd);
  11041. else if( sd->state.storage_flag == 3 )
  11042. storage_premiumStorage_close(sd);
  11043. }
  11044. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11045. /// 023a <info>.W
  11046. /// info:
  11047. /// 0 = password has not been set yet
  11048. /// 1 = storage is password-protected
  11049. /// 8 = too many wrong passwords
  11050. /// ? = ignored
  11051. /// NOTE: This packet is only available on certain non-kRO clients.
  11052. void clif_storagepassword(struct map_session_data* sd, short info)
  11053. {
  11054. int fd = sd->fd;
  11055. WFIFOHEAD(fd,packet_len(0x23a));
  11056. WFIFOW(fd,0) = 0x23a;
  11057. WFIFOW(fd,2) = info;
  11058. WFIFOSET(fd,packet_len(0x23a));
  11059. }
  11060. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11061. /// 023b <type>.W <password>.16B <new password>.16B
  11062. /// type:
  11063. /// 2 = change password
  11064. /// 3 = check password
  11065. /// NOTE: This packet is only available on certain non-kRO clients.
  11066. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11067. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11068. // int type = RFIFOW(fd,info->pos[0]);
  11069. // char* password = RFIFOP(fd,info->pos[1]);
  11070. // char* new_password = RFIFOP(fd,info->pos[2]);
  11071. // storage_changepass(sd,password,new_password);
  11072. }
  11073. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11074. /// 023c <result>.W <error count>.W
  11075. /// result:
  11076. /// 4 = password change success
  11077. /// 5 = password change failure
  11078. /// 6 = password check success
  11079. /// 7 = password check failure
  11080. /// 8 = too many wrong passwords
  11081. /// ? = ignored
  11082. /// NOTE: This packet is only available on certain non-kRO clients.
  11083. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11084. {
  11085. int fd = sd->fd;
  11086. WFIFOHEAD(fd,packet_len(0x23c));
  11087. WFIFOW(fd,0) = 0x23c;
  11088. WFIFOW(fd,2) = result;
  11089. WFIFOW(fd,4) = error_count;
  11090. WFIFOSET(fd,packet_len(0x23c));
  11091. }
  11092. /// Party creation request
  11093. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11094. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11095. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11096. name[NAME_LENGTH-1] = '\0';
  11097. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11098. clif_displaymessage(fd, msg_txt(sd,227));
  11099. return;
  11100. }
  11101. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11102. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11103. return;
  11104. }
  11105. party_create(sd,name,0,0);
  11106. }
  11107. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11108. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11109. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11110. char* name = RFIFOCP(fd,info->pos[0]);
  11111. int item1 = RFIFOB(fd,info->pos[1]);
  11112. int item2 = RFIFOB(fd,info->pos[2]);
  11113. name[NAME_LENGTH-1] = '\0';
  11114. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11115. clif_displaymessage(fd, msg_txt(sd,227));
  11116. return;
  11117. }
  11118. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11119. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11120. return;
  11121. }
  11122. party_create(sd,name,item1,item2);
  11123. }
  11124. /// Party invitation request
  11125. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11126. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11127. {
  11128. struct map_session_data *t_sd;
  11129. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11130. clif_displaymessage(fd, msg_txt(sd,227));
  11131. return;
  11132. }
  11133. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11134. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11135. clif_noask_sub(sd, t_sd, 1);
  11136. return;
  11137. }
  11138. party_invite(sd, t_sd);
  11139. }
  11140. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11141. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11142. struct map_session_data *t_sd;
  11143. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11144. name[NAME_LENGTH-1] = '\0';
  11145. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11146. clif_displaymessage(fd, msg_txt(sd,227));
  11147. return;
  11148. }
  11149. t_sd = map_nick2sd(name,false);
  11150. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11151. clif_noask_sub(sd, t_sd, 1);
  11152. return;
  11153. }
  11154. party_invite(sd, t_sd);
  11155. }
  11156. /// Party invitation reply
  11157. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11158. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11159. /// flag:
  11160. /// 0 = reject
  11161. /// 1 = accept
  11162. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11163. {
  11164. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11165. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11166. RFIFOL(fd,info->pos[1]));
  11167. }
  11168. //(CZ_PARTY_JOIN_REQ_ACK)
  11169. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11170. {
  11171. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11172. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11173. RFIFOB(fd,info->pos[1]));
  11174. }
  11175. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11176. /// 0100
  11177. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11178. {
  11179. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11180. clif_displaymessage(fd, msg_txt(sd,227));
  11181. return;
  11182. }
  11183. party_leave(sd);
  11184. }
  11185. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11186. /// 0103 <account id>.L <char name>.24B
  11187. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11188. {
  11189. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11190. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11191. clif_displaymessage(fd, msg_txt(sd,227));
  11192. return;
  11193. }
  11194. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11195. RFIFOCP(fd,info->pos[1]));
  11196. }
  11197. /// Request to change party options.
  11198. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11199. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11200. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11201. {
  11202. struct party_data *p;
  11203. int i,expflag;
  11204. int cmd = RFIFOW(fd,0);
  11205. struct s_packet_db* info = &packet_db[cmd];
  11206. if( !sd->status.party_id )
  11207. return;
  11208. p = party_search(sd->status.party_id);
  11209. if( p == NULL )
  11210. return;
  11211. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11212. if( i == MAX_PARTY )
  11213. return; //Shouldn't happen
  11214. if( !p->party.member[i].leader )
  11215. return;
  11216. expflag = RFIFOL(fd,info->pos[0]);
  11217. if(cmd == 0x0102){ //Client can't change the item-field
  11218. party_changeoption(sd, expflag, p->party.item);
  11219. }
  11220. else {
  11221. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11222. party_changeoption(sd, expflag, itemflag);
  11223. }
  11224. }
  11225. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11226. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11227. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11228. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11229. // validate packet and retrieve name and message
  11230. if( !clif_process_message( sd, false, name, message, output ) )
  11231. return;
  11232. party_send_message(sd, output, strlen(output) + 1 );
  11233. }
  11234. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11235. /// 07da <account id>.L
  11236. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11237. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11238. }
  11239. /// Party Booking in KRO [Spiria]
  11240. ///
  11241. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11242. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11243. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11244. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11245. short level = RFIFOW(fd,info->pos[0]);
  11246. short mapid = RFIFOW(fd,info->pos[1]);
  11247. int idxpbj = info->pos[2];
  11248. short job[MAX_PARTY_BOOKING_JOBS];
  11249. int i;
  11250. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11251. job[i] = RFIFOB(fd,idxpbj+i*2);
  11252. party_booking_register(sd, level, mapid, job);
  11253. }
  11254. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11255. /// 0803 <result>.W
  11256. /// result:
  11257. /// 0 = success
  11258. /// 1 = failure
  11259. /// 2 = already registered
  11260. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11261. {
  11262. int fd = sd->fd;
  11263. WFIFOHEAD(fd,packet_len(0x803));
  11264. WFIFOW(fd,0) = 0x803;
  11265. WFIFOW(fd,2) = flag;
  11266. WFIFOSET(fd,packet_len(0x803));
  11267. }
  11268. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11269. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11270. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11271. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11272. short level = RFIFOW(fd,info->pos[0]);
  11273. short mapid = RFIFOW(fd,info->pos[1]);
  11274. short job = RFIFOW(fd,info->pos[2]);
  11275. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11276. short resultcount = RFIFOW(fd,info->pos[4]);
  11277. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11278. }
  11279. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11280. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11281. /// more results:
  11282. /// 0 = no
  11283. /// 1 = yes
  11284. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11285. {
  11286. int i, j;
  11287. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11288. struct party_booking_ad_info *pb_ad;
  11289. WFIFOHEAD(fd,size*count + 5);
  11290. WFIFOW(fd,0) = 0x805;
  11291. WFIFOW(fd,2) = size*count + 5;
  11292. WFIFOB(fd,4) = more_result;
  11293. for(i=0; i<count; i++)
  11294. {
  11295. pb_ad = results[i];
  11296. WFIFOL(fd,i*size+5) = pb_ad->index;
  11297. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11298. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11299. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11300. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11301. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11302. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11303. }
  11304. WFIFOSET(fd,WFIFOW(fd,2));
  11305. }
  11306. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11307. /// 0806
  11308. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11309. {
  11310. if(party_booking_delete(sd))
  11311. clif_PartyBookingDeleteAck(sd, 0);
  11312. }
  11313. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11314. /// 0807 <result>.W
  11315. /// result:
  11316. /// 0 = success
  11317. /// 1 = success (auto-removed expired ad)
  11318. /// 2 = failure
  11319. /// 3 = nothing registered
  11320. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11321. {
  11322. int fd = sd->fd;
  11323. WFIFOHEAD(fd,packet_len(0x807));
  11324. WFIFOW(fd,0) = 0x807;
  11325. WFIFOW(fd,2) = flag;
  11326. WFIFOSET(fd,packet_len(0x807));
  11327. }
  11328. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11329. /// 0808 { <job>.W }*6
  11330. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11331. {
  11332. short job[MAX_PARTY_BOOKING_JOBS];
  11333. int i;
  11334. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11335. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11336. job[i] = RFIFOW(fd,idxpbu+i*2);
  11337. party_booking_update(sd, job);
  11338. }
  11339. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11340. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11341. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11342. {
  11343. int i;
  11344. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11345. if(pb_ad == NULL) return;
  11346. WBUFW(buf,0) = 0x809;
  11347. WBUFL(buf,2) = pb_ad->index;
  11348. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11349. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11350. WBUFW(buf,34) = pb_ad->p_detail.level;
  11351. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11352. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11353. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11354. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11355. }
  11356. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11357. /// 080a <index>.L { <job>.W }*6
  11358. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11359. {
  11360. int i;
  11361. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11362. if(pb_ad == NULL) return;
  11363. WBUFW(buf,0) = 0x80a;
  11364. WBUFL(buf,2) = pb_ad->index;
  11365. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11366. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11367. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11368. }
  11369. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11370. /// 080b <index>.L
  11371. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11372. {
  11373. uint8 buf[6];
  11374. WBUFW(buf,0) = 0x80b;
  11375. WBUFL(buf,2) = index;
  11376. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11377. }
  11378. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11379. /// 012e
  11380. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11381. {
  11382. vending_closevending(sd);
  11383. }
  11384. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11385. /// 0130 <account id>.L
  11386. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11387. {
  11388. if( sd->npc_id ) {// using an NPC
  11389. return;
  11390. }
  11391. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11392. }
  11393. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11394. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11395. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11396. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11397. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11398. int id = (int)RFIFOL(fd,info->pos[1]);
  11399. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11400. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11401. // whether it fails or not, the buy window is closed
  11402. sd->vended_id = 0;
  11403. }
  11404. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11405. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11406. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11407. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11408. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11409. int aid = (int)RFIFOL(fd,info->pos[1]);
  11410. int uid = (int)RFIFOL(fd,info->pos[2]);
  11411. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11412. vending_purchasereq(sd, aid, uid, data, len/4);
  11413. // whether it fails or not, the buy window is closed
  11414. sd->vended_id = 0;
  11415. }
  11416. /// Confirm or cancel the shop preparation window.
  11417. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11418. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11419. /// result:
  11420. /// 0 = canceled
  11421. /// 1 = open
  11422. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11423. int cmd = RFIFOW(fd,0);
  11424. struct s_packet_db* info = &packet_db[cmd];
  11425. short len = (short)RFIFOW(fd,info->pos[0]);
  11426. const char* message = RFIFOCP(fd,info->pos[1]);
  11427. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11428. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11429. len -= 84;
  11430. }
  11431. else { //(CZ_REQ_OPENSTORE2)
  11432. bool flag;
  11433. len -= 85;
  11434. flag = RFIFOB(fd,info->pos[2]) != 0;
  11435. if (!flag) {
  11436. sd->state.prevend = 0;
  11437. sd->state.workinprogress = WIP_DISABLE_NONE;
  11438. }
  11439. }
  11440. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11441. return;
  11442. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11443. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11444. return;
  11445. }
  11446. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11447. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11448. return;
  11449. }
  11450. if( message[0] == '\0' ) // invalid input
  11451. return;
  11452. vending_openvending(sd, message, data, len/8, NULL);
  11453. }
  11454. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11455. /// 0165 <char id>.L <guild name>.24B
  11456. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11457. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11458. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11459. name[NAME_LENGTH-1] = '\0';
  11460. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11461. clif_displaymessage(fd, msg_txt(sd,228));
  11462. return;
  11463. }
  11464. if(sd->clan){
  11465. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11466. return;
  11467. }
  11468. guild_create(sd, name);
  11469. }
  11470. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11471. /// 014d
  11472. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11473. {
  11474. clif_guild_masterormember(sd);
  11475. }
  11476. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11477. /// 014f <type>.L
  11478. /// type:
  11479. /// 0 = basic info
  11480. /// 1 = member manager
  11481. /// 2 = positions
  11482. /// 3 = skills
  11483. /// 4 = expulsion list
  11484. /// 5 = unknown (GM_ALLGUILDLIST)
  11485. /// 6 = notice
  11486. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11487. {
  11488. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11489. if( !sd->status.guild_id && !sd->bg_id )
  11490. return;
  11491. switch( type )
  11492. {
  11493. case 0: // Basic Information Guild, hostile alliance information
  11494. clif_guild_basicinfo(sd);
  11495. clif_guild_allianceinfo(sd);
  11496. break;
  11497. case 1: // Members list, list job title
  11498. clif_guild_positionnamelist(sd);
  11499. clif_guild_memberlist(sd);
  11500. break;
  11501. case 2: // List job title, title information list
  11502. clif_guild_positionnamelist(sd);
  11503. clif_guild_positioninfolist(sd);
  11504. break;
  11505. case 3: // Skill list
  11506. clif_guild_skillinfo(sd);
  11507. break;
  11508. case 4: // Expulsion list
  11509. clif_guild_expulsionlist(sd);
  11510. break;
  11511. default:
  11512. ShowError("clif: guild request info: unknown type %d\n", type);
  11513. break;
  11514. }
  11515. }
  11516. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11517. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11518. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11519. {
  11520. int i;
  11521. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11522. int len = RFIFOW(fd,info->pos[0]);
  11523. int idxgpos = info->pos[1];
  11524. if(!sd->state.gmaster_flag)
  11525. return;
  11526. for(i = idxgpos; i < len; i += 40 ){
  11527. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11528. }
  11529. }
  11530. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11531. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11532. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11533. {
  11534. int i;
  11535. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11536. int len = RFIFOW(fd,info->pos[0]);
  11537. int idxgpos = info->pos[1];
  11538. if(!sd->state.gmaster_flag)
  11539. return;
  11540. // Guild leadership change
  11541. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11542. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11543. clif_msg(sd, GUILD_MASTER_WOE);
  11544. return;
  11545. }
  11546. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11547. clif_msg(sd, GUILD_MASTER_DELAY);
  11548. return;
  11549. }
  11550. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11551. return;
  11552. }
  11553. for(i=idxgpos;i<len;i+=12){
  11554. int position = RFIFOL(fd,i+8);
  11555. if( position > 0 ){
  11556. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11557. }
  11558. }
  11559. }
  11560. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11561. /// 0151 <guild id>.L
  11562. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11563. {
  11564. struct guild* g;
  11565. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11566. if( (g = guild_search(guild_id)) != NULL )
  11567. clif_guild_emblem(sd,g);
  11568. }
  11569. /// Validates data of a guild emblem (compressed bitmap)
  11570. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11571. EMBVALIDATE_SUCCESS = 0,
  11572. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11573. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11574. };
  11575. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11576. {
  11577. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11578. unsigned long buf_len = sizeof(buf);
  11579. int offset = 0;
  11580. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11581. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11582. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11583. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11584. ))
  11585. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11586. if(battle_config.emblem_transparency_limit != 100) {
  11587. int i, transcount = 1, tmp[3];
  11588. for(i = offset; i < buf_len-1; i++) {
  11589. int j = i%3;
  11590. tmp[j] = RBUFL(buf,i);
  11591. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11592. transcount++;
  11593. }
  11594. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11595. return EMBVALIDATE_ERR_TRANSPARENCY;
  11596. }
  11597. return EMBVALIDATE_SUCCESS;
  11598. }
  11599. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11600. /// 0153 <packet len>.W <emblem data>.?B
  11601. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11602. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11603. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11604. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11605. int emb_val=0;
  11606. if( !emblem_len || !sd->state.gmaster_flag )
  11607. return;
  11608. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11609. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11610. return;
  11611. }
  11612. emb_val = clif_validate_emblem(emblem, emblem_len);
  11613. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11614. 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);
  11615. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11616. return;
  11617. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11618. char output[128];
  11619. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11620. 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"
  11621. return;
  11622. }
  11623. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11624. }
  11625. /// Guild notice update request (CZ_GUILD_NOTICE).
  11626. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11627. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11628. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11629. int guild_id = RFIFOL(fd,info->pos[0]);
  11630. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11631. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11632. if(!sd->state.gmaster_flag)
  11633. return;
  11634. // compensate for some client defects when using multilanguage mode
  11635. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11636. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11637. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11638. guild_change_notice(sd, guild_id, msg1, msg2);
  11639. }
  11640. // Helper function for guild invite functions
  11641. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11642. {
  11643. if (t_sd == NULL) // not online or does not exist
  11644. return 1;
  11645. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11646. clif_displaymessage(fd, msg_txt(sd,228));
  11647. return 1;
  11648. }
  11649. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11650. clif_noask_sub(sd, t_sd, 2);
  11651. return 1;
  11652. }
  11653. // Players in a clan can not join a guild
  11654. if(t_sd && t_sd->clan){
  11655. return 1;
  11656. }
  11657. guild_invite(sd, t_sd);
  11658. return 0;
  11659. }
  11660. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11661. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11662. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11663. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11664. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11665. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11666. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11667. if (clif_sub_guild_invite(fd, sd, t_sd))
  11668. return;
  11669. }
  11670. /// Guild invite request (/guildinvite)
  11671. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11672. void
  11673. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11674. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11675. if (clif_sub_guild_invite(fd, sd, t_sd))
  11676. return;
  11677. }
  11678. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11679. /// 016b <guild id>.L <answer>.L
  11680. /// answer:
  11681. /// 0 = refuse
  11682. /// 1 = accept
  11683. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11684. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11685. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11686. RFIFOL(fd,info->pos[1]));
  11687. }
  11688. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11689. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11690. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11691. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11692. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11693. clif_displaymessage(fd, msg_txt(sd,228));
  11694. return;
  11695. }
  11696. if( sd->bg_id ) {
  11697. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11698. return;
  11699. }
  11700. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11701. RFIFOL(fd,info->pos[1]),
  11702. RFIFOL(fd,info->pos[2]),
  11703. RFIFOCP(fd,info->pos[3]));
  11704. }
  11705. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11706. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11707. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11708. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11709. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11710. { // Guild locked.
  11711. clif_displaymessage(fd, msg_txt(sd,228));
  11712. return;
  11713. }
  11714. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11715. RFIFOL(fd,info->pos[1]),
  11716. RFIFOL(fd,info->pos[2]),
  11717. RFIFOCP(fd,info->pos[3]));
  11718. }
  11719. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11720. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11721. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11722. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11723. // validate packet and retrieve name and message
  11724. if( !clif_process_message( sd, false, name, message, output ) )
  11725. return;
  11726. if( sd->bg_id )
  11727. bg_send_message(sd, output, strlen(output) );
  11728. else
  11729. guild_send_message(sd, output, strlen(output) );
  11730. }
  11731. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11732. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11733. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11734. {
  11735. struct map_session_data *t_sd;
  11736. if(!sd->state.gmaster_flag)
  11737. return;
  11738. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11739. clif_displaymessage(fd, msg_txt(sd,228));
  11740. return;
  11741. }
  11742. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11743. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11744. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11745. // @noask [LuzZza]
  11746. if(t_sd && t_sd->state.noask) {
  11747. clif_noask_sub(sd, t_sd, 3);
  11748. return;
  11749. }
  11750. guild_reqalliance(sd,t_sd);
  11751. }
  11752. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11753. /// 0172 <inviter account id>.L <answer>.L
  11754. /// answer:
  11755. /// 0 = refuse
  11756. /// 1 = accept
  11757. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11758. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11759. guild_reply_reqalliance(sd,
  11760. RFIFOL(fd,info->pos[0]),
  11761. RFIFOL(fd,info->pos[1]));
  11762. }
  11763. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11764. /// 0183 <opponent guild id>.L <relation>.L
  11765. /// relation:
  11766. /// 0 = Ally
  11767. /// 1 = Enemy
  11768. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11769. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11770. if(!sd->state.gmaster_flag)
  11771. return;
  11772. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11773. clif_displaymessage(fd, msg_txt(sd,228));
  11774. return;
  11775. }
  11776. guild_delalliance(sd,
  11777. RFIFOL(fd,info->pos[0]),
  11778. RFIFOL(fd,info->pos[1]));
  11779. }
  11780. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11781. /// 0180 <account id>.L
  11782. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11783. {
  11784. struct map_session_data *t_sd;
  11785. if(!sd->state.gmaster_flag)
  11786. return;
  11787. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11788. clif_displaymessage(fd, msg_txt(sd,228));
  11789. return;
  11790. }
  11791. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11792. // @noask [LuzZza]
  11793. if(t_sd && t_sd->state.noask) {
  11794. clif_noask_sub(sd, t_sd, 4);
  11795. return;
  11796. }
  11797. guild_opposition(sd,t_sd);
  11798. }
  11799. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11800. /// 015d <key>.40B
  11801. /// key:
  11802. /// now guild name; might have been (intended) email, since the
  11803. /// field name and size is same as the one in CH_DELETE_CHAR.
  11804. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11805. {
  11806. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11807. clif_displaymessage(fd, msg_txt(sd,228));
  11808. return;
  11809. }
  11810. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11811. }
  11812. /// Pet
  11813. ///
  11814. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11815. /// 01a1 <type>.B
  11816. /// type:
  11817. /// 0 = pet information
  11818. /// 1 = feed
  11819. /// 2 = performance
  11820. /// 3 = return to egg
  11821. /// 4 = unequip accessory
  11822. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11823. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11824. }
  11825. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11826. /// 019f <id>.L
  11827. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11828. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11829. }
  11830. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11831. /// 01a7 <index>.W
  11832. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11833. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11834. return;
  11835. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11836. clif_menuskill_clear(sd);
  11837. }
  11838. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11839. /// 01a9 <data>.L
  11840. /// data:
  11841. /// is either emotion (@see enum emotion_type) or a compound value
  11842. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11843. /// entry (given in parentheses) in data\pettalktable.xml
  11844. /// act id:
  11845. /// 0 = feeding
  11846. /// 1 = hunting
  11847. /// 2 = danger
  11848. /// 3 = dead
  11849. /// 4 = normal (stand)
  11850. /// 5 = special performance (perfor_s)
  11851. /// 6 = level up (levelup)
  11852. /// 7 = performance 1 (perfor_1)
  11853. /// 8 = performance 2 (perfor_2)
  11854. /// 9 = performance 3 (perfor_3)
  11855. /// 10 = log-in greeting (connect)
  11856. /// hungry value:
  11857. /// 0 = very hungry (hungry)
  11858. /// 1 = hungry (bit_hungry)
  11859. /// 2 = satisfied (noting)
  11860. /// 3 = stuffed (full)
  11861. /// 4 = full (so_full)
  11862. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11863. {
  11864. if(sd->pd)
  11865. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11866. }
  11867. /// Request to change pet's name (CZ_RENAME_PET).
  11868. /// 01a5 <name>.24B
  11869. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11870. {
  11871. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11872. }
  11873. /// /kill (CZ_DISCONNECT_CHARACTER).
  11874. /// Request to disconnect a character.
  11875. /// 00cc <account id>.L
  11876. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11877. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11878. {
  11879. struct block_list *target;
  11880. int tid;
  11881. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11882. target = map_id2bl(tid);
  11883. if (!target) {
  11884. clif_GM_kickack(sd, 0);
  11885. return;
  11886. }
  11887. switch (target->type) {
  11888. case BL_PC:
  11889. {
  11890. char command[NAME_LENGTH+6];
  11891. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11892. is_atcommand(fd, sd, command, 1);
  11893. }
  11894. break;
  11895. /**
  11896. * This one does not invoke any atcommand, so we need to check for permissions.
  11897. */
  11898. case BL_MOB:
  11899. {
  11900. char command[100];
  11901. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11902. clif_GM_kickack(sd, 0);
  11903. return;
  11904. }
  11905. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11906. log_atcommand(sd, command);
  11907. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11908. }
  11909. break;
  11910. case BL_NPC:
  11911. {
  11912. struct npc_data* nd = (struct npc_data *)target;
  11913. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11914. npc_unload_duplicates(nd);
  11915. npc_unload(nd,true);
  11916. npc_read_event_script();
  11917. }
  11918. }
  11919. break;
  11920. default:
  11921. clif_GM_kickack(sd, 0);
  11922. }
  11923. }
  11924. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11925. /// Request to disconnect all characters.
  11926. /// 00ce
  11927. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11928. char cmd[15];
  11929. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11930. is_atcommand(fd, sd, cmd, 1);
  11931. }
  11932. /// /remove (CZ_REMOVE_AID).
  11933. /// Request to warp to a character with given login ID.
  11934. /// 01ba <account name>.24B
  11935. /// /shift (CZ_SHIFT).
  11936. /// Request to warp to a character with given name.
  11937. /// 01bb <char name>.24B
  11938. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11939. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11940. char *player_name;
  11941. char command[NAME_LENGTH+8];
  11942. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11943. player_name[NAME_LENGTH-1] = '\0';
  11944. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11945. is_atcommand(fd, sd, command, 1);
  11946. }
  11947. /// /remove (CZ_REMOVE_AID_SSO).
  11948. /// Request to warp to a character with given account ID.
  11949. /// 0843 <account id>.L
  11950. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11951. {
  11952. uint32 account_id;
  11953. struct map_session_data* pl_sd;
  11954. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11955. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11956. char command[NAME_LENGTH+8];
  11957. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11958. is_atcommand(fd, sd, command, 1);
  11959. }
  11960. }
  11961. /// /recall (CZ_RECALL).
  11962. /// Request to summon a player with given login ID to own position.
  11963. /// 01bc <account name>.24B
  11964. /// /summon (CZ_RECALL_GID).
  11965. /// Request to summon a player with given name to own position.
  11966. /// 01bd <char name>.24B
  11967. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11968. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11969. char *player_name;
  11970. char command [NAME_LENGTH+8];
  11971. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11972. player_name[NAME_LENGTH-1] = '\0';
  11973. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11974. is_atcommand(fd, sd, command, 1);
  11975. }
  11976. /// /recall (CZ_RECALL_SSO).
  11977. /// Request to summon a player with given account ID to own position.
  11978. /// 0842 <account id>.L
  11979. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11980. {
  11981. uint32 account_id;
  11982. struct map_session_data* pl_sd;
  11983. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11984. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11985. char command[NAME_LENGTH+8];
  11986. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11987. is_atcommand(fd, sd, command, 1);
  11988. }
  11989. }
  11990. /// /item /monster (CZ_ITEM_CREATE).
  11991. /// Request to execute GM commands.
  11992. /// Usage:
  11993. /// /item n - summon n monster or acquire n item/s
  11994. /// /item money - grants 2147483647 zenies
  11995. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11996. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11997. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11998. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11999. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12000. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12001. /// 013f <item/mob name>.24B
  12002. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12003. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12004. {
  12005. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12006. int mob_id = 0;
  12007. struct item_data *id = NULL;
  12008. struct mob_db *mob = NULL;
  12009. StringBuf command;
  12010. char *str;
  12011. //#if PACKETVER >= 20131218
  12012. // char str[100];
  12013. //#else
  12014. // char str[24];
  12015. //#endif
  12016. str = RFIFOCP(fd,info->pos[0]);
  12017. if (!str || str[0] == '\0')
  12018. return;
  12019. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12020. return;
  12021. trim(str);
  12022. // Zeny
  12023. if( strcmpi(str, "money") == 0 ) {
  12024. StringBuf_Init(&command);
  12025. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12026. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12027. StringBuf_Destroy(&command);
  12028. return;
  12029. }
  12030. // Item
  12031. if( (id = itemdb_searchname(str)) ) {
  12032. StringBuf_Init(&command);
  12033. if( !itemdb_isstackable2(id) ) //Nonstackable
  12034. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12035. else {
  12036. if (id->flag.guid)
  12037. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12038. else
  12039. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12040. }
  12041. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12042. StringBuf_Destroy(&command);
  12043. return;
  12044. }
  12045. // Monster
  12046. if ((mob_id = mobdb_searchname(str)) == 0)
  12047. mob_id = mobdb_checkid(atoi(str));
  12048. if( (mob = mob_db(mob_id)) ) {
  12049. StringBuf_Init(&command);
  12050. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12051. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12052. StringBuf_Destroy(&command);
  12053. return;
  12054. }
  12055. }
  12056. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12057. /// 019d <effect state>.L
  12058. /// effect state:
  12059. /// TODO: Any OPTION_* ?
  12060. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12061. char cmd[6];
  12062. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12063. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12064. is_atcommand(fd, sd, cmd, 1);
  12065. }
  12066. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12067. /// 0149 <account id>.L <type>.B <value>.W
  12068. /// type:
  12069. /// 0 = positive points
  12070. /// 1 = negative points
  12071. /// 2 = self mute (+10 minutes)
  12072. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12073. {
  12074. int id, type, value;
  12075. struct map_session_data *dstsd;
  12076. char command[NAME_LENGTH+15];
  12077. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12078. id = RFIFOL(fd,info->pos[0]);
  12079. type = RFIFOB(fd,info->pos[1]);
  12080. value = RFIFOW(fd,info->pos[2]);
  12081. if( type == 0 )
  12082. value = -value;
  12083. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12084. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12085. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12086. return;
  12087. dstsd = map_id2sd(id);
  12088. if( dstsd == NULL )
  12089. return;
  12090. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12091. is_atcommand(fd, sd, command, 1);
  12092. }
  12093. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12094. /// GM adjustment of a player's manner value by -60.
  12095. /// 0212 <char name>.24B
  12096. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12097. {
  12098. char command[NAME_LENGTH+15];
  12099. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12100. name[NAME_LENGTH-1] = '\0';
  12101. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12102. is_atcommand(fd, sd, command, 1);
  12103. }
  12104. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12105. /// 01e0 <account id>.L <account name>.24B
  12106. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12107. {
  12108. WFIFOHEAD(fd,packet_len(0x1e0));
  12109. WFIFOW(fd,0) = 0x1e0;
  12110. WFIFOL(fd,2) = account_id;
  12111. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12112. WFIFOSET(fd,packet_len(0x1e0));
  12113. }
  12114. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12115. /// 01df <account id>.L
  12116. //! TODO: Figure out how does this actually work
  12117. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12118. {
  12119. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12120. /*
  12121. char query[30];
  12122. safesnprintf(query,sizeof(query),"%d", account_id);
  12123. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12124. */
  12125. clif_account_name(fd, account_id, "");
  12126. }
  12127. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12128. /// GM single cell type change request.
  12129. /// 0198 <x>.W <y>.W <type>.W
  12130. /// type:
  12131. /// 0 = not walkable
  12132. /// 1 = walkable
  12133. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12134. {
  12135. int x,y,type;
  12136. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12137. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12138. return;
  12139. x = RFIFOW(fd,info->pos[0]);
  12140. y = RFIFOW(fd,info->pos[1]);
  12141. type = RFIFOW(fd,info->pos[2]);
  12142. map_setgatcell(sd->bl.m,x,y,type);
  12143. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12144. //FIXME: once players leave the map, the client 'forgets' this information.
  12145. }
  12146. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12147. /// Request to allow/deny whispers from a nick.
  12148. /// 00cf <nick>.24B <type>.B
  12149. /// type:
  12150. /// 0 = (/ex nick) deny speech from nick
  12151. /// 1 = (/in nick) allow speech from nick
  12152. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12153. {
  12154. char* nick;
  12155. uint8 type;
  12156. int i;
  12157. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12158. nick = RFIFOCP(fd,info->pos[0]);
  12159. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12160. type = RFIFOB(fd,info->pos[1]);
  12161. if( type == 0 ) { // Add name to ignore list (block)
  12162. if (strcmp(wisp_server_name, nick) == 0) {
  12163. clif_wisexin(sd, type, 1); // fail
  12164. return;
  12165. }
  12166. // try to find a free spot, while checking for duplicates at the same time
  12167. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12168. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12169. clif_wisexin(sd, type, 2); // too many blocks
  12170. return;
  12171. }
  12172. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12173. clif_wisexin(sd, type, 0); // Aegis reports success.
  12174. return;
  12175. }
  12176. //Insert in position i
  12177. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12178. } else { // Remove name from ignore list (unblock)
  12179. // find entry
  12180. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12181. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12182. clif_wisexin(sd, type, 1); // fail
  12183. return;
  12184. }
  12185. // move everything one place down to overwrite removed entry
  12186. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12187. // wipe last entry
  12188. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12189. }
  12190. clif_wisexin(sd, type, 0); // success
  12191. }
  12192. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12193. /// Request to allow/deny all whispers.
  12194. /// 00d0 <type>.B
  12195. /// type:
  12196. /// 0 = (/exall) deny all speech
  12197. /// 1 = (/inall) allow all speech
  12198. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12199. {
  12200. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12201. if( type == 0 ) {// Deny all
  12202. if( sd->state.ignoreAll ) {
  12203. flag = 1; // fail
  12204. } else {
  12205. sd->state.ignoreAll = 1;
  12206. flag = 0; // success
  12207. }
  12208. } else {//Unblock everyone
  12209. if( sd->state.ignoreAll ) {
  12210. sd->state.ignoreAll = 0;
  12211. flag = 0; // success
  12212. } else {
  12213. if (sd->ignore[0].name[0] != '\0')
  12214. { //Wipe the ignore list.
  12215. memset(sd->ignore, 0, sizeof(sd->ignore));
  12216. flag = 0; // success
  12217. } else {
  12218. flag = 1; // fail
  12219. }
  12220. }
  12221. }
  12222. clif_wisall(sd, type, flag);
  12223. }
  12224. /// Whisper ignore list (ZC_WHISPER_LIST).
  12225. /// 00d4 <packet len>.W { <char name>.24B }*
  12226. void clif_PMIgnoreList(struct map_session_data* sd)
  12227. {
  12228. int i, fd = sd->fd;
  12229. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12230. WFIFOW(fd,0) = 0xd4;
  12231. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12232. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12233. }
  12234. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12235. WFIFOSET(fd,WFIFOW(fd,2));
  12236. }
  12237. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12238. /// 00d3
  12239. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12240. {
  12241. clif_PMIgnoreList(sd);
  12242. }
  12243. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12244. /// 01e7
  12245. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12246. {
  12247. if (sd->state.doridori) return;
  12248. switch (sd->class_&MAPID_UPPERMASK) {
  12249. case MAPID_SOUL_LINKER:
  12250. case MAPID_STAR_GLADIATOR:
  12251. case MAPID_TAEKWON:
  12252. if (!sd->state.rest)
  12253. break;
  12254. case MAPID_SUPER_NOVICE:
  12255. case MAPID_SUPER_BABY:
  12256. case MAPID_SUPER_NOVICE_E:
  12257. case MAPID_SUPER_BABY_E:
  12258. sd->state.doridori=1;
  12259. break;
  12260. }
  12261. }
  12262. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12263. /// 01ed
  12264. /// Note: This packet is caused by 7 lines of any text, followed by
  12265. /// the prayer and an another line of any text. The prayer is
  12266. /// defined by lines 790~793 in data\msgstringtable.txt
  12267. /// "Dear angel, can you hear my voice?"
  12268. /// "I am" (space separated player name) "Super Novice~"
  12269. /// "Help me out~ Please~ T_T"
  12270. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12271. {
  12272. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12273. unsigned int next = pc_nextbaseexp(sd);
  12274. if( next ) {
  12275. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12276. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12277. 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]
  12278. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12279. }
  12280. }
  12281. }
  12282. }
  12283. /// Friends List
  12284. ///
  12285. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12286. /// 0206 <account id>.L <char id>.L <state>.B
  12287. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12288. /// state:
  12289. /// 0 = online
  12290. /// 1 = offline
  12291. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12292. {
  12293. int i, fd = sd->fd;
  12294. //Seek friend.
  12295. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12296. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12297. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12298. return; //Not found
  12299. WFIFOHEAD(fd,packet_len(0x206));
  12300. WFIFOW(fd, 0) = 0x206;
  12301. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12302. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12303. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12304. #if PACKETVER >= 20180221
  12305. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12306. #endif
  12307. WFIFOSET(fd, packet_len(0x206));
  12308. }
  12309. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12310. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12311. {
  12312. uint32 account_id, char_id, online;
  12313. account_id = va_arg(ap, int);
  12314. char_id = va_arg(ap, int);
  12315. online = va_arg(ap, int);
  12316. clif_friendslist_toggle(sd, account_id, char_id, online);
  12317. return 0;
  12318. }
  12319. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12320. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12321. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12322. void clif_friendslist_send(struct map_session_data *sd)
  12323. {
  12324. int i = 0, n, fd = sd->fd;
  12325. #if PACKETVER >= 20180221
  12326. const int size = 8;
  12327. #else
  12328. const int size = 8 + NAME_LENGTH;
  12329. #endif
  12330. // Send friends list
  12331. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12332. WFIFOW(fd, 0) = 0x201;
  12333. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12334. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12335. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12336. #if PACKETVER < 20180221
  12337. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12338. #endif
  12339. }
  12340. if (i) {
  12341. WFIFOW(fd,2) = 4 + size * i;
  12342. WFIFOSET(fd, WFIFOW(fd,2));
  12343. }
  12344. for (n = 0; n < i; n++) { //Sending the online players
  12345. if (map_charid2sd(sd->status.friends[n].char_id))
  12346. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12347. }
  12348. }
  12349. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12350. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12351. /// result:
  12352. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12353. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12354. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12355. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12356. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12357. {
  12358. int fd;
  12359. nullpo_retv(sd);
  12360. fd = sd->fd;
  12361. WFIFOHEAD(fd,packet_len(0x209));
  12362. WFIFOW(fd,0) = 0x209;
  12363. WFIFOW(fd,2) = type;
  12364. if (f_sd) {
  12365. WFIFOL(fd,4) = f_sd->status.account_id;
  12366. WFIFOL(fd,8) = f_sd->status.char_id;
  12367. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12368. }
  12369. WFIFOSET(fd, packet_len(0x209));
  12370. }
  12371. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12372. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12373. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12374. {
  12375. int fd = sd->fd;
  12376. WFIFOHEAD(fd,packet_len(0x207));
  12377. WFIFOW(fd,0) = 0x207;
  12378. WFIFOL(fd,2) = account_id;
  12379. WFIFOL(fd,6) = char_id;
  12380. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12381. WFIFOSET(fd,packet_len(0x207));
  12382. }
  12383. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12384. /// 0202 <name>.24B
  12385. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12386. {
  12387. struct map_session_data *f_sd;
  12388. int i;
  12389. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12390. // Friend doesn't exist (no player with this name)
  12391. if (f_sd == NULL) {
  12392. clif_displaymessage(fd, msg_txt(sd,3));
  12393. return;
  12394. }
  12395. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12396. return;
  12397. }
  12398. // ensure that the request player's friend list is not full
  12399. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12400. if( i == MAX_FRIENDS ){
  12401. clif_friendslist_reqack(sd, f_sd, 2);
  12402. return;
  12403. }
  12404. // @noask [LuzZza]
  12405. if(f_sd->state.noask) {
  12406. clif_noask_sub(sd, f_sd, 5);
  12407. return;
  12408. }
  12409. // Friend already exists
  12410. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12411. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12412. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12413. return;
  12414. }
  12415. }
  12416. f_sd->friend_req = sd->status.char_id;
  12417. sd->friend_req = f_sd->status.char_id;
  12418. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12419. }
  12420. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12421. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12422. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12423. /// reply:
  12424. /// 0 = rejected
  12425. /// 1 = accepted
  12426. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12427. {
  12428. struct map_session_data *f_sd;
  12429. uint32 account_id;
  12430. char reply;
  12431. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12432. account_id = RFIFOL(fd,info->pos[0]);
  12433. //char_id = RFIFOL(fd,info->pos[1]);
  12434. #if PACKETVER < 6
  12435. reply = RFIFOB(fd,info->pos[2]);
  12436. #else
  12437. reply = RFIFOL(fd,info->pos[2]);
  12438. #endif
  12439. if( sd->bl.id == account_id ) {// adding oneself as friend
  12440. return;
  12441. }
  12442. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12443. if (f_sd == NULL)
  12444. return;
  12445. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12446. clif_friendslist_reqack(f_sd, sd, 1);
  12447. else {
  12448. int i;
  12449. // Find an empty slot
  12450. for (i = 0; i < MAX_FRIENDS; i++)
  12451. if (f_sd->status.friends[i].char_id == 0)
  12452. break;
  12453. if (i == MAX_FRIENDS) {
  12454. clif_friendslist_reqack(f_sd, sd, 2);
  12455. return;
  12456. }
  12457. f_sd->status.friends[i].account_id = sd->status.account_id;
  12458. f_sd->status.friends[i].char_id = sd->status.char_id;
  12459. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12460. clif_friendslist_reqack(f_sd, sd, 0);
  12461. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12462. if (battle_config.friend_auto_add) {
  12463. // Also add f_sd to sd's friendlist.
  12464. for (i = 0; i < MAX_FRIENDS; i++) {
  12465. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12466. return; //No need to add anything.
  12467. if (sd->status.friends[i].char_id == 0)
  12468. break;
  12469. }
  12470. if (i == MAX_FRIENDS) {
  12471. clif_friendslist_reqack(sd, f_sd, 2);
  12472. return;
  12473. }
  12474. sd->status.friends[i].account_id = f_sd->status.account_id;
  12475. sd->status.friends[i].char_id = f_sd->status.char_id;
  12476. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12477. clif_friendslist_reqack(sd, f_sd, 0);
  12478. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12479. }
  12480. }
  12481. }
  12482. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12483. /// 0203 <account id>.L <char id>.L
  12484. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12485. {
  12486. struct map_session_data *f_sd = NULL;
  12487. uint32 account_id, char_id;
  12488. int i, j;
  12489. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12490. account_id = RFIFOL(fd,info->pos[0]);
  12491. char_id = RFIFOL(fd,info->pos[1]);
  12492. // Search friend
  12493. for (i = 0; i < MAX_FRIENDS &&
  12494. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12495. if (i == MAX_FRIENDS) {
  12496. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12497. return;
  12498. }
  12499. //remove from friend's list first
  12500. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12501. for (i = 0; i < MAX_FRIENDS &&
  12502. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12503. if (i != MAX_FRIENDS) {
  12504. // move all chars up
  12505. for(j = i + 1; j < MAX_FRIENDS; j++)
  12506. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12507. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12508. //should the guy be notified of some message? we should add it here if so
  12509. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12510. WFIFOW(f_sd->fd,0) = 0x20a;
  12511. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12512. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12513. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12514. }
  12515. } else { //friend not online -- ask char server to delete from his friendlist
  12516. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12517. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12518. return;
  12519. }
  12520. }
  12521. // We can now delete from original requester
  12522. for (i = 0; i < MAX_FRIENDS &&
  12523. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12524. // move all chars up
  12525. for(j = i + 1; j < MAX_FRIENDS; j++)
  12526. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12527. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12528. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12529. WFIFOHEAD(fd,packet_len(0x20a));
  12530. WFIFOW(fd,0) = 0x20a;
  12531. WFIFOL(fd,2) = account_id;
  12532. WFIFOL(fd,6) = char_id;
  12533. WFIFOSET(fd, packet_len(0x20a));
  12534. }
  12535. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12536. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12537. void clif_PVPInfo(struct map_session_data* sd)
  12538. {
  12539. int fd = sd->fd;
  12540. WFIFOHEAD(fd,packet_len(0x210));
  12541. WFIFOW(fd,0) = 0x210;
  12542. WFIFOL(fd,2) = sd->status.char_id;
  12543. WFIFOL(fd,6) = sd->status.account_id;
  12544. WFIFOL(fd,10) = sd->pvp_won; // times won
  12545. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12546. WFIFOL(fd,18) = sd->pvp_point;
  12547. WFIFOSET(fd, packet_len(0x210));
  12548. }
  12549. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12550. /// 020f <char id>.L <account id>.L
  12551. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12552. {
  12553. // TODO: Is there a way to use this on an another player (char/acc id)?
  12554. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12555. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12556. clif_PVPInfo(sd);
  12557. }
  12558. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12559. /// 0254 <which>.B
  12560. /// which: (unused atm for security purpose)
  12561. /// 0 = sun
  12562. /// 1 = moon
  12563. /// 2 = star
  12564. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12565. {
  12566. int i;
  12567. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12568. if (sd->menuskill_id != SG_FEEL)
  12569. return;
  12570. i = sd->menuskill_val-1;
  12571. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12572. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12573. sd->feel_map[i].m = sd->bl.m;
  12574. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12575. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12576. // clif_misceffect2(&sd->bl, 0x1b0);
  12577. // clif_misceffect2(&sd->bl, 0x21f);
  12578. clif_feel_info(sd, i, 0);
  12579. clif_menuskill_clear(sd);
  12580. }
  12581. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12582. /// 0253 <which>.B
  12583. /// which:
  12584. /// 0 = sun
  12585. /// 1 = moon
  12586. /// 2 = star
  12587. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12588. {
  12589. WFIFOHEAD(fd,packet_len(0x253));
  12590. WFIFOW(fd,0)=0x253;
  12591. WFIFOB(fd,2)=TOB(skill_lv-1);
  12592. WFIFOSET(fd, packet_len(0x253));
  12593. sd->menuskill_id = SG_FEEL;
  12594. sd->menuskill_val = skill_lv;
  12595. }
  12596. /// Request to change homunculus' name (CZ_RENAME_MER).
  12597. /// 0231 <name>.24B
  12598. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12599. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12600. }
  12601. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12602. /// 0234 <id>.L
  12603. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12604. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12605. struct block_list *bl = NULL;
  12606. struct unit_data *ud = NULL;
  12607. if( sd->md && sd->md->bl.id == id )
  12608. bl = &sd->md->bl;
  12609. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12610. bl = &sd->hd->bl; // Moving Homunculus
  12611. else
  12612. return;
  12613. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12614. ud = unit_bl2ud(bl);
  12615. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12616. }
  12617. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12618. /// 0232 <id>.L <position data>.3B
  12619. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12620. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12621. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12622. struct block_list *bl = NULL;
  12623. short x, y;
  12624. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12625. if( sd->md && sd->md->bl.id == id )
  12626. bl = &sd->md->bl; // Moving Mercenary
  12627. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12628. bl = &sd->hd->bl; // Moving Homunculus
  12629. else
  12630. return;
  12631. unit_walktoxy(bl, x, y, 4);
  12632. }
  12633. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12634. /// 0233 <id>.L <target id>.L <action>.B
  12635. /// action:
  12636. /// always 0
  12637. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12638. {
  12639. struct block_list *bl = NULL;
  12640. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12641. int id = RFIFOL(fd,info->pos[0]);
  12642. int target_id = RFIFOL(fd,info->pos[1]);
  12643. int action_type = RFIFOB(fd,info->pos[2]);
  12644. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12645. bl = &sd->hd->bl;
  12646. else if( sd->md && sd->md->bl.id == id )
  12647. bl = &sd->md->bl;
  12648. else return;
  12649. unit_stop_attack(bl);
  12650. unit_attack(bl, target_id, action_type != 0);
  12651. }
  12652. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12653. /// 022d <type>.W <command>.B
  12654. /// type:
  12655. /// always 0
  12656. /// command:
  12657. /// 0 = homunculus information
  12658. /// 1 = feed
  12659. /// 2 = delete
  12660. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12661. { //[orn]
  12662. int cmd = RFIFOW(fd,0);
  12663. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12664. if(!hom_is_active(sd->hd))
  12665. return;
  12666. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12667. }
  12668. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12669. /// 0292
  12670. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12671. {
  12672. pc_revive_item(sd);
  12673. }
  12674. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12675. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12676. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12677. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12678. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12679. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12680. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12681. void clif_check(int fd, struct map_session_data* pl_sd)
  12682. {
  12683. WFIFOHEAD(fd,packet_len(0x214));
  12684. WFIFOW(fd, 0) = 0x214;
  12685. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12686. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12687. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12688. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12689. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12690. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12691. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12692. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12693. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12694. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12695. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12696. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12697. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12698. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12699. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12700. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12701. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12702. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12703. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12704. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12705. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12706. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12707. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12708. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12709. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12710. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12711. WFIFOSET(fd,packet_len(0x214));
  12712. }
  12713. /// /check (CZ_REQ_STATUS_GM).
  12714. /// Request character's status values.
  12715. /// 0213 <char name>.24B
  12716. void clif_parse_Check(int fd, struct map_session_data *sd)
  12717. {
  12718. char charname[NAME_LENGTH];
  12719. struct map_session_data* pl_sd;
  12720. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12721. return;
  12722. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12723. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12724. {
  12725. return;
  12726. }
  12727. clif_check(fd, pl_sd);
  12728. }
  12729. /// MAIL SYSTEM
  12730. /// By Zephyrus
  12731. ///
  12732. /// Notification about the result of adding an item to mail
  12733. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12734. /// result:
  12735. /// 0 = success
  12736. /// 1 = failure
  12737. /// 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)
  12738. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12739. /// result:
  12740. /// 0 = success
  12741. /// 1 = over weight
  12742. /// 2 = fatal error
  12743. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  12744. int fd = sd->fd;
  12745. #if PACKETVER < 20150513
  12746. WFIFOHEAD(fd,packet_len(0x255));
  12747. WFIFOW(fd,0) = 0x255;
  12748. WFIFOW(fd,2) = index;
  12749. WFIFOB(fd,4) = flag;
  12750. WFIFOSET(fd,packet_len(0x255));
  12751. #else
  12752. struct PACKET_ZC_ADD_ITEM_TO_MAIL p;
  12753. if( flag ){
  12754. memset( &p, 0, sizeof( p ) );
  12755. }else{
  12756. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  12757. p.index = index;
  12758. p.count = amount;
  12759. p.itemId = client_nameid( item->nameid );
  12760. p.type = itemtype( item->nameid );
  12761. p.IsIdentified = item->identify ? 1 : 0;
  12762. p.IsDamaged = item->attribute ? 1 : 0;
  12763. p.refiningLevel = item->refine;
  12764. clif_addcards( &p.slot, item );
  12765. clif_add_random_options( p.optionData, item );
  12766. p.weight = 0;
  12767. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  12768. if( sd->mail.item[i].nameid == 0 ){
  12769. continue;
  12770. }
  12771. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12772. }
  12773. p.favorite = item->favorite;
  12774. p.location = pc_equippoint( sd, server_index( index ) );
  12775. }
  12776. p.PacketType = rodexadditem;
  12777. p.result = flag;
  12778. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  12779. #endif
  12780. }
  12781. /// Notification about the result of retrieving a mail attachment
  12782. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12783. /// result:
  12784. /// 0 = success
  12785. /// 1 = failure
  12786. /// 2 = too many items
  12787. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12788. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12789. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12790. int fd = sd->fd;
  12791. #if PACKETVER < 20150513
  12792. WFIFOHEAD(fd,packet_len(0x245));
  12793. WFIFOW(fd,0) = 0x245;
  12794. WFIFOB(fd,2) = result;
  12795. WFIFOSET(fd,packet_len(0x245));
  12796. #else
  12797. switch( type ){
  12798. case MAIL_ATT_ITEM:
  12799. case MAIL_ATT_ZENY:
  12800. break;
  12801. default:
  12802. return;
  12803. }
  12804. WFIFOHEAD(fd, 12);
  12805. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12806. WFIFOQ(fd, 2) = msg->id;
  12807. WFIFOB(fd, 10) = msg->type;
  12808. WFIFOB(fd, 11) = result;
  12809. WFIFOSET(fd, 12);
  12810. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12811. #endif
  12812. }
  12813. /// Notification about the result of sending a mail
  12814. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12815. /// result:
  12816. /// 0 = success
  12817. /// 1 = recipinent does not exist
  12818. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12819. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12820. int fd = sd->fd;
  12821. #if PACKETVER < 20150513
  12822. WFIFOHEAD(fd,packet_len(0x249));
  12823. WFIFOW(fd,0) = 0x249;
  12824. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12825. WFIFOSET(fd,packet_len(0x249));
  12826. #else
  12827. WFIFOHEAD(fd, 3);
  12828. WFIFOW(fd, 0) = 0x9ed;
  12829. WFIFOB(fd, 2) = result;
  12830. WFIFOSET(fd, 3);
  12831. #endif
  12832. }
  12833. /// Notification about the result of deleting a mail.
  12834. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12835. /// result:
  12836. /// 0 = success
  12837. /// 1 = failure
  12838. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12839. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12840. int fd = sd->fd;
  12841. #if PACKETVER < 20150513
  12842. WFIFOHEAD(fd, packet_len(0x257));
  12843. WFIFOW(fd,0) = 0x257;
  12844. WFIFOL(fd,2) = msg->id;
  12845. WFIFOW(fd,6) = !success;
  12846. WFIFOSET(fd, packet_len(0x257));
  12847. #else
  12848. // This is only a success notification
  12849. if( success ){
  12850. WFIFOHEAD(fd, 11);
  12851. WFIFOW(fd, 0) = 0x9f6;
  12852. WFIFOB(fd, 2) = msg->type;
  12853. WFIFOQ(fd, 3) = msg->id;
  12854. WFIFOSET(fd, 11);
  12855. }
  12856. #endif
  12857. }
  12858. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12859. /// 0274 <mail id>.L <result>.W
  12860. /// result:
  12861. /// 0 = success
  12862. /// 1 = failure
  12863. void clif_Mail_return(int fd, int mail_id, short fail)
  12864. {
  12865. WFIFOHEAD(fd,packet_len(0x274));
  12866. WFIFOW(fd,0) = 0x274;
  12867. WFIFOL(fd,2) = mail_id;
  12868. WFIFOW(fd,6) = fail;
  12869. WFIFOSET(fd,packet_len(0x274));
  12870. }
  12871. /// Notification about new mail.
  12872. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12873. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12874. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12875. int fd = sd->fd;
  12876. #if PACKETVER < 20150513
  12877. WFIFOHEAD(fd,packet_len(0x24a));
  12878. WFIFOW(fd,0) = 0x24a;
  12879. WFIFOL(fd,2) = mail_id;
  12880. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12881. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12882. WFIFOSET(fd,packet_len(0x24a));
  12883. #else
  12884. WFIFOHEAD(fd,3);
  12885. WFIFOW(fd,0) = 0x9e7;
  12886. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12887. WFIFOSET(fd,3);
  12888. #endif
  12889. }
  12890. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12891. /// 0260 <type>.L
  12892. /// type:
  12893. /// 0 = open
  12894. /// 1 = close
  12895. void clif_Mail_window(int fd, int flag)
  12896. {
  12897. WFIFOHEAD(fd,packet_len(0x260));
  12898. WFIFOW(fd,0) = 0x260;
  12899. WFIFOL(fd,2) = flag;
  12900. WFIFOSET(fd,packet_len(0x260));
  12901. }
  12902. /// Lists mails stored in inbox.
  12903. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12904. /// read:
  12905. /// 0 = unread
  12906. /// 1 = read
  12907. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12908. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12909. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12910. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12911. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12912. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12913. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12914. #if PACKETVER < 20150513
  12915. int fd = sd->fd;
  12916. struct mail_data *md = &sd->mail.inbox;
  12917. struct mail_message *msg;
  12918. int len, i, j;
  12919. len = 8 + (73 * md->amount);
  12920. WFIFOHEAD(fd,len);
  12921. WFIFOW(fd,0) = 0x240;
  12922. WFIFOW(fd,2) = len;
  12923. WFIFOL(fd,4) = md->amount;
  12924. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12925. {
  12926. msg = &md->msg[i];
  12927. if (msg->id < 1)
  12928. continue;
  12929. WFIFOL(fd,8+73*j) = msg->id;
  12930. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12931. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12932. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12933. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12934. j++;
  12935. }
  12936. WFIFOSET(fd,len);
  12937. if( md->full ) {// TODO: is this official?
  12938. char output[100];
  12939. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12940. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12941. }
  12942. #else
  12943. int fd = sd->fd;
  12944. struct mail_data *md = &sd->mail.inbox;
  12945. struct mail_message *msg;
  12946. int i, j, k, offset, titleLength;
  12947. uint8 mailType, amount, remaining;
  12948. uint32 now = (uint32)time(NULL);
  12949. #if PACKETVER >= 20170419
  12950. int cmd = 0xac2;
  12951. #elif PACKETVER >= 20160601
  12952. int cmd = 0xa7d;
  12953. #else
  12954. int cmd = 0x9f0;
  12955. #endif
  12956. if( battle_config.mail_daily_count ){
  12957. mail_refresh_remaining_amount(sd);
  12958. }
  12959. #if PACKETVER >= 20170419
  12960. // Always send all
  12961. i = md->amount;
  12962. #else
  12963. // If a starting mail id was sent
  12964. if( mailID != 0 ){
  12965. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  12966. // Unknown mail
  12967. if( i == md->amount ){
  12968. // Ignore the request for now
  12969. return; // TODO: Should we just show the first page instead?
  12970. }
  12971. // It was actually the oldest/first mail, there is no further page
  12972. if( i == 0 ){
  12973. return;
  12974. }
  12975. // We actually want the next/older mail
  12976. i -= 1;
  12977. }else{
  12978. i = md->amount;
  12979. }
  12980. #endif
  12981. // Count the remaining mails from the starting mail or the beginning
  12982. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  12983. for( j = i, remaining = 0; j >= 0; j-- ){
  12984. msg = &md->msg[j];
  12985. if (msg->id < 1)
  12986. continue;
  12987. #if PACKETVER < 20170419
  12988. if (msg->type != type)
  12989. continue;
  12990. #endif
  12991. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12992. continue;
  12993. remaining++;
  12994. }
  12995. #if PACKETVER >= 20170419
  12996. // Always send all
  12997. amount = remaining;
  12998. #else
  12999. if( remaining > MAIL_PAGE_SIZE ){
  13000. amount = MAIL_PAGE_SIZE;
  13001. }else{
  13002. amount = remaining;
  13003. }
  13004. #endif
  13005. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13006. WFIFOW(fd, 0) = cmd;
  13007. #if PACKETVER >= 20170419
  13008. WFIFOB(fd, 4) = 1; // Unknown
  13009. offset = 5;
  13010. #else
  13011. WFIFOB(fd, 4) = type;
  13012. WFIFOB(fd, 5) = amount;
  13013. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13014. offset = 7;
  13015. #endif
  13016. for( amount = 0; i >= 0; i-- ){
  13017. msg = &md->msg[i];
  13018. if (msg->id < 1)
  13019. continue;
  13020. #if PACKETVER < 20170419
  13021. if (msg->type != type)
  13022. continue;
  13023. #endif
  13024. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13025. continue;
  13026. #if PACKETVER >= 20170419
  13027. WFIFOB(fd, offset) = msg->type;
  13028. offset += 1;
  13029. #endif
  13030. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13031. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13032. mailType = MAIL_TYPE_TEXT; // Normal letter
  13033. if( msg->zeny > 0 ){
  13034. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13035. }
  13036. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13037. if( msg->item[k].nameid > 0 ){
  13038. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13039. break;
  13040. }
  13041. }
  13042. #if PACKETVER >= 20170419
  13043. // If it came from an npc?
  13044. if( !msg->send_id ){
  13045. mailType |= MAIL_TYPE_NPC;
  13046. }
  13047. #endif
  13048. WFIFOB(fd, offset + 9) = mailType;
  13049. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13050. #if PACKETVER < 20170419
  13051. // How much time has passed since you received the mail
  13052. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13053. offset += 4;
  13054. #endif
  13055. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13056. if( msg->scheduled_deletion > 0 ){
  13057. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13058. }else{
  13059. // Fake the scheduled deletion to one year in the future
  13060. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13061. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13062. }
  13063. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13064. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13065. offset += 40 + titleLength;
  13066. }
  13067. WFIFOW(fd, 2) = (int16)offset;
  13068. WFIFOSET(fd, offset);
  13069. #endif
  13070. }
  13071. /// Mail inbox list request.
  13072. /// 023f (CZ_MAIL_GET_LIST)
  13073. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13074. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13075. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13076. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13077. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13078. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13079. #if PACKETVER < 20150513
  13080. struct mail_data* md = &sd->mail.inbox;
  13081. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13082. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13083. else
  13084. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13085. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13086. mail_removezeny(sd, false);
  13087. #else
  13088. int cmd = RFIFOW(fd, 0);
  13089. #if PACKETVER < 20170419
  13090. uint8 openType = RFIFOB(fd, 2);
  13091. uint64 mailId = RFIFOQ(fd, 3);
  13092. #else
  13093. uint8 openType;
  13094. uint64 mailId = RFIFOQ(fd, 2);
  13095. int i;
  13096. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13097. if( i == MAIL_MAX_INBOX ){
  13098. openType = MAIL_INBOX_NORMAL;
  13099. mailId = 0;
  13100. }else{
  13101. openType = sd->mail.inbox.msg[i].type;
  13102. mailId = 0;
  13103. }
  13104. #endif
  13105. switch( openType ){
  13106. case MAIL_INBOX_NORMAL:
  13107. case MAIL_INBOX_ACCOUNT:
  13108. case MAIL_INBOX_RETURNED:
  13109. break;
  13110. default:
  13111. // Unknown type: ignore request
  13112. return;
  13113. }
  13114. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13115. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13116. return;
  13117. }
  13118. // If it is not a next page request
  13119. if( cmd != 0x9ee ){
  13120. mailId = 0;
  13121. }
  13122. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13123. #endif
  13124. }
  13125. /// Opens a mail
  13126. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13127. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13128. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13129. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13130. /// { }*n
  13131. // TODO: Packet description => for repeated block
  13132. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13133. int i, fd = sd->fd;
  13134. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13135. if( i == MAIL_MAX_INBOX ) {
  13136. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13137. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13138. return;
  13139. } else {
  13140. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13141. struct item *item;
  13142. struct item_data *data;
  13143. int msg_len = strlen(msg->body);
  13144. if( msg_len == 0 ) {
  13145. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13146. msg_len = strlen(msg->body);
  13147. }
  13148. #if PACKETVER < 20150513
  13149. item = &msg->item[0];
  13150. int len = 101 + msg_len;
  13151. WFIFOHEAD(fd,len);
  13152. WFIFOW(fd,0) = 0x242;
  13153. WFIFOW(fd,2) = len;
  13154. WFIFOL(fd,4) = msg->id;
  13155. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13156. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13157. WFIFOL(fd,72) = 0;
  13158. WFIFOL(fd,76) = msg->zeny;
  13159. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13160. WFIFOL(fd,80) = item->amount;
  13161. WFIFOW(fd,84) = client_nameid( item->nameid );
  13162. WFIFOW(fd,86) = itemtype( item->nameid );
  13163. WFIFOB(fd,88) = item->identify;
  13164. WFIFOB(fd,89) = item->attribute;
  13165. WFIFOB(fd,90) = item->refine;
  13166. WFIFOW(fd,91) = item->card[0];
  13167. WFIFOW(fd,93) = item->card[1];
  13168. WFIFOW(fd,95) = item->card[2];
  13169. WFIFOW(fd,97) = item->card[3];
  13170. } else // no item, set all to zero
  13171. memset(WFIFOP(fd,80), 0x00, 19);
  13172. WFIFOB(fd,99) = (unsigned char)msg_len;
  13173. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13174. WFIFOSET(fd,len);
  13175. #else
  13176. msg_len += 1; // Zero Termination
  13177. int length = sizeof( struct PACKET_ZC_READ_MAIL ) + MAIL_BODY_LENGTH + sizeof( struct mail_item ) * MAIL_MAX_ITEM;
  13178. WFIFOHEAD( fd, length );
  13179. struct PACKET_ZC_READ_MAIL *p = (struct PACKET_ZC_READ_MAIL *)WFIFOP( fd, 0 );
  13180. p->PacketType = rodexread;
  13181. p->PacketLength = length;
  13182. p->opentype = msg->type;
  13183. p->MailID = msg->id;
  13184. p->TextcontentsLength = msg_len;
  13185. p->zeny = msg->zeny;
  13186. int offset = sizeof( struct PACKET_ZC_READ_MAIL );
  13187. safestrncpy( WFIFOCP( fd, offset ), msg->body, msg_len );
  13188. offset += msg_len;
  13189. int count = 0;
  13190. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13191. item = &msg->item[j];
  13192. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13193. struct mail_item* mailitem = (struct mail_item *)WFIFOP( fd, offset );
  13194. mailitem->ITID = client_nameid( item->nameid );
  13195. mailitem->count = item->amount;
  13196. mailitem->type = itemtype( item->nameid );
  13197. mailitem->IsIdentified = item->identify ? 1 : 0;
  13198. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13199. mailitem->refiningLevel = item->refine;
  13200. mailitem->location = pc_equippoint_sub( sd, data );
  13201. mailitem->viewSprite = data->look;
  13202. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13203. clif_addcards( &mailitem->slot, item );
  13204. clif_add_random_options( mailitem->optionData, item );
  13205. offset += sizeof( struct mail_item );
  13206. count++;
  13207. }
  13208. }
  13209. p->ItemCnt = count;
  13210. p->PacketLength = sizeof( struct PACKET_ZC_READ_MAIL ) + p->TextcontentsLength + sizeof( struct mail_item ) * p->ItemCnt;
  13211. WFIFOSET( fd, p->PacketLength );
  13212. #endif
  13213. if (msg->status == MAIL_UNREAD) {
  13214. msg->status = MAIL_READ;
  13215. intif_Mail_read(mail_id);
  13216. clif_parse_Mail_refreshinbox(fd, sd);
  13217. sd->mail.inbox.unread--;
  13218. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13219. }
  13220. }
  13221. }
  13222. /// Request to open a mail.
  13223. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13224. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13225. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13226. #if PACKETVER < 20150513
  13227. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13228. #else
  13229. //uint8 openType = RFIFOB(fd, 2);
  13230. int mail_id = (int)RFIFOQ(fd, 3);
  13231. #endif
  13232. if( mail_id <= 0 )
  13233. return;
  13234. if( mail_invalid_operation(sd) )
  13235. return;
  13236. clif_Mail_read(sd, mail_id);
  13237. }
  13238. /// Allow a player to begin writing a mail
  13239. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13240. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13241. int fd = sd->fd;
  13242. WFIFOHEAD(fd, 27);
  13243. WFIFOW(fd, 0) = 0xa12;
  13244. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13245. WFIFOB(fd, 26) = success;
  13246. WFIFOSET(fd, 27);
  13247. }
  13248. /// Request to start writing a mail
  13249. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13250. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13251. char name[NAME_LENGTH];
  13252. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13253. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13254. clif_send_Mail_beginwrite_ack(sd, name, false);
  13255. return;
  13256. }
  13257. mail_clear(sd);
  13258. sd->state.mail_writing = true;
  13259. clif_send_Mail_beginwrite_ack(sd, name,true);
  13260. }
  13261. /// Notification that the client cancelled writing a mail
  13262. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13263. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13264. sd->state.mail_writing = false;
  13265. }
  13266. /// Give the client information about the recipient, if available
  13267. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13268. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13269. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13270. int fd = sd->fd;
  13271. #if PACKETVER <= 20160302
  13272. int cmd = 0xa14;
  13273. #else
  13274. int cmd = 0xa51;
  13275. #endif
  13276. WFIFOHEAD(fd, packet_len(cmd));
  13277. WFIFOW(fd, 0) = cmd;
  13278. WFIFOL(fd, 2) = char_id;
  13279. WFIFOW(fd, 6) = class_;
  13280. WFIFOW(fd, 8) = level;
  13281. #if PACKETVER >= 20160302
  13282. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13283. #endif
  13284. WFIFOSET(fd, packet_len(cmd));
  13285. }
  13286. /// Request information about the recipient
  13287. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13288. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13289. static char name[NAME_LENGTH];
  13290. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13291. intif_mail_checkreceiver(sd, name);
  13292. }
  13293. /// Request to receive mail's attachment.
  13294. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13295. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13296. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13297. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13298. int i;
  13299. struct mail_message* msg;
  13300. #if PACKETVER < 20150513
  13301. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13302. int attachment = MAIL_ATT_ALL;
  13303. #else
  13304. uint16 packet_id = RFIFOW(fd, 0);
  13305. int mail_id = (int)RFIFOQ(fd, 2);
  13306. //int openType = RFIFOB(fd, 10);
  13307. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13308. #endif
  13309. if( !chrif_isconnected() )
  13310. return;
  13311. if( mail_id <= 0 )
  13312. return;
  13313. if( mail_invalid_operation(sd) )
  13314. return;
  13315. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13316. if( i == MAIL_MAX_INBOX )
  13317. return;
  13318. msg = &sd->mail.inbox.msg[i];
  13319. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13320. attachment &= ~MAIL_ATT_ZENY;
  13321. }
  13322. if( attachment&MAIL_ATT_ITEM ){
  13323. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13324. // No items were found
  13325. if( i == MAIL_MAX_ITEM ){
  13326. attachment &= ~MAIL_ATT_ITEM;
  13327. }
  13328. }
  13329. // Either no attachment requested at all or there are no zeny or items in the mail
  13330. if( attachment == MAIL_ATT_NONE ){
  13331. return;
  13332. }
  13333. if( attachment&MAIL_ATT_ZENY ){
  13334. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13335. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13336. return;
  13337. }else{
  13338. // To make sure another request fails
  13339. msg->zeny = 0;
  13340. }
  13341. }
  13342. if( attachment&MAIL_ATT_ITEM ){
  13343. int new_ = 0, totalweight = 0;
  13344. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13345. struct item* item = &msg->item[i];
  13346. if( item->nameid > 0 && item->amount > 0 ){
  13347. struct item_data *data;
  13348. if((data = itemdb_exists(item->nameid)) == NULL)
  13349. continue;
  13350. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13351. case CHKADDITEM_NEW:
  13352. new_++;
  13353. break;
  13354. case CHKADDITEM_OVERAMOUNT:
  13355. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13356. return;
  13357. }
  13358. totalweight += data->weight * item->amount;
  13359. }
  13360. }
  13361. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13362. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13363. return;
  13364. }else if( pc_inventoryblank(sd) < new_ ){
  13365. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13366. return;
  13367. }
  13368. // To make sure another request fails
  13369. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13370. }
  13371. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13372. clif_Mail_read(sd, mail_id);
  13373. }
  13374. /// Request to delete a mail.
  13375. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13376. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13377. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13378. #if PACKETVER < 20150513
  13379. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13380. #else
  13381. //int openType = RFIFOB(fd, 2);
  13382. int mail_id = (int)RFIFOQ(fd, 3);
  13383. #endif
  13384. int i, j;
  13385. if( !chrif_isconnected() )
  13386. return;
  13387. if( mail_id <= 0 )
  13388. return;
  13389. if( mail_invalid_operation(sd) )
  13390. return;
  13391. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13392. if (i < MAIL_MAX_INBOX) {
  13393. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13394. // can't delete mail without removing zeny first
  13395. if( msg->zeny > 0 ){
  13396. clif_mail_delete(sd, msg, false);
  13397. return;
  13398. }
  13399. // can't delete mail without removing attachment(s) first
  13400. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13401. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13402. clif_mail_delete(sd, msg, false);
  13403. return;
  13404. }
  13405. }
  13406. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13407. sd->mail.inbox.unread--;
  13408. clif_Mail_new(sd,0,NULL,NULL);
  13409. }
  13410. }
  13411. }
  13412. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13413. /// 0273 <mail id>.L <receive name>.24B
  13414. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13415. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13416. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13417. int i;
  13418. if( mail_id <= 0 )
  13419. return;
  13420. if( mail_invalid_operation(sd) )
  13421. return;
  13422. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13423. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13424. intif_Mail_return(sd->status.char_id, mail_id);
  13425. else
  13426. clif_Mail_return(sd->fd, mail_id, 1);
  13427. }
  13428. /// Request to add an item or Zeny to mail.
  13429. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13430. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13431. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13432. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13433. int idx = RFIFOW(fd,info->pos[0]);
  13434. #if PACKETVER < 20150513
  13435. int amount = RFIFOL(fd,info->pos[1]);
  13436. #else
  13437. int amount = RFIFOW(fd,info->pos[1]);
  13438. #endif
  13439. unsigned char flag;
  13440. if( !chrif_isconnected() )
  13441. return;
  13442. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13443. return;
  13444. flag = mail_setitem(sd, idx, amount);
  13445. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13446. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13447. }else{
  13448. clif_Mail_setattachment(sd,idx,amount,flag);
  13449. }
  13450. }
  13451. /// Remove an item from a mail
  13452. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13453. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13454. int fd = sd->fd;
  13455. WFIFOHEAD(fd, 9);
  13456. WFIFOW(fd, 0) = 0xa07;
  13457. WFIFOB(fd, 2) = success;
  13458. WFIFOW(fd, 3) = index;
  13459. WFIFOW(fd, 5) = amount;
  13460. int total = 0;
  13461. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13462. if( sd->mail.item[i].nameid == 0 ){
  13463. break;
  13464. }
  13465. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13466. }
  13467. WFIFOW(fd, 7) = total;
  13468. WFIFOSET(fd, 9);
  13469. }
  13470. /// Request to reset mail item and/or Zeny
  13471. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13472. /// type:
  13473. /// 0 = reset all
  13474. /// 1 = remove item
  13475. /// 2 = remove zeny
  13476. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13477. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13478. {
  13479. #if PACKETVER < 20150513
  13480. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13481. if (type == 0 || type == 1)
  13482. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13483. if (type == 0 || type == 2)
  13484. mail_removezeny(sd, false);
  13485. #else
  13486. uint16 index = RFIFOW(fd, 2);
  13487. uint16 count = RFIFOW(fd, 4);
  13488. mail_removeitem(sd,0,index,count);
  13489. #endif
  13490. }
  13491. /// Request to send mail
  13492. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13493. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13494. /// 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)
  13495. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13496. #if PACKETVER < 20150513
  13497. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13498. if( !chrif_isconnected() )
  13499. return;
  13500. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13501. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13502. return;
  13503. }
  13504. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13505. #else
  13506. uint16 length = RFIFOW(fd, 2);
  13507. if( length < 0x3e ){
  13508. ShowWarning("Too short...\n");
  13509. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13510. return;
  13511. }
  13512. // Forged request without a begin writing packet?
  13513. if( !sd->state.mail_writing ){
  13514. return; // Ignore it
  13515. }
  13516. char receiver[NAME_LENGTH];
  13517. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13518. // char sender[NAME_LENGTH];
  13519. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13520. uint64 zeny = RFIFOQ(fd, 52);
  13521. uint16 titleLength = RFIFOW(fd, 60);
  13522. uint16 textLength = RFIFOW(fd, 62);
  13523. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13524. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13525. char title[MAIL_TITLE_LENGTH];
  13526. char text[MAIL_BODY_LENGTH];
  13527. #if PACKETVER <= 20160330
  13528. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13529. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13530. #else
  13531. // 64 = <char id>.L
  13532. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13533. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13534. #endif
  13535. if( zeny > 0 ){
  13536. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13537. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13538. return;
  13539. }
  13540. }
  13541. mail_send(sd, receiver, title, text, realTextLength);
  13542. #endif
  13543. }
  13544. /// AUCTION SYSTEM
  13545. /// By Zephyrus
  13546. ///
  13547. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13548. /// 025f <type>.L
  13549. /// type:
  13550. /// 0 = open
  13551. /// 1 = close
  13552. void clif_Auction_openwindow(struct map_session_data *sd)
  13553. {
  13554. int fd = sd->fd;
  13555. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13556. return;
  13557. if( !battle_config.feature_auction )
  13558. return;
  13559. WFIFOHEAD(fd,packet_len(0x25f));
  13560. WFIFOW(fd,0) = 0x25f;
  13561. WFIFOL(fd,2) = 0;
  13562. WFIFOSET(fd,packet_len(0x25f));
  13563. }
  13564. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13565. /// 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 }*
  13566. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13567. {
  13568. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13569. struct auction_data auction;
  13570. WFIFOHEAD(fd,12 + (count * 83));
  13571. WFIFOW(fd,0) = 0x252;
  13572. WFIFOW(fd,2) = 12 + (count * 83);
  13573. WFIFOL(fd,4) = pages;
  13574. WFIFOL(fd,8) = count;
  13575. for( i = 0; i < count; i++ ) {
  13576. int k = 12 + (i * 83);
  13577. memcpy(&auction, RBUFP(buf,i * len), len);
  13578. WFIFOL(fd,k) = auction.auction_id;
  13579. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13580. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13581. WFIFOL(fd,30+k) = auction.type;
  13582. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13583. WFIFOB(fd,36+k) = auction.item.identify;
  13584. WFIFOB(fd,37+k) = auction.item.attribute;
  13585. WFIFOB(fd,38+k) = auction.item.refine;
  13586. WFIFOW(fd,39+k) = auction.item.card[0];
  13587. WFIFOW(fd,41+k) = auction.item.card[1];
  13588. WFIFOW(fd,43+k) = auction.item.card[2];
  13589. WFIFOW(fd,45+k) = auction.item.card[3];
  13590. WFIFOL(fd,47+k) = auction.price;
  13591. WFIFOL(fd,51+k) = auction.buynow;
  13592. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13593. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13594. }
  13595. WFIFOSET(fd,WFIFOW(fd,2));
  13596. }
  13597. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13598. /// 0256 <index>.W <result>.B
  13599. /// result:
  13600. /// 0 = success
  13601. /// 1 = failure
  13602. static void clif_Auction_setitem(int fd, int index, bool fail)
  13603. {
  13604. WFIFOHEAD(fd,packet_len(0x256));
  13605. WFIFOW(fd,0) = 0x256;
  13606. WFIFOW(fd,2) = index;
  13607. WFIFOB(fd,4) = fail;
  13608. WFIFOSET(fd,packet_len(0x256));
  13609. }
  13610. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13611. /// 024b <type>.W
  13612. /// type:
  13613. /// 0 = create (any other action in auction window)
  13614. /// 1 = cancel (cancel pressed on register tab)
  13615. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13616. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13617. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13618. if( sd->auction.amount > 0 )
  13619. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13620. sd->auction.amount = 0;
  13621. }
  13622. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13623. /// 024c <index>.W <count>.L
  13624. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13625. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13626. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13627. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13628. struct item_data *item;
  13629. if( !battle_config.feature_auction )
  13630. return;
  13631. if( sd->auction.amount > 0 )
  13632. sd->auction.amount = 0;
  13633. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13634. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13635. return;
  13636. }
  13637. 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.
  13638. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13639. return;
  13640. }
  13641. 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) )
  13642. { // Consumable or pets are not allowed
  13643. clif_Auction_setitem(sd->fd, idx, true);
  13644. return;
  13645. }
  13646. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13647. !sd->inventory.u.items_inventory[idx].identify ||
  13648. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13649. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13650. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13651. clif_Auction_setitem(sd->fd, idx, true);
  13652. return;
  13653. }
  13654. sd->auction.index = idx;
  13655. sd->auction.amount = amount;
  13656. clif_Auction_setitem(fd, idx + 2, false);
  13657. }
  13658. /// Result from an auction action (ZC_AUCTION_RESULT).
  13659. /// 0250 <result>.B
  13660. /// result:
  13661. /// 0 = You have failed to bid into the auction
  13662. /// 1 = You have successfully bid in the auction
  13663. /// 2 = The auction has been canceled
  13664. /// 3 = An auction with at least one bidder cannot be canceled
  13665. /// 4 = You cannot register more than 5 items in an auction at a time
  13666. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13667. /// 6 = You have won the auction
  13668. /// 7 = You have failed to win the auction
  13669. /// 8 = You do not have enough Zeny
  13670. /// 9 = You cannot place more than 5 bids at a time
  13671. void clif_Auction_message(int fd, unsigned char flag)
  13672. {
  13673. WFIFOHEAD(fd,packet_len(0x250));
  13674. WFIFOW(fd,0) = 0x250;
  13675. WFIFOB(fd,2) = flag;
  13676. WFIFOSET(fd,packet_len(0x250));
  13677. }
  13678. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13679. /// 025e <result>.W
  13680. /// result:
  13681. /// 0 = You have ended the auction
  13682. /// 1 = You cannot end the auction
  13683. /// 2 = Auction ID is incorrect
  13684. void clif_Auction_close(int fd, unsigned char flag)
  13685. {
  13686. WFIFOHEAD(fd,packet_len(0x25e));
  13687. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13688. WFIFOW(fd,2) = flag;
  13689. WFIFOSET(fd,packet_len(0x25e));
  13690. }
  13691. /// Request to add an auction (CZ_AUCTION_ADD).
  13692. /// 024d <now money>.L <max money>.L <delete hour>.W
  13693. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13694. {
  13695. struct auction_data auction;
  13696. struct item_data *item;
  13697. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13698. if( !battle_config.feature_auction )
  13699. return;
  13700. auction.price = RFIFOL(fd,info->pos[0]);
  13701. auction.buynow = RFIFOL(fd,info->pos[1]);
  13702. auction.hours = RFIFOW(fd,info->pos[2]);
  13703. // Invalid Situations...
  13704. if( sd->auction.amount < 1 ) {
  13705. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13706. return;
  13707. }
  13708. if( auction.price >= auction.buynow ) {
  13709. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13710. return;
  13711. }
  13712. if( auction.hours < 1 || auction.hours > 48 ) {
  13713. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13714. return;
  13715. }
  13716. // Auction checks...
  13717. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13718. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13719. clif_Auction_message(fd, 2); // The auction has been canceled
  13720. return;
  13721. }
  13722. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13723. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13724. return;
  13725. }
  13726. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13727. auction.buynow = battle_config.auction_maximumprice;
  13728. if( auction.price >= auction.buynow )
  13729. auction.price = auction.buynow - 1;
  13730. }
  13731. auction.auction_id = 0;
  13732. auction.seller_id = sd->status.char_id;
  13733. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13734. auction.buyer_id = 0;
  13735. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13736. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13737. {
  13738. clif_Auction_message(fd, 2); // The auction has been canceled
  13739. return;
  13740. }
  13741. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13742. { // Just in case
  13743. clif_Auction_message(fd, 2); // The auction has been canceled
  13744. return;
  13745. }
  13746. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13747. auction.type = item->type;
  13748. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13749. auction.item.amount = 1;
  13750. auction.timestamp = 0;
  13751. if( !intif_Auction_register(&auction) )
  13752. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13753. else
  13754. {
  13755. int zeny = auction.hours*battle_config.auction_feeperhour;
  13756. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13757. sd->auction.amount = 0;
  13758. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13759. }
  13760. }
  13761. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13762. /// 024e <auction id>.L
  13763. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13764. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13765. intif_Auction_cancel(sd->status.char_id, auction_id);
  13766. }
  13767. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13768. /// 025d <auction id>.L
  13769. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13770. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13771. intif_Auction_close(sd->status.char_id, auction_id);
  13772. }
  13773. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13774. /// 024f <auction id>.L <money>.L
  13775. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13776. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13777. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13778. int bid = RFIFOL(fd,info->pos[1]);
  13779. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13780. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13781. return;
  13782. }
  13783. if( bid <= 0 )
  13784. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13785. else if( bid > sd->status.zeny )
  13786. clif_Auction_message(fd, 8); // You do not have enough zeny
  13787. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13788. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13789. else {
  13790. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13791. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13792. }
  13793. }
  13794. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13795. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13796. /// search type:
  13797. /// 0 = armor
  13798. /// 1 = weapon
  13799. /// 2 = card
  13800. /// 3 = misc
  13801. /// 4 = name search
  13802. /// 5 = auction id search
  13803. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13804. char search_text[NAME_LENGTH];
  13805. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13806. short type = RFIFOW(fd,info->pos[0]);
  13807. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13808. int page = RFIFOW(fd,info->pos[3]);
  13809. if( !battle_config.feature_auction )
  13810. return;
  13811. clif_parse_Auction_cancelreg(fd, sd);
  13812. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13813. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13814. }
  13815. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13816. /// 025c <type>.W
  13817. /// type:
  13818. /// 0 = sell (own auctions)
  13819. /// 1 = buy (own bids)
  13820. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13821. {
  13822. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13823. if( !battle_config.feature_auction )
  13824. return;
  13825. clif_parse_Auction_cancelreg(fd, sd);
  13826. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13827. }
  13828. /// CASH/POINT SHOP
  13829. ///
  13830. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  13831. nullpo_retv( sd );
  13832. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  13833. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  13834. p.cashPoints = sd->cashPoints;
  13835. p.kafraPoints = sd->kafraPoints;
  13836. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  13837. p.tab = tab;
  13838. #endif
  13839. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13840. }
  13841. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13842. nullpo_retv( sd );
  13843. int tab = 0;
  13844. #if PACKETVER >= 20191224
  13845. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  13846. tab = p->tab;
  13847. #endif
  13848. sd->state.cashshop_open = true;
  13849. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13850. clif_cashshop_open( sd, tab );
  13851. }
  13852. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13853. sd->state.cashshop_open = false;
  13854. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13855. // No need to do anything here
  13856. }
  13857. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13858. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13859. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13860. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13861. int j;
  13862. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13863. return;
  13864. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13865. WFIFOW(fd, 0) = 0x8c0;
  13866. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13867. WFIFOL(fd, 4) = tab;
  13868. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13869. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13870. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  13871. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13872. }
  13873. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13874. }
  13875. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13876. void clif_cashshop_list( struct map_session_data* sd ){
  13877. nullpo_retv( sd );
  13878. int fd = sd->fd;
  13879. if( !session_isActive( fd ) ){
  13880. return;
  13881. }
  13882. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13883. // Skip empty tabs, the client only expects filled ones
  13884. if( cash_shop_items[tab].count == 0 ){
  13885. continue;
  13886. }
  13887. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  13888. WFIFOHEAD( fd, len );
  13889. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  13890. p->packetType = 0x8ca;
  13891. p->packetLength = len;
  13892. p->count = cash_shop_items[tab].count;
  13893. p->tabNum = tab;
  13894. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  13895. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  13896. p->items[i].price = cash_shop_items[tab].item[i]->price;
  13897. }
  13898. WFIFOSET( fd, len );
  13899. }
  13900. }
  13901. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13902. if( !sd->status.cashshop_sent ) {
  13903. clif_cashshop_list( sd );
  13904. #if PACKETVER_SUPPORTS_SALES
  13905. sale_notify_login(sd);
  13906. #endif
  13907. sd->status.cashshop_sent = true;
  13908. }
  13909. }
  13910. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13911. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13912. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13913. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  13914. nullpo_retv( sd );
  13915. nullpo_retv( nd );
  13916. int fd = sd->fd;
  13917. if( !session_isActive( fd ) ){
  13918. return;
  13919. }
  13920. sd->npc_shopid = nd->bl.id;
  13921. int cost[2] = { 0, 0 };
  13922. npc_shop_currency_type( sd, nd, cost, true );
  13923. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  13924. WFIFOHEAD( fd, len );
  13925. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  13926. p->packetType = 0x287;
  13927. p->packetLength = len;
  13928. p->cashPoints = cost[0];
  13929. #if PACKETVER >= 20070711
  13930. p->kafraPoints = cost[1];
  13931. #endif
  13932. for( int i = 0; i < nd->u.shop.count; i++ ) {
  13933. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  13934. p->items[i].price = nd->u.shop.shop_item[i].value;
  13935. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  13936. p->items[i].itemType = itemtype( id->nameid );
  13937. p->items[i].itemId = client_nameid( id->nameid );
  13938. }
  13939. WFIFOSET( fd, len );
  13940. }
  13941. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13942. /// 0289 <cash point>.L <error>.W
  13943. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13944. /// error:
  13945. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13946. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13947. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13948. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13949. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13950. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13951. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13952. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13953. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13954. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13955. {
  13956. int fd, cost[2] = { 0, 0 };
  13957. struct npc_data *nd;
  13958. nullpo_retv(sd);
  13959. fd = sd->fd;
  13960. nd = map_id2nd(sd->npc_shopid);
  13961. npc_shop_currency_type(sd, nd, cost, false);
  13962. WFIFOHEAD(fd, packet_len(0x289));
  13963. WFIFOW(fd,0) = 0x289;
  13964. WFIFOL(fd,2) = cost[0];
  13965. #if PACKETVER < 20070711
  13966. WFIFOW(fd,6) = TOW(error);
  13967. #else
  13968. WFIFOL(fd,6) = cost[1];
  13969. WFIFOW(fd,10) = TOW(error);
  13970. #endif
  13971. WFIFOSET(fd, packet_len(0x289));
  13972. }
  13973. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13974. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  13975. nullpo_retv( sd );
  13976. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  13977. packet.packetType = 0x849;
  13978. packet.itemId = client_nameid( item_id );
  13979. packet.result = result;
  13980. packet.cashPoints = sd->cashPoints;
  13981. packet.kafraPoints = sd->kafraPoints;
  13982. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  13983. #endif
  13984. }
  13985. /// Request to buy item(s) from cash shop.
  13986. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  13987. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13988. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13989. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  13990. nullpo_retv( sd );
  13991. if( sd->state.trading || !sd->npc_shopid ){
  13992. clif_cashshop_ack( sd, 1 );
  13993. return;
  13994. }
  13995. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  13996. #if PACKETVER < 20070711
  13997. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  13998. #elif PACKETVER < 20101116
  13999. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14000. #else
  14001. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14002. 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 ){
  14003. 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 );
  14004. return;
  14005. }
  14006. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, p->count, p->items ) );
  14007. #endif
  14008. }
  14009. /// Request to buy item(s) from cash shop.
  14010. /// 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)
  14011. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14012. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14013. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14014. 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 ){
  14015. 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 );
  14016. return;
  14017. }
  14018. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14019. }
  14020. /// Adoption System
  14021. ///
  14022. /// Adoption message (ZC_BABYMSG).
  14023. /// 0216 <msg>.L
  14024. /// msg:
  14025. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14026. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14027. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14028. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14029. {
  14030. int fd = sd->fd;
  14031. WFIFOHEAD(fd,6);
  14032. WFIFOW(fd,0) = 0x216;
  14033. WFIFOL(fd,2) = type;
  14034. WFIFOSET(fd,6);
  14035. }
  14036. /// Adoption confirmation (ZC_REQ_BABY).
  14037. /// 01f6 <account id>.L <char id>.L <name>.B
  14038. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14039. {
  14040. int fd = sd->fd;
  14041. WFIFOHEAD(fd,34);
  14042. WFIFOW(fd,0) = 0x1f6;
  14043. WFIFOL(fd,2) = src->status.account_id;
  14044. WFIFOL(fd,6) = p_id;
  14045. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14046. WFIFOSET(fd,34);
  14047. }
  14048. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14049. /// 01f9 <account id>.L
  14050. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14051. {
  14052. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14053. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14054. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14055. {
  14056. tsd->adopt_invite = sd->status.account_id;
  14057. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14058. }
  14059. }
  14060. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14061. /// 01f7 <account id>.L <char id>.L <answer>.L
  14062. /// answer:
  14063. /// 0 = rejected
  14064. /// 1 = accepted
  14065. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14066. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14067. int p1_id = RFIFOL(fd,info->pos[0]);
  14068. int p2_id = RFIFOL(fd,info->pos[1]);
  14069. int result = RFIFOL(fd,info->pos[2]);
  14070. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14071. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14072. int pid = sd->adopt_invite;
  14073. sd->adopt_invite = 0;
  14074. if( p1_sd == NULL || p2_sd == NULL )
  14075. return; // Both players need to be online
  14076. if( pid != p1_sd->status.account_id )
  14077. return; // Incorrect values
  14078. if( result == 0 )
  14079. return; // Rejected
  14080. pc_adoption(p1_sd, p2_sd, sd);
  14081. }
  14082. /// Convex Mirror (ZC_BOSS_INFO).
  14083. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14084. /// infoType:
  14085. /// BOSS_INFO_NOT = No boss on this map.
  14086. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14087. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14088. /// BOSS_INFO_DEAD = Boss is dead.
  14089. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14090. {
  14091. int fd = sd->fd;
  14092. WFIFOHEAD(fd,70);
  14093. memset(WFIFOP(fd,0),0,70);
  14094. WFIFOW(fd,0) = 0x293;
  14095. switch (flag) {
  14096. case BOSS_INFO_NOT:
  14097. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14098. // No data required
  14099. break;
  14100. case BOSS_INFO_ALIVE:
  14101. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14102. // Update X/Y
  14103. WFIFOL(fd,3) = md->bl.x;
  14104. WFIFOL(fd,7) = md->bl.y;
  14105. break;
  14106. case BOSS_INFO_ALIVE_WITHMSG:
  14107. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14108. // Current X/Y
  14109. WFIFOL(fd,3) = md->bl.x;
  14110. WFIFOL(fd,7) = md->bl.y;
  14111. break;
  14112. case BOSS_INFO_DEAD:
  14113. {
  14114. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14115. unsigned int seconds;
  14116. int hours, minutes;
  14117. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14118. hours = seconds / (60 * 60);
  14119. seconds = seconds - (60 * 60 * hours);
  14120. minutes = seconds / 60;
  14121. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14122. // Add respawn info
  14123. WFIFOW(fd,11) = hours; // Hours
  14124. WFIFOW(fd,13) = minutes; // Minutes
  14125. }
  14126. break;
  14127. }
  14128. if (md != NULL)
  14129. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14130. WFIFOSET(fd,70);
  14131. }
  14132. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14133. /// 02d6 <account id>.L
  14134. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14135. {
  14136. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14137. struct map_session_data* tsd = map_id2sd(aid);
  14138. if (!tsd)
  14139. return;
  14140. if (sd->bl.m != tsd->bl.m)
  14141. return;
  14142. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14143. clif_viewequip_ack(sd, tsd);
  14144. else
  14145. clif_msg(sd, VIEW_EQUIP_FAIL);
  14146. }
  14147. /// Request to a configuration.
  14148. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14149. /// type: see enum e_config_type
  14150. /// flag:
  14151. /// false = disabled
  14152. /// true = enabled
  14153. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14154. int cmd = RFIFOW(fd,0);
  14155. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14156. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14157. switch( type ){
  14158. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14159. sd->status.show_equip = flag;
  14160. break;
  14161. case CONFIG_PET_AUTOFEED:
  14162. // Player can not click this if he does not have a pet
  14163. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14164. return;
  14165. }
  14166. sd->pd->pet.autofeed = flag;
  14167. break;
  14168. case CONFIG_HOMUNCULUS_AUTOFEED:
  14169. // Player can not click this if he does not have a homunculus or it is vaporized
  14170. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14171. return;
  14172. }
  14173. sd->hd->homunculus.autofeed = flag;
  14174. break;
  14175. default:
  14176. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14177. return;
  14178. }
  14179. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14180. }
  14181. /// Request to change party invitation tick.
  14182. /// value:
  14183. /// 0 = disabled
  14184. /// 1 = enabled
  14185. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14186. {
  14187. bool flag = RFIFOB(fd,6) ? true : false;
  14188. sd->status.allow_party = flag;
  14189. clif_partytickack(sd, flag);
  14190. }
  14191. /// Questlog System [Kevin] [Inkfish]
  14192. ///
  14193. /**
  14194. * Safe check to init packet len & quest num for player.
  14195. * @param def_len
  14196. * @param info_len Length of each quest info.
  14197. * @param avail_quests Avail quests that player has.
  14198. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14199. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14200. **/
  14201. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14202. (*limit_out) = (0xFFFF - def_len) / info_len;
  14203. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14204. (*len_out) = ((*limit_out) * info_len) + def_len;
  14205. }
  14206. /// Sends list of all quest states
  14207. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14208. /// 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)
  14209. /// 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)
  14210. void clif_quest_send_list(struct map_session_data *sd)
  14211. {
  14212. int fd = sd->fd;
  14213. int i;
  14214. int offset = 8;
  14215. int limit = 0;
  14216. #if PACKETVER >= 20141022
  14217. #if PACKETVER >= 20150513
  14218. int size = 22 + NAME_LENGTH;
  14219. #else
  14220. int size = 10 + NAME_LENGTH;
  14221. #endif
  14222. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14223. WFIFOHEAD(fd,i);
  14224. #if PACKETVER >= 20150513
  14225. WFIFOW(fd, 0) = 0x9f8;
  14226. #else
  14227. WFIFOW(fd, 0) = 0x97a;
  14228. #endif
  14229. WFIFOL(fd, 4) = limit;
  14230. for (i = 0; i < limit; i++) {
  14231. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14232. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14233. offset += 4;
  14234. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14235. offset++;
  14236. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14237. offset += 4;
  14238. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14239. offset += 4;
  14240. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14241. offset += 2;
  14242. if (!qi->objectives.empty()) {
  14243. struct mob_db *mob;
  14244. for (int j = 0; j < qi->objectives.size(); j++) {
  14245. mob = mob_db(qi->objectives[j]->mob_id);
  14246. #if PACKETVER >= 20150513
  14247. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14248. offset += 4;
  14249. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14250. offset += 4;
  14251. #endif
  14252. WFIFOL(fd, offset) = qi->objectives[j]->mob_id;
  14253. offset += 4;
  14254. #if PACKETVER >= 20150513
  14255. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14256. offset += 2;
  14257. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14258. offset += 2;
  14259. #endif
  14260. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14261. offset += 2;
  14262. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14263. offset += 2;
  14264. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14265. offset += NAME_LENGTH;
  14266. }
  14267. }
  14268. }
  14269. WFIFOW(fd, 2) = offset;
  14270. WFIFOSET(fd, offset);
  14271. #else
  14272. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14273. WFIFOHEAD(fd,i);
  14274. WFIFOW(fd, 0) = 0x2b1;
  14275. WFIFOL(fd, 4) = limit;
  14276. for (i = 0; i < limit; i++) {
  14277. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14278. offset += 4;
  14279. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14280. offset += 1;
  14281. }
  14282. WFIFOW(fd, 2) = offset;
  14283. WFIFOSET(fd, offset);
  14284. #endif
  14285. }
  14286. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14287. /// 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
  14288. void clif_quest_send_mission(struct map_session_data *sd)
  14289. {
  14290. int fd = sd->fd;
  14291. int limit = 0;
  14292. int len = sd->avail_quests*104+8;
  14293. struct mob_db *mob;
  14294. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14295. WFIFOHEAD(fd, len);
  14296. WFIFOW(fd, 0) = 0x2b2;
  14297. WFIFOW(fd, 2) = len;
  14298. WFIFOL(fd, 4) = limit;
  14299. for (int i = 0; i < limit; i++) {
  14300. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14301. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14302. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14303. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14304. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14305. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14306. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j]->mob_id;
  14307. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14308. mob = mob_db(qi->objectives[j]->mob_id);
  14309. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14310. }
  14311. }
  14312. WFIFOSET(fd, len);
  14313. }
  14314. /// Notification about a new quest
  14315. /// 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)
  14316. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14317. /// 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)
  14318. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14319. {
  14320. int fd = sd->fd;
  14321. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14322. #if PACKETVER >= 20150513
  14323. int cmd = 0x9f9;
  14324. #else
  14325. int cmd = 0x2b3;
  14326. #endif
  14327. WFIFOHEAD(fd, packet_len(cmd));
  14328. WFIFOW(fd, 0) = cmd;
  14329. WFIFOL(fd, 2) = qd->quest_id;
  14330. WFIFOB(fd, 6) = qd->state;
  14331. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14332. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14333. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14334. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14335. struct mob_db *mob;
  14336. #if PACKETVER >= 20150513
  14337. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14338. offset += 4;
  14339. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14340. offset += 4;
  14341. #endif
  14342. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14343. offset += 4;
  14344. #if PACKETVER >= 20150513
  14345. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14346. offset += 2;
  14347. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14348. offset += 2;
  14349. #endif
  14350. WFIFOW(fd, offset) = qd->count[i];
  14351. offset += 2;
  14352. mob = mob_db(qi->objectives[i]->mob_id);
  14353. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14354. offset += NAME_LENGTH;
  14355. }
  14356. WFIFOSET(fd, packet_len(cmd));
  14357. #if PACKETVER >= 20150513
  14358. int len = 4 + qi->objectives.size() * 12;
  14359. WFIFOHEAD(fd, len);
  14360. WFIFOW(fd, 0) = 0x8fe;
  14361. WFIFOW(fd, 2) = len;
  14362. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14363. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14364. WFIFOL(fd, offset+4) = qi->objectives[i]->mob_id;
  14365. WFIFOW(fd, offset + 10) = qi->objectives[i]->count;
  14366. WFIFOW(fd, offset + 12) = qd->count[i];
  14367. }
  14368. WFIFOSET(fd, len);
  14369. #endif
  14370. }
  14371. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14372. /// 02b4 <quest id>.L
  14373. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14374. {
  14375. int fd = sd->fd;
  14376. WFIFOHEAD(fd, packet_len(0x2b4));
  14377. WFIFOW(fd, 0) = 0x2b4;
  14378. WFIFOL(fd, 2) = quest_id;
  14379. WFIFOSET(fd, packet_len(0x2b4));
  14380. }
  14381. /// Notification of an update to the hunting mission counter
  14382. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14383. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14384. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14385. {
  14386. int fd = sd->fd;
  14387. int offset = 6;
  14388. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14389. int len = qi->objectives.size() * 12 + 6;
  14390. #if PACKETVER >= 20150513
  14391. int cmd = 0x9fa;
  14392. #else
  14393. int cmd = 0x2b5;
  14394. #endif
  14395. WFIFOHEAD(fd, len);
  14396. WFIFOW(fd, 0) = cmd;
  14397. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14398. for (int i = 0; i < qi->objectives.size(); i++) {
  14399. if (mobid == 0 || mobid == qi->objectives[i]->mob_id) {
  14400. WFIFOL(fd, offset) = qd->quest_id;
  14401. offset += 4;
  14402. #if PACKETVER >= 20150513
  14403. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14404. offset += 4;
  14405. #else
  14406. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14407. offset += 4;
  14408. #endif
  14409. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14410. offset += 2;
  14411. WFIFOW(fd, offset) = qd->count[i];
  14412. offset += 2;
  14413. }
  14414. }
  14415. WFIFOW(fd, 2) = offset;
  14416. WFIFOSET(fd, offset);
  14417. }
  14418. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14419. /// 02b6 <quest id>.L <active>.B
  14420. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14421. {
  14422. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14423. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14424. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14425. }
  14426. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14427. /// 02b7 <quest id>.L <active>.B
  14428. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14429. {
  14430. int fd = sd->fd;
  14431. WFIFOHEAD(fd, packet_len(0x2b7));
  14432. WFIFOW(fd, 0) = 0x2b7;
  14433. WFIFOL(fd, 2) = quest_id;
  14434. WFIFOB(fd, 6) = active;
  14435. WFIFOSET(fd, packet_len(0x2b7));
  14436. }
  14437. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14438. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14439. /// effect:
  14440. /// 0 = none
  14441. /// 1 = exclamation mark icon
  14442. /// 2 = question mark icon
  14443. /// color:
  14444. /// 0 = yellow
  14445. /// 1 = orange
  14446. /// 2 = green
  14447. /// 3 = purple
  14448. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14449. {
  14450. #if PACKETVER >= 20090218
  14451. nullpo_retv(sd);
  14452. nullpo_retv(bl);
  14453. int fd = sd->fd;
  14454. WFIFOHEAD(fd, packet_len(0x446));
  14455. WFIFOW(fd, 0) = 0x446;
  14456. WFIFOL(fd, 2) = bl->id;
  14457. WFIFOW(fd, 6) = bl->x;
  14458. WFIFOW(fd, 8) = bl->y;
  14459. WFIFOW(fd, 10) = effect;
  14460. WFIFOW(fd, 12) = color;
  14461. WFIFOSET(fd, packet_len(0x446));
  14462. #endif
  14463. }
  14464. /// Mercenary System
  14465. ///
  14466. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14467. /// 02a2 <var id>.W <value>.L
  14468. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14469. {
  14470. struct mercenary_data *md;
  14471. struct status_data *status;
  14472. int fd;
  14473. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14474. return;
  14475. fd = sd->fd;
  14476. status = &md->battle_status;
  14477. WFIFOHEAD(fd,packet_len(0x2a2));
  14478. WFIFOW(fd,0) = 0x2a2;
  14479. WFIFOW(fd,2) = type;
  14480. switch( type ) {
  14481. case SP_ATK1:
  14482. {
  14483. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14484. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14485. }
  14486. break;
  14487. case SP_MATK1:
  14488. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14489. break;
  14490. case SP_HIT:
  14491. WFIFOL(fd,4) = status->hit;
  14492. break;
  14493. case SP_CRITICAL:
  14494. WFIFOL(fd,4) = status->cri/10;
  14495. break;
  14496. case SP_DEF1:
  14497. WFIFOL(fd,4) = status->def;
  14498. break;
  14499. case SP_MDEF1:
  14500. WFIFOL(fd,4) = status->mdef;
  14501. break;
  14502. case SP_MERCFLEE:
  14503. WFIFOL(fd,4) = status->flee;
  14504. break;
  14505. case SP_ASPD:
  14506. WFIFOL(fd,4) = status->amotion;
  14507. break;
  14508. case SP_HP:
  14509. WFIFOL(fd,4) = status->hp;
  14510. break;
  14511. case SP_MAXHP:
  14512. WFIFOL(fd,4) = status->max_hp;
  14513. break;
  14514. case SP_SP:
  14515. WFIFOL(fd,4) = status->sp;
  14516. break;
  14517. case SP_MAXSP:
  14518. WFIFOL(fd,4) = status->max_sp;
  14519. break;
  14520. case SP_MERCKILLS:
  14521. WFIFOL(fd,4) = md->mercenary.kill_count;
  14522. break;
  14523. case SP_MERCFAITH:
  14524. WFIFOL(fd,4) = mercenary_get_faith(md);
  14525. break;
  14526. }
  14527. WFIFOSET(fd,packet_len(0x2a2));
  14528. }
  14529. /// Mercenary base status data (ZC_MER_INIT).
  14530. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14531. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14532. /// <calls>.L <kills>.L <atk range>.W
  14533. void clif_mercenary_info(struct map_session_data *sd)
  14534. {
  14535. int fd;
  14536. struct mercenary_data *md;
  14537. struct status_data *status;
  14538. int atk;
  14539. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14540. return;
  14541. fd = sd->fd;
  14542. status = &md->battle_status;
  14543. WFIFOHEAD(fd,packet_len(0x29b));
  14544. WFIFOW(fd,0) = 0x29b;
  14545. WFIFOL(fd,2) = md->bl.id;
  14546. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14547. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14548. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14549. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14550. WFIFOW(fd,10) = status->hit;
  14551. WFIFOW(fd,12) = status->cri/10;
  14552. WFIFOW(fd,14) = status->def;
  14553. WFIFOW(fd,16) = status->mdef;
  14554. WFIFOW(fd,18) = status->flee;
  14555. WFIFOW(fd,20) = status->amotion;
  14556. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14557. WFIFOW(fd,46) = md->db->lv;
  14558. WFIFOL(fd,48) = status->hp;
  14559. WFIFOL(fd,52) = status->max_hp;
  14560. WFIFOL(fd,56) = status->sp;
  14561. WFIFOL(fd,60) = status->max_sp;
  14562. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14563. WFIFOW(fd,68) = mercenary_get_faith(md);
  14564. WFIFOL(fd,70) = mercenary_get_calls(md);
  14565. WFIFOL(fd,74) = md->mercenary.kill_count;
  14566. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14567. WFIFOSET(fd,packet_len(0x29b));
  14568. }
  14569. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14570. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14571. void clif_mercenary_skillblock(struct map_session_data *sd)
  14572. {
  14573. struct mercenary_data *md;
  14574. int fd, i, len = 4;
  14575. if( sd == NULL || (md = sd->md) == NULL )
  14576. return;
  14577. fd = sd->fd;
  14578. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14579. WFIFOW(fd,0) = 0x29d;
  14580. for( i = 0; i < MAX_MERCSKILL; i++ )
  14581. {
  14582. uint16 id;
  14583. short idx = -1;
  14584. if( (id = md->db->skill[i].id) == 0 )
  14585. continue;
  14586. if ((idx = mercenary_skill_get_index(id)) == -1)
  14587. continue;
  14588. WFIFOW(fd,len) = id;
  14589. WFIFOL(fd,len+2) = skill_get_inf(id);
  14590. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14591. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14592. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14593. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14594. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14595. len += 37;
  14596. }
  14597. WFIFOW(fd,2) = len;
  14598. WFIFOSET(fd,len);
  14599. }
  14600. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14601. /// 029f <command>.B
  14602. /// 1 = mercenary information
  14603. /// 2 = delete
  14604. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14605. {
  14606. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14607. if( sd->md == NULL )
  14608. return;
  14609. if( option == 2 ) mercenary_delete(sd->md, 2);
  14610. }
  14611. /// Mercenary Message
  14612. /// message:
  14613. /// 0 = Mercenary soldier's duty hour is over.
  14614. /// 1 = Your mercenary soldier has been killed.
  14615. /// 2 = Your mercenary soldier has been fired.
  14616. /// 3 = Your mercenary soldier has ran away.
  14617. void clif_mercenary_message(struct map_session_data* sd, int message){
  14618. clif_msg(sd, MERC_MSG_BASE + message);
  14619. }
  14620. /// Notification about the remaining time of a rental item.
  14621. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  14622. void clif_rental_time( struct map_session_data* sd, unsigned short nameid, int seconds ){
  14623. // '<ItemName>' item will disappear in <seconds/60> minutes.
  14624. struct PACKET_ZC_CASH_TIME_COUNTER p;
  14625. p.packetType = 0x298;
  14626. p.itemId = client_nameid( nameid );
  14627. p.seconds = seconds;
  14628. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14629. }
  14630. /// Deletes a rental item from client's inventory.
  14631. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  14632. void clif_rental_expired( struct map_session_data* sd, int index, unsigned short nameid ){
  14633. // '<ItemName>' item has been deleted from the Inventory
  14634. struct PACKET_ZC_CASH_ITEM_DELETE p;
  14635. p.packetType = 0x299;
  14636. p.index = client_index( index );
  14637. p.itemId = client_nameid( nameid );
  14638. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14639. }
  14640. /// Book Reading (ZC_READ_BOOK).
  14641. /// 0294 <book id>.L <page>.L
  14642. void clif_readbook(int fd, int book_id, int page)
  14643. {
  14644. WFIFOHEAD(fd,packet_len(0x294));
  14645. WFIFOW(fd,0) = 0x294;
  14646. WFIFOL(fd,2) = book_id;
  14647. WFIFOL(fd,6) = page;
  14648. WFIFOSET(fd,packet_len(0x294));
  14649. }
  14650. /// Battlegrounds
  14651. ///
  14652. /// Updates HP bar of a camp member.
  14653. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14654. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14655. void clif_bg_hp(struct map_session_data *sd) {
  14656. #if PACKETVER < 20140613
  14657. unsigned char buf[34];
  14658. const int cmd = 0x2e0;
  14659. #else
  14660. unsigned char buf[14];
  14661. const int cmd = 0xa0e;
  14662. #endif
  14663. nullpo_retv(sd);
  14664. WBUFW(buf,0) = cmd;
  14665. WBUFL(buf,2) = sd->status.account_id;
  14666. #if PACKETVER < 20140613
  14667. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14668. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14669. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14670. WBUFW(buf,32) = 100;
  14671. } else {
  14672. WBUFW(buf,30) = sd->battle_status.hp;
  14673. WBUFW(buf,32) = sd->battle_status.max_hp;
  14674. }
  14675. #else
  14676. if( sd->battle_status.max_hp > INT32_MAX ) {
  14677. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14678. WBUFL(buf,10) = 100;
  14679. } else {
  14680. WBUFL(buf,6) = sd->battle_status.hp;
  14681. WBUFL(buf,10) = sd->battle_status.max_hp;
  14682. }
  14683. #endif
  14684. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14685. }
  14686. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14687. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14688. void clif_bg_xy(struct map_session_data *sd)
  14689. {
  14690. unsigned char buf[36];
  14691. nullpo_retv(sd);
  14692. WBUFW(buf,0)=0x2df;
  14693. WBUFL(buf,2)=sd->status.account_id;
  14694. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14695. WBUFW(buf,30)=sd->status.class_;
  14696. WBUFW(buf,32)=sd->bl.x;
  14697. WBUFW(buf,34)=sd->bl.y;
  14698. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14699. }
  14700. void clif_bg_xy_remove(struct map_session_data *sd)
  14701. {
  14702. unsigned char buf[36];
  14703. nullpo_retv(sd);
  14704. WBUFW(buf,0)=0x2df;
  14705. WBUFL(buf,2)=sd->status.account_id;
  14706. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14707. WBUFW(buf,30)=0;
  14708. WBUFW(buf,32)=-1;
  14709. WBUFW(buf,34)=-1;
  14710. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14711. }
  14712. /// Notifies clients of a battleground message.
  14713. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14714. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14715. struct map_session_data *sd = bg_getavailablesd( bg );
  14716. if( sd == nullptr ){
  14717. return;
  14718. }
  14719. // limit length
  14720. len = min( len + 1, CHAT_SIZE_MAX );
  14721. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14722. WBUFW(buf,0) = 0x2dc;
  14723. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14724. WBUFL(buf,4) = src_id;
  14725. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14726. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14727. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14728. }
  14729. /// Validates and processes battlechat messages.
  14730. /// All messages that are sent after enabling battleground chat with /battlechat.
  14731. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14732. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14733. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14734. if( !clif_process_message( sd, false, name, message, output ) )
  14735. return;
  14736. bg_send_message(sd, output, strlen(output) );
  14737. }
  14738. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14739. /// 02de <camp A points>.W <camp B points>.W
  14740. void clif_bg_updatescore(int16 m)
  14741. {
  14742. struct block_list bl;
  14743. unsigned char buf[6];
  14744. struct map_data *mapdata = map_getmapdata(m);
  14745. bl.id = 0;
  14746. bl.type = BL_NUL;
  14747. bl.m = m;
  14748. WBUFW(buf,0) = 0x2de;
  14749. WBUFW(buf,2) = mapdata->bgscore_lion;
  14750. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14751. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14752. }
  14753. void clif_bg_updatescore_single(struct map_session_data *sd)
  14754. {
  14755. int fd;
  14756. nullpo_retv(sd);
  14757. fd = sd->fd;
  14758. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14759. WFIFOHEAD(fd,packet_len(0x2de));
  14760. WFIFOW(fd,0) = 0x2de;
  14761. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14762. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14763. WFIFOSET(fd,packet_len(0x2de));
  14764. }
  14765. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14766. /// 02dd <account id>.L <name>.24B <camp>.W
  14767. void clif_sendbgemblem_area(struct map_session_data *sd)
  14768. {
  14769. unsigned char buf[33];
  14770. nullpo_retv(sd);
  14771. WBUFW(buf, 0) = 0x2dd;
  14772. WBUFL(buf,2) = sd->bl.id;
  14773. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14774. WBUFW(buf,30) = sd->bg_id;
  14775. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14776. }
  14777. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14778. {
  14779. nullpo_retv(sd);
  14780. WFIFOHEAD(fd,32);
  14781. WFIFOW(fd,0) = 0x2dd;
  14782. WFIFOL(fd,2) = sd->bl.id;
  14783. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14784. WFIFOW(fd,30) = sd->bg_id;
  14785. WFIFOSET(fd,packet_len(0x2dd));
  14786. }
  14787. /// Battlegrounds queue incoming apply request from client.
  14788. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  14789. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  14790. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  14791. {
  14792. if (!battle_config.feature_bgqueue)
  14793. return;
  14794. nullpo_retv(sd);
  14795. short type = RFIFOW(fd,2);
  14796. char name[NAME_LENGTH];
  14797. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  14798. if (sd->bg_queue_id > 0) {
  14799. //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);
  14800. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  14801. return;
  14802. } else if (type == 1) // Solo
  14803. bg_queue_join_solo(name, sd);
  14804. else if (type == 2) // Party
  14805. bg_queue_join_party(name, sd);
  14806. else if (type == 4) // Guild
  14807. bg_queue_join_guild(name, sd);
  14808. else {
  14809. 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);
  14810. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  14811. return;
  14812. }
  14813. }
  14814. /// Outgoing battlegrounds queue apply result.
  14815. /// Result types: @see e_bg_queue_apply_ack
  14816. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  14817. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  14818. {
  14819. nullpo_retv(sd);
  14820. int fd = sd->fd;
  14821. WFIFOHEAD(fd, packet_len(0x8d8));
  14822. WFIFOW(fd,0) = 0x8d8;
  14823. WFIFOB(fd,2) = result;
  14824. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14825. WFIFOSET(fd, packet_len(0x8d8));
  14826. }
  14827. /// Outgoing battlegrounds queue apply notification.
  14828. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  14829. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  14830. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  14831. {
  14832. nullpo_retv(sd);
  14833. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  14834. if (queue == nullptr) {
  14835. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  14836. return;
  14837. }
  14838. int fd = sd->fd;
  14839. WFIFOHEAD(fd, packet_len(0x8d9));
  14840. WFIFOW(fd,0) = 0x8d9;
  14841. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  14842. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  14843. WFIFOSET(fd, packet_len(0x8d9));
  14844. }
  14845. /// Battlegrounds queue outgoing cancel result.
  14846. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  14847. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  14848. {
  14849. nullpo_retv(sd);
  14850. int fd = sd->fd;
  14851. WFIFOHEAD(fd, packet_len(0x8d8));
  14852. WFIFOW(fd,0) = 0x8db;
  14853. WFIFOB(fd,2) = success;
  14854. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14855. WFIFOSET(fd, packet_len(0x8d8));
  14856. }
  14857. /// Battlegrounds queue incoming cancel request from client.
  14858. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  14859. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  14860. {
  14861. if (!battle_config.feature_bgqueue)
  14862. return;
  14863. nullpo_retv(sd);
  14864. bool success;
  14865. if (sd->bg_queue_id > 0) {
  14866. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  14867. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  14868. 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.
  14869. else
  14870. success = bg_queue_leave(sd);
  14871. } else {
  14872. 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);
  14873. success = false;
  14874. }
  14875. char name[NAME_LENGTH];
  14876. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  14877. clif_bg_queue_cancel_result(success, name, sd);
  14878. }
  14879. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  14880. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  14881. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  14882. {
  14883. nullpo_retv(sd);
  14884. int fd = sd->fd;
  14885. WFIFOHEAD(fd, packet_len(0x8df));
  14886. WFIFOW(fd,0) = 0x8df;
  14887. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  14888. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  14889. WFIFOSET(fd, packet_len(0x8df));
  14890. }
  14891. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  14892. /// Result types: 1(Accept), 2(Decline).
  14893. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  14894. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  14895. {
  14896. nullpo_retv(sd);
  14897. if(sd->bg_queue_id > 0) {
  14898. uint8 result = RFIFOB(fd, 2);
  14899. if(result == 1) { // Accept
  14900. bg_queue_on_accept_invite(sd);
  14901. } else if(result == 2) { // Decline
  14902. bg_queue_leave(sd);
  14903. clif_bg_queue_entry_init(sd);
  14904. }
  14905. }
  14906. }
  14907. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  14908. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  14909. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  14910. {
  14911. nullpo_retv(sd);
  14912. int fd = sd->fd;
  14913. WFIFOHEAD(fd, packet_len(0x8e1));
  14914. WFIFOW(fd,0) = 0x8e1;
  14915. WFIFOB(fd,2) = result;
  14916. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14917. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  14918. WFIFOSET(fd, packet_len(0x8e1));
  14919. }
  14920. /// Battlegrounds queue incoming queue number request from client.
  14921. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  14922. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  14923. {
  14924. nullpo_retv(sd);
  14925. char name[NAME_LENGTH];
  14926. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  14927. clif_bg_queue_apply_notify(name, sd);
  14928. }
  14929. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  14930. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  14931. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  14932. void clif_bg_queue_entry_init(struct map_session_data *sd)
  14933. {
  14934. nullpo_retv(sd);
  14935. int fd = sd->fd;
  14936. WFIFOHEAD(fd, packet_len(0x90e));
  14937. WFIFOW(fd,0) = 0x90e;
  14938. WFIFOSET(fd, packet_len(0x90e));
  14939. }
  14940. /// Custom Fonts (ZC_NOTIFY_FONT).
  14941. /// 02ef <account_id>.L <font id>.W
  14942. void clif_font(struct map_session_data *sd)
  14943. {
  14944. #if PACKETVER >= 20080102
  14945. unsigned char buf[8];
  14946. nullpo_retv(sd);
  14947. WBUFW(buf,0) = 0x2ef;
  14948. WBUFL(buf,2) = sd->bl.id;
  14949. WBUFW(buf,6) = sd->status.font;
  14950. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14951. #endif
  14952. }
  14953. /// Required to start the instancing information window on Client
  14954. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14955. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14956. void clif_instance_create(int instance_id, int num)
  14957. {
  14958. #if PACKETVER >= 20071128
  14959. struct map_session_data *sd = NULL;
  14960. enum send_target target = PARTY;
  14961. unsigned char buf[65];
  14962. instance_getsd(instance_id, sd, &target);
  14963. if (!sd)
  14964. return;
  14965. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  14966. if (!db)
  14967. return;
  14968. WBUFW(buf,0) = 0x2cb;
  14969. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  14970. WBUFW(buf,63) = num;
  14971. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14972. #endif
  14973. return;
  14974. }
  14975. /// To announce Instancing queue creation if no maps available
  14976. /// S 0x2cc <Standby Position>.W
  14977. void clif_instance_changewait(int instance_id, int num)
  14978. {
  14979. #if PACKETVER >= 20071128
  14980. struct map_session_data *sd = NULL;
  14981. enum send_target target = PARTY;
  14982. unsigned char buf[4];
  14983. instance_getsd(instance_id, sd, &target);
  14984. if (!sd)
  14985. return;
  14986. WBUFW(buf,0) = 0x2cc;
  14987. WBUFW(buf,2) = num;
  14988. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14989. #endif
  14990. return;
  14991. }
  14992. /// Notify the current status to members
  14993. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14994. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  14995. {
  14996. #if PACKETVER >= 20071128
  14997. struct map_session_data *sd = NULL;
  14998. enum send_target target = PARTY;
  14999. unsigned char buf[71];
  15000. instance_getsd(instance_id, sd, &target);
  15001. if (!sd)
  15002. return;
  15003. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15004. if (!db)
  15005. return;
  15006. WBUFW(buf,0) = 0x2cd;
  15007. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15008. WBUFL(buf,63) = limit1;
  15009. WBUFL(buf,67) = limit2;
  15010. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15011. #endif
  15012. return;
  15013. }
  15014. /// Notify a status change to members
  15015. /// S 0x2ce <Message ID>.L
  15016. /// 0 = Notification (EnterLimitDate update?)
  15017. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15018. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15019. /// 3 = The Memorial Dungeon has been removed.
  15020. /// 4 = Create failure (removes the instance window)
  15021. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15022. {
  15023. #if PACKETVER >= 20071128
  15024. struct map_session_data *sd = NULL;
  15025. enum send_target target = PARTY;
  15026. unsigned char buf[10];
  15027. instance_getsd(instance_id, sd, &target);
  15028. if (!sd)
  15029. return;
  15030. WBUFW(buf,0) = 0x2ce;
  15031. WBUFL(buf,2) = type;
  15032. WBUFL(buf,6) = limit;
  15033. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15034. #endif
  15035. return;
  15036. }
  15037. /// Notifies clients about item picked up by a party member.
  15038. /// 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)
  15039. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15040. #if PACKETVER >= 20071002
  15041. nullpo_retv( sd );
  15042. nullpo_retv( item_data );
  15043. struct item_data* id = itemdb_search( item_data->nameid );
  15044. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15045. p.packetType = 0x2b8;
  15046. p.AID = sd->status.account_id;
  15047. p.itemId = item_data->nameid;
  15048. p.identified = item_data->identify;
  15049. p.damaged = item_data->attribute;
  15050. p.refine = item_data->refine;
  15051. clif_addcards( &p.slot, item_data );
  15052. p.location = id->equip; // equip location
  15053. p.itemType = itemtype( id->nameid ); // item type
  15054. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15055. #endif
  15056. }
  15057. /** Display gained exp.
  15058. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15059. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15060. * amount: INT32_MIN ~ INT32_MAX
  15061. * var id:
  15062. * SP_BASEEXP, SP_JOBEXP
  15063. * exp type:
  15064. * 0 = normal exp gained/lost
  15065. * 1 = quest exp gained/lost
  15066. * @param sd Player
  15067. * @param exp EXP value gained/loss
  15068. * @param type SP_BASEEXP, SP_JOBEXP
  15069. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15070. * @param lost True:if lossing EXP
  15071. */
  15072. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  15073. {
  15074. int fd;
  15075. int offset;
  15076. #if PACKETVER >= 20170830
  15077. int cmd = 0xacc;
  15078. #else
  15079. int cmd = 0x7f6;
  15080. #endif
  15081. nullpo_retv(sd);
  15082. fd = sd->fd;
  15083. WFIFOHEAD(fd, packet_len(cmd));
  15084. WFIFOW(fd,0) = cmd;
  15085. WFIFOL(fd,2) = sd->bl.id;
  15086. #if PACKETVER >= 20170830
  15087. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  15088. offset = 4;
  15089. #else
  15090. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  15091. offset = 0;
  15092. #endif
  15093. WFIFOW(fd,10+offset) = type;
  15094. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15095. WFIFOSET(fd,packet_len(cmd));
  15096. }
  15097. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15098. /// type:
  15099. /// 0 = Displays 'value' for 5 seconds.
  15100. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15101. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15102. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15103. /// value:
  15104. /// 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).
  15105. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15106. {
  15107. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15108. WFIFOW(sd->fd,0) = 0x1b1;
  15109. WFIFOB(sd->fd,2) = type;
  15110. WFIFOL(sd->fd,3) = value;
  15111. WFIFOSET(sd->fd, packet_len(0x1b1));
  15112. }
  15113. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15114. /// 021d <state>.L
  15115. /// state:
  15116. /// 0 = Full effects
  15117. /// 1 = Reduced effects
  15118. ///
  15119. /// NOTE: The state is used on Aegis for sending skill unit packet
  15120. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15121. /// whenever possible. Due to the way the decision check is
  15122. /// constructed, this state tracking was rendered useless,
  15123. /// as the only skill unit, that is sent with 0x1c9 is
  15124. /// Graffiti.
  15125. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15126. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15127. sd->state.lesseffect = ( isLess != 0 );
  15128. }
  15129. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15130. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15131. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15132. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15133. int type = RFIFOL(fd,info->pos[1]);
  15134. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15135. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15136. if( sd->state.trading || sd->npc_shopid )
  15137. return;
  15138. if( flag == 0 || n == 0) {
  15139. clif_menuskill_clear(sd);
  15140. return; // Canceled by player.
  15141. }
  15142. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15143. clif_menuskill_clear(sd);
  15144. return; // Prevent hacking.
  15145. }
  15146. switch( type ) {
  15147. case 0: // Change Material
  15148. skill_changematerial(sd,n,item_list);
  15149. break;
  15150. case 1: // Level 1: Pure to Rough
  15151. case 2: // Level 2: Rough to Pure
  15152. skill_elementalanalysis(sd,n,type,item_list);
  15153. break;
  15154. }
  15155. clif_menuskill_clear(sd);
  15156. return;
  15157. }
  15158. /*==========================================
  15159. * Elemental System
  15160. *==========================================*/
  15161. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15162. struct elemental_data *ed;
  15163. struct status_data *status;
  15164. int fd;
  15165. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15166. return;
  15167. fd = sd->fd;
  15168. status = &ed->battle_status;
  15169. WFIFOHEAD(fd,8);
  15170. WFIFOW(fd,0) = 0x81e;
  15171. WFIFOW(fd,2) = type;
  15172. switch( type ) {
  15173. case SP_HP:
  15174. WFIFOL(fd,4) = status->hp;
  15175. break;
  15176. case SP_MAXHP:
  15177. WFIFOL(fd,4) = status->max_hp;
  15178. break;
  15179. case SP_SP:
  15180. WFIFOL(fd,4) = status->sp;
  15181. break;
  15182. case SP_MAXSP:
  15183. WFIFOL(fd,4) = status->max_sp;
  15184. break;
  15185. }
  15186. WFIFOSET(fd,8);
  15187. }
  15188. void clif_elemental_info(struct map_session_data *sd) {
  15189. int fd;
  15190. struct elemental_data *ed;
  15191. struct status_data *status;
  15192. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15193. return;
  15194. fd = sd->fd;
  15195. status = &ed->battle_status;
  15196. WFIFOHEAD(fd,22);
  15197. WFIFOW(fd, 0) = 0x81d;
  15198. WFIFOL(fd, 2) = ed->bl.id;
  15199. WFIFOL(fd, 6) = status->hp;
  15200. WFIFOL(fd,10) = status->max_hp;
  15201. WFIFOL(fd,14) = status->sp;
  15202. WFIFOL(fd,18) = status->max_sp;
  15203. WFIFOSET(fd,22);
  15204. }
  15205. /// Buying Store System
  15206. ///
  15207. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15208. /// 0810 <slots>.B
  15209. void clif_buyingstore_open(struct map_session_data* sd)
  15210. {
  15211. int fd = sd->fd;
  15212. WFIFOHEAD(fd,packet_len(0x810));
  15213. WFIFOW(fd,0) = 0x810;
  15214. WFIFOB(fd,2) = sd->buyingstore.slots;
  15215. WFIFOSET(fd,packet_len(0x810));
  15216. }
  15217. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15218. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15219. /// result:
  15220. /// 0 = cancel
  15221. /// 1 = open
  15222. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15223. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15224. // TODO: Make this check global for all variable length packets.
  15225. // minimum packet length
  15226. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15227. 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 );
  15228. return;
  15229. }
  15230. char storename[MESSAGE_SIZE];
  15231. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15232. // so that buyingstore_create knows, how many elements it has access to
  15233. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15234. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15235. 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 ) );
  15236. return;
  15237. }
  15238. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15239. }
  15240. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15241. /// 0812 <result>.W <total weight>.L
  15242. /// result:
  15243. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15244. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15245. /// 8 = "No sale (purchase) information available." (0x705)
  15246. /// ? = nothing
  15247. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15248. {
  15249. int fd = sd->fd;
  15250. WFIFOHEAD(fd,packet_len(0x812));
  15251. WFIFOW(fd,0) = 0x812;
  15252. WFIFOW(fd,2) = result;
  15253. WFIFOL(fd,4) = weight;
  15254. WFIFOSET(fd,packet_len(0x812));
  15255. }
  15256. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15257. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15258. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15259. nullpo_retv( sd );
  15260. int fd = sd->fd;
  15261. if( !session_isActive( fd ) ){
  15262. return;
  15263. }
  15264. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15265. WFIFOHEAD( fd, length );
  15266. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15267. p->packetType = 0x813;
  15268. p->packetLength = length;
  15269. p->AID = sd->bl.id;
  15270. p->zenyLimit = sd->buyingstore.zenylimit;
  15271. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15272. p->items[i].price = sd->buyingstore.items[i].price;
  15273. p->items[i].amount = sd->buyingstore.items[i].amount;
  15274. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15275. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15276. }
  15277. WFIFOSET( fd, p->packetLength );
  15278. }
  15279. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15280. /// 0814 <account id>.L <store name>.80B
  15281. void clif_buyingstore_entry(struct map_session_data* sd)
  15282. {
  15283. uint8 buf[MESSAGE_SIZE+6];
  15284. WBUFW(buf,0) = 0x814;
  15285. WBUFL(buf,2) = sd->bl.id;
  15286. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15287. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15288. }
  15289. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15290. {
  15291. int fd = sd->fd;
  15292. WFIFOHEAD(fd,packet_len(0x814));
  15293. WFIFOW(fd,0) = 0x814;
  15294. WFIFOL(fd,2) = pl_sd->bl.id;
  15295. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15296. WFIFOSET(fd,packet_len(0x814));
  15297. }
  15298. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15299. /// 0815
  15300. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15301. {
  15302. buyingstore_close(sd);
  15303. }
  15304. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15305. /// 0816 <account id>.L
  15306. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15307. {
  15308. uint8 buf[6];
  15309. WBUFW(buf,0) = 0x816;
  15310. WBUFL(buf,2) = sd->bl.id;
  15311. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15312. }
  15313. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15314. {
  15315. int fd = sd->fd;
  15316. WFIFOHEAD(fd,packet_len(0x816));
  15317. WFIFOW(fd,0) = 0x816;
  15318. WFIFOL(fd,2) = pl_sd->bl.id;
  15319. WFIFOSET(fd,packet_len(0x816));
  15320. }
  15321. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15322. /// 0817 <account id>.L
  15323. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15324. {
  15325. uint32 account_id;
  15326. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15327. buyingstore_open(sd, account_id);
  15328. }
  15329. /// Sends buying store item list.
  15330. /// 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)
  15331. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15332. nullpo_retv( sd );
  15333. nullpo_retv( pl_sd );
  15334. int fd = sd->fd;
  15335. if( !session_isActive( fd ) ){
  15336. return;
  15337. }
  15338. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15339. WFIFOHEAD( fd, length );
  15340. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15341. p->packetType = 0x818;
  15342. p->packetLength = length;
  15343. p->AID = pl_sd->bl.id;
  15344. p->storeId = pl_sd->buyer_id;
  15345. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15346. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15347. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15348. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15349. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15350. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15351. }
  15352. WFIFOSET( fd, p->packetLength );
  15353. }
  15354. /// Request to sell items to a buying store.
  15355. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15356. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15357. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15358. // minimum packet length
  15359. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15360. 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 );
  15361. return;
  15362. }
  15363. // so that buyingstore_trade knows, how many elements it has access to
  15364. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15365. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15366. 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 ) );
  15367. return;
  15368. }
  15369. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15370. }
  15371. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15372. /// 081a <result>.W
  15373. /// result:
  15374. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15375. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15376. /// ? = nothing
  15377. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15378. {
  15379. int fd = sd->fd;
  15380. WFIFOHEAD(fd,packet_len(0x81a));
  15381. WFIFOW(fd,0) = 0x81a;
  15382. WFIFOW(fd,2) = result;
  15383. WFIFOSET(fd,packet_len(0x81a));
  15384. }
  15385. /// Updates the zeny limit and an item in the buying store item list.
  15386. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15387. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15388. void clif_buyingstore_update_item( struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny ){
  15389. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15390. p.packetType = buyingStoreUpdateItemType;
  15391. p.itemId = nameid;
  15392. p.amount = amount;
  15393. p.zenyLimit = sd->buyingstore.zenylimit;
  15394. #if PACKETVER >= 20141016
  15395. p.zeny = zeny;
  15396. p.charId = char_id; // GID
  15397. p.updateTime = (int)time(NULL);
  15398. #endif
  15399. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15400. }
  15401. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15402. /// 081c <index>.W <amount>.W <price>.L
  15403. /// message:
  15404. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15405. ///
  15406. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15407. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15408. {
  15409. int fd = sd->fd;
  15410. WFIFOHEAD(fd,packet_len(0x81c));
  15411. WFIFOW(fd,0) = 0x81c;
  15412. WFIFOW(fd,2) = client_index( index );
  15413. WFIFOW(fd,4) = amount;
  15414. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15415. WFIFOSET(fd,packet_len(0x81c));
  15416. }
  15417. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15418. /// 0824 <result>.W <name id>.W
  15419. /// result:
  15420. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15421. /// 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)
  15422. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15423. /// ? = nothing
  15424. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, unsigned short nameid ){
  15425. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15426. p.packetType = 0x824;
  15427. p.result = result;
  15428. p.itemId = client_nameid( nameid );
  15429. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15430. }
  15431. /// Search Store Info System
  15432. ///
  15433. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15434. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15435. /// type:
  15436. /// 0 = Vending
  15437. /// 1 = Buying Store
  15438. ///
  15439. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15440. /// amount of card slots. If the client does not know about the item it
  15441. /// cannot be searched.
  15442. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15443. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15444. // minimum packet length
  15445. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15446. 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 );
  15447. return;
  15448. }
  15449. // check, if there is enough data for the claimed count of items
  15450. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15451. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15452. 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 ) );
  15453. return;
  15454. }
  15455. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15456. if( count < p->itemsCount + p->cardsCount ){
  15457. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15458. return;
  15459. }
  15460. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15461. }
  15462. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15463. /// 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 }*
  15464. /// is first page:
  15465. /// 0 = appends to existing results
  15466. /// 1 = clears previous results before displaying this result set
  15467. /// is next page:
  15468. /// 0 = no "next" label
  15469. /// 1 = "next" label to retrieve more results
  15470. void clif_search_store_info_ack( struct map_session_data* sd ){
  15471. nullpo_retv( sd );
  15472. int fd = sd->fd;
  15473. if( !session_isActive( fd ) ){
  15474. return;
  15475. }
  15476. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15477. unsigned int end = umin( sd->searchstore.count, start + SEARCHSTORE_RESULTS_PER_PAGE );
  15478. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15479. WFIFOHEAD( fd, len );
  15480. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15481. p->packetType = 0x836;
  15482. p->packetLength = len;
  15483. p->firstPage = !sd->searchstore.pages;
  15484. p->nextPage = searchstore_querynext( sd );
  15485. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15486. for( int i = start; i < end; i++ ) {
  15487. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15488. p->items[i].storeId = ssitem->store_id;
  15489. p->items[i].AID = ssitem->account_id;
  15490. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15491. p->items[i].itemId = client_nameid( ssitem->nameid );
  15492. p->items[i].itemType = itemtype( ssitem->nameid );
  15493. p->items[i].price = ssitem->price;
  15494. p->items[i].amount = ssitem->amount;
  15495. p->items[i].refine = ssitem->refine;
  15496. // make-up an item for clif_addcards
  15497. struct item it;
  15498. memset( &it, 0, sizeof( it ) );
  15499. memcpy( &it.card, &ssitem->card, sizeof( it.card ) );
  15500. it.nameid = ssitem->nameid;
  15501. it.amount = ssitem->amount;
  15502. clif_addcards( &p->items[i].slot, &it );
  15503. #if PACKETVER >= 20150226
  15504. clif_add_random_options( p->items[i].option_data, &it );
  15505. #endif
  15506. }
  15507. WFIFOSET( fd, len );
  15508. }
  15509. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15510. /// 0837 <reason>.B
  15511. /// reason:
  15512. /// 0 = "No matching stores were found." (0x70b)
  15513. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15514. /// 2 = "You cannot search anymore." (0x706)
  15515. /// 3 = "You cannot search yet." (0x708)
  15516. /// 4 = "No sale (purchase) information available." (0x705)
  15517. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15518. {
  15519. int fd = sd->fd;
  15520. WFIFOHEAD(fd,packet_len(0x837));
  15521. WFIFOW(fd,0) = 0x837;
  15522. WFIFOB(fd,2) = reason;
  15523. WFIFOSET(fd,packet_len(0x837));
  15524. }
  15525. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15526. /// 0838
  15527. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15528. {
  15529. searchstore_next(sd);
  15530. }
  15531. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15532. /// 083a <type>.W <remaining uses>.B
  15533. /// type:
  15534. /// 0 = Search Stores
  15535. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15536. void clif_open_search_store_info(struct map_session_data* sd)
  15537. {
  15538. int fd = sd->fd;
  15539. WFIFOHEAD(fd,packet_len(0x83a));
  15540. WFIFOW(fd,0) = 0x83a;
  15541. WFIFOW(fd,2) = sd->searchstore.effect;
  15542. #if PACKETVER > 20100701
  15543. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15544. #endif
  15545. WFIFOSET(fd,packet_len(0x83a));
  15546. }
  15547. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15548. /// 083b
  15549. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15550. {
  15551. searchstore_close(sd);
  15552. }
  15553. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15554. /// 083c <account id>.L <store id>.L <nameid>.W
  15555. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  15556. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  15557. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  15558. }
  15559. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15560. /// 083d <xPos>.W <yPos>.W
  15561. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15562. {
  15563. int fd = sd->fd;
  15564. WFIFOHEAD(fd,packet_len(0x83d));
  15565. WFIFOW(fd,0) = 0x83d;
  15566. WFIFOW(fd,2) = x;
  15567. WFIFOW(fd,4) = y;
  15568. WFIFOSET(fd,packet_len(0x83d));
  15569. }
  15570. /// Parse function for packet debugging.
  15571. void clif_parse_debug(int fd,struct map_session_data *sd)
  15572. {
  15573. int cmd, packet_len;
  15574. // clif_parse ensures, that there is at least 2 bytes of data
  15575. cmd = RFIFOW(fd,0);
  15576. if( sd ) {
  15577. packet_len = packet_db[cmd].len;
  15578. if( packet_len == 0 )
  15579. {// unknown
  15580. packet_len = RFIFOREST(fd);
  15581. }
  15582. else if( packet_len == -1 )
  15583. {// variable length
  15584. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15585. }
  15586. 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);
  15587. }
  15588. else
  15589. {
  15590. packet_len = RFIFOREST(fd);
  15591. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15592. }
  15593. ShowDump(RFIFOP(fd,0), packet_len);
  15594. }
  15595. /*==========================================
  15596. * Server tells client to display a window similar to Magnifier (item) one
  15597. * Server populates the window with avilable elemental converter options according to player's inventory
  15598. *------------------------------------------*/
  15599. void clif_elementalconverter_list( struct map_session_data *sd ){
  15600. nullpo_retv( sd );
  15601. int fd = sd->fd;
  15602. if( !session_isActive( fd ) ){
  15603. return;
  15604. }
  15605. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15606. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15607. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15608. int count = 0;
  15609. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  15610. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  15611. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  15612. count++;
  15613. }
  15614. }
  15615. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15616. WFIFOSET( fd, p->packetLength );
  15617. if( count > 0 ){
  15618. sd->menuskill_id = SA_CREATECON;
  15619. sd->menuskill_val = count;
  15620. }
  15621. }
  15622. /**
  15623. * Rune Knight
  15624. **/
  15625. void clif_millenniumshield(struct block_list *bl, short shields) {
  15626. #if PACKETVER >= 20081217
  15627. unsigned char buf[10];
  15628. WBUFW(buf,0) = 0x440;
  15629. WBUFL(buf,2) = bl->id;
  15630. WBUFW(buf,6) = shields;
  15631. WBUFW(buf,8) = 0;
  15632. clif_send(buf,packet_len(0x440),bl,AREA);
  15633. #endif
  15634. }
  15635. /**
  15636. * Warlock
  15637. **/
  15638. /*==========================================
  15639. * Spellbook list [LimitLine/3CeAM]
  15640. *------------------------------------------*/
  15641. void clif_spellbook_list( struct map_session_data *sd ){
  15642. nullpo_retv( sd );
  15643. int fd = sd->fd;
  15644. if( !session_isActive( fd ) ){
  15645. return;
  15646. }
  15647. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15648. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15649. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15650. int count = 0;
  15651. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15652. if( reading_spellbook_db.findBook( sd->inventory.u.items_inventory[i].nameid ) ){
  15653. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15654. count++;
  15655. }
  15656. }
  15657. if( count > 0 ){
  15658. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15659. WFIFOSET( fd, p->packetLength );
  15660. sd->menuskill_id = WL_READING_SB;
  15661. sd->menuskill_val = count;
  15662. }else{
  15663. status_change_end( &sd->bl, SC_STOP, INVALID_TIMER );
  15664. clif_skill_fail( sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0 );
  15665. }
  15666. }
  15667. /**
  15668. * Mechanic
  15669. **/
  15670. /*==========================================
  15671. * Magic Decoy Material List
  15672. *------------------------------------------*/
  15673. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  15674. nullpo_retv( sd );
  15675. int fd = sd->fd;
  15676. if( !session_isActive( fd ) ){
  15677. return;
  15678. }
  15679. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15680. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  15681. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15682. int count = 0;
  15683. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15684. if( itemdb_group_item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  15685. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15686. count++;
  15687. }
  15688. }
  15689. if( count > 0 ) {
  15690. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15691. WFIFOSET( fd, p->packetLength );
  15692. sd->menuskill_id = NC_MAGICDECOY;
  15693. sd->menuskill_val = skill_lv;
  15694. sd->sc.comet_x = x;
  15695. sd->sc.comet_y = y;
  15696. }else{
  15697. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  15698. }
  15699. }
  15700. /*==========================================
  15701. * Guillotine Cross Poisons List
  15702. *------------------------------------------*/
  15703. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  15704. nullpo_retv( sd );
  15705. int fd = sd->fd;
  15706. if( !session_isActive( fd ) ){
  15707. return;
  15708. }
  15709. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15710. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15711. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15712. int count = 0;
  15713. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15714. if( itemdb_group_item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  15715. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15716. count++;
  15717. }
  15718. }
  15719. if( count > 0 ){
  15720. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15721. WFIFOSET( fd, p->packetLength );
  15722. sd->menuskill_id = GC_POISONINGWEAPON;
  15723. sd->menuskill_val = skill_lv;
  15724. }else{
  15725. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  15726. }
  15727. }
  15728. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15729. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15730. int fd, i, c;
  15731. nullpo_ret(sd);
  15732. fd = sd->fd;
  15733. if( !fd )
  15734. return 0;
  15735. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15736. return 0;
  15737. WFIFOHEAD(fd, 2 * 6 + 4);
  15738. WFIFOW(fd,0) = 0x442;
  15739. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15740. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15741. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15742. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  15743. {
  15744. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15745. c++;
  15746. }
  15747. if( c > 0 ) {
  15748. WFIFOW(fd,2) = 8 + c * 2;
  15749. WFIFOL(fd,4) = c;
  15750. WFIFOSET(fd,WFIFOW(fd,2));
  15751. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15752. sd->menuskill_val = c;
  15753. } else {
  15754. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15755. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15756. }
  15757. return 1;
  15758. }
  15759. /*===========================================
  15760. * Skill list for Four Elemental Analysis
  15761. * and Change Material skills.
  15762. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15763. *------------------------------------------*/
  15764. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15765. #if PACKETVER >= 20090922
  15766. int fd = sd->fd;
  15767. nullpo_ret(sd);
  15768. sd->menuskill_id = skill_id; // To prevent hacking.
  15769. sd->menuskill_val = skill_lv;
  15770. if( skill_id == GN_CHANGEMATERIAL )
  15771. skill_lv = 0; // Changematerial
  15772. WFIFOHEAD(fd, packet_len(0x7e3));
  15773. WFIFOW(fd,0) = 0x7e3;
  15774. WFIFOL(fd,2) = skill_lv;
  15775. WFIFOL(fd,4) = 0;
  15776. WFIFOSET(fd, packet_len(0x7e3));
  15777. #endif
  15778. return 1;
  15779. }
  15780. /*==========================================
  15781. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  15782. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15783. * RFIFOL(fd,2) - type (currently not used)
  15784. *------------------------------------------*/
  15785. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15786. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15787. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15788. if (sd->menuskill_id == SA_AUTOSPELL) {
  15789. sd->state.workinprogress = WIP_DISABLE_NONE;
  15790. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  15791. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  15792. if (pc_istrading(sd)) {
  15793. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  15794. clif_menuskill_clear(sd);
  15795. return;
  15796. }
  15797. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  15798. } else
  15799. return;
  15800. clif_menuskill_clear(sd);
  15801. }
  15802. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15803. /// 08cf <id>.L <type>.W <num>.W
  15804. void clif_spiritcharm(struct map_session_data *sd) {
  15805. unsigned char buf[10];
  15806. nullpo_retv(sd);
  15807. WBUFW(buf,0) = 0x08cf;
  15808. WBUFL(buf,2) = sd->bl.id;
  15809. WBUFW(buf,6) = sd->spiritcharm_type;
  15810. WBUFW(buf,8) = sd->spiritcharm;
  15811. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15812. }
  15813. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15814. /// 0907 <index>.W
  15815. ///
  15816. /// R 0908 <index>.w <type>.b
  15817. /// type:
  15818. /// 0 = move item to personal tab
  15819. /// 1 = move item to normal tab
  15820. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15821. #if PACKETVER >= 20111122
  15822. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15823. int index = RFIFOW(fd,info->pos[0]) - 2;
  15824. int type = RFIFOB(fd, info->pos[1]);
  15825. /* can't move while dead. */
  15826. if(pc_isdead(sd)) {
  15827. return;
  15828. }
  15829. if (index < 0 || index >= MAX_INVENTORY)
  15830. return;
  15831. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15832. sd->inventory.u.items_inventory[index].favorite = 0;
  15833. else if( type == 0 )
  15834. sd->inventory.u.items_inventory[index].favorite = 1;
  15835. else
  15836. return;/* nothing to do. */
  15837. clif_favorite_item(sd, index);
  15838. #endif
  15839. }
  15840. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15841. /// 0900 <index>.W <favorite>.B
  15842. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15843. int fd = sd->fd;
  15844. WFIFOHEAD(fd,packet_len(0x908));
  15845. WFIFOW(fd,0) = 0x908;
  15846. WFIFOW(fd,2) = index+2;
  15847. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15848. WFIFOSET(fd,packet_len(0x908));
  15849. }
  15850. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15851. void clif_snap( struct block_list *bl, short x, short y ) {
  15852. unsigned char buf[10];
  15853. WBUFW(buf,0) = 0x8d2;
  15854. WBUFL(buf,2) = bl->id;
  15855. WBUFW(buf,6) = x;
  15856. WBUFW(buf,8) = y;
  15857. if( disguised(bl) )
  15858. {
  15859. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15860. WBUFL(buf,2) = disguised_bl_id(bl->id);
  15861. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15862. } else
  15863. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15864. }
  15865. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15866. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15867. #if PACKETVER >= 20120404
  15868. WFIFOHEAD(fd,packet_len(0x977));
  15869. WFIFOW(fd,0) = 0x977;
  15870. WFIFOL(fd,2) = md->bl.id;
  15871. WFIFOL(fd,6) = md->status.hp;
  15872. WFIFOL(fd,10) = md->status.max_hp;
  15873. WFIFOSET(fd,packet_len(0x977));
  15874. #endif
  15875. }
  15876. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15877. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15878. return;
  15879. }
  15880. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15881. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15882. WFIFOW(sd->fd,0) = 0x2c9;
  15883. WFIFOB(sd->fd,2) = flag;
  15884. WFIFOSET(sd->fd, packet_len(0x2c9));
  15885. }
  15886. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15887. /// 0979 <world name>.24B <char name>.24B
  15888. void clif_ackworldinfo(struct map_session_data* sd) {
  15889. int fd;
  15890. nullpo_retv(sd);
  15891. fd = sd->fd;
  15892. WFIFOHEAD(fd,packet_len(0x979));
  15893. WFIFOW(fd,0)=0x979;
  15894. //AID -> world name ?
  15895. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15896. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15897. WFIFOSET(fd,packet_len(0x979));
  15898. }
  15899. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15900. /// 0978 <AID>.L
  15901. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15902. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15903. if(sd)
  15904. clif_ackworldinfo(sd);
  15905. }
  15906. static void clif_loadConfirm( struct map_session_data *sd ){
  15907. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  15908. nullpo_retv( sd );
  15909. struct PACKET_ZC_LOAD_CONFIRM p;
  15910. p.packetType = HEADER_ZC_LOAD_CONFIRM;
  15911. clif_send( &p, sizeof(p), &sd->bl, SELF );
  15912. #endif
  15913. }
  15914. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15915. /// 0447
  15916. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  15917. clif_loadConfirm( sd );
  15918. }
  15919. /// req world info (CZ_CLIENT_VERSION)
  15920. /// 044A <version>.L
  15921. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15922. //if(sd)
  15923. ;
  15924. }
  15925. /// Ranking list
  15926. /// ranking pointlist { <name>.24B <point>.L }*10
  15927. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15928. struct fame_list* list;
  15929. int i, size = MAX_FAME_LIST;
  15930. switch(rankingtype) {
  15931. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15932. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15933. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15934. // PK currently unsupported
  15935. case RANK_KILLER: list = NULL; size = 0; break;
  15936. default:
  15937. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15938. return;
  15939. }
  15940. //Packet size limits this list to 10 elements. [Skotlex]
  15941. for (i = 0; i < min(10,size); i++) {
  15942. if (list[i].id > 0) {
  15943. const char* name;
  15944. if (strcmp(list[i].name, "-") == 0 &&
  15945. (name = map_charid2nick(list[i].id)) != NULL)
  15946. {
  15947. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15948. } else {
  15949. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15950. }
  15951. } else {
  15952. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15953. }
  15954. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15955. }
  15956. for(;i < 10; i++) { //In case the MAX is less than 10.
  15957. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15958. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15959. }
  15960. }
  15961. /// Request for the blacksmith ranklist.
  15962. /// /blacksmith command sends this packet to the server.
  15963. /// 0217 (CZ_BLACKSMITH_RANK)
  15964. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15965. clif_ranklist(sd,RANK_BLACKSMITH);
  15966. }
  15967. /// Request for the alchemist ranklist.
  15968. /// /alchemist command sends this packet to the server.
  15969. /// 0218 (CZ_ALCHEMIST_RANK)
  15970. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15971. clif_ranklist(sd,RANK_ALCHEMIST);
  15972. }
  15973. /// Request for the taekwon ranklist.
  15974. /// /taekwon command sends this packet to the server.
  15975. /// 0225 (CZ_TAEKWON_RANK)
  15976. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15977. clif_ranklist(sd,RANK_TAEKWON);
  15978. }
  15979. /// Request for the killer ranklist.
  15980. /// /pk command sends this packet to the server.
  15981. /// 0237 (CZ_KILLER_RANK)
  15982. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15983. clif_ranklist(sd,RANK_KILLER);
  15984. }
  15985. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15986. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15987. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15988. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15989. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15990. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15991. enum e_rank rank;
  15992. #if PACKETVER < 20130710
  15993. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15994. short cmd;
  15995. switch( rankingType ){
  15996. case RANK_BLACKSMITH: cmd = 0x219; break;
  15997. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15998. case RANK_TAEKWON: cmd = 0x226; break;
  15999. case RANK_KILLER: cmd = 0x238; break;
  16000. default:
  16001. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16002. return;
  16003. }
  16004. // Can be safely casted here, since we validated it before
  16005. rank = (enum e_rank)rankingType;
  16006. WBUFW(buf,0) = cmd;
  16007. clif_sub_ranklist(buf,2,sd,rank);
  16008. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16009. #else
  16010. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16011. int mypoint = 0;
  16012. switch( rankingType ){
  16013. case RANK_BLACKSMITH:
  16014. case RANK_ALCHEMIST:
  16015. case RANK_TAEKWON:
  16016. case RANK_KILLER:
  16017. break;
  16018. default:
  16019. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16020. return;
  16021. }
  16022. // Can be safely casted here, since we validated it before
  16023. rank = (enum e_rank)rankingType;
  16024. WBUFW(buf,0) = 0x97d;
  16025. WBUFW(buf,2) = rank;
  16026. clif_sub_ranklist(buf,4,sd,rank);
  16027. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16028. case MAPID_BLACKSMITH:
  16029. case MAPID_ALCHEMIST:
  16030. case MAPID_TAEKWON:
  16031. mypoint = sd->status.fame;
  16032. }
  16033. WBUFL(buf,284) = mypoint; //mypoint
  16034. clif_send(buf, 288, &sd->bl, SELF);
  16035. #endif
  16036. }
  16037. /*
  16038. * 097c <type> (CZ_REQ_RANKING)
  16039. * type
  16040. * 0: /blacksmith
  16041. * 1: /alchemist
  16042. * 2: /taekwon
  16043. * 3: /pk
  16044. * */
  16045. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16046. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16047. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16048. clif_ranklist(sd,rankingtype);
  16049. }
  16050. /// Updates the fame rank points for the given ranking.
  16051. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16052. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16053. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16054. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16055. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16056. int fd=sd->fd;
  16057. #if PACKETVER < 20130710
  16058. short cmd;
  16059. switch(rankingtype){
  16060. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16061. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16062. case RANK_TAEKWON: cmd = 0x224; break;
  16063. default:
  16064. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16065. return;
  16066. }
  16067. WFIFOHEAD(fd,packet_len(cmd));
  16068. WFIFOW(fd,0) = cmd;
  16069. WFIFOL(fd,2) = point;
  16070. WFIFOL(fd,6) = sd->status.fame;
  16071. WFIFOSET(fd, packet_len(cmd));
  16072. #else
  16073. WFIFOHEAD(fd,packet_len(0x97e));
  16074. WFIFOW(fd,0) = 0x97e;
  16075. WFIFOW(fd,2) = rankingtype;
  16076. WFIFOL(fd,4) = point;
  16077. WFIFOL(fd,8) = sd->status.fame;
  16078. WFIFOSET(fd,packet_len(0x97e));
  16079. #endif
  16080. }
  16081. /**
  16082. * Transmit personal information to player. (rates)
  16083. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16084. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16085. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16086. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16087. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16088. * FIXME!
  16089. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16090. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16091. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16092. */
  16093. #ifdef VIP_ENABLE
  16094. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16095. if (sd) {
  16096. struct s_packet_db* info;
  16097. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16098. int cmd = 0, fd, i = 0;
  16099. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16100. int details_bexp[PINFO_MAX];
  16101. int details_drop[PINFO_MAX];
  16102. int details_penalty[PINFO_MAX];
  16103. /**
  16104. * Set for EXP
  16105. */
  16106. //0:PCRoom
  16107. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16108. if (details_bexp[0] == 100 || !details_bexp[0])
  16109. details_bexp[0] = 0;
  16110. else {
  16111. if (details_bexp[0] < 100) {
  16112. details_bexp[0] = 100 - details_bexp[0];
  16113. details_bexp[0] = 0 - details_bexp[0];
  16114. }
  16115. else
  16116. details_bexp[0] = details_bexp[0] - 100;
  16117. }
  16118. //1:Premium
  16119. if (pc_isvip(sd)) {
  16120. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16121. if (details_bexp[1] < 0)
  16122. details_bexp[1] = 0 - details_bexp[1];
  16123. }
  16124. else
  16125. details_bexp[1] = 0;
  16126. //2:Server
  16127. details_bexp[2] = battle_config.base_exp_rate;
  16128. if (details_bexp[2] == 100)
  16129. details_bexp[2] = 0;
  16130. else {
  16131. if (details_bexp[2] < 100) {
  16132. details_bexp[2] = 100 - details_bexp[2];
  16133. details_bexp[2] = 0 - details_bexp[2];
  16134. }
  16135. else
  16136. details_bexp[2] = details_bexp[2] - 100;
  16137. }
  16138. //3:TPLUS
  16139. details_bexp[3] = 0;
  16140. /* End - EXP set*/
  16141. /**
  16142. * Set for Drop rate
  16143. */
  16144. //0:PCRoom
  16145. details_drop[0] = 0;
  16146. //1:Premium
  16147. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16148. if (pc_isvip(sd)) {
  16149. if (details_drop[1] < 0)
  16150. details_drop[1] = 0 - details_drop[1];
  16151. }
  16152. else
  16153. details_drop[1] = 0;
  16154. //2:Server
  16155. details_drop[2] = battle_config.item_rate_common;
  16156. if (details_drop[2] == 100)
  16157. details_drop[2] = 0;
  16158. else {
  16159. if (details_drop[2] < 100) {
  16160. details_drop[2] = 100 - details_drop[2];
  16161. details_drop[2] = 0 - details_drop[2];
  16162. }
  16163. else
  16164. details_drop[2] = details_drop[2] - 100;
  16165. }
  16166. //3:TPLUS
  16167. details_drop[3] = 0;
  16168. /* End - Drop set*/
  16169. /**
  16170. * Set for Penalty rate
  16171. */
  16172. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16173. //0:PCRoom
  16174. details_penalty[0] = 0;
  16175. //1:Premium
  16176. if (pc_isvip(sd)) {
  16177. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16178. if (details_penalty[1] == 100)
  16179. details_penalty[1] = 0;
  16180. else {
  16181. if (details_penalty[1] < 100) {
  16182. details_penalty[1] = 100 - details_penalty[1];
  16183. details_penalty[1] = 0 - details_penalty[1];
  16184. }
  16185. else
  16186. details_penalty[1] = details_penalty[1] - 100;
  16187. }
  16188. }
  16189. else
  16190. details_penalty[1] = 0;
  16191. //2:Server
  16192. details_penalty[2] = battle_config.death_penalty_base;
  16193. if (details_penalty[2] == 100)
  16194. details_penalty[2] = 0;
  16195. else {
  16196. if (details_penalty[2] < 100) {
  16197. details_penalty[2] = 100 - details_penalty[2];
  16198. details_penalty[2] = 0 - details_penalty[2];
  16199. }
  16200. else
  16201. details_penalty[2] = details_penalty[2] - 100;
  16202. }
  16203. //3:TPLUS
  16204. details_penalty[3] = 0;
  16205. /* End - Penalty set*/
  16206. cmd = packet_db_ack[cmdtype];
  16207. info = &packet_db[cmd];
  16208. len = info->len; //this is the base len without details
  16209. if(!len) return; //version as packet disable
  16210. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16211. szdetails = 7;
  16212. factor = 1;
  16213. }
  16214. else if (cmd == 0x097b) {
  16215. tot_baseexp *= factor;
  16216. tot_drop *= factor;
  16217. tot_penalty *= factor;
  16218. }
  16219. fd = sd->fd;
  16220. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16221. WFIFOW(fd,0) = cmd;
  16222. for (i = 0; i < maxinfotype; i++) {
  16223. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16224. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16225. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16226. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16227. tot_baseexp += details_bexp[i]*factor;
  16228. tot_drop += details_penalty[i]*factor;
  16229. tot_penalty += details_drop[i]*factor;
  16230. len += szdetails;
  16231. }
  16232. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16233. if (cmd == 0x08cb) { //0x08cb version
  16234. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16235. WFIFOW(fd,info->pos[2]) = tot_drop;
  16236. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16237. }
  16238. else { //2013-08-07aRagexe uses 0x097b
  16239. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16240. WFIFOL(fd,info->pos[2]) = tot_drop;
  16241. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16242. }
  16243. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16244. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16245. WFIFOSET(fd,len);
  16246. }
  16247. }
  16248. #endif
  16249. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16250. char cmd[30];
  16251. int t_aid = RFIFOL(fd,2);
  16252. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16253. is_atcommand(fd, sd, cmd, 1);
  16254. }
  16255. /**
  16256. * Marks Crimson Marker target on mini-map to the caster
  16257. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16258. * @param fd
  16259. * @param bl Crimson Marker target
  16260. **/
  16261. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16262. struct s_packet_db* info;
  16263. int cmd = 0;
  16264. int16 len;
  16265. unsigned char buf[11];
  16266. nullpo_retv(sd);
  16267. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16268. if (!cmd)
  16269. cmd = 0x09C1; //default
  16270. info = &packet_db[cmd];
  16271. if (!(len = info->len))
  16272. return;
  16273. WBUFW(buf, 0) = cmd;
  16274. WBUFL(buf, info->pos[0]) = bl->id;
  16275. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16276. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16277. clif_send(buf, len, &sd->bl, SELF);
  16278. }
  16279. /**
  16280. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16281. **/
  16282. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16283. struct s_packet_db *info = NULL;
  16284. int cmd = 0;
  16285. nullpo_retv(sd);
  16286. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16287. info = &packet_db[cmd];
  16288. if (!cmd || !info->len)
  16289. return;
  16290. WFIFOHEAD(sd->fd, info->len);
  16291. WFIFOW(sd->fd, 0) = cmd;
  16292. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16293. WFIFOSET(sd->fd, info->len);
  16294. }
  16295. /**
  16296. * [Ind/Hercules]
  16297. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16298. **/
  16299. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16300. char buf[256];
  16301. size_t len;
  16302. nullpo_retv(bl);
  16303. if(!message)
  16304. return;
  16305. len = strlen(message)+1;
  16306. if( len > sizeof(buf)-8 ) {
  16307. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16308. len = sizeof(buf)-8;
  16309. }
  16310. WBUFW(buf,0) = 0x8b3;
  16311. WBUFW(buf,2) = (uint16)(len+8);
  16312. WBUFL(buf,4) = bl->id;
  16313. safestrncpy(WBUFCP(buf,8), message, len);
  16314. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16315. }
  16316. /**
  16317. * [Ind/Hercules]
  16318. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16319. **/
  16320. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16321. unsigned char buf[10];
  16322. nullpo_retv(sd);
  16323. WBUFW(buf,0) = 0x7fc;
  16324. WBUFL(buf,2) = prev_leader_aid;
  16325. WBUFL(buf,6) = new_leader_aid;
  16326. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16327. }
  16328. /**
  16329. * Sends a clan message to a player
  16330. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16331. **/
  16332. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16333. #if PACKETVER >= 20131223
  16334. struct map_session_data *sd;
  16335. uint8 buf[256];
  16336. if( len == 0 ){
  16337. return;
  16338. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16339. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16340. len = sizeof(buf)-5-NAME_LENGTH;
  16341. }
  16342. WBUFW(buf, 0) = 0x98e;
  16343. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16344. // 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
  16345. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16346. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16347. if((sd = clan_getavailablesd(clan)) != NULL)
  16348. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16349. #endif
  16350. }
  16351. /**
  16352. * Parses a clan message from a player.
  16353. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16354. **/
  16355. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16356. #if PACKETVER >= 20131223
  16357. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16358. // validate packet and retrieve name and message
  16359. if( !clif_process_message(sd, false, name, message, output ) )
  16360. return;
  16361. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16362. #endif
  16363. }
  16364. /**
  16365. * Sends the basic clan informations to the client.
  16366. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16367. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16368. **/
  16369. void clif_clan_basicinfo( struct map_session_data *sd ){
  16370. #if PACKETVER >= 20131223
  16371. int fd, offset, length, i, flag;
  16372. struct clan* clan;
  16373. char mapname[MAP_NAME_LENGTH_EXT];
  16374. nullpo_retv( sd );
  16375. nullpo_retv( clan = sd->clan );
  16376. // Check if the player has a valid session and is not autotrading
  16377. if( !clif_session_isValid( sd ) ){
  16378. return;
  16379. }
  16380. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16381. fd = sd->fd;
  16382. WFIFOHEAD(fd,length);
  16383. memset( WFIFOP(fd, 0), 0, length );
  16384. WFIFOW( fd, 0 ) = 0x98a;
  16385. WFIFOL( fd, 4 ) = clan->id;
  16386. offset = 8;
  16387. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16388. offset += NAME_LENGTH;
  16389. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16390. offset += NAME_LENGTH;
  16391. mapindex_getmapname_ext( clan->map, mapname );
  16392. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16393. offset += MAP_NAME_LENGTH_EXT;
  16394. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16395. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16396. for( flag = 0; flag < 2; flag++ ){
  16397. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16398. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16399. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16400. offset += NAME_LENGTH;
  16401. }
  16402. }
  16403. }
  16404. WFIFOW( fd, 2 ) = offset;
  16405. WFIFOSET(fd,offset);
  16406. #endif
  16407. }
  16408. /**
  16409. * Updates the online and maximum player count of a clan.
  16410. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16411. **/
  16412. void clif_clan_onlinecount( struct clan* clan ){
  16413. #if PACKETVER >= 20131223
  16414. uint8 buf[6];
  16415. struct map_session_data *sd;
  16416. WBUFW(buf,0) = 0x988;
  16417. WBUFW(buf,2) = clan->connect_member;
  16418. WBUFW(buf,4) = clan->max_member;
  16419. if((sd = clan_getavailablesd(clan)) != NULL)
  16420. clif_send(buf, 6, &sd->bl, CLAN);
  16421. #endif
  16422. }
  16423. /**
  16424. * Notifies the client that the player has left his clan.
  16425. * 0989 (ZC_ACK_CLAN_LEAVE)
  16426. **/
  16427. void clif_clan_leave( struct map_session_data* sd ){
  16428. #if PACKETVER >= 20131223
  16429. int fd;
  16430. nullpo_retv( sd );
  16431. if( !clif_session_isValid( sd ) ){
  16432. return;
  16433. }
  16434. fd = sd->fd;
  16435. WFIFOHEAD(fd,2);
  16436. WFIFOW(fd,0) = 0x989;
  16437. WFIFOSET(fd,2);
  16438. #endif
  16439. }
  16440. /**
  16441. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16442. * 0A2F <result>.B <title_id>.L
  16443. */
  16444. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16445. {
  16446. #if PACKETVER >= 20150513
  16447. int fd;
  16448. nullpo_retv(sd);
  16449. if (!clif_session_isValid(sd))
  16450. return;
  16451. fd = sd->fd;
  16452. WFIFOHEAD(fd, packet_len(0xa2f));
  16453. WFIFOW(fd, 0) = 0xa2f;
  16454. WFIFOB(fd, 2) = result;
  16455. WFIFOL(fd, 3) = title_id;
  16456. WFIFOSET(fd, packet_len(0xa2f));
  16457. #endif
  16458. }
  16459. /**
  16460. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16461. * 0A2E <title_id>.L
  16462. */
  16463. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16464. {
  16465. int title_id;
  16466. nullpo_retv(sd);
  16467. title_id = RFIFOL(fd, 2);
  16468. if( title_id == sd->status.title_id ){
  16469. // It is exactly the same as the old one
  16470. return;
  16471. }else if( title_id <= 0 ){
  16472. sd->status.title_id = 0;
  16473. }else{
  16474. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16475. clif_change_title_ack(sd, 1, title_id);
  16476. return;
  16477. }
  16478. sd->status.title_id = title_id;
  16479. }
  16480. clif_name_area(&sd->bl);
  16481. clif_change_title_ack(sd, 0, title_id);
  16482. }
  16483. #ifdef DUMP_UNKNOWN_PACKET
  16484. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16485. {
  16486. const char* packet_txt = "save/packet.txt";
  16487. FILE* fp;
  16488. time_t time_server;
  16489. struct tm *datetime;
  16490. char datestr[512];
  16491. time(&time_server); // get time in seconds since 1/1/1970
  16492. datetime = localtime(&time_server); // convert seconds in structure
  16493. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16494. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16495. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16496. if( sd ) {
  16497. 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);
  16498. } else {
  16499. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16500. }
  16501. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16502. fprintf(fp, "\n");
  16503. fclose(fp);
  16504. } else {
  16505. ShowError("Failed to write '%s'.\n", packet_txt);
  16506. // Dump on console instead
  16507. if( sd ) {
  16508. 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);
  16509. } else {
  16510. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16511. }
  16512. ShowDump(RFIFOP(fd,0), packet_len);
  16513. }
  16514. }
  16515. #endif
  16516. /// Roulette System
  16517. /// Author: Yommy
  16518. /// Opens the roulette window
  16519. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16520. void clif_roulette_open( struct map_session_data* sd ){
  16521. nullpo_retv( sd );
  16522. struct packet_roulette_open_ack p;
  16523. p.PacketType = 0xa1a;
  16524. p.Result = 0; // result
  16525. p.Serial = 0; // serial
  16526. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16527. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16528. p.AdditionItemID = -1; //! TODO: Display bonus item
  16529. p.GoldPoint = sd->roulette_point.gold;
  16530. p.SilverPoint = sd->roulette_point.silver;
  16531. p.BronzePoint = sd->roulette_point.bronze;
  16532. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16533. }
  16534. /// Request to open the roulette window
  16535. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16536. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16537. nullpo_retv(sd);
  16538. if (!battle_config.feature_roulette) {
  16539. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16540. return;
  16541. }
  16542. clif_roulette_open(sd);
  16543. }
  16544. /// Sends the info about the available roulette rewards to the client
  16545. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16546. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16547. void clif_roulette_info( struct map_session_data* sd ){
  16548. nullpo_retv(sd);
  16549. struct packet_roulette_info_ack p;
  16550. p.PacketType = rouletteinfoackType;
  16551. p.PacketLength = sizeof(p);
  16552. p.RouletteSerial = 1;
  16553. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16554. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16555. p.ItemInfo[count].Row = i;
  16556. p.ItemInfo[count].Position = j;
  16557. p.ItemInfo[count].ItemId = rd.nameid[i][j];
  16558. p.ItemInfo[count].Count = rd.qty[i][j];
  16559. #if PACKETVER >= 20180511
  16560. p.ItemInfo[count].unused = 0;
  16561. #endif
  16562. count++;
  16563. }
  16564. }
  16565. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16566. }
  16567. /// Request the roulette reward data
  16568. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16569. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16570. nullpo_retv(sd);
  16571. if (!battle_config.feature_roulette) {
  16572. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16573. return;
  16574. }
  16575. clif_roulette_info(sd);
  16576. }
  16577. /// Notification of the client that the roulette window was closed
  16578. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16579. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16580. nullpo_retv(sd);
  16581. if (!battle_config.feature_roulette) {
  16582. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16583. return;
  16584. }
  16585. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16586. }
  16587. /// Response to a item reward request
  16588. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16589. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16590. #if PACKETVER >= 20141016
  16591. nullpo_retv(sd);
  16592. struct packet_roulette_itemrecv_ack p;
  16593. p.PacketType = roulettercvitemackType;
  16594. p.Result = type;
  16595. p.AdditionItemID = 0; //! TODO: Additional item
  16596. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16597. #endif
  16598. }
  16599. /**
  16600. * Claim roulette reward
  16601. * @param sd Player
  16602. * @return 0:Success
  16603. **/
  16604. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16605. struct item it;
  16606. uint8 res = 1;
  16607. nullpo_retr(1, sd);
  16608. if (sd->roulette.prizeIdx < 0)
  16609. return RECV_ITEM_FAILED;
  16610. memset(&it, 0, sizeof(it));
  16611. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16612. it.identify = 1;
  16613. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16614. ; // onSuccess
  16615. }
  16616. sd->roulette.claimPrize = false;
  16617. sd->roulette.prizeStage = 0;
  16618. sd->roulette.prizeIdx = -1;
  16619. sd->roulette.stage = 0;
  16620. return res;
  16621. }
  16622. /// Update Roulette window with current stats
  16623. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16624. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16625. nullpo_retv( sd );
  16626. struct packet_roulette_generate_ack p;
  16627. p.PacketType = roulettgenerateackType;
  16628. p.Result = result;
  16629. p.Step = stage;
  16630. p.Idx = prizeIdx;
  16631. p.AdditionItemID = bonusItemID;
  16632. p.RemainBronze = sd->roulette_point.gold;
  16633. p.RemainGold = sd->roulette_point.silver;
  16634. p.RemainSilver = sd->roulette_point.bronze;
  16635. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16636. }
  16637. /// Request to start the roulette
  16638. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16639. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16640. enum GENERATE_ROULETTE_ACK result;
  16641. nullpo_retv(sd);
  16642. if (!battle_config.feature_roulette) {
  16643. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16644. return;
  16645. }
  16646. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16647. return;
  16648. }
  16649. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16650. sd->roulette.stage = 0;
  16651. sd->roulette.claimPrize = false;
  16652. sd->roulette.prizeStage = 0;
  16653. sd->roulette.prizeIdx = -1;
  16654. }
  16655. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16656. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16657. }else{
  16658. if (!sd->roulette.stage) {
  16659. if (sd->roulette_point.bronze > 0) {
  16660. sd->roulette_point.bronze -= 1;
  16661. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16662. } else if (sd->roulette_point.silver > 9) {
  16663. sd->roulette_point.silver -= 10;
  16664. sd->roulette.stage = 2;
  16665. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16666. } else if (sd->roulette_point.gold > 9) {
  16667. sd->roulette_point.gold -= 10;
  16668. sd->roulette.stage = 4;
  16669. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16670. }
  16671. }
  16672. sd->roulette.prizeStage = sd->roulette.stage;
  16673. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16674. sd->roulette.claimPrize = true;
  16675. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16676. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16677. result = GENERATE_ROULETTE_LOSING;
  16678. sd->roulette.stage = 0;
  16679. }else{
  16680. result = GENERATE_ROULETTE_SUCCESS;
  16681. sd->roulette.stage++;
  16682. }
  16683. }
  16684. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16685. }
  16686. /// Request to claim a prize
  16687. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16688. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16689. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16690. nullpo_retv(sd);
  16691. if (!battle_config.feature_roulette) {
  16692. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16693. return;
  16694. }
  16695. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16696. return;
  16697. }
  16698. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16699. switch (clif_roulette_getitem(sd)) {
  16700. case ADDITEM_SUCCESS:
  16701. type = RECV_ITEM_SUCCESS;
  16702. break;
  16703. case ADDITEM_INVALID:
  16704. case ADDITEM_OVERITEM:
  16705. case ADDITEM_OVERAMOUNT:
  16706. type = RECV_ITEM_OVERCOUNT;
  16707. break;
  16708. case ADDITEM_OVERWEIGHT:
  16709. type = RECV_ITEM_OVERWEIGHT;
  16710. break;
  16711. case ADDITEM_STACKLIMIT:
  16712. default:
  16713. type = RECV_ITEM_FAILED;
  16714. break;
  16715. }
  16716. }
  16717. clif_roulette_recvitem_ack(sd,type);
  16718. }
  16719. /// MERGE ITEM
  16720. /**
  16721. * Acknowledge the client about item merger result
  16722. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16723. * @param fd
  16724. * @param sd
  16725. **/
  16726. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16727. unsigned char buf[9];
  16728. struct s_packet_db *info = NULL;
  16729. short cmd = 0;
  16730. nullpo_retv(sd);
  16731. if (!clif_session_isValid(sd))
  16732. return;
  16733. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16734. return;
  16735. if (!(info = &packet_db[cmd]) || info->len == 0)
  16736. return;
  16737. WBUFW(buf, 0) = cmd;
  16738. WBUFW(buf, info->pos[0]) = index;
  16739. WBUFW(buf, info->pos[1]) = count;
  16740. WBUFB(buf, info->pos[2]) = type;
  16741. clif_send(buf, info->len, &sd->bl, SELF);
  16742. }
  16743. /**
  16744. * Check if item has the pair to be merged
  16745. * @param sd
  16746. * @param it Item
  16747. * @return True if has pair, False if not
  16748. **/
  16749. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16750. struct item *it_;
  16751. unsigned short i;
  16752. nullpo_retr(false, sd);
  16753. 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);
  16754. if (i < MAX_INVENTORY)
  16755. return true;
  16756. return false;
  16757. }
  16758. /**
  16759. * Check if item can be merged
  16760. * @param id Item Data
  16761. * @param it Item
  16762. * @return True if can be merged, False if not
  16763. **/
  16764. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16765. if (!id || !it)
  16766. return false;
  16767. if (id->type == IT_CASH)
  16768. return false;
  16769. if (!itemdb_isstackable2(id))
  16770. return false;
  16771. if (itemdb_isspecial(it->card[0]))
  16772. return false;
  16773. if (!it->unique_id)
  16774. return false;
  16775. return true;
  16776. }
  16777. /**
  16778. * Open available item to be merged.
  16779. * Only show 1 item in 1 process.
  16780. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16781. * @param sd
  16782. **/
  16783. void clif_merge_item_open(struct map_session_data *sd) {
  16784. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16785. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16786. int len = 0;
  16787. struct s_packet_db *info = NULL;
  16788. struct item *it;
  16789. nullpo_retv(sd);
  16790. if (!clif_session_isValid(sd))
  16791. return;
  16792. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16793. return;
  16794. if (!(info = &packet_db[cmd]) || info->len == 0)
  16795. return;
  16796. // Get entries
  16797. for (i = 0; i < MAX_INVENTORY; i++) {
  16798. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16799. continue;
  16800. if (clif_merge_item_has_pair(sd, it))
  16801. indexes[n++] = i;
  16802. }
  16803. if (n < 2) { // No item need to be merged
  16804. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16805. return;
  16806. }
  16807. WBUFW(buf, 0) = cmd;
  16808. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16809. for (i = 0; i < n; i++) {
  16810. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16811. }
  16812. clif_send(buf, len, &sd->bl, SELF);
  16813. }
  16814. /**
  16815. * Process item merger
  16816. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16817. * @param fd
  16818. * @param sd
  16819. **/
  16820. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16821. struct s_packet_db *info = NULL;
  16822. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16823. unsigned int count = 0;
  16824. struct item_data *id = NULL;
  16825. nullpo_retv(sd);
  16826. if (!clif_session_isValid(sd))
  16827. return;
  16828. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16829. return;
  16830. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16831. if (n < 2) { // No item need to be merged
  16832. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16833. return;
  16834. }
  16835. for (i = 0, j = 0; i < n; i++) {
  16836. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16837. if( idx < 0 || idx >= MAX_INVENTORY ){
  16838. return;
  16839. }
  16840. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16841. continue;
  16842. indexes[j] = idx;
  16843. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16844. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16845. return;
  16846. }
  16847. count += sd->inventory.u.items_inventory[idx].amount;
  16848. j++;
  16849. }
  16850. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16851. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16852. return;
  16853. }
  16854. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16855. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16856. return;
  16857. }
  16858. // Merrrrge!!!!
  16859. for (i = 1; i < n; i++) {
  16860. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16861. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16862. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16863. sd->inventory_data[idx] = NULL;
  16864. clif_delitem(sd, idx, amt, 0);
  16865. }
  16866. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16867. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16868. }
  16869. /**
  16870. * Cancel item merge
  16871. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16872. * @param fd
  16873. * @param sd
  16874. **/
  16875. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16876. return; // Nothing todo yet
  16877. }
  16878. /**
  16879. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16880. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16881. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16882. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16883. **/
  16884. void clif_broadcast_obtain_special_item( const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  16885. char name[NAME_LENGTH];
  16886. if( battle_config.broadcast_hide_name ){
  16887. std::string dispname = std::string( char_name );
  16888. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  16889. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  16890. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  16891. }else{
  16892. safestrncpy( name, char_name, sizeof( name ) );
  16893. }
  16894. switch( type ){
  16895. case ITEMOBTAIN_TYPE_BOXITEM:
  16896. {
  16897. struct packet_package_item_announce p;
  16898. p.PacketType = package_item_announceType;
  16899. p.type = type;
  16900. p.ItemID = client_nameid( nameid );
  16901. p.len = NAME_LENGTH;
  16902. safestrncpy( p.Name, name, sizeof( p.Name ) );
  16903. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  16904. p.BoxItemID = client_nameid( container );
  16905. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  16906. p.PacketLength = 15 + p.len;
  16907. #else
  16908. p.PacketLength = 11 + p.len;
  16909. #endif
  16910. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  16911. }
  16912. break;
  16913. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16914. case ITEMOBTAIN_TYPE_NPC:
  16915. {
  16916. struct packet_item_drop_announce p;
  16917. p.PacketType = item_drop_announceType;
  16918. p.type = type;
  16919. p.ItemID = client_nameid( nameid );
  16920. p.len = NAME_LENGTH;
  16921. safestrncpy( p.Name, name, sizeof( p.Name ) );
  16922. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  16923. struct mob_db *db = mob_db( container );
  16924. p.monsterNameLen = NAME_LENGTH;
  16925. safestrncpy( p.monsterName, db->name, NAME_LENGTH );
  16926. }else{
  16927. p.monsterNameLen = 0;
  16928. p.monsterName[0] = '\0';
  16929. }
  16930. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  16931. p.PacketLength = 12 + p.len + p.monsterNameLen;
  16932. #else
  16933. p.PacketLength = 8 + p.len + p.monsterNameLen;
  16934. #endif
  16935. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  16936. }
  16937. break;
  16938. }
  16939. }
  16940. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16941. /// 0A02 <view>.W
  16942. /// Value <flag> has the following effects:
  16943. /// 1: Open a Dress Room window.
  16944. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16945. #if PACKETVER >= 20150513
  16946. int fd = sd->fd;
  16947. nullpo_retv(sd);
  16948. WFIFOHEAD(fd, packet_len(0xa02));
  16949. WFIFOW(fd,0) = 0xa02;
  16950. WFIFOW(fd,2) = flag;
  16951. WFIFOSET(fd, packet_len(0xa02));
  16952. #endif
  16953. }
  16954. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16955. /// 0A35 <result>.W
  16956. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16957. #if PACKETVER >= 20150513
  16958. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16959. // Ignore the request
  16960. // - Invalid item index
  16961. // - Invalid item ID or item doesn't exist
  16962. // - Item is already identified
  16963. if (idx < 0 || idx >= MAX_INVENTORY ||
  16964. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16965. sd->inventory.u.items_inventory[idx].identify)
  16966. return;
  16967. // Ignore the request - No magnifiers in inventory
  16968. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16969. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16970. return;
  16971. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16972. return;
  16973. skill_identify(sd, idx);
  16974. #endif
  16975. }
  16976. /// Starts navigation to the given target on client side
  16977. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16978. #if PACKETVER >= 20111010
  16979. int fd = sd->fd;
  16980. WFIFOHEAD(fd,27);
  16981. WFIFOW(fd,0) = 0x08e2;
  16982. // How detailed will our navigation be?
  16983. if( mob_id > 0 ){
  16984. x = 0;
  16985. y = 0;
  16986. WFIFOB(fd,2) = 3; // monster with destination field
  16987. }else if( x > 0 && y > 0 ){
  16988. WFIFOB(fd,2) = 0; // with coordinates
  16989. }else{
  16990. x = 0;
  16991. y = 0;
  16992. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16993. }
  16994. // Which services can be used for transportation?
  16995. WFIFOB(fd,3) = flag;
  16996. // If this flag is set, the navigation window will not be opened up
  16997. WFIFOB(fd,4) = hideWindow;
  16998. // Target map
  16999. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17000. // Target x
  17001. WFIFOW(fd,21) = x;
  17002. // Target y
  17003. WFIFOW(fd,23) = y;
  17004. // Target monster ID
  17005. WFIFOW(fd,25) = mob_id;
  17006. WFIFOSET(fd,27);
  17007. #endif
  17008. }
  17009. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17010. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17011. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17012. #if PACKETVER >= 20150513
  17013. unsigned char* buf;
  17014. int len,i;
  17015. struct map_session_data *tsd;
  17016. struct block_list* tbl;
  17017. if( target == SELF ){
  17018. tsd = BL_CAST(BL_PC,bl);
  17019. tbl = &sd->bl;
  17020. }else{
  17021. tsd = sd;
  17022. tbl = bl;
  17023. }
  17024. if( !tsd->hatEffectCount )
  17025. return;
  17026. len = 9 + tsd->hatEffectCount * 2;
  17027. buf = (unsigned char*)aMalloc( len );
  17028. WBUFW(buf,0) = 0xa3b;
  17029. WBUFW(buf,2) = len;
  17030. WBUFL(buf,4) = tsd->bl.id;
  17031. WBUFB(buf,8) = 1;
  17032. for( i = 0; i < tsd->hatEffectCount; i++ ){
  17033. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  17034. }
  17035. clif_send(buf, len,tbl,target);
  17036. aFree(buf);
  17037. #endif
  17038. }
  17039. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17040. #if PACKETVER >= 20150513
  17041. unsigned char buf[13];
  17042. WBUFW(buf,0) = 0xa3b;
  17043. WBUFW(buf,2) = 13;
  17044. WBUFL(buf,4) = sd->bl.id;
  17045. WBUFB(buf,8) = enable;
  17046. WBUFL(buf,9) = effectId;
  17047. clif_send(buf,13,&sd->bl,AREA);
  17048. #endif
  17049. }
  17050. /// Notify the client that a sale has started
  17051. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17052. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17053. #if PACKETVER_SUPPORTS_SALES
  17054. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17055. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17056. p.itemId = client_nameid( sale_item->nameid );
  17057. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17058. clif_send( &p, sizeof( p ), bl, target );
  17059. #endif
  17060. }
  17061. /// Notify the clien that a sale has ended
  17062. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17063. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17064. #if PACKETVER_SUPPORTS_SALES
  17065. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17066. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17067. p.itemId = client_nameid( sale_item->nameid );
  17068. clif_send( &p, sizeof( p ), bl, target );
  17069. #endif
  17070. }
  17071. /// Update the remaining amount of a sale item.
  17072. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17073. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17074. #if PACKETVER_SUPPORTS_SALES
  17075. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17076. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17077. p.itemId = client_nameid( sale_item->nameid );
  17078. p.amount = sale_item->amount;
  17079. clif_send( &p, sizeof( p ), bl, target );
  17080. #endif
  17081. }
  17082. /// The client requested a refresh of the current remaining count of a sale item
  17083. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17084. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17085. #if PACKETVER_SUPPORTS_SALES
  17086. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17087. struct sale_item_data* sale;
  17088. if( p->AID != sd->status.account_id ){
  17089. return;
  17090. }
  17091. sale = sale_find_item( p->itemId, true );
  17092. if( sale == NULL ){
  17093. return;
  17094. }
  17095. clif_sale_amount(sale, &sd->bl, SELF);
  17096. #endif
  17097. }
  17098. /// Opens the sale administration window on the client
  17099. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17100. void clif_sale_open( struct map_session_data* sd ){
  17101. #if PACKETVER_SUPPORTS_SALES
  17102. nullpo_retv(sd);
  17103. if( sd->state.sale_open ){
  17104. return;
  17105. }
  17106. sd->state.sale_open = true;
  17107. int fd = sd->fd;
  17108. WFIFOHEAD(fd, 2);
  17109. WFIFOW(fd, 0) = 0x9b5;
  17110. WFIFOSET(fd, 2);
  17111. #endif
  17112. }
  17113. /// Client request to open the sale administration window.
  17114. /// This is sent by /limitedsale
  17115. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17116. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17117. #if PACKETVER_SUPPORTS_SALES
  17118. nullpo_retv(sd);
  17119. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17120. return;
  17121. }
  17122. char command[CHAT_SIZE_MAX];
  17123. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17124. is_atcommand(fd, sd, command, 1);
  17125. #endif
  17126. }
  17127. /// Closes the sale administration window on the client.
  17128. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17129. void clif_sale_close(struct map_session_data* sd) {
  17130. #if PACKETVER_SUPPORTS_SALES
  17131. nullpo_retv(sd);
  17132. if( !sd->state.sale_open ){
  17133. return;
  17134. }
  17135. sd->state.sale_open = false;
  17136. int fd = sd->fd;
  17137. WFIFOHEAD(fd, 2);
  17138. WFIFOW(fd, 0) = 0x9bd;
  17139. WFIFOSET(fd, 2);
  17140. #endif
  17141. }
  17142. /// Client request to close the sale administration window.
  17143. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17144. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17145. #if PACKETVER_SUPPORTS_SALES
  17146. nullpo_retv(sd);
  17147. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17148. return;
  17149. }
  17150. clif_sale_close(sd);
  17151. #endif
  17152. }
  17153. /// Reply to a item search request for item sale administration.
  17154. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17155. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17156. #if PACKETVER_SUPPORTS_SALES
  17157. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17158. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17159. if( item != NULL ){
  17160. p.result = 0;
  17161. p.itemId = client_nameid( item->nameid );
  17162. p.price = item->price;
  17163. }else{
  17164. p.result = 1;
  17165. p.itemId = 0;
  17166. p.price = 0;
  17167. }
  17168. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17169. #endif
  17170. }
  17171. /// Search request for an item sale administration.
  17172. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17173. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17174. #if PACKETVER_SUPPORTS_SALES
  17175. char item_name[ITEM_NAME_LENGTH];
  17176. struct item_data *id = NULL;
  17177. nullpo_retv(sd);
  17178. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17179. return;
  17180. }
  17181. if( !sd->state.sale_open ){
  17182. return;
  17183. }
  17184. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17185. id = itemdb_searchname(item_name);
  17186. if( id ){
  17187. int i;
  17188. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17189. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17190. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17191. return;
  17192. }
  17193. }
  17194. }
  17195. // not found
  17196. clif_sale_search_reply( sd, NULL );
  17197. #endif
  17198. }
  17199. /// Reply if an item was successfully put on sale or not.
  17200. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17201. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17202. #if PACKETVER_SUPPORTS_SALES
  17203. int fd = sd->fd;
  17204. WFIFOHEAD(fd, 4);
  17205. WFIFOW(fd, 0) = 0x9af;
  17206. WFIFOW(fd, 2) = (uint16)result;
  17207. WFIFOSET(fd, 4);
  17208. #endif
  17209. }
  17210. /// A client request to put an item on sale.
  17211. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17212. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17213. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17214. #if PACKETVER_SUPPORTS_SALES
  17215. nullpo_retv( sd );
  17216. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17217. if( p->AID != sd->status.account_id ){
  17218. return;
  17219. }
  17220. if( !sd->state.sale_open ){
  17221. return;
  17222. }
  17223. time_t endTime = p->startTime + p->hours * 60 * 60;
  17224. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17225. #endif
  17226. }
  17227. /// Reply to an item removal from sale.
  17228. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17229. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17230. #if PACKETVER_SUPPORTS_SALES
  17231. int fd = sd->fd;
  17232. WFIFOHEAD(fd, 4);
  17233. WFIFOW(fd, 0) = 0x9b1;
  17234. WFIFOW(fd, 2) = failed;
  17235. WFIFOSET(fd, 4);
  17236. #endif
  17237. }
  17238. /// Request to remove an item from sale.
  17239. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17240. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17241. #if PACKETVER_SUPPORTS_SALES
  17242. nullpo_retv( sd );
  17243. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17244. if( p->AID != sd->status.account_id ){
  17245. return;
  17246. }
  17247. if( !sd->state.sale_open ){
  17248. return;
  17249. }
  17250. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17251. #endif
  17252. }
  17253. /// Achievement System
  17254. /// Author: Luxuri, Aleos
  17255. /**
  17256. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17257. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17258. */
  17259. void clif_achievement_list_all(struct map_session_data *sd)
  17260. {
  17261. nullpo_retv(sd);
  17262. if (!battle_config.feature_achievement) {
  17263. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17264. return;
  17265. }
  17266. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17267. if (count == 0)
  17268. return;
  17269. int len = (50 * count) + 22;
  17270. int fd = sd->fd;
  17271. int *info = achievement_level(sd, true);
  17272. WFIFOHEAD(fd,len);
  17273. WFIFOW(fd, 0) = 0xa23;
  17274. WFIFOW(fd, 2) = len;
  17275. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17276. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17277. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17278. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17279. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17280. for (int i = 0; i < count; i++) {
  17281. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17282. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17283. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17284. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17285. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17286. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17287. }
  17288. WFIFOSET(fd, len);
  17289. }
  17290. /**
  17291. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17292. * 0a24 <packetType>.W <ACHPoint>.L
  17293. */
  17294. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17295. {
  17296. nullpo_retv(sd);
  17297. if (!battle_config.feature_achievement) {
  17298. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17299. return;
  17300. }
  17301. int fd = sd->fd;
  17302. int *info = achievement_level(sd, true);
  17303. WFIFOHEAD(fd, packet_len(0xa24));
  17304. WFIFOW(fd, 0) = 0xa24;
  17305. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17306. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17307. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17308. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17309. if (ach) {
  17310. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17311. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17312. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17313. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17314. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17315. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17316. } else
  17317. memset(WFIFOP(fd, 16), 0, 40);
  17318. WFIFOSET(fd, packet_len(0xa24));
  17319. }
  17320. /**
  17321. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17322. * 0a25 <packetType>.W <achievementID>.L
  17323. */
  17324. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17325. {
  17326. nullpo_retv(sd);
  17327. if( sd->achievement_data.save )
  17328. intif_achievement_save(sd);
  17329. achievement_check_reward(sd, RFIFOL(fd,2));
  17330. }
  17331. /**
  17332. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17333. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17334. */
  17335. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17336. {
  17337. WFIFOHEAD(fd, packet_len(0xa26));
  17338. WFIFOW(fd, 0) = 0xa26;
  17339. WFIFOB(fd, 2) = result;
  17340. WFIFOL(fd, 3) = achievement_id;
  17341. WFIFOSET(fd, packet_len(0xa26));
  17342. }
  17343. /// Process the pet evolution request
  17344. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17345. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17346. #if PACKETVER >= 20141008
  17347. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17348. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17349. if (!pet) {
  17350. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17351. return;
  17352. }
  17353. pet_evolution(sd, pet->class_);
  17354. #endif
  17355. }
  17356. /// Sends the result of the evolution to the client.
  17357. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17358. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17359. #if PACKETVER >= 20141008
  17360. int fd = sd->fd;
  17361. WFIFOHEAD(fd, packet_len(0x9fc));
  17362. WFIFOW(fd, 0) = 0x9fc;
  17363. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17364. WFIFOSET(fd, packet_len(0x9fc));
  17365. #endif
  17366. }
  17367. /*
  17368. * This packet is sent by /changedress or /nocosplay
  17369. *
  17370. * 0ae8
  17371. */
  17372. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17373. #if PACKETVER >= 20180103
  17374. char command[CHAT_SIZE_MAX];
  17375. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17376. is_atcommand( fd, sd, command, 1 );
  17377. #endif
  17378. }
  17379. /// Opens an UI window of the given type and initializes it with the given data
  17380. /// 0AE2 <type>.B <data>.L
  17381. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17382. nullpo_retv(sd);
  17383. int fd = sd->fd;
  17384. WFIFOHEAD(fd,packet_len(0xae2));
  17385. WFIFOW(fd,0) = 0xae2;
  17386. WFIFOB(fd,2) = ui_type;
  17387. WFIFOL(fd,3) = data;
  17388. WFIFOSET(fd,packet_len(0xae2));
  17389. }
  17390. /// Request to open an UI window of the given type
  17391. /// 0A68 <type>.B
  17392. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17393. switch( RFIFOB(fd,2) ){
  17394. case IN_UI_ATTENDANCE:
  17395. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17396. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17397. }else if( pc_attendance_enabled() ){
  17398. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17399. }else{
  17400. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17401. }
  17402. break;
  17403. }
  17404. }
  17405. /// Response for attedance request
  17406. /// 0AF0 <unknown>.L <data>.L
  17407. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17408. nullpo_retv(sd);
  17409. int fd = sd->fd;
  17410. WFIFOHEAD(fd,packet_len(0xAF0));
  17411. WFIFOW(fd,0) = 0xAF0;
  17412. WFIFOL(fd,2) = 0;
  17413. WFIFOL(fd,6) = data;
  17414. WFIFOSET(fd,packet_len(0xAF0));
  17415. }
  17416. /// Request from the client to retrieve today's attendance reward
  17417. /// 0AEF
  17418. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17419. pc_attendance_claim_reward(sd);
  17420. }
  17421. /// Send out the percentage of weight that causes it to be displayed in red.
  17422. /// 0ADE <percentage>.L
  17423. void clif_weight_limit( struct map_session_data* sd ){
  17424. #if PACKETVER >= 20171025
  17425. nullpo_retv(sd);
  17426. int fd = sd->fd;
  17427. WFIFOHEAD(fd, packet_len(0xADE));
  17428. WFIFOW(fd, 0) = 0xADE;
  17429. #ifdef RENEWAL
  17430. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17431. #else
  17432. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17433. #endif
  17434. WFIFOSET(fd, packet_len(0xADE));
  17435. #endif
  17436. }
  17437. enum e_private_airship_response : uint32{
  17438. PRIVATEAIRSHIP_OK,
  17439. PRIVATEAIRSHIP_RETRY,
  17440. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17441. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17442. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17443. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17444. };
  17445. /// Send out the response to a private airship request
  17446. /// 0A4A <response>.L
  17447. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17448. #if PACKETVER >= 20180321
  17449. nullpo_retv( sd );
  17450. int fd = sd->fd;
  17451. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17452. WFIFOW( fd, 0 ) = 0xA4A;
  17453. WFIFOL( fd, 2 ) = response;
  17454. WFIFOSET( fd, packet_len( 0xA4A ) );
  17455. #endif
  17456. }
  17457. /// Parses a request for a private airship
  17458. /// 0A49 <mapname>.16B <itemid>.W
  17459. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17460. #if PACKETVER >= 20180321
  17461. // Check if the feature is enabled
  17462. if( !battle_config.feature_privateairship ){
  17463. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17464. return;
  17465. }
  17466. // Check if the player is allowed to warp from the source map
  17467. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17468. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17469. return;
  17470. }
  17471. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17472. char mapname[MAP_NAME_LENGTH_EXT];
  17473. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17474. int16 mapindex = mapindex_name2id( mapname );
  17475. // Check if we know the mapname
  17476. if( mapindex < 0 ){
  17477. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17478. return;
  17479. }
  17480. int16 mapid = map_mapindex2mapid( mapindex );
  17481. // Check if the map is available on this server
  17482. if( mapid < 0 ){
  17483. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17484. return;
  17485. }
  17486. // Check if the player tried to warp to the map he is on
  17487. if( sd->bl.m == mapid ){
  17488. // This is blocked by the client, but just to be sure
  17489. return;
  17490. }
  17491. // This can only be a hack, so we prevent it
  17492. if( map_getmapdata( mapid )->instance_id ){
  17493. // Ignore requests to warp directly into a running instance
  17494. return;
  17495. }
  17496. // Check if the player is allowed to warp to the target map
  17497. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17498. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17499. return;
  17500. }
  17501. uint16 item_id = p->ItemID;
  17502. // Check if the item sent by the client is known to us
  17503. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17504. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17505. return;
  17506. }
  17507. int idx = pc_search_inventory( sd, item_id );
  17508. // Check if the player has the item at all
  17509. if( idx < 0 ){
  17510. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17511. return;
  17512. }
  17513. // Delete the chosen item
  17514. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17515. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17516. return;
  17517. }
  17518. // Warp the player to a random spot on the destination map
  17519. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17520. #endif
  17521. }
  17522. /// Sends out the usage history of the guild storage
  17523. /// 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
  17524. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17525. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17526. #if PACKETVER >= 20140205
  17527. nullpo_retv( sd );
  17528. static struct PACKET_ZC_ACK_GUILDSTORAGE_LOG guild_storage_log;
  17529. int size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17530. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17531. size = log.size() * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17532. }else{
  17533. log.clear();
  17534. }
  17535. guild_storage_log.packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17536. guild_storage_log.PacketLength = size;
  17537. guild_storage_log.result = result;
  17538. guild_storage_log.amount = (uint16)log.size();
  17539. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17540. for( int i = 0; i < log.size(); i++ ){
  17541. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &guild_storage_log.items[i];
  17542. struct guild_log_entry& entry = log[i];
  17543. item->id = entry.id;
  17544. item->itemId = client_nameid( entry.item.nameid );
  17545. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17546. item->action = entry.amount > 0; // action = true(put), false(get)
  17547. item->refine = entry.item.refine;
  17548. item->uniqueId = entry.item.unique_id;
  17549. item->IsIdentified = entry.item.identify;
  17550. item->itemType = itemtype( entry.item.nameid );
  17551. clif_addcards( &item->slot, &entry.item );
  17552. safestrncpy( item->name, entry.name, NAME_LENGTH );
  17553. safestrncpy( item->time, entry.time, NAME_LENGTH );
  17554. item->attribute = entry.item.attribute;
  17555. }
  17556. }
  17557. clif_send( &guild_storage_log, guild_storage_log.PacketLength, &sd->bl, SELF );
  17558. #endif
  17559. }
  17560. /// Activates the client camera info or updates the client camera with the given values.
  17561. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17562. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17563. #if PACKETVER >= 20160525
  17564. int fd = sd->fd;
  17565. WFIFOHEAD(fd, packet_len(0xa78));
  17566. WFIFOW(fd, 0) = 0xa78;
  17567. WFIFOB(fd, 2) = show;
  17568. WFIFOF(fd, 3) = range;
  17569. WFIFOF(fd, 7) = rotation;
  17570. WFIFOF(fd, 11) = latitude;
  17571. WFIFOSET(fd, packet_len(0xa78));
  17572. #endif
  17573. }
  17574. /// Activates or deactives the client camera info or updates the camera settings.
  17575. /// This packet is triggered by /viewpointvalue or /setcamera
  17576. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17577. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17578. char command[CHAT_SIZE_MAX];
  17579. // /viewpointvalue
  17580. if( RFIFOB( fd, 2 ) == 1 ){
  17581. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17582. // /setcamera
  17583. }else{
  17584. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17585. }
  17586. is_atcommand( fd, sd, command, 1 );
  17587. }
  17588. /// Send the full list of items in the equip switch window
  17589. /// 0a9b <length>.W { <index>.W <position>.L }*
  17590. void clif_equipswitch_list( struct map_session_data* sd ){
  17591. #if PACKETVER >= 20170208
  17592. int fd = sd->fd;
  17593. int offset, i, position;
  17594. WFIFOW(fd, 0) = 0xa9b;
  17595. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17596. short index = sd->equip_switch_index[i];
  17597. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17598. WFIFOW(fd, offset) = index + 2;
  17599. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17600. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17601. offset += 6;
  17602. }
  17603. }
  17604. WFIFOW(fd, 2) = offset;
  17605. WFIFOSET(fd, offset);
  17606. #endif
  17607. }
  17608. /// Acknowledgement for removing an equip to the equip switch window
  17609. /// 0a9a <index>.W <position.>.L <failure>.W
  17610. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17611. #if PACKETVER >= 20170208
  17612. int fd = sd->fd;
  17613. WFIFOHEAD(fd, packet_len(0xa9a));
  17614. WFIFOW(fd, 0) = 0xa9a;
  17615. WFIFOW(fd, 2) = index + 2;
  17616. WFIFOL(fd, 4) = pos;
  17617. WFIFOW(fd, 8) = failed;
  17618. WFIFOSET(fd, packet_len(0xa9a));
  17619. #endif
  17620. }
  17621. /// Request to remove an equip from the equip switch window
  17622. /// 0a99 <index>.W <position>.L <= 20170502
  17623. /// 0a99 <index>.W
  17624. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17625. #if PACKETVER >= 20170208
  17626. uint16 index = RFIFOW(fd, 2) - 2;
  17627. bool removed = false;
  17628. if( !battle_config.feature_equipswitch ){
  17629. return;
  17630. }
  17631. // Check if the index is valid
  17632. if( index >= MAX_INVENTORY ){
  17633. return;
  17634. }
  17635. pc_equipswitch_remove( sd, index );
  17636. #endif
  17637. }
  17638. /// Acknowledgement for adding an equip to the equip switch window
  17639. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17640. /// 0a98 <index>.W <position.>.L <flag>.W
  17641. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17642. #if PACKETVER >= 20170208
  17643. int fd = sd->fd;
  17644. WFIFOHEAD(fd, packet_len(0xa98));
  17645. WFIFOW(fd, 0) = 0xa98;
  17646. WFIFOW(fd, 2) = index + 2;
  17647. WFIFOL(fd, 4) = pos;
  17648. #if PACKETVER <= 20170502
  17649. WFIFOL(fd, 8) = flag;
  17650. #else
  17651. WFIFOW(fd, 8) = flag;
  17652. #endif
  17653. WFIFOSET(fd,packet_len(0xa98));
  17654. #endif
  17655. }
  17656. /// Request to add an equip to the equip switch window
  17657. /// 0a97 <index>.W <position>.L
  17658. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17659. #if PACKETVER >= 20170208
  17660. uint16 index = RFIFOW(fd, 2) - 2;
  17661. uint32 position = RFIFOL(fd, 4);
  17662. if( !battle_config.feature_equipswitch ){
  17663. return;
  17664. }
  17665. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17666. return;
  17667. }
  17668. if( sd->state.trading || sd->npc_shopid ){
  17669. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17670. return;
  17671. }
  17672. if( sd->inventory_data[index]->type == IT_AMMO ){
  17673. position = EQP_AMMO;
  17674. }
  17675. pc_equipitem( sd, index, position, true );
  17676. #endif
  17677. }
  17678. /// Acknowledgement packet for the full equip switch
  17679. /// 0a9d <failed>.W
  17680. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17681. #if PACKETVER >= 20170208
  17682. int fd = sd->fd;
  17683. WFIFOHEAD(fd, packet_len(0xa9d));
  17684. WFIFOW(fd, 0) = 0xa9d;
  17685. WFIFOW(fd, 2) = failed;
  17686. WFIFOSET(fd, packet_len(0xa9d));
  17687. #endif
  17688. }
  17689. /// Request to do a full equip switch
  17690. /// 0a9c
  17691. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17692. #if PACKETVER >= 20170208
  17693. int i;
  17694. t_tick tick = gettick();
  17695. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17696. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17697. // Client will not let you send a request
  17698. return;
  17699. }
  17700. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17701. if( !battle_config.feature_equipswitch ){
  17702. return;
  17703. }
  17704. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17705. if( i == EQI_MAX ){
  17706. // client will show: "There is no item to replace." and should not even come here
  17707. clif_equipswitch_reply( sd, false );
  17708. return;
  17709. }
  17710. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17711. return;
  17712. }
  17713. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17714. #endif
  17715. }
  17716. /// Request to do a single equip switch
  17717. /// 0ace <index>.W
  17718. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17719. #if PACKETVER >= 20170502
  17720. uint16 index = RFIFOW(fd, 2) - 2;
  17721. if( !battle_config.feature_equipswitch ){
  17722. return;
  17723. }
  17724. // Check if the index is valid
  17725. if( index >= MAX_INVENTORY ){
  17726. return;
  17727. }
  17728. // Check if the item exists
  17729. if (sd->inventory_data[index] == nullptr)
  17730. return;
  17731. // Check if the item was already added to equip switch
  17732. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17733. if( sd->npc_id ){
  17734. #ifdef RENEWAL
  17735. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17736. clif_msg( sd, WORK_IN_PROGRESS );
  17737. return;
  17738. }
  17739. #endif
  17740. if( !sd->npc_item_flag ){
  17741. return;
  17742. }
  17743. }
  17744. pc_equipswitch( sd, index );
  17745. return;
  17746. }
  17747. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  17748. #endif
  17749. }
  17750. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  17751. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  17752. const struct PACKET_CZ_START_USE_SKILL *p = (struct PACKET_CZ_START_USE_SKILL *)RFIFOP( fd, 0 );
  17753. // Only rolling cutter is supported for now
  17754. if( p->skillId != GC_ROLLINGCUTTER ){
  17755. return;
  17756. }
  17757. // Already running - cant happen on officials, since only one skill is supported
  17758. if( sd->skill_keep_using.skill_id != 0 ){
  17759. return;
  17760. }
  17761. sd->skill_keep_using.tid = INVALID_TIMER;
  17762. sd->skill_keep_using.skill_id = p->skillId;
  17763. sd->skill_keep_using.level = p->skillLv;
  17764. sd->skill_keep_using.target = p->targetId;
  17765. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  17766. #endif
  17767. }
  17768. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  17769. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  17770. const struct PACKET_CZ_STOP_USE_SKILL *p = (struct PACKET_CZ_STOP_USE_SKILL *)RFIFOP( fd, 0 );
  17771. // Not running
  17772. if( sd->skill_keep_using.skill_id == 0 ){
  17773. return;
  17774. }
  17775. #if 0
  17776. // Hack
  17777. if( p->skillId != sd->skill_keep_using.skill_id ){
  17778. return;
  17779. }
  17780. #endif
  17781. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  17782. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  17783. sd->skill_keep_using.tid = INVALID_TIMER;
  17784. }
  17785. sd->skill_keep_using.skill_id = 0;
  17786. sd->skill_keep_using.level = 0;
  17787. sd->skill_keep_using.target = 0;
  17788. #endif
  17789. }
  17790. void clif_ping( struct map_session_data* sd ){
  17791. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  17792. nullpo_retv( sd );
  17793. int fd = sd->fd;
  17794. if( !session_isActive( fd ) ){
  17795. return;
  17796. }
  17797. struct PACKET_ZC_PING p;
  17798. p.packetType = HEADER_ZC_PING;
  17799. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17800. #endif
  17801. }
  17802. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  17803. nullpo_ret( sd );
  17804. int fd = sd->fd;
  17805. if( !session_isActive( fd ) ){
  17806. return 0;
  17807. }
  17808. t_tick tick = va_arg( ap, t_tick );
  17809. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  17810. clif_ping( sd );
  17811. }
  17812. return 0;
  17813. }
  17814. TIMER_FUNC( clif_ping_timer ){
  17815. map_foreachpc( clif_ping_timer_sub, gettick() );
  17816. return 0;
  17817. }
  17818. /*==========================================
  17819. * Main client packet processing function
  17820. *------------------------------------------*/
  17821. static int clif_parse(int fd)
  17822. {
  17823. int cmd, packet_len;
  17824. TBL_PC* sd;
  17825. int pnum;
  17826. #ifdef PACKET_OBFUSCATION
  17827. int cmd2;
  17828. #endif
  17829. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17830. // Note: "click masters" can do 80+ clicks in 10 seconds
  17831. 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]
  17832. { // begin main client packet processing loop
  17833. sd = (TBL_PC *)session[fd]->session_data;
  17834. if (session[fd]->flag.eof) {
  17835. if (sd) {
  17836. if (sd->state.autotrade) {
  17837. //Disassociate character from the socket connection.
  17838. session[fd]->session_data = NULL;
  17839. sd->fd = 0;
  17840. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17841. } else
  17842. if (sd->state.active) {
  17843. // Player logout display [Valaris]
  17844. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17845. clif_quitsave(fd, sd);
  17846. } else {
  17847. //Unusual logout (during log on/off/map-changer procedure)
  17848. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17849. map_quit(sd);
  17850. }
  17851. } else {
  17852. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17853. }
  17854. do_close(fd);
  17855. return 0;
  17856. }
  17857. if (RFIFOREST(fd) < 2)
  17858. return 0;
  17859. cmd = RFIFOW(fd, 0);
  17860. #ifdef PACKET_OBFUSCATION
  17861. // Check if it is a player that tries to connect to the map server.
  17862. if( sd ){
  17863. // Decrypt the current packet ID with the last key stored in the session.
  17864. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17865. }else{
  17866. // Store the original value for checking
  17867. cmd2 = cmd;
  17868. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17869. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17870. }
  17871. #endif
  17872. // filter out invalid / unsupported packets
  17873. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17874. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17875. #ifdef DUMP_INVALID_PACKET
  17876. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17877. #endif
  17878. #ifdef PACKET_OBFUSCATION_WARN
  17879. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17880. if( !sd ){
  17881. #ifdef PACKET_OBFUSCATION
  17882. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17883. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17884. }
  17885. #else
  17886. // Try to use the initial keys for the decryption of the packet ID.
  17887. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17888. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17889. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17890. }
  17891. #endif
  17892. }
  17893. #endif
  17894. set_eof(fd);
  17895. return 0;
  17896. }
  17897. // determine real packet length
  17898. packet_len = packet_db[cmd].len;
  17899. if (packet_len == -1) { // variable-length packet
  17900. if (RFIFOREST(fd) < 4)
  17901. return 0;
  17902. packet_len = RFIFOW(fd,2);
  17903. if (packet_len < 4 || packet_len > 32768) {
  17904. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17905. #ifdef DUMP_INVALID_PACKET
  17906. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17907. #endif
  17908. set_eof(fd);
  17909. return 0;
  17910. }
  17911. }
  17912. if ((int)RFIFOREST(fd) < packet_len){
  17913. 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 );
  17914. #ifdef DUMP_INVALID_PACKET
  17915. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  17916. #endif
  17917. set_eof( fd );
  17918. return 0; // not enough data received to form the packet
  17919. }
  17920. #ifdef PACKET_OBFUSCATION
  17921. RFIFOW(fd, 0) = cmd;
  17922. if (sd)
  17923. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17924. #endif
  17925. if( packet_db[cmd].func == clif_parse_debug )
  17926. packet_db[cmd].func(fd, sd);
  17927. else if( packet_db[cmd].func != NULL ) {
  17928. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17929. ; //Only valid packet when there is no session
  17930. else
  17931. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17932. ; //Only valid packet when player is not on a map
  17933. else
  17934. packet_db[cmd].func(fd, sd);
  17935. }
  17936. #ifdef DUMP_UNKNOWN_PACKET
  17937. else DumpUnknown(fd,sd,cmd,packet_len);
  17938. #endif
  17939. RFIFOSKIP(fd, packet_len);
  17940. }; // main loop end
  17941. return 0;
  17942. }
  17943. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17944. va_list argp;
  17945. int i;
  17946. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17947. return;
  17948. packet_db[cmd].len = length;
  17949. packet_db[cmd].func = func;
  17950. va_start(argp, func);
  17951. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17952. int offset = va_arg(argp, int);
  17953. if( offset == 0 ){
  17954. break;
  17955. }
  17956. packet_db[cmd].pos[i] = offset;
  17957. }
  17958. if( i == MAX_PACKET_POS ){
  17959. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17960. }
  17961. va_end(argp);
  17962. }
  17963. /*==========================================
  17964. * Reads packets and setups its array reference
  17965. *------------------------------------------*/
  17966. void packetdb_readdb(){
  17967. memset(packet_db,0,sizeof(packet_db));
  17968. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17969. #include "clif_packetdb.hpp"
  17970. #include "clif_shuffle.hpp"
  17971. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17972. #ifdef PACKET_OBFUSCATION
  17973. 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]);
  17974. #else
  17975. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17976. #endif
  17977. }
  17978. /*==========================================
  17979. *
  17980. *------------------------------------------*/
  17981. void do_init_clif(void) {
  17982. const char* colors[COLOR_MAX] = {
  17983. "0x00FF00",
  17984. "0xFF0000",
  17985. "0xFFFFFF",
  17986. "0xFFFF00",
  17987. "0x00FFFF",
  17988. "0xB5FFB5",
  17989. };
  17990. int i;
  17991. /**
  17992. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17993. **/
  17994. for(i = 0; i < COLOR_MAX; i++) {
  17995. color_table[i] = strtoul(colors[i],NULL,0);
  17996. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17997. }
  17998. packetdb_readdb();
  17999. set_defaultparse(clif_parse);
  18000. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  18001. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  18002. exit(EXIT_FAILURE);
  18003. }
  18004. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  18005. add_timer_func_list(clif_delayquit, "clif_delayquit");
  18006. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  18007. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  18008. if( battle_config.ping_timer_interval > 0 ){
  18009. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  18010. }
  18011. #endif
  18012. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  18013. }
  18014. void do_final_clif(void) {
  18015. ers_destroy(delay_clearunit_ers);
  18016. }