clif.cpp 629 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // Copyright (c) Hercules Dev Team - Licensed under GNU GPL
  3. // For more information, see LICENCE in the main folder
  4. #include "clif.hpp"
  5. #include <cstdarg>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include "../common/cbasetypes.hpp"
  11. #include "../common/conf.hpp"
  12. #include "../common/ers.hpp"
  13. #include "../common/grfio.hpp"
  14. #include "../common/malloc.hpp"
  15. #include "../common/nullpo.hpp"
  16. #include "../common/random.hpp"
  17. #include "../common/showmsg.hpp"
  18. #include "../common/socket.hpp"
  19. #include "../common/strlib.hpp"
  20. #include "../common/timer.hpp"
  21. #include "../common/utilities.hpp"
  22. #include "../common/utils.hpp"
  23. #include "achievement.hpp"
  24. #include "atcommand.hpp"
  25. #include "battle.hpp"
  26. #include "battleground.hpp"
  27. #include "cashshop.hpp"
  28. #include "channel.hpp"
  29. #include "chat.hpp"
  30. #include "chrif.hpp"
  31. #include "clan.hpp"
  32. #include "clif.hpp"
  33. #include "elemental.hpp"
  34. #include "guild.hpp"
  35. #include "homunculus.hpp"
  36. #include "instance.hpp"
  37. #include "intif.hpp"
  38. #include "itemdb.hpp"
  39. #include "log.hpp"
  40. #include "mail.hpp"
  41. #include "map.hpp"
  42. #include "mercenary.hpp"
  43. #include "mob.hpp"
  44. #include "npc.hpp"
  45. #include "party.hpp"
  46. #include "pc.hpp"
  47. #include "pc_groups.hpp"
  48. #include "pet.hpp"
  49. #include "quest.hpp"
  50. #include "script.hpp"
  51. #include "skill.hpp"
  52. #include "status.hpp"
  53. #include "storage.hpp"
  54. #include "trade.hpp"
  55. #include "unit.hpp"
  56. #include "vending.hpp"
  57. using namespace rathena;
  58. static inline uint32 client_tick( t_tick tick ){
  59. return (uint32)tick;
  60. }
  61. #if PACKETVER >= 20170830
  62. static inline int64 client_exp(t_exp exp) {
  63. return (int64)u64min(exp, MAX_EXP);
  64. }
  65. #else
  66. static inline int32 client_exp(t_exp exp) {
  67. return (int32)u64min(exp, MAX_EXP);
  68. }
  69. #endif
  70. /* for clif_clearunit_delayed */
  71. static struct eri *delay_clearunit_ers;
  72. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  73. int packet_db_ack[MAX_ACK_FUNC + 1];
  74. unsigned long color_table[COLOR_MAX];
  75. #include "clif_obfuscation.hpp"
  76. static bool clif_session_isValid(struct map_session_data *sd);
  77. static void clif_loadConfirm( struct map_session_data *sd );
  78. #if PACKETVER >= 20150513
  79. enum mail_type {
  80. MAIL_TYPE_TEXT = 0x0,
  81. MAIL_TYPE_ZENY = 0x2,
  82. MAIL_TYPE_ITEM = 0x4,
  83. MAIL_TYPE_NPC = 0x8
  84. };
  85. #endif
  86. enum e_inventory_type{
  87. INVTYPE_INVENTORY = 0,
  88. INVTYPE_CART = 1,
  89. INVTYPE_STORAGE = 2,
  90. INVTYPE_GUILD_STORAGE = 3,
  91. };
  92. /** Converts item type to display it on client if necessary.
  93. * @param nameid: Item ID
  94. * @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
  95. */
  96. static inline int itemtype(unsigned short nameid) {
  97. 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
  98. int type = id->type;
  99. if( type == IT_SHADOWGEAR ) {
  100. if( id->equip&EQP_SHADOW_WEAPON )
  101. return IT_WEAPON;
  102. else
  103. return IT_ARMOR;
  104. }
  105. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  106. }
  107. // TODO: doc
  108. static inline uint16 client_index( uint16 server_index ){
  109. return server_index + 2;
  110. }
  111. static inline uint16 server_index( uint16 client_index ){
  112. return client_index - 2;
  113. }
  114. static inline uint16 client_storage_index( uint16 server_index ){
  115. return server_index + 1;
  116. }
  117. static inline uint16 server_storage_index( uint16 client_index ){
  118. return client_index - 1;
  119. }
  120. static inline uint32 disguised_bl_id( uint32 bl_id ){
  121. // Casting to prevent a compiler warning
  122. return -((int32)bl_id);
  123. }
  124. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  125. static inline uint32 client_nameid( uint32 server_nameid ){
  126. uint32 view = itemdb_viewid( server_nameid );
  127. if( view > 0 ){
  128. return view;
  129. }else{
  130. return server_nameid;
  131. }
  132. }
  133. #else
  134. static inline uint16 client_nameid( uint32 server_nameid ){
  135. uint32 view = itemdb_viewid( server_nameid );
  136. if( view > 0 ){
  137. return (uint16)view;
  138. }else{
  139. return (uint16)server_nameid;
  140. }
  141. }
  142. #endif
  143. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  144. p += pos;
  145. p[0] = (uint8)(x>>2);
  146. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  147. p[2] = (uint8)((y<<4) | (dir&0xf));
  148. }
  149. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  150. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  151. p += pos;
  152. p[0] = (uint8)(x0>>2);
  153. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  154. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  155. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  156. p[4] = (uint8)y1;
  157. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  158. }
  159. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  160. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  161. }
  162. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  163. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  164. }
  165. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  166. p += pos;
  167. if( x ) {
  168. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  169. }
  170. if( y ) {
  171. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  172. }
  173. if( dir ) {
  174. dir[0] = ( p[2] & 0x0f );
  175. }
  176. }
  177. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  178. p += pos;
  179. if( x0 ) {
  180. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  181. }
  182. if( y0 ) {
  183. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  184. }
  185. if( x1 ) {
  186. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  187. }
  188. if( y1 ) {
  189. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  190. }
  191. if( sx0 ) {
  192. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  193. }
  194. if( sy0 ) {
  195. sy0[0] = ( p[5] & 0x0f ) >> 0;
  196. }
  197. }
  198. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  199. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  200. }
  201. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  202. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  203. }
  204. //To idenfity disguised characters.
  205. static inline bool disguised(struct block_list* bl) {
  206. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  207. }
  208. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  209. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  210. if( len > max )
  211. len = max;
  212. mes[len-1] = '\0';
  213. return len;
  214. }
  215. static char map_ip_str[128];
  216. static uint32 map_ip;
  217. static uint32 bind_ip = INADDR_ANY;
  218. static uint16 map_port = 5121;
  219. static bool clif_ally_only = false;
  220. int map_fd;
  221. static int clif_parse (int fd);
  222. /*==========================================
  223. * Ip setting of map-server
  224. *------------------------------------------*/
  225. int clif_setip(const char* ip) {
  226. char ip_str[16];
  227. map_ip = host2ip(ip);
  228. if (!map_ip) {
  229. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  230. return 0;
  231. }
  232. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  233. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  234. return 1;
  235. }
  236. void clif_setbindip(const char* ip)
  237. {
  238. bind_ip = host2ip(ip);
  239. if (bind_ip) {
  240. char ip_str[16];
  241. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  242. } else {
  243. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  244. }
  245. }
  246. /*==========================================
  247. * Sets map port to 'port'
  248. * is run from map.cpp upon loading map server configuration
  249. *------------------------------------------*/
  250. void clif_setport(uint16 port)
  251. {
  252. map_port = port;
  253. }
  254. /*==========================================
  255. * Returns map server IP
  256. *------------------------------------------*/
  257. uint32 clif_getip(void)
  258. {
  259. return map_ip;
  260. }
  261. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  262. uint32 clif_refresh_ip(void)
  263. {
  264. uint32 new_ip;
  265. new_ip = host2ip(map_ip_str);
  266. if (new_ip && new_ip != map_ip) {
  267. map_ip = new_ip;
  268. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  269. return map_ip;
  270. }
  271. return 0;
  272. }
  273. /*==========================================
  274. * Returns map port which is set by clif_setport()
  275. *------------------------------------------*/
  276. uint16 clif_getport(void)
  277. {
  278. return map_port;
  279. }
  280. #if PACKETVER >= 20071106
  281. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  282. switch (bl->type) {
  283. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  284. case BL_ITEM: return 0x2; //ITEM_TYPE
  285. case BL_SKILL: return 0x3; //SKILL_TYPE
  286. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  287. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  288. case BL_NPC:
  289. // From 2017-07-26 on NPC type units can also use player sprites.
  290. // There is one exception and this is if they are walking.
  291. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  292. #if PACKETVER >= 20170726
  293. return ( pcdb_checkid(status_get_viewdata(bl)->class_) && walking ) ? 0x0 : 0x6; //NPC_EVT_TYPE
  294. #else
  295. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  296. #endif
  297. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  298. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  299. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  300. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  301. default: return 0x1; //NPC_TYPE
  302. }
  303. }
  304. #endif
  305. static bool clif_session_isValid(struct map_session_data *sd) {
  306. return ( sd != NULL && session_isActive(sd->fd) );
  307. }
  308. /*==========================================
  309. * sub process of clif_send
  310. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  311. * In order to send area-wise packets, such as:
  312. * - AREA : everyone nearby your area
  313. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  314. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  315. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  316. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  317. *------------------------------------------*/
  318. static int clif_send_sub(struct block_list *bl, va_list ap)
  319. {
  320. struct block_list *src_bl;
  321. struct map_session_data *sd;
  322. unsigned char *buf;
  323. int len, type, fd;
  324. nullpo_ret(bl);
  325. nullpo_ret(sd = (struct map_session_data *)bl);
  326. // Don't send to disconnected clients.
  327. if( !session_isActive( fd = sd->fd ) ){
  328. return 0;
  329. }
  330. buf = va_arg(ap,unsigned char*);
  331. len = va_arg(ap,int);
  332. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  333. type = va_arg(ap,int);
  334. switch(type) {
  335. case AREA_WOS:
  336. if (bl == src_bl)
  337. return 0;
  338. break;
  339. case AREA_WOC:
  340. if (sd->chatID || bl == src_bl)
  341. return 0;
  342. break;
  343. case AREA_WOSC:
  344. {
  345. if(src_bl->type == BL_PC) {
  346. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  347. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  348. return 0;
  349. }
  350. else if(src_bl->type == BL_NPC) {
  351. struct npc_data *nd = (struct npc_data *)src_bl;
  352. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  353. return 0;
  354. }
  355. }
  356. break;
  357. }
  358. /* unless visible, hold it here */
  359. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  360. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  361. return 0;
  362. WFIFOHEAD(fd, len);
  363. if (WFIFOP(fd,0) == buf) {
  364. ShowError("WARNING: Invalid use of clif_send function\n");
  365. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  366. ShowError(" Please correct your code.\n");
  367. // don't send to not move the pointer of the packet for next sessions in the loop
  368. //WFIFOSET(fd,0);//## TODO is this ok?
  369. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  370. return 0;
  371. }
  372. memcpy(WFIFOP(fd,0), buf, len);
  373. WFIFOSET(fd,len);
  374. return 0;
  375. }
  376. /*==========================================
  377. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  378. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  379. *------------------------------------------*/
  380. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  381. {
  382. int i;
  383. struct map_session_data *sd, *tsd;
  384. struct party_data *p = NULL;
  385. struct guild *g = NULL;
  386. std::shared_ptr<s_battleground_data> bg;
  387. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  388. struct s_mapiterator* iter;
  389. if( type != ALL_CLIENT )
  390. nullpo_ret(bl);
  391. sd = BL_CAST(BL_PC, bl);
  392. switch(type) {
  393. case ALL_CLIENT: //All player clients.
  394. iter = mapit_getallusers();
  395. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  396. if( session_isActive( fd = tsd->fd ) ){
  397. WFIFOHEAD( fd, len );
  398. memcpy( WFIFOP( fd, 0 ), buf, len );
  399. WFIFOSET( fd, len );
  400. }
  401. }
  402. mapit_free(iter);
  403. break;
  404. case ALL_SAMEMAP: //All players on the same map
  405. iter = mapit_getallusers();
  406. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  407. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  408. WFIFOHEAD( fd, len );
  409. memcpy( WFIFOP( fd, 0 ), buf, len );
  410. WFIFOSET( fd, len );
  411. }
  412. }
  413. mapit_free(iter);
  414. break;
  415. case AREA:
  416. case AREA_WOSC:
  417. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  418. clif_send (buf, len, bl, SELF);
  419. case AREA_WOC:
  420. case AREA_WOS:
  421. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  422. BL_PC, buf, len, bl, type);
  423. break;
  424. case AREA_CHAT_WOC:
  425. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  426. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  427. break;
  428. case CHAT:
  429. case CHAT_WOS:
  430. {
  431. struct chat_data *cd;
  432. if (sd) {
  433. cd = (struct chat_data*)map_id2bl(sd->chatID);
  434. } else if (bl->type == BL_CHAT) {
  435. cd = (struct chat_data*)bl;
  436. } else break;
  437. if (cd == NULL)
  438. break;
  439. for(i = 0; i < cd->users; i++) {
  440. if (type == CHAT_WOS && cd->usersd[i] == sd)
  441. continue;
  442. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  443. WFIFOHEAD(fd,len);
  444. memcpy(WFIFOP(fd,0), buf, len);
  445. WFIFOSET(fd,len);
  446. }
  447. }
  448. }
  449. break;
  450. case PARTY_AREA:
  451. case PARTY_AREA_WOS:
  452. x0 = bl->x - AREA_SIZE;
  453. y0 = bl->y - AREA_SIZE;
  454. x1 = bl->x + AREA_SIZE;
  455. y1 = bl->y + AREA_SIZE;
  456. case PARTY:
  457. case PARTY_WOS:
  458. case PARTY_SAMEMAP:
  459. case PARTY_SAMEMAP_WOS:
  460. if (sd && sd->status.party_id)
  461. p = party_search(sd->status.party_id);
  462. if (p) {
  463. for(i=0;i<MAX_PARTY;i++){
  464. if( (sd = p->data[i].sd) == NULL )
  465. continue;
  466. if( !session_isActive( fd = sd->fd ) )
  467. continue;
  468. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  469. continue;
  470. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  471. continue;
  472. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  473. continue;
  474. WFIFOHEAD(fd, len);
  475. memcpy(WFIFOP(fd, 0), buf, len);
  476. WFIFOSET(fd, len);
  477. }
  478. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  479. break;
  480. iter = mapit_getallusers();
  481. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  482. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  483. WFIFOHEAD( fd, len );
  484. memcpy( WFIFOP( fd, 0 ), buf, len );
  485. WFIFOSET( tsd->fd, len );
  486. }
  487. }
  488. mapit_free(iter);
  489. }
  490. break;
  491. case DUEL:
  492. case DUEL_WOS:
  493. if (!sd || !sd->duel_group) break; //Invalid usage.
  494. iter = mapit_getallusers();
  495. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  496. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  497. continue;
  498. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  499. WFIFOHEAD( fd, len );
  500. memcpy( WFIFOP( fd, 0 ), buf, len );
  501. WFIFOSET( fd, len );
  502. }
  503. }
  504. mapit_free(iter);
  505. break;
  506. case SELF:
  507. if( sd && session_isActive( fd=sd->fd ) ){
  508. WFIFOHEAD(fd,len);
  509. memcpy(WFIFOP(fd,0), buf, len);
  510. WFIFOSET(fd,len);
  511. }
  512. break;
  513. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  514. case GUILD_AREA:
  515. case GUILD_AREA_WOS:
  516. x0 = bl->x - AREA_SIZE;
  517. y0 = bl->y - AREA_SIZE;
  518. x1 = bl->x + AREA_SIZE;
  519. y1 = bl->y + AREA_SIZE;
  520. case GUILD_SAMEMAP:
  521. case GUILD_SAMEMAP_WOS:
  522. case GUILD:
  523. case GUILD_WOS:
  524. case GUILD_NOBG:
  525. if (sd && sd->status.guild_id)
  526. g = sd->guild;
  527. if (g) {
  528. for(i = 0; i < g->max_member; i++) {
  529. if( (sd = g->member[i].sd) != nullptr ){
  530. if( !session_isActive( fd = sd->fd ) )
  531. continue;
  532. if( type == GUILD_NOBG && sd->bg_id )
  533. continue;
  534. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  535. continue;
  536. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  537. continue;
  538. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  539. continue;
  540. WFIFOHEAD(fd,len);
  541. memcpy(WFIFOP(fd,0), buf, len);
  542. WFIFOSET(fd,len);
  543. }
  544. }
  545. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  546. break;
  547. iter = mapit_getallusers();
  548. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  549. if( tsd->guildspy == g->guild_id && session_isActive( fd = tsd->fd ) ){
  550. WFIFOHEAD( fd, len );
  551. memcpy( WFIFOP( fd, 0 ), buf, len );
  552. WFIFOSET( fd, len );
  553. }
  554. }
  555. mapit_free(iter);
  556. }
  557. break;
  558. case BG_AREA:
  559. case BG_AREA_WOS:
  560. x0 = bl->x - AREA_SIZE;
  561. y0 = bl->y - AREA_SIZE;
  562. x1 = bl->x + AREA_SIZE;
  563. y1 = bl->y + AREA_SIZE;
  564. case BG_SAMEMAP:
  565. case BG_SAMEMAP_WOS:
  566. case BG:
  567. case BG_WOS:
  568. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  569. {
  570. for (const auto &member : bg->members) {
  571. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  572. continue;
  573. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  574. continue;
  575. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  576. continue;
  577. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  578. continue;
  579. WFIFOHEAD(fd,len);
  580. memcpy(WFIFOP(fd,0), buf, len);
  581. WFIFOSET(fd,len);
  582. }
  583. }
  584. break;
  585. case CLAN:
  586. if( sd && sd->clan ){
  587. struct clan* clan = sd->clan;
  588. for( i = 0; i < clan->max_member; i++ ){
  589. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  590. continue;
  591. }
  592. WFIFOHEAD(fd,len);
  593. memcpy(WFIFOP(fd,0), buf, len);
  594. WFIFOSET(fd,len);
  595. }
  596. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  597. break;
  598. iter = mapit_getallusers();
  599. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  600. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  601. WFIFOHEAD(fd, len);
  602. memcpy(WFIFOP(fd, 0), buf, len);
  603. WFIFOSET(fd, len);
  604. }
  605. }
  606. mapit_free(iter);
  607. }
  608. break;
  609. default:
  610. ShowError("clif_send: Unrecognized type %d\n",type);
  611. return -1;
  612. }
  613. return 0;
  614. }
  615. /// Notifies the client, that it's connection attempt was accepted.
  616. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  617. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  618. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  619. void clif_authok(struct map_session_data *sd)
  620. {
  621. #if PACKETVER < 20080102
  622. const int cmd = 0x73;
  623. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  624. const int cmd = 0x2eb;
  625. #else
  626. const int cmd = 0xa18;
  627. #endif
  628. int fd = sd->fd;
  629. WFIFOHEAD(fd,packet_len(cmd));
  630. WFIFOW(fd, 0) = cmd;
  631. WFIFOL(fd, 2) = client_tick(gettick());
  632. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  633. WFIFOB(fd, 9) = 5; // ignored
  634. WFIFOB(fd,10) = 5; // ignored
  635. #if PACKETVER >= 20080102
  636. WFIFOW(fd,11) = sd->status.font;
  637. #endif
  638. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  639. WFIFOB(fd,13) = sd->status.sex;
  640. #endif
  641. WFIFOSET(fd,packet_len(cmd));
  642. }
  643. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  644. /// 0074 <error code>.B
  645. /// error code:
  646. /// 0 = client type mismatch
  647. /// 1 = ID mismatch
  648. /// 2 = mobile - out of available time
  649. /// 3 = mobile - already logged in
  650. /// 4 = mobile - waiting state
  651. void clif_authrefuse(int fd, uint8 error_code)
  652. {
  653. WFIFOHEAD(fd,packet_len(0x74));
  654. WFIFOW(fd,0) = 0x74;
  655. WFIFOB(fd,2) = error_code;
  656. WFIFOSET(fd,packet_len(0x74));
  657. }
  658. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  659. /// 0081 <error code>.B
  660. /// error code:
  661. /// 0 = BAN_UNFAIR
  662. /// 1 = server closed -> MsgStringTable[4]
  663. /// 2 = ID already logged in -> MsgStringTable[5]
  664. /// 3 = timeout/too much lag -> MsgStringTable[241]
  665. /// 4 = server full -> MsgStringTable[264]
  666. /// 5 = underaged -> MsgStringTable[305]
  667. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  668. /// 9 = too many connections from this ip -> MsgStringTable[529]
  669. /// 10 = out of available time paid for -> MsgStringTable[530]
  670. /// 11 = BAN_PAY_SUSPEND
  671. /// 12 = BAN_PAY_CHANGE
  672. /// 13 = BAN_PAY_WRONGIP
  673. /// 14 = BAN_PAY_PNGAMEROOM
  674. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  675. /// 16 = BAN_JAPAN_REFUSE1
  676. /// 17 = BAN_JAPAN_REFUSE2
  677. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  678. /// 100 = BAN_PC_IP_UNFAIR
  679. /// 101 = BAN_PC_IP_COUNT_ALL
  680. /// 102 = BAN_PC_IP_COUNT
  681. /// 103 = BAN_GRAVITY_MEM_AGREE
  682. /// 104 = BAN_GAME_MEM_AGREE
  683. /// 105 = BAN_HAN_VALID
  684. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  685. /// 107 = BAN_OVER_CHARACTER_LIST
  686. /// 108 = BAN_IP_BLOCK
  687. /// 109 = BAN_INVALID_PWD_CNT
  688. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  689. /// ? = disconnected -> MsgStringTable[3]
  690. void clif_authfail_fd(int fd, int type)
  691. {
  692. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  693. return;
  694. WFIFOHEAD(fd, packet_len(0x81));
  695. WFIFOW(fd,0) = 0x81;
  696. WFIFOB(fd,2) = type;
  697. WFIFOSET(fd,packet_len(0x81));
  698. set_eof(fd);
  699. }
  700. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  701. /// 00b3 <type>.B
  702. /// type:
  703. /// 1 = disconnect, char-select
  704. /// ? = nothing
  705. void clif_charselectok(int id, uint8 ok)
  706. {
  707. struct map_session_data* sd;
  708. int fd;
  709. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  710. return;
  711. fd = sd->fd;
  712. WFIFOHEAD(fd,packet_len(0xb3));
  713. WFIFOW(fd,0) = 0xb3;
  714. WFIFOB(fd,2) = ok;
  715. WFIFOSET(fd,packet_len(0xb3));
  716. }
  717. /// Makes an item appear on the ground.
  718. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  719. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  720. /// 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)
  721. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  722. nullpo_retv(fitem);
  723. if( fitem->item.nameid <= 0 ){
  724. return;
  725. }
  726. int view = itemdb_viewid( fitem->item.nameid );
  727. struct packet_dropflooritem p;
  728. p.PacketType = dropflooritemType;
  729. p.ITAID = fitem->bl.id;
  730. p.ITID = ( view > 0 ) ? view : fitem->item.nameid;
  731. #if PACKETVER >= 20130000 /* not sure date */
  732. p.type = itemtype( fitem->item.nameid );
  733. #endif
  734. p.IsIdentified = fitem->item.identify ? 1 : 0;
  735. p.xPos = fitem->bl.x;
  736. p.yPos = fitem->bl.y;
  737. p.subX = fitem->subx;
  738. p.subY = fitem->suby;
  739. p.count = fitem->item.amount;
  740. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  741. if( canShowEffect ){
  742. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  743. if( dropEffect > 0 ){
  744. p.showdropeffect = 1;
  745. p.dropeffectmode = dropEffect - 1;
  746. }else{
  747. p.showdropeffect = 0;
  748. p.dropeffectmode = 0;
  749. }
  750. }else{
  751. p.showdropeffect = 0;
  752. p.dropeffectmode = 0;
  753. }
  754. #endif
  755. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  756. }
  757. /// Makes an item disappear from the ground.
  758. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  759. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  760. {
  761. unsigned char buf[16];
  762. nullpo_retv(fitem);
  763. WBUFW(buf,0) = 0xa1;
  764. WBUFL(buf,2) = fitem->bl.id;
  765. if (fd == 0) {
  766. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  767. } else {
  768. WFIFOHEAD(fd,packet_len(0xa1));
  769. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  770. WFIFOSET(fd,packet_len(0xa1));
  771. }
  772. }
  773. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  774. /// 0080 <id>.L <type>.B
  775. /// type:
  776. /// 0 = out of sight
  777. /// 1 = died
  778. /// 2 = logged out
  779. /// 3 = teleport
  780. /// 4 = trickdead
  781. void clif_clearunit_single(int id, clr_type type, int fd)
  782. {
  783. WFIFOHEAD(fd, packet_len(0x80));
  784. WFIFOW(fd,0) = 0x80;
  785. WFIFOL(fd,2) = id;
  786. WFIFOB(fd,6) = type;
  787. WFIFOSET(fd, packet_len(0x80));
  788. }
  789. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  790. /// 0080 <id>.L <type>.B
  791. /// type:
  792. /// 0 = out of sight
  793. /// 1 = died
  794. /// 2 = logged out
  795. /// 3 = teleport
  796. /// 4 = trickdead
  797. void clif_clearunit_area(struct block_list* bl, clr_type type)
  798. {
  799. unsigned char buf[8];
  800. nullpo_retv(bl);
  801. WBUFW(buf,0) = 0x80;
  802. WBUFL(buf,2) = bl->id;
  803. WBUFB(buf,6) = type;
  804. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  805. if(disguised(bl)) {
  806. WBUFL(buf,2) = disguised_bl_id( bl->id );
  807. clif_send(buf, packet_len(0x80), bl, SELF);
  808. }
  809. }
  810. /// Used to make monsters with player-sprites disappear after dying
  811. /// like normal monsters, because the client does not remove those
  812. /// automatically.
  813. static TIMER_FUNC(clif_clearunit_delayed_sub){
  814. struct block_list *bl = (struct block_list *)data;
  815. clif_clearunit_area(bl, (clr_type) id);
  816. ers_free(delay_clearunit_ers,bl);
  817. return 0;
  818. }
  819. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  820. {
  821. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  822. memcpy (tbl, bl, sizeof (struct block_list));
  823. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  824. }
  825. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  826. {
  827. if(sd->sc.option&OPTION_COSTUME)
  828. {
  829. *rhand = *lhand = 0;
  830. return;
  831. }
  832. #if PACKETVER < 4
  833. *rhand = sd->status.weapon;
  834. *lhand = sd->status.shield;
  835. #else
  836. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  837. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  838. {
  839. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  840. if (id->view_id > 0)
  841. *rhand = id->view_id;
  842. else
  843. *rhand = id->nameid;
  844. } else
  845. *rhand = 0;
  846. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  847. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  848. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  849. {
  850. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  851. if (id->view_id > 0)
  852. *lhand = id->view_id;
  853. else
  854. *lhand = id->nameid;
  855. } else
  856. *lhand = 0;
  857. #endif
  858. }
  859. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  860. static int clif_setlevel_sub(int lv) {
  861. if( lv < battle_config.max_lv ) {
  862. ;
  863. } else if( lv < battle_config.aura_lv ) {
  864. lv = battle_config.max_lv - 1;
  865. } else {
  866. lv = battle_config.max_lv;
  867. }
  868. return lv;
  869. }
  870. static int clif_setlevel(struct block_list* bl) {
  871. int lv = status_get_lv(bl);
  872. if( battle_config.client_limit_unit_lv&bl->type )
  873. return clif_setlevel_sub(lv);
  874. switch( bl->type ) {
  875. case BL_NPC:
  876. case BL_PET:
  877. // npcs and pets do not have level
  878. return 0;
  879. }
  880. return lv;
  881. }
  882. /*==========================================
  883. * Prepares 'unit standing/spawning' packet
  884. *------------------------------------------*/
  885. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  886. nullpo_retv( bl );
  887. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  888. struct status_change* sc = status_get_sc( bl );
  889. struct view_data* vd = status_get_viewdata( bl );
  890. int g_id = status_get_guild_id( bl );
  891. #if PACKETVER < 20091103
  892. if( !pcdb_checkid( vd->class_ ) ){
  893. struct packet_idle_unit2 p;
  894. p.PacketType = idle_unit2Type;
  895. #if PACKETVER >= 20071106
  896. p.objecttype = clif_bl_type( bl, walking );
  897. #endif
  898. p.GID = bl->id;
  899. p.speed = status_get_speed( bl );
  900. p.bodyState = ( sc ) ? sc->opt1 : 0;
  901. p.healthState = ( sc ) ? sc->opt2 : 0;
  902. p.effectState = ( sc ) ? sc->option : 0;
  903. p.job = vd->class_;
  904. p.head = vd->hair_style;
  905. p.weapon = vd->weapon;
  906. p.accessory = vd->head_bottom;
  907. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  908. // The hell, why flags work like this?
  909. p.shield = status_get_emblem_id( bl );
  910. p.accessory2 = GetWord( g_id, 1 );
  911. p.accessory3 = GetWord( g_id, 0 );
  912. }else{
  913. p.shield = vd->shield;
  914. p.accessory2 = vd->head_top;
  915. p.accessory3 = vd->head_mid;
  916. }
  917. p.headpalette = vd->hair_color;
  918. p.bodypalette = vd->cloth_color;
  919. p.headDir = ( sd )? sd->head_dir : 0;
  920. p.GUID = g_id;
  921. p.GEmblemVer = status_get_emblem_id( bl );
  922. p.honor = ( sd ) ? sd->status.manner : 0;
  923. p.virtue = ( sc ) ? sc->opt3 : 0;
  924. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  925. p.sex = vd->sex;
  926. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  927. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  928. p.state = vd->dead_sit;
  929. p.clevel = clif_setlevel( bl );
  930. clif_send( &p, sizeof( p ), tbl, target );
  931. return;
  932. }
  933. #endif
  934. struct packet_idle_unit p;
  935. p.PacketType = idle_unitType;
  936. #if PACKETVER >= 20091103
  937. p.PacketLength = sizeof(p);
  938. p.objecttype = clif_bl_type( bl, walking );
  939. #endif
  940. #if PACKETVER >= 20131223
  941. p.AID = bl->id;
  942. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  943. #else
  944. p.GID = bl->id;
  945. #endif
  946. p.speed = status_get_speed(bl);
  947. p.bodyState = (sc) ? sc->opt1 : 0;
  948. p.healthState = (sc) ? sc->opt2 : 0;
  949. // npc option changed?
  950. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  951. struct map_session_data* sd = (struct map_session_data*)tbl;
  952. struct npc_data* nd = (struct npc_data*)bl;
  953. int option = (sc) ? sc->option : 0;
  954. if( !nd->vd.dead_sit ){
  955. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  956. option ^= OPTION_CLOAK;
  957. }
  958. }
  959. p.effectState = option;
  960. }else{
  961. p.effectState = (sc) ? sc->option : 0;
  962. }
  963. p.job = vd->class_;
  964. p.head = vd->hair_style;
  965. p.weapon = vd->weapon;
  966. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  967. p.shield = vd->shield;
  968. #endif
  969. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  970. // The hell, why flags work like this?
  971. p.accessory = status_get_emblem_id( bl );
  972. p.accessory2 = GetWord( g_id, 1 );
  973. p.accessory3 = GetWord( g_id, 0 );
  974. }else{
  975. p.accessory = vd->head_bottom;
  976. p.accessory2 = vd->head_top;
  977. p.accessory3 = vd->head_mid;
  978. }
  979. p.headpalette = vd->hair_color;
  980. p.bodypalette = vd->cloth_color;
  981. p.headDir = (sd)? sd->head_dir : 0;
  982. #if PACKETVER >= 20101124
  983. p.robe = vd->robe;
  984. #endif
  985. p.GUID = g_id;
  986. p.GEmblemVer = status_get_emblem_id( bl );
  987. p.honor = (sd) ? sd->status.manner : 0;
  988. p.virtue = (sc) ? sc->opt3 : 0;
  989. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  990. p.sex = vd->sex;
  991. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  992. p.xSize = p.ySize = (sd) ? 5 : 0;
  993. p.state = vd->dead_sit;
  994. p.clevel = clif_setlevel( bl );
  995. #if PACKETVER >= 20080102
  996. p.font = (sd) ? sd->status.font : 0;
  997. #endif
  998. #if PACKETVER >= 20120221
  999. 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 ) ) ){
  1000. p.maxHP = status_get_max_hp(bl);
  1001. p.HP = status_get_hp(bl);
  1002. }else{
  1003. p.maxHP = -1;
  1004. p.HP = -1;
  1005. }
  1006. p.isBoss = ( bl->type == BL_MOB && ( ( ( TBL_MOB *)bl )->db->mexp > 0 ) ) ? 1 : 0;
  1007. #endif
  1008. #if PACKETVER >= 20150513
  1009. p.body = vd->body_style;
  1010. #endif
  1011. /* Might be earlier, this is when the named item bug began */
  1012. #if PACKETVER >= 20131223
  1013. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1014. #endif
  1015. if( disguised( bl ) ){
  1016. #if PACKETVER >= 20091103
  1017. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1018. #if PACKETVER >= 20131223
  1019. p.AID = disguised_bl_id( bl->id );
  1020. #else
  1021. p.GID = disguised_bl_id( bl->id );
  1022. #endif
  1023. #else
  1024. p.GID = disguised_bl_id( bl->id );
  1025. #endif
  1026. }
  1027. clif_send( &p, sizeof( p ), tbl, target );
  1028. }
  1029. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1030. nullpo_retv( bl );
  1031. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  1032. struct status_change* sc = status_get_sc( bl );
  1033. struct view_data* vd = status_get_viewdata( bl );
  1034. int g_id = status_get_guild_id( bl );
  1035. #if PACKETVER < 20091103
  1036. if( !pcdb_checkid( vd->class_ ) ){
  1037. struct packet_spawn_unit2 p;
  1038. p.PacketType = spawn_unit2Type;
  1039. #if PACKETVER >= 20071106
  1040. p.objecttype = clif_bl_type( bl, false );
  1041. #endif
  1042. p.GID = bl->id;
  1043. p.speed = status_get_speed( bl );
  1044. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1045. p.healthState = ( sc ) ? sc->opt2 : 0;
  1046. p.effectState = ( sc ) ? sc->option : 0;
  1047. p.head = vd->hair_style;
  1048. p.weapon = vd->weapon;
  1049. p.accessory = vd->head_bottom;
  1050. p.job = vd->class_;
  1051. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1052. // The hell, why flags work like this?
  1053. p.shield = status_get_emblem_id( bl );
  1054. p.accessory2 = GetWord( g_id, 1 );
  1055. p.accessory3 = GetWord( g_id, 0 );
  1056. }else{
  1057. p.shield = vd->shield;
  1058. p.accessory2 = vd->head_top;
  1059. p.accessory3 = vd->head_mid;
  1060. }
  1061. p.headpalette = vd->hair_color;
  1062. p.bodypalette = vd->cloth_color;
  1063. p.headDir = ( sd ) ? sd->head_dir : 0;
  1064. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1065. p.sex = vd->sex;
  1066. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1067. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1068. clif_send( &p, sizeof( p ), bl, target );
  1069. return;
  1070. }
  1071. #endif
  1072. struct packet_spawn_unit p;
  1073. p.PacketType = spawn_unitType;
  1074. #if PACKETVER >= 20091103
  1075. p.PacketLength = sizeof(p);
  1076. p.objecttype = clif_bl_type( bl, false );
  1077. #endif
  1078. #if PACKETVER >= 20131223
  1079. p.AID = bl->id;
  1080. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1081. #else
  1082. p.GID = bl->id;
  1083. #endif
  1084. p.speed = status_get_speed( bl );
  1085. p.bodyState = (sc) ? sc->opt1 : 0;
  1086. p.healthState = (sc) ? sc->opt2 : 0;
  1087. p.effectState = (sc) ? sc->option : 0;
  1088. p.job = vd->class_;
  1089. p.head = vd->hair_style;
  1090. p.weapon = vd->weapon;
  1091. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1092. p.shield = vd->shield;
  1093. #endif
  1094. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1095. // The hell, why flags work like this?
  1096. p.accessory = status_get_emblem_id( bl );
  1097. p.accessory2 = GetWord( g_id, 1 );
  1098. p.accessory3 = GetWord( g_id, 0 );
  1099. }else{
  1100. p.accessory = vd->head_bottom;
  1101. p.accessory2 = vd->head_top;
  1102. p.accessory3 = vd->head_mid;
  1103. }
  1104. p.headpalette = vd->hair_color;
  1105. p.bodypalette = vd->cloth_color;
  1106. p.headDir = (sd)? sd->head_dir : 0;
  1107. #if PACKETVER >= 20101124
  1108. p.robe = vd->robe;
  1109. #endif
  1110. p.GUID = g_id;
  1111. p.GEmblemVer = status_get_emblem_id( bl );
  1112. p.honor = (sd) ? sd->status.manner : 0;
  1113. p.virtue = (sc) ? sc->opt3 : 0;
  1114. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1115. p.sex = vd->sex;
  1116. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1117. p.xSize = p.ySize = (sd) ? 5 : 0;
  1118. p.clevel = clif_setlevel( bl );
  1119. #if PACKETVER >= 20080102
  1120. p.font = (sd) ? sd->status.font : 0;
  1121. #endif
  1122. #if PACKETVER >= 20120221
  1123. 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 ) ) ){
  1124. p.maxHP = status_get_max_hp( bl );
  1125. p.HP = status_get_hp( bl );
  1126. }else{
  1127. p.maxHP = -1;
  1128. p.HP = -1;
  1129. }
  1130. p.isBoss = ( bl->type == BL_MOB && ( ( ( TBL_MOB *)bl)->db->mexp > 0 ) ) ? 1 : 0;
  1131. #endif
  1132. #if PACKETVER >= 20150513
  1133. p.body = vd->body_style;
  1134. #endif
  1135. /* Might be earlier, this is when the named item bug began */
  1136. #if PACKETVER >= 20131223
  1137. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1138. #endif
  1139. if( disguised( bl ) ){
  1140. nullpo_retv( sd );
  1141. if( sd->status.class_ != sd->disguise ){
  1142. clif_send( &p, sizeof( p ), bl, target );
  1143. }
  1144. #if PACKETVER >= 20091103
  1145. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1146. #if PACKETVER >= 20131223
  1147. p.AID = disguised_bl_id( bl->id );
  1148. #else
  1149. p.GID = disguised_bl_id( bl->id );
  1150. #endif
  1151. #else
  1152. p.GID = disguised_bl_id( bl->id );
  1153. #endif
  1154. clif_send( &p, sizeof( p ), bl, SELF );
  1155. }else{
  1156. clif_send( &p, sizeof( p ), bl, target );
  1157. }
  1158. }
  1159. /*==========================================
  1160. * Prepares 'unit walking' packet
  1161. *------------------------------------------*/
  1162. static void clif_set_unit_walking( struct block_list *bl, struct map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1163. nullpo_retv( bl );
  1164. nullpo_retv( ud );
  1165. struct map_session_data* sd;
  1166. struct status_change* sc = status_get_sc( bl );
  1167. struct view_data* vd = status_get_viewdata( bl );
  1168. struct packet_unit_walking p;
  1169. int g_id = status_get_guild_id(bl);
  1170. sd = BL_CAST(BL_PC, bl);
  1171. p.PacketType = unit_walkingType;
  1172. #if PACKETVER >= 20091103
  1173. p.PacketLength = sizeof(p);
  1174. #endif
  1175. #if PACKETVER >= 20071106
  1176. p.objecttype = clif_bl_type( bl, true );
  1177. #endif
  1178. #if PACKETVER >= 20131223
  1179. p.AID = bl->id;
  1180. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1181. #else
  1182. p.GID = bl->id;
  1183. #endif
  1184. p.speed = status_get_speed(bl);
  1185. p.bodyState = (sc) ? sc->opt1 : 0;
  1186. p.healthState = (sc) ? sc->opt2 : 0;
  1187. p.effectState = (sc) ? sc->option : 0;
  1188. p.job = vd->class_;
  1189. p.head = vd->hair_style;
  1190. p.weapon = vd->weapon;
  1191. p.accessory = vd->head_bottom;
  1192. p.moveStartTime = client_tick(gettick());
  1193. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1194. p.shield = vd->shield;
  1195. #endif
  1196. p.accessory2 = vd->head_top;
  1197. p.accessory3 = vd->head_mid;
  1198. p.headpalette = vd->hair_color;
  1199. p.bodypalette = vd->cloth_color;
  1200. p.headDir = (sd) ? sd->head_dir : 0;
  1201. #if PACKETVER >= 20101124
  1202. p.robe = vd->robe;
  1203. #endif
  1204. p.GUID = g_id;
  1205. p.GEmblemVer = status_get_emblem_id(bl);
  1206. p.honor = (sd) ? sd->status.manner : 0;
  1207. p.virtue = (sc) ? sc->opt3 : 0;
  1208. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1209. p.sex = vd->sex;
  1210. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1211. p.xSize = p.ySize = (sd) ? 5 : 0;
  1212. p.clevel = clif_setlevel(bl);
  1213. #if PACKETVER >= 20080102
  1214. p.font = (sd) ? sd->status.font : 0;
  1215. #endif
  1216. #if PACKETVER >= 20120221
  1217. 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 ) ) ){
  1218. p.maxHP = status_get_max_hp(bl);
  1219. p.HP = status_get_hp(bl);
  1220. } else {
  1221. p.maxHP = -1;
  1222. p.HP = -1;
  1223. }
  1224. p.isBoss = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0;
  1225. #endif
  1226. #if PACKETVER >= 20150513
  1227. p.body = vd->body_style;
  1228. #endif
  1229. /* Might be earlier, this is when the named item bug began */
  1230. #if PACKETVER >= 20131223
  1231. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1232. #endif
  1233. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1234. if( disguised( bl ) ){
  1235. #if PACKETVER >= 20091103
  1236. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1237. #if PACKETVER >= 20131223
  1238. p.AID = disguised_bl_id( bl->id );
  1239. #else
  1240. p.GID = disguised_bl_id( bl->id );
  1241. #endif
  1242. #else
  1243. p.GID = disguised_bl_id( bl->id );
  1244. #endif
  1245. clif_send(&p,sizeof(p),bl,SELF);
  1246. }
  1247. }
  1248. //Modifies the buffer for disguise characters and sends it to self.
  1249. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1250. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1251. {
  1252. #if PACKETVER >= 20091103
  1253. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1254. WBUFL(buf,5)=-bl->id;
  1255. #elif PACKETVER >= 20071106
  1256. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1257. WBUFL(buf,3)=-bl->id;
  1258. #else
  1259. WBUFL(buf,2)=-bl->id;
  1260. #endif
  1261. clif_send(buf, len, bl, SELF);
  1262. }
  1263. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1264. /// 01b0 <id>.L <type>.B <value>.L
  1265. /// type:
  1266. /// unused
  1267. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1268. {
  1269. nullpo_retv(bl);
  1270. if(!pcdb_checkid(class_))
  1271. {// player classes yield missing sprites
  1272. unsigned char buf[16];
  1273. WBUFW(buf,0)=0x1b0;
  1274. WBUFL(buf,2)=bl->id;
  1275. WBUFB(buf,6)=type;
  1276. WBUFL(buf,7)=class_;
  1277. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1278. }
  1279. }
  1280. /// Notifies the client of an object's spirits.
  1281. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1282. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1283. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1284. {
  1285. WFIFOHEAD(fd, packet_len(0x1e1));
  1286. WFIFOW(fd,0)=0x1e1;
  1287. WFIFOL(fd,2)=sd->bl.id;
  1288. WFIFOW(fd,6)=sd->spiritball;
  1289. WFIFOSET(fd, packet_len(0x1e1));
  1290. }
  1291. /// Notifies the client of an object's Millenium Shields.
  1292. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1293. {
  1294. nullpo_retv(sd);
  1295. if (sd->sc.data[SC_MILLENNIUMSHIELD] == nullptr)
  1296. return;
  1297. WFIFOHEAD(fd, packet_len(0x440));
  1298. WFIFOW(fd, 0) = 0x440;
  1299. WFIFOL(fd, 2) = sd->bl.id;
  1300. WFIFOW(fd, 6) = sd->sc.data[SC_MILLENNIUMSHIELD]->val2;
  1301. WFIFOW(fd, 8) = 0;
  1302. WFIFOSET(fd, packet_len(0x440));
  1303. }
  1304. /*==========================================
  1305. * Kagerou/Oboro amulet spirit
  1306. *------------------------------------------*/
  1307. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1308. {
  1309. WFIFOHEAD(fd, packet_len(0x08cf));
  1310. WFIFOW(fd,0)=0x08cf;
  1311. WFIFOL(fd,2)=sd->bl.id;
  1312. WFIFOW(fd,6)=sd->spiritcharm_type;
  1313. WFIFOW(fd,8)=sd->spiritcharm;
  1314. WFIFOSET(fd, packet_len(0x08cf));
  1315. }
  1316. /// Notifies the client of an object's souls.
  1317. /// Note: Spirit spheres and Soul spheres work on
  1318. /// seprate systems officially, but both send out
  1319. /// the same packet which leads to confusion on how
  1320. /// much soul energy a Soul Reaper acturally has
  1321. /// should the player also have spirit spheres.
  1322. /// They will likely create a new packet for this soon
  1323. /// to seprate the animations for spirit and soul spheres.
  1324. /// For now well use this and replace it later when possible. [Rytech]
  1325. ///
  1326. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1327. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1328. static void clif_soulball_single(int fd, struct map_session_data *sd)
  1329. {
  1330. WFIFOHEAD(fd, packet_len(0x1d0));
  1331. WFIFOW(fd,0)=0x1d0;
  1332. WFIFOL(fd,2)=sd->bl.id;
  1333. WFIFOW(fd,6)=sd->soulball;
  1334. WFIFOSET(fd, packet_len(0x1d0));
  1335. }
  1336. /*==========================================
  1337. * Run when player changes map / refreshes
  1338. * Tells its client to display all weather settings being used by this map
  1339. *------------------------------------------*/
  1340. static void clif_weather_check(struct map_session_data *sd)
  1341. {
  1342. int16 m = sd->bl.m;
  1343. int fd = sd->fd;
  1344. if (map_getmapflag(m, MF_SNOW)
  1345. || map_getmapflag(m, MF_CLOUDS)
  1346. || map_getmapflag(m, MF_FOG)
  1347. || map_getmapflag(m, MF_FIREWORKS)
  1348. || map_getmapflag(m, MF_SAKURA)
  1349. || map_getmapflag(m, MF_LEAVES)
  1350. || map_getmapflag(m, MF_CLOUDS2))
  1351. {
  1352. if (map_getmapflag(m, MF_SNOW))
  1353. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1354. if (map_getmapflag(m, MF_CLOUDS))
  1355. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1356. if (map_getmapflag(m, MF_CLOUDS2))
  1357. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1358. if (map_getmapflag(m, MF_FOG))
  1359. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1360. if (map_getmapflag(m, MF_FIREWORKS)) {
  1361. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1362. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1363. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1364. }
  1365. if (map_getmapflag(m, MF_SAKURA))
  1366. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1367. if (map_getmapflag(m, MF_LEAVES))
  1368. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1369. }
  1370. }
  1371. /**
  1372. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1373. **/
  1374. void clif_weather(int16 m)
  1375. {
  1376. struct s_mapiterator* iter;
  1377. struct map_session_data *sd=NULL;
  1378. iter = mapit_getallusers();
  1379. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1380. {
  1381. if( sd->bl.m == m )
  1382. clif_weather_check(sd);
  1383. }
  1384. mapit_free(iter);
  1385. }
  1386. /**
  1387. * Hide a NPC from the effects of Maya Purple card.
  1388. * @param bl: Block data
  1389. * @return True if NPC is disabled or false otherwise
  1390. */
  1391. static inline bool clif_npc_mayapurple(block_list *bl) {
  1392. nullpo_retr(false, bl);
  1393. if (bl->type == BL_NPC) {
  1394. npc_data *nd = map_id2nd(bl->id);
  1395. // TODO: Confirm if waitingroom cause any special cases
  1396. if (/* nd->chat_id == 0 && */ nd->sc.option & OPTION_INVISIBLE)
  1397. return true;
  1398. }
  1399. return false;
  1400. }
  1401. /**
  1402. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1403. **/
  1404. int clif_spawn( struct block_list *bl, bool walking ){
  1405. struct view_data *vd;
  1406. vd = status_get_viewdata(bl);
  1407. if( !vd || vd->class_ == JT_INVISIBLE )
  1408. return 0;
  1409. // Hide NPC from Maya Purple card
  1410. if (clif_npc_mayapurple(bl))
  1411. return 0;
  1412. if( bl->type == BL_NPC && !vd->dead_sit ){
  1413. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1414. }else{
  1415. clif_spawn_unit( bl, AREA_WOS );
  1416. }
  1417. if (vd->cloth_color)
  1418. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1419. if (vd->body_style)
  1420. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1421. switch (bl->type)
  1422. {
  1423. case BL_PC:
  1424. {
  1425. TBL_PC *sd = ((TBL_PC*)bl);
  1426. if (sd->spiritball > 0)
  1427. clif_spiritball(&sd->bl);
  1428. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  1429. clif_millenniumshield(&sd->bl, sd->sc.data[SC_MILLENNIUMSHIELD]->val2);
  1430. if (sd->soulball > 0)
  1431. clif_soulball(sd);
  1432. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1433. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1434. else if(sd->state.size==SZ_MEDIUM)
  1435. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1436. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1437. clif_sendbgemblem_area(sd);
  1438. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1439. clif_spiritcharm(sd);
  1440. if (sd->status.robe)
  1441. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1442. clif_efst_status_change_sub(bl, bl, AREA);
  1443. clif_hat_effects(sd,bl,AREA);
  1444. }
  1445. break;
  1446. case BL_MOB:
  1447. {
  1448. TBL_MOB *md = ((TBL_MOB*)bl);
  1449. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1450. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1451. else if(md->special_state.size==SZ_MEDIUM)
  1452. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1453. }
  1454. break;
  1455. case BL_NPC:
  1456. {
  1457. TBL_NPC *nd = ((TBL_NPC*)bl);
  1458. if( nd->size == SZ_BIG )
  1459. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1460. else if( nd->size == SZ_MEDIUM )
  1461. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1462. clif_efst_status_change_sub(bl, bl, AREA);
  1463. clif_progressbar_npc_area(nd);
  1464. }
  1465. break;
  1466. case BL_PET:
  1467. if (vd->head_bottom)
  1468. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1469. break;
  1470. }
  1471. return 0;
  1472. }
  1473. /// Sends information about owned homunculus to the client . [orn]
  1474. /// 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)
  1475. /// 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)
  1476. void clif_hominfo( struct map_session_data *sd, struct homun_data *hd, int flag ){
  1477. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1478. nullpo_retv( sd );
  1479. nullpo_retv( hd );
  1480. struct status_data *status = &hd->battle_status;
  1481. struct PACKET_ZC_PROPERTY_HOMUN p;
  1482. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1483. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1484. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1485. 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 );
  1486. p.level = hd->homunculus.level;
  1487. p.hunger = hd->homunculus.hunger;
  1488. p.intimacy = hd->homunculus.intimacy / 100;
  1489. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1490. p.itemId = 0; // equip id
  1491. #endif
  1492. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1493. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1494. p.hit = status->hit;
  1495. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1496. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1497. }else{
  1498. p.crit = status->cri / 10;
  1499. }
  1500. #ifdef RENEWAL
  1501. p.def = status->def + status->def2;
  1502. p.mdef = status->mdef + status->mdef2;
  1503. #else
  1504. p.def = status->def + status->vit;
  1505. p.mdef = status->mdef;
  1506. #endif
  1507. p.flee = status->flee;
  1508. p.amotion = (flag) ? 0 : status->amotion;
  1509. #if PACKETVER >= 20141016
  1510. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1511. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1512. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1513. p.hp = status->hp / ( status->max_hp / 100 );
  1514. p.maxHp = 100;
  1515. }else{
  1516. p.hp = status->hp;
  1517. p.maxHp = status->max_hp;
  1518. }
  1519. #else
  1520. if( status->max_hp > INT16_MAX ){
  1521. p.hp = status->hp / ( status->max_hp / 100 );
  1522. p.maxHp = 100;
  1523. }else{
  1524. p.hp = status->hp;
  1525. p.maxHp = status->max_hp;
  1526. }
  1527. #endif
  1528. if( status->max_sp > INT16_MAX ){
  1529. p.sp = status->sp / ( status->max_sp / 100 );
  1530. p.maxSp = 100;
  1531. }else{
  1532. p.sp = status->sp;
  1533. p.maxSp = status->max_sp;
  1534. }
  1535. p.exp = hd->homunculus.exp;
  1536. p.expNext = hd->exp_next;
  1537. switch( hom_class2type( hd->homunculus.class_ ) ){
  1538. case HT_REG:
  1539. case HT_EVO:
  1540. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1541. p.expNext = 0;
  1542. }
  1543. break;
  1544. case HT_S:
  1545. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1546. p.expNext = 0;
  1547. }
  1548. break;
  1549. }
  1550. p.skillPoints = hd->homunculus.skillpts;
  1551. p.range = status_get_range( &hd->bl );
  1552. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1553. #endif
  1554. }
  1555. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1556. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1557. /// type:
  1558. /// unused
  1559. /// state:
  1560. /// 0 = pre-init
  1561. /// 1 = intimacy
  1562. /// 2 = hunger
  1563. /// 3 = accessory?
  1564. /// ? = ignored
  1565. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1566. { //[orn]
  1567. int fd = sd->fd;
  1568. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1569. hom_calc_skilltree(sd->hd, 0);
  1570. WFIFOHEAD(fd, packet_len(0x230));
  1571. WFIFOW(fd,0)=0x230;
  1572. WFIFOB(fd,2)=0;
  1573. WFIFOB(fd,3)=state;
  1574. WFIFOL(fd,4)=sd->hd->bl.id;
  1575. WFIFOL(fd,8)=param;
  1576. WFIFOSET(fd,packet_len(0x230));
  1577. }
  1578. int clif_homskillinfoblock(struct map_session_data *sd)
  1579. { //[orn]
  1580. struct homun_data *hd;
  1581. int fd = sd->fd;
  1582. int i, len=4;
  1583. nullpo_ret(sd);
  1584. hd = sd->hd;
  1585. if ( !hd )
  1586. return 0 ;
  1587. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1588. WFIFOW(fd,0)=0x235;
  1589. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1590. int id = hd->homunculus.hskill[i].id;
  1591. if( id != 0 ){
  1592. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1593. short idx = hom_skill_get_index(id);
  1594. if (idx == -1)
  1595. continue;
  1596. WFIFOW(fd,len ) = id;
  1597. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1598. WFIFOW(fd,len+4) = 0;
  1599. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1600. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1601. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1602. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1603. 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;
  1604. len+=37;
  1605. }
  1606. }
  1607. WFIFOW(fd,2)=len;
  1608. WFIFOSET(fd,len);
  1609. return 0;
  1610. }
  1611. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1612. { //[orn]
  1613. struct homun_data *hd;
  1614. int fd;
  1615. short idx = -1;
  1616. nullpo_retv(sd);
  1617. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1618. return;
  1619. fd = sd->fd;
  1620. hd = sd->hd;
  1621. WFIFOHEAD(fd, packet_len(0x239));
  1622. WFIFOW(fd,0) = 0x239;
  1623. WFIFOW(fd,2) = skill_id;
  1624. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1625. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1626. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1627. 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;
  1628. WFIFOSET(fd,packet_len(0x239));
  1629. }
  1630. /// Result of request to feed a homun/merc.
  1631. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1632. /// result:
  1633. /// 0 = failure
  1634. /// 1 = success
  1635. void clif_hom_food( struct map_session_data *sd, int foodid, int fail ){
  1636. nullpo_retv( sd );
  1637. struct PACKET_ZC_FEED_MER p;
  1638. p.packetType = 0x22f;
  1639. p.result = fail;
  1640. p.itemId = client_nameid( foodid );
  1641. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1642. }
  1643. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1644. /// 0087 <walk start time>.L <walk data>.6B
  1645. void clif_walkok(struct map_session_data *sd)
  1646. {
  1647. int fd=sd->fd;
  1648. WFIFOHEAD(fd, packet_len(0x87));
  1649. WFIFOW(fd,0)=0x87;
  1650. WFIFOL(fd,2)=client_tick(gettick());
  1651. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1652. WFIFOSET(fd,packet_len(0x87));
  1653. }
  1654. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1655. struct status_change *sc = NULL;
  1656. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1657. clif_ally_only = true;
  1658. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1659. if(vd->cloth_color)
  1660. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1661. if(vd->body_style)
  1662. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1663. switch(bl->type) {
  1664. case BL_PC:
  1665. {
  1666. TBL_PC *sd = ((TBL_PC*)bl);
  1667. // clif_movepc(sd);
  1668. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1669. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1670. else if(sd->state.size==SZ_MEDIUM)
  1671. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1672. if (sd->status.robe)
  1673. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1674. }
  1675. break;
  1676. case BL_MOB:
  1677. {
  1678. TBL_MOB *md = ((TBL_MOB*)bl);
  1679. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1680. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1681. else if(md->special_state.size==SZ_MEDIUM)
  1682. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1683. }
  1684. break;
  1685. case BL_PET:
  1686. if(vd->head_bottom) // needed to display pet equip properly
  1687. clif_pet_equip_area((TBL_PET*)bl);
  1688. break;
  1689. }
  1690. clif_ally_only = false;
  1691. }
  1692. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1693. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1694. /// Note: unit must not be self
  1695. void clif_move(struct unit_data *ud)
  1696. {
  1697. unsigned char buf[16];
  1698. struct view_data* vd;
  1699. struct block_list* bl = ud->bl;
  1700. struct status_change *sc = NULL;
  1701. vd = status_get_viewdata(bl);
  1702. if (!vd )
  1703. return;
  1704. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1705. else if( vd->class_ == JT_INVISIBLE ){
  1706. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1707. if(disguised(bl)) {
  1708. WBUFW(buf,0)=0x86;
  1709. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1710. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1711. WBUFL(buf,12)=client_tick(gettick());
  1712. clif_send(buf, packet_len(0x86), bl, SELF);
  1713. }
  1714. return;
  1715. }
  1716. // Hide NPC from Maya Purple card
  1717. if (clif_npc_mayapurple(bl))
  1718. return;
  1719. if (ud->state.speed_changed) {
  1720. // Since we don't know how to update the speed of other objects,
  1721. // use the old walk packet to update the data.
  1722. ud->state.speed_changed = 0;
  1723. clif_move2(bl, vd, ud);
  1724. return;
  1725. }
  1726. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1727. clif_ally_only = true;
  1728. WBUFW(buf,0)=0x86;
  1729. WBUFL(buf,2)=bl->id;
  1730. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1731. WBUFL(buf,12)=client_tick(gettick());
  1732. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1733. if (disguised(bl)) {
  1734. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1735. clif_send(buf, packet_len(0x86), bl, SELF);
  1736. }
  1737. clif_ally_only = false;
  1738. }
  1739. /*==========================================
  1740. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1741. *------------------------------------------*/
  1742. static TIMER_FUNC(clif_delayquit){
  1743. struct map_session_data *sd = NULL;
  1744. //Remove player from map server
  1745. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1746. map_quit(sd);
  1747. return 0;
  1748. }
  1749. /*==========================================
  1750. *
  1751. *------------------------------------------*/
  1752. void clif_quitsave(int fd,struct map_session_data *sd) {
  1753. if (!battle_config.prevent_logout ||
  1754. sd->canlog_tick == 0 ||
  1755. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1756. map_quit(sd);
  1757. else if (sd->fd) {
  1758. //Disassociate session from player (session is deleted after this function was called)
  1759. //And set a timer to make him quit later.
  1760. session[sd->fd]->session_data = NULL;
  1761. sd->fd = 0;
  1762. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1763. }
  1764. }
  1765. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1766. /// 0091 <map name>.16B <x>.W <y>.W
  1767. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1768. {
  1769. int fd;
  1770. nullpo_retv(sd);
  1771. fd = sd->fd;
  1772. WFIFOHEAD(fd,packet_len(0x91));
  1773. WFIFOW(fd,0) = 0x91;
  1774. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1775. WFIFOW(fd,18) = x;
  1776. WFIFOW(fd,20) = y;
  1777. WFIFOSET(fd,packet_len(0x91));
  1778. }
  1779. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1780. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1781. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1782. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1783. {
  1784. int fd;
  1785. #if PACKETVER >= 20170315
  1786. int cmd = 0xac7;
  1787. #else
  1788. int cmd = 0x92;
  1789. #endif
  1790. nullpo_retv(sd);
  1791. fd = sd->fd;
  1792. WFIFOHEAD(fd,packet_len(cmd));
  1793. WFIFOW(fd,0) = cmd;
  1794. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1795. WFIFOW(fd,18) = x;
  1796. WFIFOW(fd,20) = y;
  1797. WFIFOL(fd,22) = htonl(ip);
  1798. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1799. #if PACKETVER >= 20170315
  1800. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1801. #endif
  1802. WFIFOSET(fd,packet_len(cmd));
  1803. }
  1804. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1805. /// This function combines both calls and allows to simplify the calling code
  1806. void clif_blown(struct block_list *bl)
  1807. {
  1808. clif_slide(bl, bl->x, bl->y);
  1809. clif_fixpos(bl);
  1810. }
  1811. /// Visually moves(slides) a character to x,y. If the target cell
  1812. /// isn't walkable, the char doesn't move at all. If the char is
  1813. /// sitting it will stand up (ZC_STOPMOVE).
  1814. /// 0088 <id>.L <x>.W <y>.W
  1815. void clif_fixpos(struct block_list *bl)
  1816. {
  1817. unsigned char buf[10];
  1818. nullpo_retv(bl);
  1819. WBUFW(buf,0) = 0x88;
  1820. WBUFL(buf,2) = bl->id;
  1821. WBUFW(buf,6) = bl->x;
  1822. WBUFW(buf,8) = bl->y;
  1823. clif_send(buf, packet_len(0x88), bl, AREA);
  1824. if( disguised(bl) ) {
  1825. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1826. clif_send(buf, packet_len(0x88), bl, SELF);
  1827. }
  1828. }
  1829. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1830. /// 00c4 <shop id>.L
  1831. void clif_npcbuysell(struct map_session_data* sd, int id)
  1832. {
  1833. int fd;
  1834. nullpo_retv(sd);
  1835. fd=sd->fd;
  1836. WFIFOHEAD(fd, packet_len(0xc4));
  1837. WFIFOW(fd,0)=0xc4;
  1838. WFIFOL(fd,2)=id;
  1839. WFIFOSET(fd,packet_len(0xc4));
  1840. }
  1841. /// Presents list of items, that can be bought in an NPC shop.
  1842. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1843. void clif_buylist( struct map_session_data *sd, struct npc_data *nd ){
  1844. nullpo_retv( sd );
  1845. nullpo_retv( nd );
  1846. int fd = sd->fd;
  1847. if( !session_isActive( fd ) ){
  1848. return;
  1849. }
  1850. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1851. WFIFOHEAD( fd, len );
  1852. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1853. p->packetType = 0xc6;
  1854. int count = 0;
  1855. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1856. int val = nd->u.shop.shop_item[i].value;
  1857. p->items[count].price = val;
  1858. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1859. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1860. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1861. count++;
  1862. }
  1863. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1864. WFIFOSET( fd, p->packetLength );
  1865. }
  1866. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1867. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1868. void clif_selllist(struct map_session_data *sd)
  1869. {
  1870. int fd,i,c=0,val;
  1871. struct npc_data *nd;
  1872. nullpo_retv(sd);
  1873. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1874. return;
  1875. fd=sd->fd;
  1876. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1877. WFIFOW(fd,0)=0xc7;
  1878. for( i = 0; i < MAX_INVENTORY; i++ )
  1879. {
  1880. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1881. {
  1882. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1883. continue;
  1884. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1885. val = 0;
  1886. else {
  1887. val = sd->inventory_data[i]->value_sell;
  1888. if( val < 0 )
  1889. continue;
  1890. }
  1891. WFIFOW(fd,4+c*10)=i+2;
  1892. WFIFOL(fd,6+c*10)=val;
  1893. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1894. c++;
  1895. }
  1896. }
  1897. WFIFOW(fd,2)=c*10+4;
  1898. WFIFOSET(fd,WFIFOW(fd,2));
  1899. }
  1900. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1901. /// 09d4
  1902. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1903. // TODO: State tracking?
  1904. sd->npc_shopid = 0;
  1905. }
  1906. /**
  1907. * Presents list of items, that can be sold to a Market shop.
  1908. * @author: Ind and Yommy
  1909. **/
  1910. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1911. #if PACKETVER >= 20131223
  1912. nullpo_retv( sd );
  1913. nullpo_retv( nd );
  1914. if( sd->state.trading ){
  1915. return;
  1916. }
  1917. int fd = sd->fd;
  1918. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1919. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1920. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1921. int count = 0;
  1922. for( int i = 0; i < nd->u.shop.count; i++ ){
  1923. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1924. if( !item->nameid ){
  1925. continue;
  1926. }
  1927. struct item_data *id = itemdb_exists( item->nameid );
  1928. if( !id ){
  1929. continue;
  1930. }
  1931. p->list[count].nameid = client_nameid( item->nameid );
  1932. p->list[count].type = itemtype( item->nameid );
  1933. p->list[count].price = item->value;
  1934. p->list[count].qty = item->qty;
  1935. p->list[count].weight = id->weight;
  1936. count++;
  1937. }
  1938. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  1939. WFIFOSET( fd, p->packetLength );
  1940. sd->state.trading = 1;
  1941. #endif
  1942. }
  1943. /// Closes the Market shop window.
  1944. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1945. nullpo_retv(sd);
  1946. sd->npc_shopid = 0;
  1947. sd->state.trading = 0;
  1948. }
  1949. /// Purchase item from Market shop.
  1950. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1951. #if PACKETVER >= 20131223
  1952. nullpo_retv( sd );
  1953. nullpo_retv( list );
  1954. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  1955. nullpo_retv( nd );
  1956. int fd = sd->fd;
  1957. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + n * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub ) );
  1958. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)WFIFOP( fd, 0 );
  1959. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  1960. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  1961. p->result = ( res == 0 ? 0 : -1 );
  1962. #else
  1963. p->result = ( res == 0 ? 1 : 0 );
  1964. #endif
  1965. int count = 0;
  1966. if( p->result ){
  1967. for( int i = 0, j; i < n; i++ ){
  1968. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  1969. // Not found
  1970. if( j == nd->u.shop.count ){
  1971. continue;
  1972. }
  1973. p->list[count].ITID = client_nameid( list[i].nameid );
  1974. p->list[count].qty = list[i].qty;
  1975. p->list[count].price = nd->u.shop.shop_item[j].value;
  1976. count++;
  1977. }
  1978. }
  1979. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  1980. WFIFOSET( fd, p->PacketLength );
  1981. #endif
  1982. }
  1983. /// Purchase item from Market shop.
  1984. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1985. #if PACKETVER >= 20131223
  1986. nullpo_retv( sd );
  1987. if( !sd->npc_shopid ){
  1988. return;
  1989. }
  1990. const struct packet_npc_market_purchase *p = (struct packet_npc_market_purchase *)RFIFOP( fd, 0 );
  1991. int count = ( p->PacketLength - sizeof( struct packet_npc_market_purchase ) ) / sizeof( struct packet_npc_market_purchase_sub );
  1992. struct s_npc_buy_list *list;
  1993. CREATE( list, struct s_npc_buy_list, count );
  1994. // Sadly order is reverse
  1995. for( int i = 0; i < count; i++ ){
  1996. list[i].nameid = p->list[i].ITID;
  1997. list[i].qty = p->list[i].qty;
  1998. }
  1999. uint8 res = npc_buylist( sd, count, list );
  2000. clif_npc_market_purchase_ack( sd, res, count, list );
  2001. aFree( list );
  2002. #endif
  2003. }
  2004. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2005. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2006. /// Client behavior (dialog window):
  2007. /// - disable mouse targeting
  2008. /// - open the dialog window
  2009. /// - set npcid of dialog window (0 by default)
  2010. /// - if set to clear on next mes, clear contents
  2011. /// - append this text
  2012. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  2013. {
  2014. int fd = sd->fd;
  2015. int slen = strlen(mes) + 9;
  2016. WFIFOHEAD(fd, slen);
  2017. WFIFOW(fd,0)=0xb4;
  2018. WFIFOW(fd,2)=slen;
  2019. WFIFOL(fd,4)=npcid;
  2020. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2021. WFIFOSET(fd,WFIFOW(fd,2));
  2022. }
  2023. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2024. /// 00b5 <npc id>.L
  2025. /// Client behavior (dialog window):
  2026. /// - disable mouse targeting
  2027. /// - open the dialog window
  2028. /// - add 'next' button
  2029. /// When 'next' is pressed:
  2030. /// - 00B9 <npcid of dialog window>.L
  2031. /// - set to clear on next mes
  2032. /// - remove 'next' button
  2033. void clif_scriptnext(struct map_session_data *sd,int npcid)
  2034. {
  2035. int fd;
  2036. nullpo_retv(sd);
  2037. fd=sd->fd;
  2038. WFIFOHEAD(fd, packet_len(0xb5));
  2039. WFIFOW(fd,0)=0xb5;
  2040. WFIFOL(fd,2)=npcid;
  2041. WFIFOSET(fd,packet_len(0xb5));
  2042. }
  2043. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2044. /// 00b6 <npc id>.L
  2045. /// Client behavior:
  2046. /// - if dialog window is open:
  2047. /// - remove 'next' button
  2048. /// - add 'close' button
  2049. /// - else:
  2050. /// - enable mouse targeting
  2051. /// - close the dialog window
  2052. /// - close the menu window
  2053. /// When 'close' is pressed:
  2054. /// - enable mouse targeting
  2055. /// - close the dialog window
  2056. /// - close the menu window
  2057. /// - 0146 <npcid of dialog window>.L
  2058. void clif_scriptclose(struct map_session_data *sd, int npcid)
  2059. {
  2060. int fd;
  2061. nullpo_retv(sd);
  2062. fd=sd->fd;
  2063. WFIFOHEAD(fd, packet_len(0xb6));
  2064. WFIFOW(fd,0)=0xb6;
  2065. WFIFOL(fd,2)=npcid;
  2066. WFIFOSET(fd,packet_len(0xb6));
  2067. }
  2068. /**
  2069. * Close script when player is idle
  2070. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2071. * @author [Ind/Hercules]
  2072. * @param sd : player pointer
  2073. * @param npcid : npc gid to close
  2074. */
  2075. void clif_scriptclear(struct map_session_data *sd, int npcid)
  2076. {
  2077. struct s_packet_db* info;
  2078. int16 len;
  2079. int cmd = 0;
  2080. int fd;
  2081. nullpo_retv(sd);
  2082. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  2083. if(!cmd) cmd = 0x8d6; //default
  2084. info = &packet_db[cmd];
  2085. len = info->len;
  2086. fd = sd->fd;
  2087. WFIFOHEAD(fd, len);
  2088. WFIFOW(fd,0)=0x8d6;
  2089. WFIFOL(fd,info->pos[0])=npcid;
  2090. WFIFOSET(fd,len);
  2091. }
  2092. /*==========================================
  2093. *
  2094. *------------------------------------------*/
  2095. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  2096. unsigned char *buf;
  2097. int fd = sd->fd;
  2098. sd->state.using_fake_npc = 1;
  2099. WFIFOHEAD(fd, packet_len(0x78));
  2100. buf = WFIFOP(fd,0);
  2101. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2102. WBUFW(buf,0)=0x78;
  2103. #if PACKETVER >= 20071106
  2104. WBUFB(buf,2) = 0; // object type
  2105. buf = WFIFOP(fd,1);
  2106. #endif
  2107. WBUFL(buf,2)=npcid;
  2108. WBUFW(buf,14)=111;
  2109. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2110. WBUFB(buf,49)=5;
  2111. WBUFB(buf,50)=5;
  2112. WFIFOSET(fd, packet_len(0x78));
  2113. }
  2114. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2115. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2116. /// Client behavior:
  2117. /// - disable mouse targeting
  2118. /// - close the menu window
  2119. /// - open the menu window
  2120. /// - add options to the menu (separated in the text by ":")
  2121. /// - set npcid of menu window
  2122. /// - if dialog window is open:
  2123. /// - remove 'next' button
  2124. /// When 'ok' is pressed:
  2125. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2126. /// - close the menu window
  2127. /// When 'cancel' is pressed:
  2128. /// - 00B8 <npcid of menu window>.L <-1>.B
  2129. /// - enable mouse targeting
  2130. /// - close a bunch of windows...
  2131. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2132. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2133. /// TODO investigate behavior of other windows [FlavioJS]
  2134. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2135. {
  2136. int fd = sd->fd;
  2137. int slen = strlen(mes) + 9;
  2138. struct block_list *bl = NULL;
  2139. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2140. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2141. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2142. clif_sendfakenpc(sd, npcid);
  2143. WFIFOHEAD(fd, slen);
  2144. WFIFOW(fd,0)=0xb7;
  2145. WFIFOW(fd,2)=slen;
  2146. WFIFOL(fd,4)=npcid;
  2147. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2148. WFIFOSET(fd,WFIFOW(fd,2));
  2149. }
  2150. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2151. /// 0142 <npc id>.L
  2152. /// Client behavior (inputnum window):
  2153. /// - if npcid exists in the client:
  2154. /// - open the inputnum window
  2155. /// - set npcid of inputnum window
  2156. /// When 'ok' is pressed:
  2157. /// - if inputnum window has text:
  2158. /// - if npcid exists in the client:
  2159. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2160. /// - close inputnum window
  2161. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2162. {
  2163. int fd;
  2164. struct block_list *bl = NULL;
  2165. nullpo_retv(sd);
  2166. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2167. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2168. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2169. clif_sendfakenpc(sd, npcid);
  2170. fd=sd->fd;
  2171. WFIFOHEAD(fd, packet_len(0x142));
  2172. WFIFOW(fd,0)=0x142;
  2173. WFIFOL(fd,2)=npcid;
  2174. WFIFOSET(fd,packet_len(0x142));
  2175. }
  2176. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2177. /// 01d4 <npc id>.L
  2178. /// Client behavior (inputstr window):
  2179. /// - if npcid is 0 or npcid exists in the client:
  2180. /// - open the inputstr window
  2181. /// - set npcid of inputstr window
  2182. /// When 'ok' is pressed:
  2183. /// - if inputstr window has text and isn't an insult(manner.txt):
  2184. /// - if npcid is 0 or npcid exists in the client:
  2185. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2186. /// - close inputstr window
  2187. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2188. {
  2189. int fd;
  2190. struct block_list *bl = NULL;
  2191. nullpo_retv(sd);
  2192. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2193. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2194. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2195. clif_sendfakenpc(sd, npcid);
  2196. fd=sd->fd;
  2197. WFIFOHEAD(fd, packet_len(0x1d4));
  2198. WFIFOW(fd,0)=0x1d4;
  2199. WFIFOL(fd,2)=npcid;
  2200. WFIFOSET(fd,packet_len(0x1d4));
  2201. }
  2202. /// Marks a position on client's minimap (ZC_COMPASS).
  2203. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2204. /// npc id:
  2205. /// is ignored in the client
  2206. /// type:
  2207. /// 0 = display mark for 15 seconds
  2208. /// 1 = display mark until dead or teleported
  2209. /// 2 = remove mark
  2210. /// color:
  2211. /// 0x00RRGGBB
  2212. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2213. {
  2214. int fd;
  2215. nullpo_retv(sd);
  2216. fd=sd->fd;
  2217. WFIFOHEAD(fd, packet_len(0x144));
  2218. WFIFOW(fd,0)=0x144;
  2219. WFIFOL(fd,2)=npc_id;
  2220. WFIFOL(fd,6)=type;
  2221. WFIFOL(fd,10)=x;
  2222. WFIFOL(fd,14)=y;
  2223. WFIFOB(fd,18)=id;
  2224. WFIFOL(fd,19)=color;
  2225. WFIFOSET(fd,packet_len(0x144));
  2226. }
  2227. /// Displays an illustration image.
  2228. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2229. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2230. /// type:
  2231. /// 0 = bottom left corner
  2232. /// 1 = bottom middle
  2233. /// 2 = bottom right corner
  2234. /// 3 = middle of screen, inside a movable window
  2235. /// 4 = middle of screen, movable with a close button, chrome-less
  2236. /// 255 = clear all displayed cutins
  2237. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2238. {
  2239. int fd;
  2240. nullpo_retv(sd);
  2241. fd=sd->fd;
  2242. WFIFOHEAD(fd, packet_len(0x1b3));
  2243. WFIFOW(fd,0)=0x1b3;
  2244. strncpy(WFIFOCP(fd,2),image,64);
  2245. WFIFOB(fd,66)=type;
  2246. WFIFOSET(fd,packet_len(0x1b3));
  2247. }
  2248. /*==========================================
  2249. * Fills in card data from the given item and into the buffer. [Skotlex]
  2250. *------------------------------------------*/
  2251. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2252. nullpo_retv( buf );
  2253. // Blank data
  2254. if( item == nullptr ){
  2255. buf->card[0] = 0;
  2256. buf->card[1] = 0;
  2257. buf->card[2] = 0;
  2258. buf->card[3] = 0;
  2259. return;
  2260. }
  2261. // Pet eggs
  2262. if( item->card[0] == CARD0_PET ){
  2263. buf->card[0] = 0;
  2264. buf->card[1] = 0;
  2265. // Pet intimacy
  2266. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2267. buf->card[2] = item->card[3] >> 1;
  2268. // Pet renamed flag
  2269. buf->card[3] = item->card[3] & 1;
  2270. return;
  2271. }
  2272. // Forged/created items
  2273. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2274. buf->card[0] = item->card[0];
  2275. buf->card[1] = item->card[1];
  2276. buf->card[2] = item->card[2];
  2277. buf->card[3] = item->card[3];
  2278. return;
  2279. }
  2280. int i = 0, j;
  2281. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2282. if( MAX_SLOTS > 4 && ( j = itemdb_slot( item->nameid ) ) > 4 ){
  2283. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2284. }
  2285. // Normal items.
  2286. if( item->card[i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2287. buf->card[0] = j;
  2288. }else{
  2289. buf->card[0] = item->card[i];
  2290. }
  2291. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2292. buf->card[1] = j;
  2293. }else{
  2294. buf->card[1] = item->card[i];
  2295. }
  2296. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2297. buf->card[2] = j;
  2298. }else{
  2299. buf->card[2] = item->card[i];
  2300. }
  2301. if( item->card[++i] > 0 && ( j = itemdb_viewid( item->card[i] ) ) > 0 ){
  2302. buf->card[3] = j;
  2303. }else{
  2304. buf->card[3] = item->card[i];
  2305. }
  2306. }
  2307. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2308. /// A maximum of 5 random options can be supported.
  2309. static uint8 clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item* it ){
  2310. nullpo_retr( 0, it );
  2311. uint8 count = 0;
  2312. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2313. if( it->option[i].id ){
  2314. buf[i].index = it->option[i].id; // OptIndex
  2315. buf[i].value = it->option[i].value; // Value
  2316. buf[i].param = it->option[i].param; // Param1
  2317. count++;
  2318. }else{
  2319. buf[i].index = 0;
  2320. buf[i].value = 0;
  2321. buf[i].param = 0;
  2322. }
  2323. }
  2324. #if MAX_ITEM_RDM_OPT < 5
  2325. for( ; i < 5; i++ ){
  2326. buf[i].index = 0; // OptIndex
  2327. buf[i].value = 0; // Value
  2328. buf[i].param = 0; // Param1
  2329. }
  2330. #endif
  2331. return count;
  2332. }
  2333. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2334. /// 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)
  2335. /// 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)
  2336. /// 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)
  2337. /// 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)
  2338. /// 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)
  2339. /// 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)
  2340. void clif_additem( struct map_session_data *sd, int n, int amount, unsigned char fail ){
  2341. nullpo_retv( sd );
  2342. int fd = sd->fd;
  2343. if( !session_isActive( fd ) ){
  2344. return;
  2345. }
  2346. struct packet_additem p;
  2347. if( fail ){
  2348. p = {};
  2349. }else{
  2350. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <= 0 || sd->inventory_data[n] == nullptr ){
  2351. return;
  2352. }
  2353. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2354. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2355. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2356. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2357. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2358. p.location = pc_equippoint(sd,n);
  2359. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2360. #if PACKETVER >= 20061218
  2361. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2362. #endif
  2363. #if PACKETVER >= 20071002
  2364. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2365. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2366. */
  2367. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2368. #endif
  2369. #if PACKETVER >= 20150226
  2370. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[n] );
  2371. #endif
  2372. #if PACKETVER >= 20160921
  2373. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2374. p.look = sd->inventory_data[n]->look;
  2375. #endif
  2376. }
  2377. p.PacketType = additemType;
  2378. p.Index = client_index( n );
  2379. p.count = amount;
  2380. p.result = fail;
  2381. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2382. }
  2383. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2384. /// 00af <index>.W <amount>.W
  2385. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2386. {
  2387. int fd;
  2388. nullpo_retv(sd);
  2389. fd=sd->fd;
  2390. WFIFOHEAD(fd, packet_len(0xaf));
  2391. WFIFOW(fd,0)=0xaf;
  2392. WFIFOW(fd,2)=n+2;
  2393. WFIFOW(fd,4)=amount;
  2394. WFIFOSET(fd,packet_len(0xaf));
  2395. }
  2396. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2397. /// 07fa <delete type>.W <index>.W <amount>.W
  2398. /// delete type:
  2399. /// 0 = Normal
  2400. /// 1 = Item used for a skill
  2401. /// 2 = Refine failed
  2402. /// 3 = Material changed
  2403. /// 4 = Moved to storage
  2404. /// 5 = Moved to cart
  2405. /// 6 = Item sold
  2406. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2407. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2408. {
  2409. #if PACKETVER < 20091117
  2410. clif_dropitem(sd,n,amount);
  2411. #else
  2412. int fd;
  2413. nullpo_retv(sd);
  2414. fd=sd->fd;
  2415. WFIFOHEAD(fd, packet_len(0x7fa));
  2416. WFIFOW(fd,0)=0x7fa;
  2417. WFIFOW(fd,2)=reason;
  2418. WFIFOW(fd,4)=n+2;
  2419. WFIFOW(fd,6)=amount;
  2420. WFIFOSET(fd,packet_len(0x7fa));
  2421. #endif
  2422. }
  2423. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2424. nullpo_retv( p );
  2425. nullpo_retv( it );
  2426. nullpo_retv( id );
  2427. p->index = idx;
  2428. p->ITID = client_nameid( it->nameid );
  2429. p->type = itemtype( it->nameid );
  2430. #if PACKETVER < 20120925
  2431. p->IsIdentified = it->identify ? 1 : 0;
  2432. #endif
  2433. p->location = eqp_pos;
  2434. p->WearState = it->equip;
  2435. #if PACKETVER < 20120925
  2436. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2437. #endif
  2438. p->RefiningLevel = it->refine;
  2439. clif_addcards( &p->slot, it );
  2440. #if PACKETVER >= 20071002
  2441. p->HireExpireDate = it->expire_time;
  2442. #endif
  2443. #if PACKETVER >= 20080102
  2444. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2445. #endif
  2446. #if PACKETVER >= 20100629
  2447. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2448. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2449. #endif
  2450. #if PACKETVER >= 20120925
  2451. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2452. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2453. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2454. p->Flag.SpareBits = 0;
  2455. #endif
  2456. #if PACKETVER >= 20150226
  2457. p->option_count = clif_add_random_options( p->option_data, it );
  2458. #endif
  2459. }
  2460. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2461. nullpo_retv(p);
  2462. nullpo_retv(i);
  2463. nullpo_retv(id);
  2464. p->index = idx;
  2465. p->ITID = client_nameid( i->nameid );
  2466. p->type = itemtype( i->nameid );
  2467. #if PACKETVER < 20120925
  2468. p->IsIdentified = i->identify ? 1 : 0;
  2469. #endif
  2470. p->count = i->amount;
  2471. p->WearState = id->equip;
  2472. #if PACKETVER >= 5
  2473. clif_addcards( &p->slot, i );
  2474. #endif
  2475. #if PACKETVER >= 20080102
  2476. p->HireExpireDate = i->expire_time;
  2477. #endif
  2478. #if PACKETVER >= 20120925
  2479. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2480. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2481. p->Flag.SpareBits = 0;
  2482. #endif
  2483. }
  2484. static void clif_inventoryStart( struct map_session_data *sd, e_inventory_type type, const char *name ){
  2485. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2486. nullpo_retv(sd);
  2487. nullpo_retv(name);
  2488. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2489. memset(buf, 0, sizeof(buf));
  2490. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2491. p->packetType = HEADER_ZC_INVENTORY_START;
  2492. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2493. p->invType = type;
  2494. #endif
  2495. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2496. int strLen = (int)safestrnlen(name, 24) + 1;
  2497. if (strLen > 24)
  2498. strLen = 24;
  2499. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2500. p->packetLength = len;
  2501. safestrncpy(p->name, name, strLen);
  2502. #else
  2503. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2504. safestrncpy(p->name, name, NAME_LENGTH);
  2505. #endif
  2506. clif_send( p, len, &sd->bl, SELF );
  2507. #endif
  2508. }
  2509. static void clif_inventoryEnd( struct map_session_data *sd, e_inventory_type type ){
  2510. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2511. nullpo_retv(sd);
  2512. struct PACKET_ZC_INVENTORY_END p;
  2513. p.packetType = HEADER_ZC_INVENTORY_END;
  2514. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2515. p.invType = type;
  2516. #endif
  2517. p.flag = 0;
  2518. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2519. #endif
  2520. }
  2521. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2522. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2523. void clif_inventorylist( struct map_session_data *sd ){
  2524. nullpo_retv( sd );
  2525. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2526. e_inventory_type type = INVTYPE_INVENTORY;
  2527. clif_inventoryStart( sd, type, "" );
  2528. #endif
  2529. static struct packet_itemlist_normal itemlist_normal;
  2530. static struct packet_itemlist_equip itemlist_equip;
  2531. int equip = 0;
  2532. int normal = 0;
  2533. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2534. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == nullptr ){
  2535. continue;
  2536. }
  2537. // Non-stackable (Equippable)
  2538. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2539. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2540. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2541. itemlist_equip.PacketType = inventorylistequipType;
  2542. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2543. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2544. itemlist_equip.invType = type;
  2545. #endif
  2546. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2547. equip = 0;
  2548. }
  2549. // Stackable (Normal)
  2550. }else{
  2551. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2552. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2553. itemlist_normal.PacketType = inventorylistnormalType;
  2554. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2555. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2556. itemlist_normal.invType = type;
  2557. #endif
  2558. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2559. normal = 0;
  2560. }
  2561. }
  2562. }
  2563. if( normal ){
  2564. itemlist_normal.PacketType = inventorylistnormalType;
  2565. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2566. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2567. itemlist_normal.invType = type;
  2568. #endif
  2569. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2570. }
  2571. if( sd->equip_index[EQI_AMMO] >= 0 )
  2572. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2573. if( equip ) {
  2574. itemlist_equip.PacketType = inventorylistequipType;
  2575. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2576. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2577. itemlist_equip.invType = type;
  2578. #endif
  2579. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2580. }
  2581. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2582. clif_inventoryEnd( sd, type );
  2583. #endif
  2584. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2585. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2586. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2587. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2588. continue;
  2589. if ( sd->inventory.u.items_inventory[i].favorite )
  2590. clif_favorite_item(sd, i);
  2591. }
  2592. #endif
  2593. }
  2594. //Required when items break/get-repaired. Only sends equippable item list.
  2595. void clif_equiplist( struct map_session_data *sd ){
  2596. // TODO: implement again => only send equip part
  2597. clif_inventorylist( sd );
  2598. }
  2599. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename){
  2600. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2601. e_inventory_type type = INVTYPE_STORAGE;
  2602. clif_inventoryStart( sd, type, storename );
  2603. #endif
  2604. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2605. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2606. int equip = 0;
  2607. int normal = 0;
  2608. for( int i = 0; i < items_length; i++ ){
  2609. if( items[i].nameid <= 0 ){
  2610. continue;
  2611. }
  2612. struct item_data* id = itemdb_search( items[i].nameid );
  2613. // Non-stackable (Equippable)
  2614. if( !itemdb_isstackable2( id ) ){
  2615. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2616. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2617. storage_itemlist_equip.PacketType = storageListEquipType;
  2618. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2619. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2620. storage_itemlist_equip.invType = type;
  2621. #elif PACKETVER >= 20120925
  2622. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2623. #endif
  2624. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2625. equip = 0;
  2626. }
  2627. // Stackable (Normal)
  2628. }else{
  2629. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2630. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2631. storage_itemlist_normal.PacketType = storageListNormalType;
  2632. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2633. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2634. storage_itemlist_normal.invType = type;
  2635. #elif PACKETVER >= 20120925
  2636. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2637. #endif
  2638. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2639. normal = 0;
  2640. }
  2641. }
  2642. }
  2643. if( normal ){
  2644. storage_itemlist_normal.PacketType = storageListNormalType;
  2645. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2646. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2647. storage_itemlist_normal.invType = type;
  2648. #elif PACKETVER >= 20120925
  2649. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2650. #endif
  2651. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2652. }
  2653. if( equip ) {
  2654. storage_itemlist_equip.PacketType = storageListEquipType;
  2655. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2656. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2657. storage_itemlist_equip.invType = type;
  2658. #elif PACKETVER >= 20120925
  2659. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2660. #endif
  2661. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2662. }
  2663. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2664. clif_inventoryEnd( sd, type );
  2665. #endif
  2666. }
  2667. void clif_cartlist( struct map_session_data *sd ){
  2668. nullpo_retv( sd );
  2669. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2670. e_inventory_type type = INVTYPE_CART;
  2671. clif_inventoryStart( sd, type, "" );
  2672. #endif
  2673. static struct packet_itemlist_normal itemlist_normal;
  2674. static struct packet_itemlist_equip itemlist_equip;
  2675. int normal = 0;
  2676. int equip = 0;
  2677. for( int i = 0; i < MAX_CART; i++ ){
  2678. if( sd->cart.u.items_cart[i].nameid <= 0 ){
  2679. continue;
  2680. }
  2681. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2682. // Non-stackable (Equippable)
  2683. if( !itemdb_isstackable2(id) ){
  2684. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2685. // Stackable (Normal)
  2686. }else{
  2687. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2688. }
  2689. }
  2690. if( normal ){
  2691. itemlist_normal.PacketType = cartlistnormalType;
  2692. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2693. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2694. itemlist_normal.invType = type;
  2695. #endif
  2696. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2697. }
  2698. if( equip ){
  2699. itemlist_equip.PacketType = cartlistequipType;
  2700. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2701. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2702. itemlist_equip.invType = type;
  2703. #endif
  2704. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2705. }
  2706. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2707. clif_inventoryEnd( sd, type );
  2708. #endif
  2709. }
  2710. /// Removes cart (ZC_CARTOFF).
  2711. /// 012b
  2712. /// Client behaviour:
  2713. /// Closes the cart storage and removes all it's items from memory.
  2714. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2715. void clif_clearcart(int fd)
  2716. {
  2717. WFIFOHEAD(fd, packet_len(0x12b));
  2718. WFIFOW(fd,0) = 0x12b;
  2719. WFIFOSET(fd, packet_len(0x12b));
  2720. }
  2721. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2722. /// 01eb <account id>.L <x>.W <y>.W
  2723. void clif_guild_xy(struct map_session_data *sd)
  2724. {
  2725. unsigned char buf[10];
  2726. nullpo_retv(sd);
  2727. WBUFW(buf,0)=0x1eb;
  2728. WBUFL(buf,2)=sd->status.account_id;
  2729. WBUFW(buf,6)=sd->bl.x;
  2730. WBUFW(buf,8)=sd->bl.y;
  2731. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2732. }
  2733. /*==========================================
  2734. * Sends x/y dot to a single fd. [Skotlex]
  2735. *------------------------------------------*/
  2736. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2737. {
  2738. if( sd->bg_id )
  2739. return;
  2740. WFIFOHEAD(fd,packet_len(0x1eb));
  2741. WFIFOW(fd,0)=0x1eb;
  2742. WFIFOL(fd,2)=sd->status.account_id;
  2743. WFIFOW(fd,6)=sd->bl.x;
  2744. WFIFOW(fd,8)=sd->bl.y;
  2745. WFIFOSET(fd,packet_len(0x1eb));
  2746. }
  2747. // Guild XY locators [Valaris]
  2748. void clif_guild_xy_remove(struct map_session_data *sd)
  2749. {
  2750. unsigned char buf[10];
  2751. nullpo_retv(sd);
  2752. WBUFW(buf,0)=0x1eb;
  2753. WBUFL(buf,2)=sd->status.account_id;
  2754. WBUFW(buf,6)=-1;
  2755. WBUFW(buf,8)=-1;
  2756. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2757. }
  2758. /*==========================================
  2759. *
  2760. *------------------------------------------*/
  2761. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2762. {
  2763. struct map_session_data *sd, *tsd;
  2764. #if PACKETVER < 20100126
  2765. const int cmd = 0x106;
  2766. #else
  2767. const int cmd = 0x80e;
  2768. #endif
  2769. sd = va_arg(ap, struct map_session_data *);
  2770. tsd = (TBL_PC *)bl;
  2771. nullpo_ret(sd);
  2772. nullpo_ret(tsd);
  2773. if( !tsd->fd || tsd == sd )
  2774. return 0;
  2775. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2776. return 0;
  2777. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2778. WFIFOW(tsd->fd,0) = cmd;
  2779. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2780. #if PACKETVER < 20100126
  2781. if( sd->battle_status.max_hp > INT16_MAX )
  2782. { //To correctly display the %hp bar. [Skotlex]
  2783. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2784. WFIFOW(tsd->fd,8) = 100;
  2785. } else {
  2786. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2787. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2788. }
  2789. #else
  2790. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2791. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2792. #endif
  2793. WFIFOSET(tsd->fd,packet_len(cmd));
  2794. return 0;
  2795. }
  2796. /*==========================================
  2797. * Server tells all players that are allowed to view HP bars
  2798. * and are nearby 'sd' that 'sd' hp bar was updated.
  2799. *------------------------------------------*/
  2800. static int clif_hpmeter(struct map_session_data *sd)
  2801. {
  2802. nullpo_ret(sd);
  2803. 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);
  2804. return 0;
  2805. }
  2806. /// Notifies client of a character parameter change.
  2807. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2808. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2809. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2810. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2811. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2812. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2813. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2814. /// TODO: Extract individual packets.
  2815. /// FIXME: Packet lengths from packet_len(cmd)
  2816. void clif_updatestatus(struct map_session_data *sd,int type)
  2817. {
  2818. int fd,len=8;
  2819. nullpo_retv(sd);
  2820. fd=sd->fd;
  2821. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2822. return;
  2823. WFIFOHEAD(fd, 14);
  2824. WFIFOW(fd,0)=0xb0;
  2825. WFIFOW(fd,2)=type;
  2826. switch(type){
  2827. // 00b0
  2828. case SP_WEIGHT:
  2829. pc_updateweightstatus(sd);
  2830. WFIFOHEAD(fd,14);
  2831. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2832. WFIFOW(fd,2)=type;
  2833. WFIFOL(fd,4)=sd->weight;
  2834. break;
  2835. case SP_MAXWEIGHT:
  2836. WFIFOL(fd,4)=sd->max_weight;
  2837. break;
  2838. case SP_SPEED:
  2839. WFIFOL(fd,4)=sd->battle_status.speed;
  2840. break;
  2841. case SP_BASELEVEL:
  2842. WFIFOL(fd,4)=sd->status.base_level;
  2843. break;
  2844. case SP_JOBLEVEL:
  2845. WFIFOL(fd,4)=sd->status.job_level;
  2846. break;
  2847. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2848. WFIFOL(fd,4)=sd->status.karma;
  2849. break;
  2850. case SP_MANNER:
  2851. WFIFOL(fd,4)=sd->status.manner;
  2852. break;
  2853. case SP_STATUSPOINT:
  2854. WFIFOL(fd,4)=sd->status.status_point;
  2855. break;
  2856. case SP_SKILLPOINT:
  2857. WFIFOL(fd,4)=sd->status.skill_point;
  2858. break;
  2859. case SP_HIT:
  2860. WFIFOL(fd,4)=sd->battle_status.hit;
  2861. break;
  2862. case SP_FLEE1:
  2863. WFIFOL(fd,4)=sd->battle_status.flee;
  2864. break;
  2865. case SP_FLEE2:
  2866. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2867. break;
  2868. case SP_MAXHP:
  2869. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2870. break;
  2871. case SP_MAXSP:
  2872. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2873. break;
  2874. case SP_HP:
  2875. // On officials the HP never go below 1, even if you die [Lemongrass]
  2876. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2877. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2878. break;
  2879. case SP_SP:
  2880. WFIFOL(fd,4)=sd->battle_status.sp;
  2881. break;
  2882. case SP_ASPD:
  2883. WFIFOL(fd,4)=sd->battle_status.amotion;
  2884. break;
  2885. case SP_ATK1:
  2886. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2887. break;
  2888. case SP_DEF1:
  2889. WFIFOL(fd,4)=pc_leftside_def(sd);
  2890. break;
  2891. case SP_MDEF1:
  2892. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2893. break;
  2894. case SP_ATK2:
  2895. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2896. break;
  2897. case SP_DEF2:
  2898. WFIFOL(fd,4)=pc_rightside_def(sd);
  2899. break;
  2900. case SP_MDEF2: {
  2901. //negative check (in case you have something like Berserk active)
  2902. int mdef2 = pc_rightside_mdef(sd);
  2903. WFIFOL(fd,4)=
  2904. #ifndef RENEWAL
  2905. ( mdef2 < 0 ) ? 0 :
  2906. #endif
  2907. mdef2;
  2908. }
  2909. break;
  2910. case SP_CRITICAL:
  2911. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2912. break;
  2913. case SP_MATK1:
  2914. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2915. break;
  2916. case SP_MATK2:
  2917. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2918. break;
  2919. case SP_ZENY:
  2920. WFIFOW(fd,0)=0xb1;
  2921. WFIFOL(fd,4)=sd->status.zeny;
  2922. break;
  2923. #if PACKETVER >= 20170830
  2924. case SP_BASEEXP:
  2925. WFIFOW(fd,0)=0xacb;
  2926. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  2927. len = packet_len(0xacb);
  2928. break;
  2929. case SP_JOBEXP:
  2930. WFIFOW(fd,0)=0xacb;
  2931. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  2932. len = packet_len(0xacb);
  2933. break;
  2934. case SP_NEXTBASEEXP:
  2935. WFIFOW(fd,0)=0xacb;
  2936. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  2937. len = packet_len(0xacb);
  2938. break;
  2939. case SP_NEXTJOBEXP:
  2940. WFIFOW(fd,0)=0xacb;
  2941. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  2942. len = packet_len(0xacb);
  2943. break;
  2944. #else
  2945. case SP_BASEEXP:
  2946. WFIFOW(fd,0)=0xb1;
  2947. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  2948. break;
  2949. case SP_JOBEXP:
  2950. WFIFOW(fd,0)=0xb1;
  2951. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  2952. break;
  2953. case SP_NEXTBASEEXP:
  2954. WFIFOW(fd,0)=0xb1;
  2955. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  2956. break;
  2957. case SP_NEXTJOBEXP:
  2958. WFIFOW(fd,0)=0xb1;
  2959. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  2960. break;
  2961. #endif
  2962. /**
  2963. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2964. **/
  2965. case SP_USTR:
  2966. case SP_UAGI:
  2967. case SP_UVIT:
  2968. case SP_UINT:
  2969. case SP_UDEX:
  2970. case SP_ULUK:
  2971. WFIFOW(fd,0)=0xbe;
  2972. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2973. len=5;
  2974. break;
  2975. /**
  2976. * Tells the client how far it is allowed to attack (weapon range)
  2977. **/
  2978. case SP_ATTACKRANGE:
  2979. WFIFOW(fd,0)=0x13a;
  2980. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2981. len=4;
  2982. break;
  2983. case SP_STR:
  2984. WFIFOW(fd,0)=0x141;
  2985. WFIFOL(fd,2)=type;
  2986. WFIFOL(fd,6)=sd->status.str;
  2987. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2988. len=14;
  2989. break;
  2990. case SP_AGI:
  2991. WFIFOW(fd,0)=0x141;
  2992. WFIFOL(fd,2)=type;
  2993. WFIFOL(fd,6)=sd->status.agi;
  2994. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2995. len=14;
  2996. break;
  2997. case SP_VIT:
  2998. WFIFOW(fd,0)=0x141;
  2999. WFIFOL(fd,2)=type;
  3000. WFIFOL(fd,6)=sd->status.vit;
  3001. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3002. len=14;
  3003. break;
  3004. case SP_INT:
  3005. WFIFOW(fd,0)=0x141;
  3006. WFIFOL(fd,2)=type;
  3007. WFIFOL(fd,6)=sd->status.int_;
  3008. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3009. len=14;
  3010. break;
  3011. case SP_DEX:
  3012. WFIFOW(fd,0)=0x141;
  3013. WFIFOL(fd,2)=type;
  3014. WFIFOL(fd,6)=sd->status.dex;
  3015. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3016. len=14;
  3017. break;
  3018. case SP_LUK:
  3019. WFIFOW(fd,0)=0x141;
  3020. WFIFOL(fd,2)=type;
  3021. WFIFOL(fd,6)=sd->status.luk;
  3022. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3023. len=14;
  3024. break;
  3025. case SP_CARTINFO:
  3026. WFIFOW(fd,0)=0x121;
  3027. WFIFOW(fd,2)=sd->cart_num;
  3028. WFIFOW(fd,4)=MAX_CART;
  3029. WFIFOL(fd,6)=sd->cart_weight;
  3030. WFIFOL(fd,10)=sd->cart_weight_max;
  3031. len=14;
  3032. break;
  3033. default:
  3034. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3035. return;
  3036. }
  3037. WFIFOSET(fd,len);
  3038. // Additional update packets that should be sent right after
  3039. switch( type ){
  3040. case SP_BASELEVEL:
  3041. if( sd->status.party_id ){
  3042. struct party_data* p;
  3043. int i;
  3044. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3045. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3046. if( i < MAX_PARTY ){
  3047. p->party.member[i].lv = sd->status.base_level;
  3048. clif_party_job_and_level(sd);
  3049. }
  3050. }
  3051. }
  3052. break;
  3053. case SP_HP:
  3054. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3055. clif_hpmeter(sd);
  3056. }
  3057. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3058. clif_party_hp(sd);
  3059. }
  3060. if( sd->bg_id ){
  3061. clif_bg_hp(sd);
  3062. }
  3063. break;
  3064. }
  3065. }
  3066. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3067. /// 01ab <account id>.L <var id>.W <value>.L
  3068. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3069. {
  3070. unsigned char buf[12];
  3071. nullpo_retv(sd);
  3072. WBUFW(buf,0)=0x1ab;
  3073. WBUFL(buf,2)=sd->bl.id;
  3074. WBUFW(buf,6)=type;
  3075. switch(type)
  3076. {
  3077. case SP_MANNER:
  3078. WBUFL(buf,8)=val;
  3079. break;
  3080. default:
  3081. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3082. return;
  3083. }
  3084. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3085. }
  3086. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3087. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3088. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3089. struct PACKET_ZC_SPRITE_CHANGE p;
  3090. p.packetType = sendLookType;
  3091. p.AID = id;
  3092. p.type = type;
  3093. p.val = val;
  3094. #if PACKETVER >= 4
  3095. p.val2 = val2;
  3096. #endif
  3097. clif_send( &p, sizeof( p ), bl, target );
  3098. }
  3099. /// Updates sprite/style properties of an object.
  3100. void clif_changelook(struct block_list *bl, int type, int val) {
  3101. struct map_session_data* sd;
  3102. struct status_change* sc;
  3103. struct view_data* vd;
  3104. enum send_target target = AREA;
  3105. int val2 = 0;
  3106. nullpo_retv(bl);
  3107. sd = BL_CAST(BL_PC, bl);
  3108. sc = status_get_sc(bl);
  3109. vd = status_get_viewdata(bl);
  3110. if( vd ) //temp hack to let Warp Portal change appearance
  3111. switch(type) {
  3112. case LOOK_WEAPON:
  3113. if (sd) {
  3114. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3115. val = vd->weapon;
  3116. }
  3117. else
  3118. vd->weapon = val;
  3119. break;
  3120. case LOOK_SHIELD:
  3121. if (sd) {
  3122. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3123. val = vd->shield;
  3124. }
  3125. else
  3126. vd->shield = val;
  3127. break;
  3128. case LOOK_BASE:
  3129. if (!sd)
  3130. break;
  3131. if ( val == JT_INVISIBLE )
  3132. return;
  3133. if (sd->sc.option&OPTION_COSTUME)
  3134. vd->weapon = vd->shield = 0;
  3135. if (!vd->cloth_color)
  3136. break;
  3137. if (sd) {
  3138. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3139. vd->cloth_color = 0;
  3140. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3141. vd->cloth_color = 0;
  3142. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3143. vd->cloth_color = 0;
  3144. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3145. vd->cloth_color = 0;
  3146. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3147. vd->cloth_color = 0;
  3148. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3149. vd->body_style = 0;
  3150. }
  3151. break;
  3152. case LOOK_HAIR:
  3153. vd->hair_style = val;
  3154. break;
  3155. case LOOK_HEAD_BOTTOM:
  3156. vd->head_bottom = val;
  3157. break;
  3158. case LOOK_HEAD_TOP:
  3159. vd->head_top = val;
  3160. break;
  3161. case LOOK_HEAD_MID:
  3162. vd->head_mid = val;
  3163. break;
  3164. case LOOK_HAIR_COLOR:
  3165. vd->hair_color = val;
  3166. break;
  3167. case LOOK_CLOTHES_COLOR:
  3168. if (val && sd) {
  3169. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3170. val = 0;
  3171. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3172. val = 0;
  3173. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3174. val = 0;
  3175. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3176. val = 0;
  3177. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3178. val = 0;
  3179. }
  3180. vd->cloth_color = val;
  3181. break;
  3182. case LOOK_SHOES:
  3183. #if PACKETVER > 3
  3184. if (sd) {
  3185. int n;
  3186. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3187. if(sd->inventory_data[n]->view_id > 0)
  3188. val = sd->inventory_data[n]->view_id;
  3189. else
  3190. val = sd->inventory.u.items_inventory[n].nameid;
  3191. } else
  3192. val = 0;
  3193. }
  3194. #endif
  3195. //Shoes? No packet uses this....
  3196. break;
  3197. case LOOK_BODY:
  3198. // unknown purpose
  3199. break;
  3200. case LOOK_ROBE:
  3201. #if PACKETVER < 20110111
  3202. return;
  3203. #else
  3204. vd->robe = val;
  3205. #endif
  3206. break;
  3207. case LOOK_BODY2:
  3208. #if PACKETVER < 20150513
  3209. return;
  3210. #else
  3211. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3212. val = 0;
  3213. vd->body_style = val;
  3214. #endif
  3215. break;
  3216. }
  3217. // prevent leaking the presence of GM-hidden objects
  3218. if( sc && sc->option&OPTION_INVISIBLE )
  3219. target = SELF;
  3220. #if PACKETVER < 4
  3221. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3222. #else
  3223. if (bl->type != BL_NPC) {
  3224. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3225. type = LOOK_WEAPON;
  3226. val = (vd ? vd->weapon : 0);
  3227. val2 = (vd ? vd->shield : 0);
  3228. }
  3229. if (disguised(bl)) {
  3230. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3231. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3232. } else
  3233. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3234. } else
  3235. unit_refresh(bl);
  3236. #endif
  3237. }
  3238. //Sends a change-base-look packet required for traps as they are triggered.
  3239. void clif_changetraplook(struct block_list *bl,int val) {
  3240. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3241. }
  3242. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3243. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3244. clif_sprite_change(bl, id, type, val, 0, target);
  3245. }
  3246. /// Character status (ZC_STATUS).
  3247. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3248. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3249. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3250. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3251. void clif_initialstatus(struct map_session_data *sd) {
  3252. int fd, mdef2;
  3253. unsigned char *buf;
  3254. nullpo_retv(sd);
  3255. fd=sd->fd;
  3256. WFIFOHEAD(fd, packet_len(0xbd));
  3257. buf = WFIFOP(fd,0);
  3258. WBUFW(buf,0) = 0xbd;
  3259. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3260. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3261. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3262. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3263. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3264. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3265. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3266. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3267. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3268. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3269. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3270. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3271. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3272. WBUFW(buf,16) = pc_leftside_atk(sd);
  3273. WBUFW(buf,18) = pc_rightside_atk(sd);
  3274. WBUFW(buf,20) = pc_rightside_matk(sd);
  3275. WBUFW(buf,22) = pc_leftside_matk(sd);
  3276. WBUFW(buf,24) = pc_leftside_def(sd);
  3277. WBUFW(buf,26) = pc_rightside_def(sd);
  3278. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3279. mdef2 = pc_rightside_mdef(sd);
  3280. WBUFW(buf,30) =
  3281. #ifndef RENEWAL
  3282. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3283. #endif
  3284. mdef2;
  3285. WBUFW(buf,32) = sd->battle_status.hit;
  3286. WBUFW(buf,34) = sd->battle_status.flee;
  3287. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3288. WBUFW(buf,38) = sd->battle_status.cri/10;
  3289. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3290. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3291. WFIFOSET(fd, packet_len(0xbd));
  3292. clif_updatestatus(sd, SP_STR);
  3293. clif_updatestatus(sd, SP_AGI);
  3294. clif_updatestatus(sd, SP_VIT);
  3295. clif_updatestatus(sd, SP_INT);
  3296. clif_updatestatus(sd, SP_DEX);
  3297. clif_updatestatus(sd, SP_LUK);
  3298. clif_updatestatus(sd, SP_ATTACKRANGE);
  3299. clif_updatestatus(sd, SP_ASPD);
  3300. }
  3301. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3302. /// 013c <index>.W
  3303. void clif_arrowequip(struct map_session_data *sd,int val) {
  3304. int fd;
  3305. nullpo_retv(sd);
  3306. #if PACKETVER >= 20121128
  3307. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3308. #endif
  3309. fd=sd->fd;
  3310. WFIFOHEAD(fd, packet_len(0x013c));
  3311. WFIFOW(fd,0) = 0x013c;
  3312. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3313. WFIFOSET(fd, packet_len(0x013c));
  3314. }
  3315. /// Ammunition action message (ZC_ACTION_FAILURE).
  3316. /// 013b <type>.W
  3317. /// type:
  3318. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3319. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3320. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3321. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3322. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3323. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3324. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3325. int fd;
  3326. nullpo_retv(sd);
  3327. fd=sd->fd;
  3328. WFIFOHEAD(fd, packet_len(0x013b));
  3329. WFIFOW(fd,0) = 0x013b;
  3330. WFIFOW(fd,2) = type;
  3331. WFIFOSET(fd, packet_len(0x013b));
  3332. }
  3333. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3334. /// 01ad <packet len>.W { <name id>.W }*
  3335. void clif_arrow_create_list( struct map_session_data *sd ){
  3336. nullpo_retv( sd );
  3337. int fd = sd->fd;
  3338. if( !session_isActive( fd ) ){
  3339. return;
  3340. }
  3341. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  3342. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  3343. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3344. int count = 0;
  3345. for( int i = 0; i < MAX_SKILL_ARROW_DB; i++ ){
  3346. short nameid = skill_arrow_db[i].nameid;
  3347. if( !itemdb_exists( nameid ) ){
  3348. continue;
  3349. }
  3350. int index = pc_search_inventory( sd, nameid );
  3351. if( index < 0 ){
  3352. continue;
  3353. }
  3354. if( sd->inventory.u.items_inventory[index].equip ){
  3355. continue;
  3356. }
  3357. if( !sd->inventory.u.items_inventory[index].identify ){
  3358. continue;
  3359. }
  3360. p->items[count].itemId = client_nameid( nameid );
  3361. count++;
  3362. }
  3363. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3364. WFIFOSET( fd, p->packetLength );
  3365. if( count > 0 ){
  3366. sd->menuskill_id = AC_MAKINGARROW;
  3367. sd->menuskill_val = count;
  3368. }
  3369. }
  3370. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3371. /// 00bc <status id>.W <result>.B <value>.B
  3372. /// status id:
  3373. /// SP_STR ~ SP_LUK
  3374. /// result:
  3375. /// 0 = failure
  3376. /// 1 = success
  3377. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3378. int fd;
  3379. nullpo_retv(sd);
  3380. fd=sd->fd;
  3381. WFIFOHEAD(fd, packet_len(0xbc));
  3382. WFIFOW(fd,0) = 0xbc;
  3383. WFIFOW(fd,2) = type;
  3384. WFIFOB(fd,4) = ok;
  3385. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3386. WFIFOSET(fd, packet_len(0xbc));
  3387. }
  3388. /// Notifies the client about the result of a request to equip an item.
  3389. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3390. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3391. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3392. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3393. /// @ok: //inversed forv2 v5
  3394. /// 0 = failure
  3395. /// 1 = success
  3396. /// 2 = failure due to low level
  3397. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3398. {
  3399. int fd = 0, cmd = 0, look = 0;
  3400. struct s_packet_db *info = NULL;
  3401. nullpo_retv(sd);
  3402. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3403. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3404. return;
  3405. fd = sd->fd;
  3406. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3407. look = sd->inventory_data[n]->look;
  3408. WFIFOHEAD(fd, info->len);
  3409. WFIFOW(fd, 0) = cmd;
  3410. WFIFOW(fd, info->pos[0]) = n+2;
  3411. switch (cmd) {
  3412. case 0xaa:
  3413. WFIFOW(fd, info->pos[1]) = pos;
  3414. #if PACKETVER < 20100629
  3415. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3416. #else
  3417. WFIFOL(fd, info->pos[2]) = look;
  3418. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3419. #endif
  3420. break;
  3421. case 0x8d0:
  3422. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3423. flag = 1;
  3424. case 0x999:
  3425. if (cmd == 0x999)
  3426. WFIFOL(fd, info->pos[1]) = pos;
  3427. else
  3428. WFIFOW(fd, info->pos[1]) = pos;
  3429. WFIFOL(fd, info->pos[2]) = look;
  3430. WFIFOW(fd, info->pos[3]) = flag;
  3431. break;
  3432. }
  3433. WFIFOSET(fd, info->len);
  3434. }
  3435. /// Notifies the client about the result of a request to take off an item.
  3436. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3437. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3438. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3439. /// @ok : //inversed for v2 v5
  3440. /// 0 = failure
  3441. /// 1 = success
  3442. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3443. {
  3444. int fd, header, offs = 0;
  3445. #if PACKETVER >= 20130000
  3446. header = 0x99a;
  3447. ok = ok ? 0 : 1;
  3448. #elif PACKETVER >= 20110824
  3449. header = 0x8d1;
  3450. ok = ok ? 0 : 1;
  3451. #else
  3452. header = 0xac;
  3453. #endif
  3454. nullpo_retv(sd);
  3455. fd=sd->fd;
  3456. WFIFOHEAD(fd, packet_len(header));
  3457. WFIFOW(fd,offs+0) = header;
  3458. WFIFOW(fd,offs+2) = n+2;
  3459. #if PACKETVER >= 20130000
  3460. WFIFOL(fd,offs+4) = pos;
  3461. offs += 2;
  3462. #else
  3463. WFIFOW(fd,offs+4) = pos;
  3464. #endif
  3465. WFIFOB(fd,offs+6) = ok;
  3466. WFIFOSET(fd, packet_len(header));
  3467. }
  3468. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3469. /// 019b <id>.L <effect id>.L
  3470. /// effect id:
  3471. /// 0 = base level up
  3472. /// 1 = job level up
  3473. /// 2 = refine failure
  3474. /// 3 = refine success
  3475. /// 4 = game over
  3476. /// 5 = pharmacy success
  3477. /// 6 = pharmacy failure
  3478. /// 7 = base level up (super novice)
  3479. /// 8 = job level up (super novice)
  3480. /// 9 = base level up (taekwon)
  3481. void clif_misceffect(struct block_list* bl,int type)
  3482. {
  3483. unsigned char buf[32];
  3484. nullpo_retv(bl);
  3485. WBUFW(buf,0) = 0x19b;
  3486. WBUFL(buf,2) = bl->id;
  3487. WBUFL(buf,6) = type;
  3488. clif_send(buf,packet_len(0x19b),bl,AREA);
  3489. }
  3490. /// Notifies clients in the area of a state change.
  3491. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3492. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3493. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3494. nullpo_retv( bl );
  3495. struct status_change* sc = status_get_sc( bl );
  3496. //How can an option change if there's no sc?
  3497. if( sc == nullptr ){
  3498. return;
  3499. }
  3500. struct map_session_data* sd = BL_CAST( BL_PC, bl );
  3501. struct PACKET_ZC_STATE_CHANGE p;
  3502. p.packetType = HEADER_ZC_STATE_CHANGE;
  3503. p.AID = bl->id;
  3504. p.bodyState = sc->opt1;
  3505. p.healthState = sc->opt2;
  3506. p.effectState = sc->option;
  3507. p.isPKModeON = sd ? sd->status.karma : false;
  3508. if( target == nullptr ){
  3509. if( disguised( bl ) ){
  3510. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3511. p.AID = disguised_bl_id( p.AID );
  3512. clif_send( &p, sizeof( p ), bl, SELF );
  3513. p.AID = disguised_bl_id( p.AID );
  3514. p.effectState = OPTION_INVISIBLE;
  3515. clif_send( &p, sizeof( p ), bl, SELF );
  3516. }else{
  3517. clif_send( &p, sizeof( p ), bl, AREA );
  3518. }
  3519. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3520. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3521. if( sc->data[SC_PROVOKE] ){
  3522. const struct TimerData *td = get_timer( sc->data[SC_PROVOKE]->timer );
  3523. clif_status_change( bl, StatusIconChangeTable[SC_PROVOKE], 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3524. }
  3525. }else{
  3526. if( disguised( bl ) ){
  3527. p.AID = disguised_bl_id( p.AID );
  3528. clif_send( &p, sizeof( p ), target, SELF );
  3529. p.AID = disguised_bl_id( p.AID );
  3530. p.effectState = OPTION_INVISIBLE;
  3531. clif_send( &p, sizeof( p ), target, SELF );
  3532. }else{
  3533. clif_send( &p, sizeof( p ), target, SELF );
  3534. }
  3535. }
  3536. }
  3537. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3538. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3539. void clif_changeoption2(struct block_list* bl)
  3540. {
  3541. unsigned char buf[20];
  3542. struct status_change *sc;
  3543. sc = status_get_sc(bl);
  3544. if (!sc) return; //How can an option change if there's no sc?
  3545. WBUFW(buf,0) = 0x28a;
  3546. WBUFL(buf,2) = bl->id;
  3547. WBUFL(buf,6) = sc->option;
  3548. WBUFL(buf,10) = clif_setlevel(bl);
  3549. WBUFL(buf,14) = sc->opt3;
  3550. if(disguised(bl)) {
  3551. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3552. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3553. clif_send(buf,packet_len(0x28a),bl,SELF);
  3554. WBUFL(buf,2) = bl->id;
  3555. WBUFL(buf,6) = OPTION_INVISIBLE;
  3556. clif_send(buf,packet_len(0x28a),bl,SELF);
  3557. } else
  3558. clif_send(buf,packet_len(0x28a),bl,AREA);
  3559. }
  3560. /// Notifies the client about the result of an item use request.
  3561. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3562. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3563. void clif_useitemack( struct map_session_data *sd, int index, int amount, bool ok ){
  3564. nullpo_retv( sd );
  3565. int fd = sd->fd;
  3566. if( !session_isActive( fd ) ){
  3567. return;
  3568. }
  3569. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid <= 0 || sd->inventory_data[index] == nullptr ){
  3570. return;
  3571. }
  3572. struct PACKET_ZC_USE_ITEM_ACK p;
  3573. p.packetType = useItemAckType;
  3574. p.index = index + 2;
  3575. #if PACKETVER > 3
  3576. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3577. p.AID = sd->bl.id;
  3578. #endif
  3579. p.amount = amount;
  3580. p.result = ok;
  3581. if( !ok ){
  3582. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3583. }else{
  3584. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3585. }
  3586. }
  3587. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3588. /// 00d6 <flag>.B
  3589. /// flag:
  3590. /// 0 = Room has been successfully created (opens chat room)
  3591. /// 1 = Room limit exceeded
  3592. /// 2 = Same room already exists
  3593. void clif_createchat(struct map_session_data* sd, int flag)
  3594. {
  3595. int fd;
  3596. nullpo_retv(sd);
  3597. fd = sd->fd;
  3598. WFIFOHEAD(fd,packet_len(0xd6));
  3599. WFIFOW(fd,0) = 0xd6;
  3600. WFIFOB(fd,2) = flag;
  3601. WFIFOSET(fd,packet_len(0xd6));
  3602. }
  3603. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3604. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3605. /// type:
  3606. /// 0 = private (password protected)
  3607. /// 1 = public
  3608. /// 2 = arena (npc waiting room)
  3609. /// 3 = PK zone (non-clickable)
  3610. void clif_dispchat(struct chat_data* cd, int fd)
  3611. {
  3612. unsigned char buf[128];
  3613. uint8 type;
  3614. if( cd == NULL || cd->owner == NULL )
  3615. return;
  3616. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3617. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3618. : 1;
  3619. WBUFW(buf, 0) = 0xd7;
  3620. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3621. WBUFL(buf, 4) = cd->owner->id;
  3622. WBUFL(buf, 8) = cd->bl.id;
  3623. WBUFW(buf,12) = cd->limit;
  3624. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3625. WBUFB(buf,16) = type;
  3626. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3627. if( fd ) {
  3628. WFIFOHEAD(fd,WBUFW(buf,2));
  3629. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3630. WFIFOSET(fd,WBUFW(buf,2));
  3631. } else {
  3632. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3633. }
  3634. }
  3635. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3636. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3637. /// type:
  3638. /// 0 = private (password protected)
  3639. /// 1 = public
  3640. /// 2 = arena (npc waiting room)
  3641. /// 3 = PK zone (non-clickable)
  3642. void clif_changechatstatus(struct chat_data* cd)
  3643. {
  3644. unsigned char buf[128];
  3645. uint8 type;
  3646. if( cd == NULL || cd->usersd[0] == NULL )
  3647. return;
  3648. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3649. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3650. : 1;
  3651. WBUFW(buf, 0) = 0xdf;
  3652. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3653. WBUFL(buf, 4) = cd->owner->id;
  3654. WBUFL(buf, 8) = cd->bl.id;
  3655. WBUFW(buf,12) = cd->limit;
  3656. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3657. WBUFB(buf,16) = type;
  3658. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3659. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3660. }
  3661. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3662. /// 00d8 <chat id>.L
  3663. void clif_clearchat(struct chat_data *cd,int fd)
  3664. {
  3665. unsigned char buf[32];
  3666. nullpo_retv(cd);
  3667. WBUFW(buf,0) = 0xd8;
  3668. WBUFL(buf,2) = cd->bl.id;
  3669. if( fd ) {
  3670. WFIFOHEAD(fd,packet_len(0xd8));
  3671. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3672. WFIFOSET(fd,packet_len(0xd8));
  3673. } else {
  3674. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3675. }
  3676. }
  3677. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3678. /// 00da <result>.B
  3679. /// result:
  3680. /// 0 = room full
  3681. /// 1 = wrong password
  3682. /// 2 = kicked
  3683. /// 3 = success (no message)
  3684. /// 4 = no enough zeny
  3685. /// 5 = too low level
  3686. /// 6 = too high level
  3687. /// 7 = unsuitable job class
  3688. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3689. {
  3690. int fd;
  3691. nullpo_retv(sd);
  3692. fd = sd->fd;
  3693. WFIFOHEAD(fd,packet_len(0xda));
  3694. WFIFOW(fd,0) = 0xda;
  3695. WFIFOB(fd,2) = flag;
  3696. WFIFOSET(fd,packet_len(0xda));
  3697. }
  3698. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3699. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3700. /// role:
  3701. /// 0 = owner (menu)
  3702. /// 1 = normal
  3703. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3704. {
  3705. int fd;
  3706. int i,t;
  3707. nullpo_retv(sd);
  3708. nullpo_retv(cd);
  3709. fd = sd->fd;
  3710. if (!session_isActive(fd))
  3711. return;
  3712. t = (int)(cd->owner->type == BL_NPC);
  3713. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3714. WFIFOW(fd, 0) = 0xdb;
  3715. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3716. WFIFOL(fd, 4) = cd->bl.id;
  3717. if(cd->owner->type == BL_NPC){
  3718. WFIFOL(fd, 30) = 1;
  3719. WFIFOL(fd, 8) = 0;
  3720. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3721. for (i = 0; i < cd->users; i++) {
  3722. WFIFOL(fd, 8+(i+1)*28) = 1;
  3723. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3724. }
  3725. }else{
  3726. for (i = 0; i < cd->users; i++) {
  3727. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3728. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3729. }
  3730. }
  3731. WFIFOSET(fd, WFIFOW(fd, 2));
  3732. }
  3733. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3734. /// 00dc <users>.W <name>.24B
  3735. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3736. {
  3737. unsigned char buf[29];
  3738. nullpo_retv(sd);
  3739. nullpo_retv(cd);
  3740. WBUFW(buf, 0) = 0xdc;
  3741. WBUFW(buf, 2) = cd->users;
  3742. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3743. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3744. }
  3745. /// Announce the new owner (ZC_ROLE_CHANGE).
  3746. /// 00e1 <role>.L <nick>.24B
  3747. /// role:
  3748. /// 0 = owner (menu)
  3749. /// 1 = normal
  3750. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3751. {
  3752. unsigned char buf[64];
  3753. nullpo_retv(sd);
  3754. nullpo_retv(cd);
  3755. WBUFW(buf, 0) = 0xe1;
  3756. WBUFL(buf, 2) = 1;
  3757. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3758. WBUFW(buf,30) = 0xe1;
  3759. WBUFL(buf,32) = 0;
  3760. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3761. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3762. }
  3763. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3764. /// 00dd <users>.W <nick>.24B <flag>.B
  3765. /// flag:
  3766. /// 0 = left
  3767. /// 1 = kicked
  3768. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3769. {
  3770. unsigned char buf[32];
  3771. nullpo_retv(sd);
  3772. nullpo_retv(cd);
  3773. WBUFW(buf, 0) = 0xdd;
  3774. WBUFW(buf, 2) = cd->users-1;
  3775. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3776. WBUFB(buf,28) = flag;
  3777. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3778. }
  3779. /// Opens a trade request window from char 'name'.
  3780. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3781. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3782. void clif_traderequest(struct map_session_data* sd, const char* name)
  3783. {
  3784. int fd = sd->fd;
  3785. #if PACKETVER < 6
  3786. WFIFOHEAD(fd,packet_len(0xe5));
  3787. WFIFOW(fd,0) = 0xe5;
  3788. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3789. WFIFOSET(fd,packet_len(0xe5));
  3790. #else
  3791. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3792. if( !tsd ) return;
  3793. WFIFOHEAD(fd,packet_len(0x1f4));
  3794. WFIFOW(fd,0) = 0x1f4;
  3795. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3796. WFIFOL(fd,26) = tsd->status.char_id;
  3797. WFIFOW(fd,30) = tsd->status.base_level;
  3798. WFIFOSET(fd,packet_len(0x1f4));
  3799. #endif
  3800. }
  3801. /// Reply to a trade-request.
  3802. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3803. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3804. /// result:
  3805. /// 0 = Char is too far
  3806. /// 1 = Character does not exist
  3807. /// 2 = Trade failed
  3808. /// 3 = Accept
  3809. /// 4 = Cancel
  3810. /// 5 = Busy
  3811. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3812. {
  3813. int fd = sd->fd;
  3814. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3815. if( PACKETVER < 6 || !tsd ) {
  3816. WFIFOHEAD(fd,packet_len(0xe7));
  3817. WFIFOW(fd,0) = 0xe7;
  3818. WFIFOB(fd,2) = type;
  3819. WFIFOSET(fd,packet_len(0xe7));
  3820. } else {
  3821. WFIFOHEAD(fd,packet_len(0x1f5));
  3822. WFIFOW(fd,0) = 0x1f5;
  3823. WFIFOB(fd,2) = type;
  3824. WFIFOL(fd,3) = tsd->status.char_id;
  3825. WFIFOW(fd,7) = tsd->status.base_level;
  3826. WFIFOSET(fd,packet_len(0x1f5));
  3827. }
  3828. }
  3829. /// Notifies the client about an item from other player in current trade.
  3830. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3831. /// 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)
  3832. /// 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)
  3833. void clif_tradeadditem( struct map_session_data* sd, struct map_session_data* tsd, int index, int amount ){
  3834. nullpo_retv( sd );
  3835. nullpo_retv( tsd );
  3836. int fd = tsd->fd;
  3837. if( !session_isActive( fd ) ){
  3838. return;
  3839. }
  3840. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3841. if( index ){
  3842. index = server_index( index );
  3843. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid <= 0 || sd->inventory_data[index] == nullptr ){
  3844. return;
  3845. }
  3846. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3847. #if PACKETVER >= 20100223
  3848. p.itemType = sd->inventory_data[index]->type;
  3849. #endif
  3850. p.identified = sd->inventory.u.items_inventory[index].identify;
  3851. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  3852. p.refine = sd->inventory.u.items_inventory[index].refine;
  3853. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  3854. #if PACKETVER >= 20150226
  3855. clif_add_random_options( p.option_data, &sd->inventory.u.items_inventory[index] );
  3856. #endif
  3857. }else{
  3858. p = {};
  3859. }
  3860. p.packetType = tradeaddType;
  3861. p.amount = amount;
  3862. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  3863. }
  3864. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3865. /// 00ea <index>.W <result>.B
  3866. /// result:
  3867. /// 0 = success
  3868. /// 1 = overweight
  3869. /// 2 = trade canceled
  3870. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3871. {
  3872. int fd;
  3873. nullpo_retv(sd);
  3874. fd = sd->fd;
  3875. WFIFOHEAD(fd,packet_len(0xea));
  3876. WFIFOW(fd,0) = 0xea;
  3877. WFIFOW(fd,2) = index;
  3878. WFIFOB(fd,4) = fail;
  3879. WFIFOSET(fd,packet_len(0xea));
  3880. }
  3881. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3882. /// 00ec <who>.B
  3883. /// who:
  3884. /// 0 = self
  3885. /// 1 = other player
  3886. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3887. {
  3888. int fd;
  3889. nullpo_retv(sd);
  3890. fd = sd->fd;
  3891. WFIFOHEAD(fd,packet_len(0xec));
  3892. WFIFOW(fd,0) = 0xec;
  3893. WFIFOB(fd,2) = fail;
  3894. WFIFOSET(fd,packet_len(0xec));
  3895. }
  3896. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3897. /// 00ee
  3898. void clif_tradecancelled(struct map_session_data* sd)
  3899. {
  3900. int fd;
  3901. nullpo_retv(sd);
  3902. fd = sd->fd;
  3903. WFIFOHEAD(fd,packet_len(0xee));
  3904. WFIFOW(fd,0) = 0xee;
  3905. WFIFOSET(fd,packet_len(0xee));
  3906. }
  3907. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3908. /// 00f0 <result>.B
  3909. /// result:
  3910. /// 0 = success
  3911. /// 1 = failure
  3912. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3913. {
  3914. int fd;
  3915. nullpo_retv(sd);
  3916. fd = sd->fd;
  3917. WFIFOHEAD(fd,packet_len(0xf0));
  3918. WFIFOW(fd,0) = 0xf0;
  3919. WFIFOB(fd,2) = fail;
  3920. WFIFOSET(fd,packet_len(0xf0));
  3921. }
  3922. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3923. /// 00f1
  3924. /// NOTE: Unknown purpose. Items are not removed until the window is
  3925. /// refreshed (ex. by putting another item in there).
  3926. void clif_tradeundo(struct map_session_data* sd)
  3927. {
  3928. int fd = sd->fd;
  3929. WFIFOHEAD(fd,packet_len(0xf1));
  3930. WFIFOW(fd,0) = 0xf1;
  3931. WFIFOSET(fd,packet_len(0xf1));
  3932. }
  3933. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3934. /// 00f2 <current count>.W <max count>.W
  3935. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3936. {
  3937. int fd;
  3938. nullpo_retv(sd);
  3939. fd=sd->fd;
  3940. WFIFOHEAD(fd,packet_len(0xf2));
  3941. WFIFOW(fd,0) = 0xf2;
  3942. WFIFOW(fd,2) = amount;
  3943. WFIFOW(fd,4) = max_amount;
  3944. WFIFOSET(fd,packet_len(0xf2));
  3945. }
  3946. /// Notifies the client of an item being added to the storage.
  3947. /// 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)
  3948. /// 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)
  3949. /// 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)
  3950. void clif_storageitemadded( struct map_session_data* sd, struct item* i, int index, int amount ){
  3951. nullpo_retv( sd );
  3952. nullpo_retv( i );
  3953. int fd = sd->fd;
  3954. if( !session_isActive( fd ) ){
  3955. return;
  3956. }
  3957. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  3958. p.packetType = storageaddType; // Storage item added
  3959. p.index = client_storage_index( index ); // index
  3960. p.amount = amount; // amount
  3961. p.itemId = client_nameid( i->nameid ); // id
  3962. #if PACKETVER >= 5
  3963. p.itemType = itemtype( i->nameid ); //type
  3964. #endif
  3965. p.identified = i->identify; //identify flag
  3966. p.damaged = i->attribute; // attribute
  3967. p.refine = i->refine; //refine
  3968. clif_addcards( &p.slot, i );
  3969. #if PACKETVER >= 20150226
  3970. clif_add_random_options( p.option_data, i );
  3971. #endif
  3972. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  3973. }
  3974. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3975. /// 00f6 <index>.W <amount>.L
  3976. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3977. {
  3978. int fd;
  3979. nullpo_retv(sd);
  3980. fd=sd->fd;
  3981. WFIFOHEAD(fd,packet_len(0xf6));
  3982. WFIFOW(fd,0)=0xf6; // Storage item removed
  3983. WFIFOW(fd,2)=client_storage_index(index);
  3984. WFIFOL(fd,4)=amount;
  3985. WFIFOSET(fd,packet_len(0xf6));
  3986. }
  3987. /// Closes storage (ZC_CLOSE_STORE).
  3988. /// 00f8
  3989. void clif_storageclose(struct map_session_data* sd)
  3990. {
  3991. int fd;
  3992. nullpo_retv(sd);
  3993. fd=sd->fd;
  3994. WFIFOHEAD(fd,packet_len(0xf8));
  3995. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3996. WFIFOSET(fd,packet_len(0xf8));
  3997. }
  3998. /// Notifies clients in an area of an object's souls.
  3999. /// Note: Spirit spheres and Soul spheres work on
  4000. /// seprate systems officially, but both send out
  4001. /// the same packet which leads to confusion on how
  4002. /// much soul energy a Soul Reaper actually has
  4003. /// should the player also have spirit spheres.
  4004. /// They will likely create a new packet for this soon
  4005. /// to seprate the animations for spirit and soul spheres.
  4006. /// For now we'll use this and replace it later when possible. [Rytech]
  4007. ///
  4008. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4009. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4010. void clif_soulball(struct map_session_data *sd)
  4011. {
  4012. unsigned char buf[8];
  4013. nullpo_retv(sd);
  4014. WBUFW(buf,0)=0x1d0;
  4015. WBUFL(buf,2)=sd->bl.id;
  4016. WBUFW(buf,6)=sd->soulball;
  4017. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  4018. return;
  4019. }
  4020. /*==========================================
  4021. * Server tells 'sd' player client the abouts of 'dstsd' player
  4022. *------------------------------------------*/
  4023. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4024. {
  4025. struct block_list *d_bl;
  4026. int i;
  4027. if( dstsd->chatID ) {
  4028. struct chat_data *cd = NULL;
  4029. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4030. clif_dispchat(cd,sd->fd);
  4031. } else if( dstsd->state.vending )
  4032. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4033. else if( dstsd->state.buyingstore )
  4034. clif_buyingstore_entry_single(sd, dstsd);
  4035. if(dstsd->spiritball > 0)
  4036. clif_spiritball_single(sd->fd, dstsd);
  4037. if (dstsd->sc.data[SC_MILLENNIUMSHIELD])
  4038. clif_millenniumshield_single(sd->fd, dstsd);
  4039. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4040. clif_spiritcharm_single(sd->fd, dstsd);
  4041. if (dstsd->soulball > 0)
  4042. clif_soulball_single(sd->fd, dstsd);
  4043. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4044. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4045. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4046. )
  4047. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4048. // display link (sd - dstsd) to sd
  4049. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4050. if( i < MAX_DEVOTION )
  4051. clif_devotion(&sd->bl, sd);
  4052. // display links (dstsd - devotees) to sd
  4053. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4054. if( i < MAX_DEVOTION )
  4055. clif_devotion(&dstsd->bl, sd);
  4056. // display link (dstsd - crusader) to sd
  4057. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4058. clif_devotion(d_bl, sd);
  4059. }
  4060. void clif_getareachar_unit( struct map_session_data* sd,struct block_list *bl ){
  4061. struct unit_data *ud;
  4062. struct view_data *vd;
  4063. bool option = false;
  4064. unsigned int option_val = 0;
  4065. vd = status_get_viewdata(bl);
  4066. if (!vd || vd->class_ == JT_INVISIBLE)
  4067. return;
  4068. // Hide NPC from Maya Purple card
  4069. if (clif_npc_mayapurple(bl))
  4070. return;
  4071. ud = unit_bl2ud(bl);
  4072. if( ud && ud->walktimer != INVALID_TIMER ){
  4073. clif_set_unit_walking( bl, sd, ud, SELF );
  4074. }else{
  4075. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4076. }
  4077. if (vd->cloth_color)
  4078. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4079. if (vd->body_style)
  4080. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4081. switch (bl->type)
  4082. {
  4083. case BL_PC:
  4084. {
  4085. TBL_PC* tsd = (TBL_PC*)bl;
  4086. clif_getareachar_pc(sd, tsd);
  4087. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4088. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4089. else if(tsd->state.size==SZ_MEDIUM)
  4090. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4091. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4092. clif_sendbgemblem_single(sd->fd,tsd);
  4093. if ( tsd->status.robe )
  4094. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4095. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4096. clif_hat_effects(sd,bl,SELF);
  4097. }
  4098. break;
  4099. case BL_MER: // Devotion Effects
  4100. if( ((TBL_MER*)bl)->devotion_flag )
  4101. clif_devotion(bl, sd);
  4102. break;
  4103. case BL_NPC:
  4104. {
  4105. TBL_NPC* nd = (TBL_NPC*)bl;
  4106. if( nd->chat_id )
  4107. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4108. if( nd->size == SZ_BIG )
  4109. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4110. else if( nd->size == SZ_MEDIUM )
  4111. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4112. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4113. clif_progressbar_npc(nd, sd);
  4114. }
  4115. break;
  4116. case BL_MOB:
  4117. {
  4118. TBL_MOB* md = (TBL_MOB*)bl;
  4119. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4120. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4121. else if(md->special_state.size==SZ_MEDIUM)
  4122. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4123. #if PACKETVER >= 20120404
  4124. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4125. int i;
  4126. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4127. if( md->dmglog[i].id == sd->status.char_id )
  4128. clif_monster_hp_bar(md, sd->fd);
  4129. }
  4130. #endif
  4131. }
  4132. break;
  4133. case BL_PET:
  4134. if (vd->head_bottom)
  4135. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4136. break;
  4137. }
  4138. }
  4139. //Modifies the type of damage according to status changes [Skotlex]
  4140. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4141. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4142. {
  4143. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4144. }
  4145. /*==========================================
  4146. * Estimates walk delay based on the damage criteria. [Skotlex]
  4147. *------------------------------------------*/
  4148. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4149. {
  4150. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4151. return 0;
  4152. if (bl->type == BL_PC) {
  4153. if (battle_config.pc_walk_delay_rate != 100)
  4154. delay = delay*battle_config.pc_walk_delay_rate/100;
  4155. } else
  4156. if (battle_config.walk_delay_rate != 100)
  4157. delay = delay*battle_config.walk_delay_rate/100;
  4158. if (div_ > 1) //Multi-hit skills mean higher delays.
  4159. delay += battle_config.multihit_delay*(div_-1);
  4160. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4161. }
  4162. /*========================================== [Playtester]
  4163. * Returns hallucination damage the client displays
  4164. *------------------------------------------*/
  4165. static int clif_hallucination_damage()
  4166. {
  4167. int digit = rnd() % 5 + 1;
  4168. switch (digit)
  4169. {
  4170. case 1:
  4171. return (rnd() % 10);
  4172. case 2:
  4173. return (rnd() % 100);
  4174. case 3:
  4175. return (rnd() % 1000);
  4176. case 4:
  4177. return (rnd() % 10000);
  4178. }
  4179. return (rnd() % 32767);
  4180. }
  4181. /// Sends a 'damage' packet (src performs action on dst)
  4182. /// 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)
  4183. /// 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)
  4184. /// 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)
  4185. /// type:
  4186. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4187. /// 1 = pick up item
  4188. /// 2 = sit down
  4189. /// 3 = stand up
  4190. /// 4 = damage (endure)
  4191. /// 5 = (splash?)
  4192. /// 6 = (skill?)
  4193. /// 7 = (repeat damage?)
  4194. /// 8 = multi-hit damage
  4195. /// 9 = multi-hit damage (endure)
  4196. /// 10 = critical hit
  4197. /// 11 = lucky dodge
  4198. /// 12 = (touch skill?)
  4199. /// 13 = multi-hit critical
  4200. 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)
  4201. {
  4202. unsigned char buf[34];
  4203. struct status_change *sc;
  4204. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4205. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4206. #if PACKETVER < 20071113
  4207. const int cmd = 0x8a;
  4208. int offset = 0;
  4209. #elif PACKETVER < 20131223
  4210. const int cmd = 0x2e1;
  4211. int offset = 2;
  4212. #else
  4213. const int cmd = 0x8c8;
  4214. int offset = 3;
  4215. #endif
  4216. nullpo_ret(src);
  4217. nullpo_ret(dst);
  4218. if (type != DMG_MULTI_HIT_CRITICAL)
  4219. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4220. sc = status_get_sc(dst);
  4221. if(sc && sc->count) {
  4222. if(sc->data[SC_HALLUCINATION]) {
  4223. if(damage) damage = clif_hallucination_damage();
  4224. if(damage2) damage2 = clif_hallucination_damage();
  4225. }
  4226. }
  4227. WBUFW(buf,0) = cmd;
  4228. WBUFL(buf,2) = src->id;
  4229. WBUFL(buf,6) = dst->id;
  4230. WBUFL(buf,10) = client_tick(tick);
  4231. WBUFL(buf,14) = sdelay;
  4232. WBUFL(buf,18) = ddelay;
  4233. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4234. #if PACKETVER < 20071113
  4235. WBUFW(buf,22) = damage ? div : 0;
  4236. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4237. #else
  4238. WBUFL(buf, 22) = damage ? div : 0;
  4239. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4240. #endif
  4241. } else {
  4242. #if PACKETVER < 20071113
  4243. WBUFW(buf,22) = min(damage, INT16_MAX);
  4244. WBUFW(buf,27+offset) = damage2;
  4245. #else
  4246. WBUFL(buf,22) = damage;
  4247. WBUFL(buf,27+offset) = damage2;
  4248. #endif
  4249. }
  4250. #if PACKETVER >= 20131223
  4251. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4252. #endif
  4253. WBUFW(buf,24+offset) = div;
  4254. WBUFB(buf,26+offset) = type;
  4255. if(disguised(dst)) {
  4256. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4257. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4258. clif_send(buf, packet_len(cmd), dst, SELF);
  4259. } else
  4260. clif_send(buf, packet_len(cmd), dst, AREA);
  4261. if(disguised(src)) {
  4262. WBUFL(buf,2) = disguised_bl_id( src->id );
  4263. if (disguised(dst))
  4264. WBUFL(buf,6) = dst->id;
  4265. #if PACKETVER < 20071113
  4266. if(damage > 0) WBUFW(buf,22) = -1;
  4267. if(damage2 > 0) WBUFW(buf,27) = -1;
  4268. #else
  4269. if(damage > 0) WBUFL(buf,22) = -1;
  4270. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4271. #endif
  4272. clif_send(buf,packet_len(cmd),src,SELF);
  4273. }
  4274. if(src == dst) {
  4275. unit_setdir(src, unit_getdir(src));
  4276. }
  4277. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4278. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4279. //Return adjusted can't walk delay for further processing.
  4280. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4281. }
  4282. /*==========================================
  4283. * src picks up dst
  4284. *------------------------------------------*/
  4285. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4286. {
  4287. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4288. unsigned char buf[32];
  4289. nullpo_retv(src);
  4290. nullpo_retv(dst);
  4291. WBUFW(buf, 0) = 0x8a;
  4292. WBUFL(buf, 2) = src->id;
  4293. WBUFL(buf, 6) = dst->id;
  4294. WBUFB(buf,26) = 1;
  4295. clif_send(buf, packet_len(0x8a), src, AREA);
  4296. }
  4297. /*==========================================
  4298. * inform clients in area that `bl` is sitting
  4299. *------------------------------------------*/
  4300. void clif_sitting(struct block_list* bl)
  4301. {
  4302. unsigned char buf[32];
  4303. nullpo_retv(bl);
  4304. WBUFW(buf, 0) = 0x8a;
  4305. WBUFL(buf, 2) = bl->id;
  4306. WBUFB(buf,26) = 2;
  4307. clif_send(buf, packet_len(0x8a), bl, AREA);
  4308. if(disguised(bl)) {
  4309. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4310. clif_send(buf, packet_len(0x8a), bl, SELF);
  4311. }
  4312. }
  4313. /*==========================================
  4314. * inform clients in area that `bl` is standing
  4315. *------------------------------------------*/
  4316. void clif_standing(struct block_list* bl)
  4317. {
  4318. unsigned char buf[32];
  4319. nullpo_retv(bl);
  4320. WBUFW(buf, 0) = 0x8a;
  4321. WBUFL(buf, 2) = bl->id;
  4322. WBUFB(buf,26) = 3;
  4323. clif_send(buf, packet_len(0x8a), bl, AREA);
  4324. if(disguised(bl)) {
  4325. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4326. clif_send(buf, packet_len(0x8a), bl, SELF);
  4327. }
  4328. }
  4329. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4330. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4331. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4332. {
  4333. unsigned char buf[32];
  4334. WBUFW(buf,0) = 0x192;
  4335. WBUFW(buf,2) = x;
  4336. WBUFW(buf,4) = y;
  4337. WBUFW(buf,6) = type;
  4338. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4339. if( fd )
  4340. {
  4341. WFIFOHEAD(fd,packet_len(0x192));
  4342. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4343. WFIFOSET(fd,packet_len(0x192));
  4344. }
  4345. else
  4346. {
  4347. struct block_list dummy_bl;
  4348. dummy_bl.type = BL_NUL;
  4349. dummy_bl.x = x;
  4350. dummy_bl.y = y;
  4351. dummy_bl.m = m;
  4352. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4353. }
  4354. }
  4355. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4356. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4357. void clif_getareachar_item( struct map_session_data* sd,struct flooritem_data* fitem ){
  4358. nullpo_retv( sd );
  4359. nullpo_retv( fitem );
  4360. struct PACKET_ZC_ITEM_ENTRY p;
  4361. int view = itemdb_viewid( fitem->item.nameid );
  4362. p.packetType = 0x9d;
  4363. p.AID = fitem->bl.id;
  4364. p.itemId = view > 0 ? view : fitem->item.nameid;
  4365. p.identify = fitem->item.identify;
  4366. p.x = fitem->bl.x;
  4367. p.y = fitem->bl.y;
  4368. p.amount = fitem->item.amount;
  4369. p.subX = fitem->subx;
  4370. p.subY = fitem->suby;
  4371. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4372. }
  4373. /// Notifes client about Graffiti
  4374. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4375. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4376. unsigned char buf[128];
  4377. nullpo_retv(bl);
  4378. nullpo_retv(unit);
  4379. WBUFW(buf, 0) = 0x1c9;
  4380. WBUFL(buf, 2) = unit->bl.id;
  4381. WBUFL(buf, 6) = unit->group->src_id;
  4382. WBUFW(buf,10) = unit->bl.x;
  4383. WBUFW(buf,12) = unit->bl.y;
  4384. WBUFB(buf,14) = unit->group->unit_id;
  4385. WBUFB(buf,15) = 1;
  4386. WBUFB(buf,16) = 1;
  4387. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4388. clif_send(buf,packet_len(0x1c9),bl,target);
  4389. }
  4390. /// Notifies the client of a skill unit.
  4391. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4392. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4393. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4394. /// 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)
  4395. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4396. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4397. unsigned char buf[128];
  4398. nullpo_retv(bl);
  4399. nullpo_retv(unit);
  4400. if (bl->type == BL_PC)
  4401. fd = ((TBL_PC*)bl)->fd;
  4402. if (unit->group->state.guildaura)
  4403. return;
  4404. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4405. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4406. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4407. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4408. else
  4409. unit_id = unit->group->unit_id;
  4410. if (!visible)
  4411. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4412. #if PACKETVER >= 3
  4413. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4414. clif_graffiti(bl, unit, target);
  4415. return;
  4416. }
  4417. #endif
  4418. #if PACKETVER <= 20120702
  4419. header = 0x011f;
  4420. //#if PACKETVER < 20110718
  4421. // header = 0x011f;
  4422. //#elif PACKETVER < 20121212
  4423. // header = 0x08c7;
  4424. #elif PACKETVER < 20130731
  4425. header = 0x099f;
  4426. #else
  4427. header = 0x09ca;
  4428. #endif
  4429. len = packet_len(header);
  4430. WBUFW(buf,pos) = header;
  4431. if (header != 0x011f) {
  4432. WBUFW(buf, pos+2) = len;
  4433. pos += 2;
  4434. }
  4435. WBUFL(buf,pos+2) = unit->bl.id;
  4436. WBUFL(buf,pos+6) = unit->group->src_id;
  4437. WBUFW(buf,pos+10) = unit->bl.x;
  4438. WBUFW(buf,pos+12) = unit->bl.y;
  4439. switch (header) {
  4440. case 0x011f:
  4441. WBUFB(buf,pos+14) = unit_id;
  4442. WBUFB(buf,pos+15) = visible;
  4443. break;
  4444. case 0x08c7:
  4445. WBUFB(buf,pos+14) = unit_id;
  4446. WBUFW(buf,pos+15) = unit->range;
  4447. WBUFB(buf,pos+17) = visible;
  4448. break;
  4449. case 0x099f:
  4450. WBUFL(buf,pos+14) = unit_id;
  4451. WBUFW(buf,pos+18) = unit->range;
  4452. WBUFB(buf,pos+20) = visible;
  4453. break;
  4454. case 0x09ca:
  4455. WBUFL(buf,pos+14) = unit_id;
  4456. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4457. WBUFB(buf,pos+19) = visible;
  4458. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4459. break;
  4460. }
  4461. clif_send(buf, len, bl, target);
  4462. if (unit->group->skill_id == WZ_ICEWALL)
  4463. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4464. }
  4465. /*==========================================
  4466. * Server tells client to remove unit of id 'unit->bl.id'
  4467. *------------------------------------------*/
  4468. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4469. {
  4470. nullpo_retv(unit);
  4471. WFIFOHEAD(fd,packet_len(0x120));
  4472. WFIFOW(fd, 0)=0x120;
  4473. WFIFOL(fd, 2)=unit->bl.id;
  4474. WFIFOSET(fd,packet_len(0x120));
  4475. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4476. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4477. }
  4478. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4479. /// 0120 <id>.L
  4480. void clif_skill_delunit(struct skill_unit *unit)
  4481. {
  4482. unsigned char buf[16];
  4483. nullpo_retv(unit);
  4484. WBUFW(buf, 0)=0x120;
  4485. WBUFL(buf, 2)=unit->bl.id;
  4486. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4487. }
  4488. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4489. /// 01ac <id>.L
  4490. /// Only affects units with class [139,153] client-side.
  4491. void clif_skillunit_update(struct block_list* bl)
  4492. {
  4493. unsigned char buf[6];
  4494. nullpo_retv(bl);
  4495. WBUFW(buf,0) = 0x1ac;
  4496. WBUFL(buf,2) = bl->id;
  4497. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4498. }
  4499. /*==========================================
  4500. *
  4501. *------------------------------------------*/
  4502. static int clif_getareachar(struct block_list* bl,va_list ap)
  4503. {
  4504. struct map_session_data *sd;
  4505. nullpo_ret(bl);
  4506. sd=va_arg(ap,struct map_session_data*);
  4507. if (sd == NULL || !sd->fd)
  4508. return 0;
  4509. switch(bl->type){
  4510. case BL_ITEM:
  4511. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4512. break;
  4513. case BL_SKILL:
  4514. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4515. break;
  4516. default:
  4517. if(&sd->bl == bl)
  4518. break;
  4519. clif_getareachar_unit(sd,bl);
  4520. break;
  4521. }
  4522. return 0;
  4523. }
  4524. /*==========================================
  4525. * tbl has gone out of view-size of bl
  4526. *------------------------------------------*/
  4527. int clif_outsight(struct block_list *bl,va_list ap)
  4528. {
  4529. struct block_list *tbl;
  4530. struct view_data *vd;
  4531. TBL_PC *sd, *tsd;
  4532. tbl=va_arg(ap,struct block_list*);
  4533. if(bl == tbl) return 0;
  4534. sd = BL_CAST(BL_PC, bl);
  4535. tsd = BL_CAST(BL_PC, tbl);
  4536. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4537. nullpo_ret(bl);
  4538. switch(bl->type){
  4539. case BL_PC:
  4540. if(sd->vd.class_ != JT_INVISIBLE)
  4541. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4542. if(sd->chatID){
  4543. struct chat_data *cd;
  4544. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4545. if(cd->usersd[0]==sd)
  4546. clif_dispchat(cd,tsd->fd);
  4547. }
  4548. if(sd->state.vending)
  4549. clif_closevendingboard(bl,tsd->fd);
  4550. if(sd->state.buyingstore)
  4551. clif_buyingstore_disappear_entry_single(tsd, sd);
  4552. break;
  4553. case BL_ITEM:
  4554. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4555. break;
  4556. case BL_SKILL:
  4557. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4558. break;
  4559. case BL_NPC:
  4560. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4561. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4562. break;
  4563. default:
  4564. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4565. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4566. break;
  4567. }
  4568. }
  4569. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4570. nullpo_ret(tbl);
  4571. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4572. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4573. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4574. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4575. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4576. }
  4577. return 0;
  4578. }
  4579. /*==========================================
  4580. * tbl has come into view of bl
  4581. *------------------------------------------*/
  4582. int clif_insight(struct block_list *bl,va_list ap)
  4583. {
  4584. struct block_list *tbl;
  4585. TBL_PC *sd, *tsd;
  4586. tbl=va_arg(ap,struct block_list*);
  4587. if (bl == tbl) return 0;
  4588. sd = BL_CAST(BL_PC, bl);
  4589. tsd = BL_CAST(BL_PC, tbl);
  4590. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4591. switch(bl->type){
  4592. case BL_ITEM:
  4593. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4594. break;
  4595. case BL_SKILL:
  4596. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4597. break;
  4598. default:
  4599. clif_getareachar_unit(tsd,bl);
  4600. break;
  4601. }
  4602. }
  4603. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4604. clif_getareachar_unit(sd,tbl);
  4605. }
  4606. return 0;
  4607. }
  4608. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4609. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4610. void clif_skillinfoblock(struct map_session_data *sd)
  4611. {
  4612. int fd;
  4613. int i,len,id;
  4614. nullpo_retv(sd);
  4615. fd = sd->fd;
  4616. if (!fd)
  4617. return;
  4618. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4619. WFIFOW(fd,0) = 0x10f;
  4620. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4621. {
  4622. if( (id = sd->status.skill[i].id) != 0 )
  4623. {
  4624. // workaround for bugreport:5348
  4625. if (len + 37 > 8192)
  4626. break;
  4627. WFIFOW(fd,len) = id;
  4628. WFIFOL(fd,len+2) = skill_get_inf(id);
  4629. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4630. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4631. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4632. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4633. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4634. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4635. else
  4636. WFIFOB(fd,len+36) = 0;
  4637. len += 37;
  4638. }
  4639. }
  4640. WFIFOW(fd,2)=len;
  4641. WFIFOSET(fd,len);
  4642. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4643. for ( ; i < MAX_SKILL; i++)
  4644. {
  4645. if( (id = sd->status.skill[i].id) != 0 )
  4646. {
  4647. clif_addskill(sd, id);
  4648. clif_skillinfo(sd, id, 0);
  4649. }
  4650. }
  4651. }
  4652. /**
  4653. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4654. **/
  4655. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4656. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4657. void clif_addskill(struct map_session_data *sd, int skill_id)
  4658. {
  4659. int fd;
  4660. uint16 idx = 0;
  4661. nullpo_retv(sd);
  4662. fd = sd->fd;
  4663. if (!fd || !(idx = skill_get_index(skill_id)))
  4664. return;
  4665. if( sd->status.skill[idx].id <= 0 )
  4666. return;
  4667. WFIFOHEAD(fd, packet_len(0x111));
  4668. WFIFOW(fd,0) = 0x111;
  4669. WFIFOW(fd,2) = skill_id;
  4670. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4671. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4672. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4673. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4674. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4675. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4676. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4677. else
  4678. WFIFOB(fd,38) = 0;
  4679. WFIFOSET(fd,packet_len(0x111));
  4680. }
  4681. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4682. /// 0441 <skill id>.W
  4683. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4684. {
  4685. #if PACKETVER >= 20081217
  4686. int fd;
  4687. uint16 idx = 0;
  4688. nullpo_retv(sd);
  4689. fd = sd->fd;
  4690. if (!fd || !(idx = skill_get_index(skill_id)))
  4691. return;
  4692. WFIFOHEAD(fd,packet_len(0x441));
  4693. WFIFOW(fd,0) = 0x441;
  4694. WFIFOW(fd,2) = skill_id;
  4695. WFIFOSET(fd,packet_len(0x441));
  4696. #endif
  4697. clif_skillinfoblock(sd);
  4698. }
  4699. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4700. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4701. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4702. int fd;
  4703. nullpo_retv(sd);
  4704. fd = sd->fd;
  4705. WFIFOHEAD(fd, packet_len(0x10e));
  4706. WFIFOW(fd, 0) = 0x10e;
  4707. WFIFOW(fd, 2) = skill_id;
  4708. WFIFOW(fd, 4) = lv;
  4709. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4710. WFIFOW(fd, 8) = range;
  4711. WFIFOB(fd, 10) = upgradable;
  4712. WFIFOSET(fd, packet_len(0x10e));
  4713. }
  4714. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4715. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4716. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4717. {
  4718. const int fd = sd->fd;
  4719. uint16 idx = skill_get_index(skill_id);
  4720. if (!idx)
  4721. return;
  4722. WFIFOHEAD(fd,packet_len(0x7e1));
  4723. WFIFOW(fd,0) = 0x7e1;
  4724. WFIFOW(fd,2) = skill_id;
  4725. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4726. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4727. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4728. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4729. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4730. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4731. else
  4732. WFIFOB(fd,14) = 0;
  4733. WFIFOSET(fd,packet_len(0x7e1));
  4734. }
  4735. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4736. #if PACKETVER >= 20151223
  4737. if( !battle_config.show_skill_scale ){
  4738. return;
  4739. }
  4740. struct PACKET_ZC_SKILL_SCALE p;
  4741. p.PacketType = skillscale;
  4742. p.AID = src_id;
  4743. p.skill_id = skill_id;
  4744. p.skill_lv = skill_lv;
  4745. p.x = x;
  4746. p.y = y;
  4747. p.casttime = casttime;
  4748. if( disguised( bl ) ){
  4749. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4750. p.AID = disguised_bl_id( bl->id );
  4751. clif_send( &p, sizeof( p ), bl, SELF );
  4752. }else{
  4753. clif_send( &p, sizeof( p ), bl, AREA );
  4754. }
  4755. #endif
  4756. }
  4757. /// Notifies clients in area, that an object is about to use a skill.
  4758. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4759. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4760. /// property:
  4761. /// 0 = Yellow cast aura
  4762. /// 1 = Water elemental cast aura
  4763. /// 2 = Earth elemental cast aura
  4764. /// 3 = Fire elemental cast aura
  4765. /// 4 = Wind elemental cast aura
  4766. /// 5 = Poison elemental cast aura
  4767. /// 6 = Holy elemental cast aura
  4768. /// ? = like 0
  4769. /// is disposable:
  4770. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4771. /// 1 = no text
  4772. 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)
  4773. {
  4774. #if PACKETVER < 20091124
  4775. const int cmd = 0x13e;
  4776. #else
  4777. const int cmd = 0x7fb;
  4778. #endif
  4779. unsigned char buf[32];
  4780. WBUFW(buf,0) = cmd;
  4781. WBUFL(buf,2) = src_id;
  4782. WBUFL(buf,6) = dst_id;
  4783. WBUFW(buf,10) = dst_x;
  4784. WBUFW(buf,12) = dst_y;
  4785. WBUFW(buf,14) = skill_id;
  4786. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4787. WBUFL(buf,20) = casttime;
  4788. #if PACKETVER >= 20091124
  4789. WBUFB(buf,24) = 0; // isDisposable
  4790. #endif
  4791. if (disguised(bl)) {
  4792. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4793. WBUFL(buf,2) = disguised_bl_id( src_id );
  4794. clif_send(buf,packet_len(cmd), bl, SELF);
  4795. } else
  4796. clif_send(buf,packet_len(cmd), bl, AREA);
  4797. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4798. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4799. }
  4800. }
  4801. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4802. /// 01b9 <id>.L
  4803. void clif_skillcastcancel(struct block_list* bl)
  4804. {
  4805. unsigned char buf[16];
  4806. nullpo_retv(bl);
  4807. WBUFW(buf,0) = 0x1b9;
  4808. WBUFL(buf,2) = bl->id;
  4809. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4810. }
  4811. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4812. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4813. /// num (only used when skill id = NV_BASIC and cause = 0):
  4814. /// 0 = "skill failed" MsgStringTable[159]
  4815. /// 1 = "no emotions" MsgStringTable[160]
  4816. /// 2 = "no sit" MsgStringTable[161]
  4817. /// 3 = "no chat" MsgStringTable[162]
  4818. /// 4 = "no party" MsgStringTable[163]
  4819. /// 5 = "no shout" MsgStringTable[164]
  4820. /// 6 = "no PKing" MsgStringTable[165]
  4821. /// 7 = "no alligning" MsgStringTable[383]
  4822. /// ? = ignored
  4823. /// cause:
  4824. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4825. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4826. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4827. /// "skill failed" MsgStringTable[204] (otherwise)
  4828. /// ... = @see enum useskill_fail_cause
  4829. /// ? = ignored
  4830. ///
  4831. /// if(result!=0) doesn't display any of the previous messages
  4832. /// Note: when this packet is received an unknown flag is always set to 0,
  4833. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4834. void clif_skill_fail( struct map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, int itemId ){
  4835. nullpo_retv( sd );
  4836. int fd = sd->fd;
  4837. if( !session_isActive( fd ) ){
  4838. return;
  4839. }
  4840. if(battle_config.display_skill_fail&1)
  4841. return; //Disable all skill failed messages
  4842. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4843. return; //Disable delay failed messages
  4844. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4845. return;
  4846. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4847. return;
  4848. struct PACKET_ZC_ACK_TOUSESKILL p;
  4849. p.packetType = 0x110;
  4850. p.skillId = skill_id;
  4851. p.btype = btype;
  4852. p.itemId = itemId;
  4853. p.flag = 0; // 0 - failed
  4854. p.cause = cause;
  4855. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4856. }
  4857. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4858. /// 043d <skill ID>.W <tick>.L
  4859. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4860. {
  4861. #if PACKETVER>=20081112
  4862. int fd;
  4863. nullpo_retv(sd);
  4864. fd=sd->fd;
  4865. WFIFOHEAD(fd,packet_len(0x43d));
  4866. WFIFOW(fd,0) = 0x43d;
  4867. WFIFOW(fd,2) = skill_id;
  4868. WFIFOL(fd,4) = client_tick(tick);
  4869. WFIFOSET(fd,packet_len(0x43d));
  4870. #endif
  4871. }
  4872. /// Skill attack effect and damage.
  4873. /// 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)
  4874. /// 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)
  4875. 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)
  4876. {
  4877. unsigned char buf[64];
  4878. struct status_change *sc;
  4879. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4880. nullpo_ret(src);
  4881. nullpo_ret(dst);
  4882. type = clif_calc_delay(type,div,damage,ddelay);
  4883. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4884. if(sc->data[SC_HALLUCINATION] && damage)
  4885. damage = clif_hallucination_damage();
  4886. }
  4887. #if PACKETVER < 3
  4888. WBUFW(buf,0)=0x114;
  4889. WBUFW(buf,2)=skill_id;
  4890. WBUFL(buf,4)=src->id;
  4891. WBUFL(buf,8)=dst->id;
  4892. WBUFL(buf,12)=client_tick(tick);
  4893. WBUFL(buf,16)=sdelay;
  4894. WBUFL(buf,20)=ddelay;
  4895. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4896. WBUFW(buf,24)=damage?div:0;
  4897. } else {
  4898. WBUFW(buf,24)=damage;
  4899. }
  4900. WBUFW(buf,26)=skill_lv;
  4901. WBUFW(buf,28)=div;
  4902. WBUFB(buf,30)=type;
  4903. if (disguised(dst)) {
  4904. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4905. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4906. clif_send(buf,packet_len(0x114),dst,SELF);
  4907. } else
  4908. clif_send(buf,packet_len(0x114),dst,AREA);
  4909. if(disguised(src)) {
  4910. WBUFL(buf,4)=disguised_bl_id(src->id);
  4911. if (disguised(dst))
  4912. WBUFL(buf,8)=dst->id;
  4913. if(damage > 0)
  4914. WBUFW(buf,24)=-1;
  4915. clif_send(buf,packet_len(0x114),src,SELF);
  4916. }
  4917. #else
  4918. WBUFW(buf,0)=0x1de;
  4919. WBUFW(buf,2)=skill_id;
  4920. WBUFL(buf,4)=src->id;
  4921. WBUFL(buf,8)=dst->id;
  4922. WBUFL(buf,12)=client_tick(tick);
  4923. WBUFL(buf,16)=sdelay;
  4924. WBUFL(buf,20)=ddelay;
  4925. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4926. WBUFL(buf,24)=damage?div:0;
  4927. } else {
  4928. WBUFL(buf,24)=damage;
  4929. }
  4930. WBUFW(buf,28)=skill_lv;
  4931. WBUFW(buf,30)=div;
  4932. // For some reason, late 2013 and newer clients have
  4933. // a issue that causes players and monsters to endure
  4934. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4935. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4936. #if PACKETVER < 20131223
  4937. WBUFB(buf,32)=type;
  4938. #else
  4939. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  4940. #endif
  4941. if (disguised(dst)) {
  4942. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4943. WBUFL(buf,8)=disguised_bl_id(dst->id);
  4944. clif_send(buf,packet_len(0x1de),dst,SELF);
  4945. } else
  4946. clif_send(buf,packet_len(0x1de),dst,AREA);
  4947. if(disguised(src)) {
  4948. WBUFL(buf,4)=disguised_bl_id(src->id);
  4949. if (disguised(dst))
  4950. WBUFL(buf,8)=dst->id;
  4951. if(damage > 0)
  4952. WBUFL(buf,24)=-1;
  4953. clif_send(buf,packet_len(0x1de),src,SELF);
  4954. }
  4955. #endif
  4956. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4957. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4958. }
  4959. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4960. /// 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
  4961. /*
  4962. 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)
  4963. {
  4964. unsigned char buf[64];
  4965. struct status_change *sc;
  4966. nullpo_ret(src);
  4967. nullpo_ret(dst);
  4968. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4969. type = clif_calc_delay(type,div,damage,ddelay);
  4970. sc = status_get_sc(dst);
  4971. if(sc && sc->count) {
  4972. if(sc->data[SC_HALLUCINATION] && damage)
  4973. damage = clif_hallucination_damage();
  4974. }
  4975. WBUFW(buf,0)=0x115;
  4976. WBUFW(buf,2)=skill_id;
  4977. WBUFL(buf,4)=src->id;
  4978. WBUFL(buf,8)=dst->id;
  4979. WBUFL(buf,12)=client_tick(tick);
  4980. WBUFL(buf,16)=sdelay;
  4981. WBUFL(buf,20)=ddelay;
  4982. WBUFW(buf,24)=dst->x;
  4983. WBUFW(buf,26)=dst->y;
  4984. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4985. WBUFW(buf,28)=damage?div:0;
  4986. } else {
  4987. WBUFW(buf,28)=damage;
  4988. }
  4989. WBUFW(buf,30)=skill_lv;
  4990. WBUFW(buf,32)=div;
  4991. WBUFB(buf,34)=type;
  4992. clif_send(buf,packet_len(0x115),src,AREA);
  4993. if(disguised(src)) {
  4994. WBUFL(buf,4)=disguised_bl_id(src->id);
  4995. if(damage > 0)
  4996. WBUFW(buf,28)=-1;
  4997. clif_send(buf,packet_len(0x115),src,SELF);
  4998. }
  4999. if (disguised(dst)) {
  5000. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5001. if (disguised(src))
  5002. WBUFL(buf,4)=src->id;
  5003. else if(damage > 0)
  5004. WBUFW(buf,28)=-1;
  5005. clif_send(buf,packet_len(0x115),dst,SELF);
  5006. }
  5007. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5008. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5009. }
  5010. */
  5011. /// Non-damaging skill effect
  5012. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5013. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5014. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5015. {
  5016. unsigned char buf[17];
  5017. #if PACKETVER < 20130731
  5018. const int cmd = 0x11a;
  5019. #else
  5020. const int cmd = 0x9cb;
  5021. #endif
  5022. int offset = 0;
  5023. bool success = ( tick != 0 );
  5024. nullpo_ret(dst);
  5025. WBUFW(buf,0) = cmd;
  5026. WBUFW(buf,2) = skill_id;
  5027. #if PACKETVER < 20130731
  5028. WBUFW(buf,4) = min(heal, INT16_MAX);
  5029. #else
  5030. WBUFL(buf,4) = min(heal, INT32_MAX);
  5031. offset += 2;
  5032. #endif
  5033. WBUFL(buf,6+offset) = dst->id;
  5034. WBUFL(buf,10+offset) = src ? src->id : 0;
  5035. WBUFB(buf,14+offset) = success;
  5036. if (disguised(dst)) {
  5037. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5038. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5039. clif_send(buf, packet_len(cmd), dst, SELF);
  5040. } else
  5041. clif_send(buf, packet_len(cmd), dst, AREA);
  5042. if(src && disguised(src)) {
  5043. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5044. if (disguised(dst))
  5045. WBUFL(buf,6+offset) = dst->id;
  5046. clif_send(buf, packet_len(cmd), src, SELF);
  5047. }
  5048. return success;
  5049. }
  5050. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5051. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5052. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5053. {
  5054. unsigned char buf[32];
  5055. nullpo_retv(src);
  5056. WBUFW(buf,0)=0x117;
  5057. WBUFW(buf,2)=skill_id;
  5058. WBUFL(buf,4)=src->id;
  5059. WBUFW(buf,8)=val;
  5060. WBUFW(buf,10)=x;
  5061. WBUFW(buf,12)=y;
  5062. WBUFL(buf,14)=client_tick(tick);
  5063. if(disguised(src)) {
  5064. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5065. WBUFL(buf,4)=disguised_bl_id(src->id);
  5066. clif_send(buf,packet_len(0x117),src,SELF);
  5067. } else
  5068. clif_send(buf,packet_len(0x117),src,AREA);
  5069. }
  5070. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5071. /// 011c <skill id>.W { <map name>.16B }*4
  5072. 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)
  5073. {
  5074. int fd;
  5075. nullpo_retv(sd);
  5076. fd = sd->fd;
  5077. WFIFOHEAD(fd,packet_len(0x11c));
  5078. WFIFOW(fd,0) = 0x11c;
  5079. WFIFOW(fd,2) = skill_id;
  5080. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5081. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5082. else // normal map name
  5083. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5084. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5085. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5086. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5087. WFIFOSET(fd,packet_len(0x11c));
  5088. sd->menuskill_id = skill_id;
  5089. if (skill_id == AL_WARP) {
  5090. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5091. sd->state.workinprogress = WIP_DISABLE_ALL;
  5092. } else
  5093. sd->menuskill_val = skill_lv;
  5094. }
  5095. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5096. /// 011e <type>.B
  5097. /// type:
  5098. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5099. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5100. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5101. ///
  5102. /// @param sd Who receives the message
  5103. /// @param type What message
  5104. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5105. {
  5106. int fd;
  5107. nullpo_retv(sd);
  5108. fd=sd->fd;
  5109. WFIFOHEAD(fd,packet_len(0x11e));
  5110. WFIFOW(fd,0)=0x11e;
  5111. WFIFOB(fd,2)=type;
  5112. WFIFOSET(fd,packet_len(0x11e));
  5113. }
  5114. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5115. /// 0189 <type>.W
  5116. /// type:
  5117. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5118. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5119. ///
  5120. /// @param sd Who receives the message
  5121. /// @param type What message
  5122. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5123. {
  5124. int fd;
  5125. nullpo_retv(sd);
  5126. fd=sd->fd;
  5127. WFIFOHEAD(fd,packet_len(0x189));
  5128. WFIFOW(fd,0)=0x189;
  5129. WFIFOW(fd,2)=type;
  5130. WFIFOSET(fd,packet_len(0x189));
  5131. }
  5132. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5133. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5134. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5135. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5136. {
  5137. struct status_data *status;
  5138. unsigned char buf[64];
  5139. int i, fix;
  5140. nullpo_retv(sd);
  5141. nullpo_retv(dst);
  5142. if( dst->type != BL_MOB )
  5143. return;
  5144. status = status_get_status_data(dst);
  5145. WBUFW(buf, 0)=0x18c;
  5146. WBUFW(buf, 2)=status_get_class(dst);
  5147. WBUFW(buf, 4)=status_get_lv(dst);
  5148. WBUFW(buf, 6)=status->size;
  5149. WBUFL(buf, 8)=status->hp;
  5150. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5151. +(battle_config.estimation_type&2?status->def2:0);
  5152. WBUFW(buf,14)=status->race;
  5153. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5154. +(battle_config.estimation_type&2?status->mdef2:0);
  5155. WBUFW(buf,18)= status->def_ele;
  5156. for(i=0;i<9;i++)
  5157. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5158. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5159. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5160. }
  5161. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5162. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5163. /// material id:
  5164. /// unused by the client
  5165. void clif_skill_produce_mix_list( struct map_session_data *sd, int skill_id, int trigger ){
  5166. nullpo_retv(sd);
  5167. int fd = sd->fd;
  5168. if( !session_isActive( fd ) ){
  5169. return;
  5170. }
  5171. if (sd->menuskill_id == skill_id)
  5172. return; //Avoid resending the menu twice or more times...
  5173. if (skill_id == GC_CREATENEWPOISON)
  5174. skill_id = GC_RESEARCHNEWPOISON;
  5175. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5176. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5177. p->packetType = 0x18d;
  5178. int count = 0;
  5179. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5180. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5181. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5182. )
  5183. {
  5184. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5185. p->items[count].material[0] = 0;
  5186. p->items[count].material[1] = 0;
  5187. p->items[count].material[2] = 0;
  5188. count++;
  5189. }
  5190. }
  5191. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5192. WFIFOSET( fd, p->packetLength );
  5193. if( count > 0 ){
  5194. sd->menuskill_id = skill_id;
  5195. sd->menuskill_val = trigger;
  5196. return;
  5197. }
  5198. }
  5199. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5200. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5201. /// mk type:
  5202. /// 1 = cooking
  5203. /// 2 = arrow
  5204. /// 3 = elemental
  5205. /// 4 = GN_MIX_COOKING
  5206. /// 5 = GN_MAKEBOMB
  5207. /// 6 = GN_S_PHARMACY
  5208. void clif_cooking_list( struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5209. nullpo_retv( sd );
  5210. // Avoid resending the menu twice or more times...
  5211. if( sd->menuskill_id == skill_id ){
  5212. return;
  5213. }
  5214. int fd = sd->fd;
  5215. if( !session_isActive( fd ) ){
  5216. return;
  5217. }
  5218. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5219. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5220. p->packetType = 0x25a;
  5221. p->makeItem = list_type; // list type
  5222. int count = 0;
  5223. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5224. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5225. continue;
  5226. }
  5227. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5228. count++;
  5229. }
  5230. if( count > 0 || skill_id == AM_PHARMACY ){
  5231. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5232. WFIFOSET( fd, p->packetLength );
  5233. sd->menuskill_id = skill_id;
  5234. sd->menuskill_val = trigger;
  5235. sd->menuskill_val2 = qty; // amount.
  5236. }else{
  5237. clif_menuskill_clear(sd);
  5238. #if PACKETVER >= 20090922
  5239. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5240. #else
  5241. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5242. WFIFOSET( fd, p->packetLength );
  5243. #endif
  5244. }
  5245. }
  5246. /// Notifies clients of a status change.
  5247. /// 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)]
  5248. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5249. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5250. /// @param bl Sends packet to clients around this object
  5251. /// @param id ID of object that has this effect
  5252. /// @param type Status icon see enum efst_types
  5253. /// @param flag 1:Active, 0:Deactive
  5254. /// @param tick Duration in ms
  5255. /// @param val1
  5256. /// @param val2
  5257. /// @param val3
  5258. 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)
  5259. {
  5260. unsigned char buf[32];
  5261. if (type == EFST_BLANK) //It shows nothing on the client...
  5262. return;
  5263. if (type == EFST_POSTDELAY && tick == 0)
  5264. return;
  5265. nullpo_retv(bl);
  5266. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5267. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5268. tick = 200;
  5269. #if PACKETVER >= 20120618
  5270. if (flag && battle_config.display_status_timers)
  5271. WBUFW(buf,0) = 0x983;
  5272. else
  5273. #elif PACKETVER >= 20090121
  5274. if (flag && battle_config.display_status_timers)
  5275. WBUFW(buf,0) = 0x43f;
  5276. else
  5277. #endif
  5278. WBUFW(buf,0) = 0x196;
  5279. WBUFW(buf,2) = type;
  5280. WBUFL(buf,4) = id;
  5281. WBUFB(buf,8) = flag;
  5282. #if PACKETVER >= 20120618
  5283. if (flag && battle_config.display_status_timers) {
  5284. if (tick <= 0)
  5285. tick = 9999; // this is indeed what official servers do
  5286. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5287. WBUFL(buf,13) = client_tick(tick);
  5288. WBUFL(buf,17) = val1;
  5289. WBUFL(buf,21) = val2;
  5290. WBUFL(buf,25) = val3;
  5291. }
  5292. #elif PACKETVER >= 20090121
  5293. if (flag && battle_config.display_status_timers) {
  5294. if (tick <= 0)
  5295. tick = 9999; // this is indeed what official servers do
  5296. WBUFL(buf,9) = client_tick(tick);
  5297. WBUFL(buf,13) = val1;
  5298. WBUFL(buf,17) = val2;
  5299. WBUFL(buf,21) = val3;
  5300. }
  5301. #endif
  5302. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5303. }
  5304. /* Sends status effect to clients around the bl
  5305. * @param bl Object that has the effect
  5306. * @param type Status icon see enum efst_types
  5307. * @param flag 1:Active, 0:Deactive
  5308. * @param tick Duration in ms
  5309. * @param val1
  5310. * @param val2
  5311. * @param val3
  5312. */
  5313. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5314. struct map_session_data *sd = NULL;
  5315. if (type == EFST_BLANK) //It shows nothing on the client...
  5316. return;
  5317. if (type == EFST_POSTDELAY && tick == 0)
  5318. return;
  5319. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5320. return;
  5321. nullpo_retv(bl);
  5322. sd = BL_CAST(BL_PC, bl);
  5323. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5324. return;
  5325. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5326. }
  5327. /**
  5328. * Send any active EFST to those around.
  5329. * @param tbl: Unit to send the packet to
  5330. * @param bl: Objects walking into view
  5331. * @param target: Client send type
  5332. */
  5333. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5334. unsigned char i;
  5335. struct sc_display_entry **sc_display;
  5336. unsigned char sc_display_count;
  5337. bool spheres_sent;
  5338. nullpo_retv(bl);
  5339. switch( bl->type ){
  5340. case BL_PC: {
  5341. struct map_session_data* sd = (struct map_session_data*)bl;
  5342. sc_display = sd->sc_display;
  5343. sc_display_count = sd->sc_display_count;
  5344. spheres_sent = !sd->state.connect_new;
  5345. }
  5346. break;
  5347. case BL_NPC: {
  5348. struct npc_data* nd = (struct npc_data*)bl;
  5349. sc_display = nd->sc_display;
  5350. sc_display_count = nd->sc_display_count;
  5351. spheres_sent = true;
  5352. }
  5353. break;
  5354. default:
  5355. return;
  5356. }
  5357. for (i = 0; i < sc_display_count; i++) {
  5358. enum sc_type type = sc_display[i]->type;
  5359. struct status_change *sc = status_get_sc(bl);
  5360. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5361. t_tick tick = 0;
  5362. if (td)
  5363. tick = DIFF_TICK(td->tick, gettick());
  5364. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5365. #if PACKETVER > 20120418
  5366. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5367. #else
  5368. 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);
  5369. #endif
  5370. }else{
  5371. #if PACKETVER > 20120418
  5372. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5373. #else
  5374. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5375. #endif
  5376. }
  5377. }
  5378. }
  5379. /// Notifies the client when a player enters the screen with an active EFST.
  5380. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5381. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5382. 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) {
  5383. #if PACKETVER >= 20111108
  5384. unsigned char buf[32];
  5385. #if PACKETVER >= 20120618
  5386. const int cmd = 0x984;
  5387. #elif PACKETVER >= 20111108
  5388. const int cmd = 0x8ff;
  5389. #endif
  5390. int offset = 0;
  5391. if (type == EFST_BLANK)
  5392. return;
  5393. nullpo_retv(bl);
  5394. if (tick <= 0)
  5395. tick = 9999;
  5396. WBUFW(buf,offset + 0) = cmd;
  5397. WBUFL(buf,offset + 2) = tid;
  5398. WBUFW(buf,offset + 6) = type;
  5399. #if PACKETVER >= 20111108
  5400. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5401. #if PACKETVER >= 20120618
  5402. WBUFL(buf,offset + 12) = client_tick(tick);
  5403. offset += 4;
  5404. #endif
  5405. WBUFL(buf,offset + 12) = val1;
  5406. WBUFL(buf,offset + 16) = val2;
  5407. WBUFL(buf,offset + 20) = val3;
  5408. #endif
  5409. clif_send(buf,packet_len(cmd),bl,target);
  5410. #endif
  5411. }
  5412. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5413. /// 008e <packet len>.W <message>.?B
  5414. void clif_displaymessage(const int fd, const char* mes)
  5415. {
  5416. nullpo_retv(mes);
  5417. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5418. if (fd == 0)
  5419. ;
  5420. else {
  5421. char *message, *line;
  5422. message = aStrdup(mes);
  5423. line = strtok(message, "\n");
  5424. while(line != NULL) {
  5425. #if PACKETVER == 20141022
  5426. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5427. /** so we redirect to ZC_NPC_CHAT **/
  5428. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5429. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5430. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5431. if (len > 0) {
  5432. WFIFOHEAD(fd, 13 + len);
  5433. WFIFOW(fd, 0) = 0x2C1;
  5434. WFIFOW(fd, 2) = 13 + len;
  5435. WFIFOL(fd, 4) = 0;
  5436. WFIFOL(fd, 8) = color;
  5437. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5438. WFIFOSET(fd, WFIFOW(fd, 2));
  5439. }
  5440. #else
  5441. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5442. int len = strnlen(line, CHAT_SIZE_MAX);
  5443. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5444. WFIFOHEAD(fd, 5 + len);
  5445. WFIFOW(fd,0) = 0x8e;
  5446. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5447. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5448. WFIFOSET(fd, 5 + len);
  5449. }
  5450. #endif
  5451. line = strtok(NULL, "\n");
  5452. }
  5453. aFree(message);
  5454. }
  5455. }
  5456. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5457. /// 009a <packet len>.W <message>.?B
  5458. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5459. {
  5460. nullpo_retv(mes);
  5461. if (len < 2)
  5462. return;
  5463. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5464. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5465. WBUFW(buf.get(),0) = 0x9a;
  5466. WBUFW(buf.get(),2) = 4 + lp + len;
  5467. if (type&BC_BLUE)
  5468. 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.
  5469. else if (type&BC_WOE)
  5470. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5471. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5472. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5473. }
  5474. /*==========================================
  5475. * Displays a message on a 'bl' to all it's nearby clients
  5476. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5477. *------------------------------------------*/
  5478. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5479. size_t len;
  5480. nullpo_retv(bl);
  5481. if(!message)
  5482. return;
  5483. len = strlen(message)+1;
  5484. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5485. if( len > CHAT_SIZE_MAX ) {
  5486. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  5487. len = CHAT_SIZE_MAX;
  5488. }
  5489. std::unique_ptr<char> buf(new char[8+len]);
  5490. WBUFW(buf.get(),0)=0x8d;
  5491. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5492. WBUFL(buf.get(),4)=bl->id;
  5493. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5494. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5495. }
  5496. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5497. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5498. 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)
  5499. {
  5500. nullpo_retv(mes);
  5501. if (len < 2)
  5502. return;
  5503. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5504. WBUFW(buf.get(),0) = 0x1c3;
  5505. WBUFW(buf.get(),2) = len + 16;
  5506. WBUFL(buf.get(),4) = fontColor;
  5507. WBUFW(buf.get(),8) = fontType;
  5508. WBUFW(buf.get(),10) = fontSize;
  5509. WBUFW(buf.get(),12) = fontAlign;
  5510. WBUFW(buf.get(),14) = fontY;
  5511. memcpy(WBUFP(buf.get(),16), mes, len);
  5512. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5513. }
  5514. /*
  5515. * Display *msg to all *users in channel
  5516. */
  5517. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5518. DBIterator *iter;
  5519. struct map_session_data *user;
  5520. unsigned short msg_len = 0, len = 0;
  5521. unsigned char buf[CHAT_SIZE_MAX];
  5522. if (!channel || !msg)
  5523. return;
  5524. msg_len = (unsigned short)(strlen(msg) + 1);
  5525. if( msg_len > sizeof(buf)-12 ) {
  5526. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5527. msg_len = sizeof(buf)-12;
  5528. }
  5529. WBUFW(buf,0) = 0x2C1;
  5530. WBUFW(buf,2) = (len = msg_len + 12);
  5531. WBUFL(buf,4) = 0;
  5532. WBUFL(buf,8) = color;
  5533. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5534. iter = db_iterator(channel->users);
  5535. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5536. clif_send(buf, len, &user->bl, SELF);
  5537. }
  5538. dbi_destroy(iter);
  5539. }
  5540. /// Displays heal effect.
  5541. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5542. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5543. /// var id:
  5544. /// 5 = HP (SP_HP)
  5545. /// 7 = SP (SP_SP)
  5546. /// ? = ignored
  5547. void clif_heal(int fd,int type,int val) {
  5548. #if PACKETVER < 20141022
  5549. const int cmd = 0x13d;
  5550. #else
  5551. const int cmd = 0xa27;
  5552. #endif
  5553. WFIFOHEAD(fd, packet_len(cmd));
  5554. WFIFOW(fd,0) = cmd;
  5555. WFIFOW(fd,2) = type;
  5556. #if PACKETVER < 20141022
  5557. WFIFOW(fd,4) = min(val, INT16_MAX);
  5558. #else
  5559. WFIFOL(fd,4) = min(val, INT32_MAX);
  5560. #endif
  5561. WFIFOSET(fd, packet_len(cmd));
  5562. }
  5563. /// Displays resurrection effect (ZC_RESURRECTION).
  5564. /// 0148 <id>.L <type>.W
  5565. /// type:
  5566. /// ignored
  5567. void clif_resurrection(struct block_list *bl,int type)
  5568. {
  5569. unsigned char buf[16];
  5570. nullpo_retv(bl);
  5571. WBUFW(buf,0)=0x148;
  5572. WBUFL(buf,2)=bl->id;
  5573. WBUFW(buf,6)=0;
  5574. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5575. if (disguised(bl))
  5576. clif_spawn(bl);
  5577. }
  5578. /// Sets the map property
  5579. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5580. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5581. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5582. {
  5583. #if PACKETVER >= 20121010
  5584. short cmd = 0x99b;
  5585. unsigned char buf[8];
  5586. #else
  5587. short cmd = 0x199;
  5588. unsigned char buf[4];
  5589. #endif
  5590. WBUFW(buf,0)=cmd;
  5591. WBUFW(buf,2)=property;
  5592. #if PACKETVER >= 20121010
  5593. struct map_data *mapdata = map_getmapdata(bl->m);
  5594. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0 || (bl->type == BL_PC && ((TBL_PC *)bl)->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5595. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5596. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5597. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5598. ((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
  5599. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5600. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5601. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5602. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5603. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5604. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5605. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5606. #endif
  5607. clif_send(buf,packet_len(cmd),bl,t);
  5608. }
  5609. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5610. /// 01d6 <type>.W
  5611. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5612. {
  5613. int fd;
  5614. nullpo_retv(sd);
  5615. fd=sd->fd;
  5616. WFIFOHEAD(fd,packet_len(0x1D6));
  5617. WFIFOW(fd,0)=0x1D6;
  5618. WFIFOW(fd,2)=type;
  5619. WFIFOSET(fd,packet_len(0x1D6));
  5620. }
  5621. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5622. /// 019a <id>.L <ranking>.L <total>.L
  5623. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5624. {
  5625. if(type == 2) {
  5626. int fd = sd->fd;
  5627. WFIFOHEAD(fd,packet_len(0x19a));
  5628. WFIFOW(fd,0) = 0x19a;
  5629. WFIFOL(fd,2) = sd->bl.id;
  5630. WFIFOL(fd,6) = pvprank;
  5631. WFIFOL(fd,10) = pvpnum;
  5632. WFIFOSET(fd,packet_len(0x19a));
  5633. } else {
  5634. unsigned char buf[32];
  5635. WBUFW(buf,0) = 0x19a;
  5636. WBUFL(buf,2) = sd->bl.id;
  5637. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5638. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5639. else
  5640. WBUFL(buf,6) = pvprank;
  5641. WBUFL(buf,10) = pvpnum;
  5642. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5643. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5644. else if(!type)
  5645. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5646. else
  5647. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5648. }
  5649. }
  5650. /*==========================================
  5651. *
  5652. *------------------------------------------*/
  5653. void clif_map_property_mapall(int map_idx, enum map_property property)
  5654. {
  5655. struct block_list bl;
  5656. bl.id = 0;
  5657. bl.type = BL_NUL;
  5658. bl.m = map_idx;
  5659. clif_map_property( &bl, property, ALL_SAMEMAP );
  5660. }
  5661. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5662. /// 0188 <result>.W <index>.W <refine>.W
  5663. /// result:
  5664. /// 0 = success
  5665. /// 1 = failure
  5666. /// 2 = downgrade
  5667. void clif_refine(int fd, int fail, int index, int val)
  5668. {
  5669. WFIFOHEAD(fd,packet_len(0x188));
  5670. WFIFOW(fd,0)=0x188;
  5671. WFIFOW(fd,2)=fail;
  5672. WFIFOW(fd,4)=index+2;
  5673. WFIFOW(fd,6)=val;
  5674. WFIFOSET(fd,packet_len(0x188));
  5675. }
  5676. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5677. /// 0223 <result>.L <nameid>.W
  5678. /// result:
  5679. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5680. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5681. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5682. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5683. void clif_upgrademessage( struct map_session_data* sd, int result, unsigned short item_id ){
  5684. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5685. p.packetType = 0x223;
  5686. p.result = result;
  5687. p.itemId = client_nameid( item_id );
  5688. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5689. }
  5690. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5691. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5692. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5693. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5694. int fd;
  5695. nullpo_retv(sd);
  5696. fd = sd->fd;
  5697. #if PACKETVER < 20091104
  5698. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5699. WFIFOW(fd,0) = 0x97;
  5700. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5701. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5702. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5703. WFIFOSET(fd,WFIFOW(fd,2));
  5704. #else
  5705. struct map_session_data *ssd = map_nick2sd(nick,false);
  5706. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5707. WFIFOW(fd,0) = 0x97;
  5708. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5709. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5710. // If it is not a message from the server or a player from another map-server
  5711. if( ssd ){
  5712. gmlvl = pc_get_group_level(ssd);
  5713. }
  5714. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5715. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5716. WFIFOSET(fd,WFIFOW(fd,2));
  5717. #endif
  5718. }
  5719. /// Inform the player about the result of his whisper action
  5720. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5721. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5722. /// result:
  5723. /// 0 = success to send wisper
  5724. /// 1 = target character is not loged in
  5725. /// 2 = ignored by target
  5726. /// 3 = everyone ignored by target
  5727. void clif_wis_end(int fd, int result)
  5728. {
  5729. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5730. #if PACKETVER < 20131223
  5731. const int cmd = 0x98;
  5732. #else
  5733. const int cmd = 0x9df;
  5734. #endif
  5735. if (!sd)
  5736. return;
  5737. WFIFOHEAD(fd,packet_len(cmd));
  5738. WFIFOW(fd,0) = cmd;
  5739. WFIFOB(fd,2) = (char)result;
  5740. #if PACKETVER >= 20131223
  5741. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5742. #endif
  5743. WFIFOSET(fd,packet_len(cmd));
  5744. }
  5745. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5746. /// 0194 <char id>.L <name>.24B
  5747. /// 0af7 <flag>.W <char id>.L <name>.24B
  5748. void clif_solved_charname(int fd, int charid, const char* name)
  5749. {
  5750. #if PACKETVER >= 20180221
  5751. WFIFOHEAD(fd,packet_len(0xaf7));
  5752. WFIFOW(fd,0) = 0xaf7;
  5753. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5754. WFIFOL(fd,4) = charid;
  5755. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5756. WFIFOSET(fd,packet_len(0x0af7));
  5757. #else
  5758. WFIFOHEAD(fd,packet_len(0x194));
  5759. WFIFOW(fd,0)=0x194;
  5760. WFIFOL(fd,2)=charid;
  5761. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5762. WFIFOSET(fd,packet_len(0x194));
  5763. #endif
  5764. }
  5765. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5766. /// 017b <packet len>.W { <name id>.W }*
  5767. void clif_use_card(struct map_session_data *sd,int idx)
  5768. {
  5769. int i,c,ep;
  5770. int fd=sd->fd;
  5771. nullpo_retv(sd);
  5772. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5773. return;
  5774. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5775. return; //Avoid parsing invalid item indexes (no card/no item)
  5776. ep=sd->inventory_data[idx]->equip;
  5777. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5778. WFIFOW(fd,0)=0x17b;
  5779. for(i=c=0;i<MAX_INVENTORY;i++){
  5780. int j;
  5781. if(sd->inventory_data[i] == NULL)
  5782. continue;
  5783. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5784. continue;
  5785. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5786. continue;
  5787. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5788. continue;
  5789. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5790. continue;
  5791. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5792. continue;
  5793. if(sd->inventory_data[i]->type == IT_ARMOR && (ep & EQP_ACC) && ((ep & EQP_ACC) != EQP_ACC) && ((sd->inventory_data[i]->equip & EQP_ACC) != (ep & EQP_ACC)) ) // specific accessory-card can only be inserted to specific accessory.
  5794. continue;
  5795. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5796. if( j == sd->inventory_data[i]->slot ) // No room
  5797. continue;
  5798. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5799. continue;
  5800. WFIFOW(fd,4+c*2)=i+2;
  5801. c++;
  5802. }
  5803. if( !c ) return; // no item is available for card insertion
  5804. WFIFOW(fd,2)=4+c*2;
  5805. WFIFOSET(fd,WFIFOW(fd,2));
  5806. }
  5807. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5808. /// 017d <equip index>.W <card index>.W <result>.B
  5809. /// result:
  5810. /// 0 = success
  5811. /// 1 = failure
  5812. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5813. {
  5814. int fd;
  5815. nullpo_retv(sd);
  5816. fd=sd->fd;
  5817. WFIFOHEAD(fd,packet_len(0x17d));
  5818. WFIFOW(fd,0)=0x17d;
  5819. WFIFOW(fd,2)=idx_equip+2;
  5820. WFIFOW(fd,4)=idx_card+2;
  5821. WFIFOB(fd,6)=flag;
  5822. WFIFOSET(fd,packet_len(0x17d));
  5823. }
  5824. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5825. /// 0177 <packet len>.W { <index>.W }*
  5826. void clif_item_identify_list(struct map_session_data *sd)
  5827. {
  5828. int i,c;
  5829. int fd;
  5830. nullpo_retv(sd);
  5831. fd=sd->fd;
  5832. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5833. WFIFOW(fd,0)=0x177;
  5834. for(i=c=0;i<MAX_INVENTORY;i++){
  5835. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5836. WFIFOW(fd,c*2+4)=i+2;
  5837. c++;
  5838. }
  5839. }
  5840. if(c > 0) {
  5841. WFIFOW(fd,2)=c*2+4;
  5842. WFIFOSET(fd,WFIFOW(fd,2));
  5843. sd->menuskill_id = MC_IDENTIFY;
  5844. sd->menuskill_val = c;
  5845. sd->state.workinprogress = WIP_DISABLE_ALL;
  5846. }
  5847. }
  5848. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5849. /// 0179 <index>.W <result>.B
  5850. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5851. {
  5852. int fd;
  5853. nullpo_retv(sd);
  5854. fd=sd->fd;
  5855. WFIFOHEAD(fd,packet_len(0x179));
  5856. WFIFOW(fd, 0)=0x179;
  5857. WFIFOW(fd, 2)=idx+2;
  5858. WFIFOB(fd, 4)=flag;
  5859. WFIFOSET(fd,packet_len(0x179));
  5860. }
  5861. /// Presents a list of items that can be repaired.
  5862. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  5863. void clif_item_repair_list( struct map_session_data *sd,struct map_session_data *dstsd, int lv ){
  5864. nullpo_retv( sd );
  5865. nullpo_retv( dstsd );
  5866. int fd = sd->fd;
  5867. if( !session_isActive( fd ) ){
  5868. return;
  5869. }
  5870. int len = MAX_INVENTORY * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5871. // Preallocate the maximum size
  5872. WFIFOHEAD( fd, len );
  5873. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  5874. int c = 0;
  5875. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5876. 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)){
  5877. p->items[c].index = i;
  5878. p->items[c].itemId = dstsd->inventory.u.items_inventory[i].nameid;
  5879. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  5880. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  5881. c++;
  5882. }
  5883. }
  5884. if( c > 0 ){
  5885. p->packetType = 0x1fc;
  5886. // Recalculate real length
  5887. len = c * sizeof( struct PACKET_ZC_REPAIRITEMLIST_sub ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  5888. p->packetLength = len;
  5889. WFIFOSET( fd, len );
  5890. sd->menuskill_id = BS_REPAIRWEAPON;
  5891. sd->menuskill_val = dstsd->bl.id;
  5892. sd->menuskill_val2 = lv;
  5893. }else{
  5894. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  5895. }
  5896. }
  5897. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5898. /// 01fe <index>.W <result>.B
  5899. /// index:
  5900. /// ignored (inventory index)
  5901. /// result:
  5902. /// 0 = Item repair success.
  5903. /// 1 = Item repair failure.
  5904. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5905. {
  5906. int fd;
  5907. nullpo_retv(sd);
  5908. fd = sd->fd;
  5909. WFIFOHEAD(fd,packet_len(0x1fe));
  5910. WFIFOW(fd, 0)=0x1fe;
  5911. WFIFOW(fd, 2)=idx+2;
  5912. WFIFOB(fd, 4)=flag;
  5913. WFIFOSET(fd,packet_len(0x1fe));
  5914. }
  5915. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5916. /// 02bb <equip location>.W <account id>.L
  5917. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5918. {
  5919. int fd = sd->fd;
  5920. WFIFOHEAD(fd,packet_len(0x2bb));
  5921. WFIFOW(fd,0) = 0x2bb;
  5922. WFIFOW(fd,2) = position;
  5923. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5924. WFIFOSET(fd,packet_len(0x2bb));
  5925. }
  5926. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5927. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5928. void clif_item_refine_list( struct map_session_data *sd ){
  5929. nullpo_retv( sd );
  5930. int fd = sd->fd;
  5931. if( !session_isActive( fd ) ){
  5932. return;
  5933. }
  5934. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * MAX_INVENTORY );
  5935. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)WFIFOP( fd, 0 );
  5936. p->packetType = 0x221;
  5937. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  5938. int refine_item[5];
  5939. refine_item[0] = -1;
  5940. refine_item[1] = pc_search_inventory( sd, ITEMID_PHRACON );
  5941. refine_item[2] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  5942. refine_item[3] = refine_item[4] = pc_search_inventory( sd, ITEMID_ORIDECON );
  5943. int count = 0;
  5944. for( int i = 0; i < MAX_INVENTORY; i++ ){
  5945. unsigned char wlv;
  5946. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5947. sd->inventory.u.items_inventory[i].identify && ( wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid ) ) >= 1 &&
  5948. refine_item[wlv] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  5949. p->items[count].index = client_index( i );
  5950. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  5951. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  5952. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  5953. count++;
  5954. }
  5955. }
  5956. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  5957. WFIFOSET( fd, p->packetLength );
  5958. if( count > 0 ){
  5959. sd->menuskill_id = WS_WEAPONREFINE;
  5960. sd->menuskill_val = skill_lv;
  5961. }
  5962. }
  5963. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5964. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5965. void clif_item_skill( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  5966. nullpo_retv( sd );
  5967. struct PACKET_ZC_AUTORUN_SKILL p;
  5968. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  5969. p.skill_id = skill_id;
  5970. p.skill_type = skill_get_inf( skill_id );
  5971. p.skill_lv = skill_lv;
  5972. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  5973. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  5974. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  5975. p.up_flag = false;
  5976. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5977. }
  5978. /// Adds an item to character's cart.
  5979. /// 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)
  5980. /// 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)
  5981. /// 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)
  5982. void clif_cart_additem( struct map_session_data *sd, int n, int amount ){
  5983. nullpo_retv( sd );
  5984. int fd = sd->fd;
  5985. if( !session_isActive( fd ) ){
  5986. return;
  5987. }
  5988. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0 ){
  5989. return;
  5990. }
  5991. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  5992. p.packetType = cartaddType;
  5993. p.index = client_index( n );
  5994. p.amount = amount;
  5995. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  5996. #if PACKETVER >= 5
  5997. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  5998. #endif
  5999. p.identified = sd->cart.u.items_cart[n].identify;
  6000. p.damaged = sd->cart.u.items_cart[n].attribute;
  6001. p.refine = sd->cart.u.items_cart[n].refine;
  6002. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6003. #if PACKETVER >= 20150226
  6004. clif_add_random_options( p.option_data, &sd->cart.u.items_cart[n] );
  6005. #endif
  6006. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6007. }
  6008. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6009. /* Acknowledge an item have been added to cart
  6010. * 012c <result>B
  6011. * result :
  6012. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6013. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6014. */
  6015. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6016. {
  6017. int fd;
  6018. unsigned char *buf;
  6019. nullpo_retv(sd);
  6020. fd = sd->fd;
  6021. buf = WFIFOP(fd,0);
  6022. WBUFW(buf,0) = 0x12c;
  6023. WBUFB(buf,2) = flag;
  6024. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6025. }
  6026. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6027. void clif_bank_open(struct map_session_data *sd){
  6028. int fd;
  6029. nullpo_retv(sd);
  6030. fd = sd->fd;
  6031. WFIFOHEAD(fd,4);
  6032. WFIFOW(fd,0) = 0x09b7;
  6033. WFIFOW(fd,2) = 0;
  6034. WFIFOSET(fd,4);
  6035. }
  6036. /*
  6037. * Request to Open the banking system
  6038. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6039. */
  6040. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6041. //TODO check if preventing trade or stuff like that
  6042. //also mark something in case char ain't available for saving, should we check now ?
  6043. nullpo_retv(sd);
  6044. if( !battle_config.feature_banking ) {
  6045. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6046. return;
  6047. }
  6048. else {
  6049. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6050. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6051. if(sd->status.account_id == aid){
  6052. sd->state.banking = 1;
  6053. //request save ?
  6054. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6055. //on succes open bank ?
  6056. clif_bank_open(sd);
  6057. }
  6058. }
  6059. }
  6060. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6061. void clif_bank_close(struct map_session_data *sd){
  6062. int fd;
  6063. nullpo_retv(sd);
  6064. fd = sd->fd;
  6065. WFIFOHEAD(fd,4);
  6066. WFIFOW(fd,0) = 0x09B9;
  6067. WFIFOW(fd,2) = 0;
  6068. WFIFOSET(fd,4);
  6069. }
  6070. /*
  6071. * Request to close the banking system
  6072. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6073. */
  6074. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6075. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6076. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  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. //still allow to go trough to not stuck player if we have disable it while they was in
  6081. }
  6082. if(sd->status.account_id == aid){
  6083. sd->state.banking = 0;
  6084. clif_bank_close(sd);
  6085. }
  6086. }
  6087. /*
  6088. * Display how much we got in bank (I suppose)
  6089. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6090. */
  6091. void clif_Bank_Check(struct map_session_data* sd) {
  6092. unsigned char buf[13];
  6093. struct s_packet_db* info;
  6094. int16 len;
  6095. int cmd = 0;
  6096. nullpo_retv(sd);
  6097. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6098. if(!cmd) cmd = 0x09A6; //default
  6099. info = &packet_db[cmd];
  6100. len = info->len;
  6101. if(!len) return; //version as packet disable
  6102. // sd->state.banking = 1; //mark opening and closing
  6103. WBUFW(buf,0) = cmd;
  6104. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6105. WBUFW(buf,info->pos[1]) = 0; //reason
  6106. clif_send(buf,len,&sd->bl,SELF);
  6107. }
  6108. /*
  6109. * Requesting the data in bank
  6110. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6111. */
  6112. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6113. nullpo_retv(sd);
  6114. if( !battle_config.feature_banking ) {
  6115. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6116. return;
  6117. }
  6118. else {
  6119. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6120. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6121. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6122. clif_Bank_Check(sd);
  6123. }
  6124. }
  6125. /*
  6126. * Acknowledge of deposit some money in bank
  6127. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6128. */
  6129. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6130. unsigned char buf[17];
  6131. struct s_packet_db* info;
  6132. int16 len;
  6133. int cmd =0;
  6134. nullpo_retv(sd);
  6135. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6136. if(!cmd) cmd = 0x09A8;
  6137. info = &packet_db[cmd];
  6138. len = info->len;
  6139. if(!len) return; //version as packet disable
  6140. WBUFW(buf,0) = cmd;
  6141. WBUFW(buf,info->pos[0]) = (short)reason;
  6142. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6143. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6144. clif_send(buf,len,&sd->bl,SELF);
  6145. }
  6146. /*
  6147. * Request saving some money in bank
  6148. * @author : original [Yommy/Hercules]
  6149. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6150. */
  6151. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6152. nullpo_retv(sd);
  6153. if( !battle_config.feature_banking ) {
  6154. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6155. return;
  6156. }
  6157. else {
  6158. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6159. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6160. int money = RFIFOL(fd,info->pos[1]);
  6161. if(sd->status.account_id == aid){
  6162. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6163. clif_bank_deposit(sd,reason);
  6164. }
  6165. }
  6166. }
  6167. /*
  6168. * Acknowledge of withdrawing some money from bank
  6169. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6170. */
  6171. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6172. unsigned char buf[17];
  6173. struct s_packet_db* info;
  6174. int16 len;
  6175. int cmd;
  6176. nullpo_retv(sd);
  6177. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6178. if(!cmd) cmd = 0x09AA;
  6179. info = &packet_db[cmd];
  6180. len = info->len;
  6181. if(!len) return; //version as packet disable
  6182. WBUFW(buf,0) = cmd;
  6183. WBUFW(buf,info->pos[0]) = (short)reason;
  6184. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6185. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6186. clif_send(buf,len,&sd->bl,SELF);
  6187. }
  6188. /*
  6189. * Request Withdrawing some money from bank
  6190. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6191. */
  6192. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6193. nullpo_retv(sd);
  6194. if( !battle_config.feature_banking ) {
  6195. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6196. return;
  6197. }
  6198. else {
  6199. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6200. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6201. int money = RFIFOL(fd,info->pos[1]);
  6202. if(sd->status.account_id == aid){
  6203. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6204. clif_bank_withdraw(sd,reason);
  6205. }
  6206. }
  6207. }
  6208. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6209. /// 0125 <index>.W <amount>.L
  6210. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6211. {
  6212. int fd;
  6213. nullpo_retv(sd);
  6214. fd=sd->fd;
  6215. WFIFOHEAD(fd,packet_len(0x125));
  6216. WFIFOW(fd,0)=0x125;
  6217. WFIFOW(fd,2)=n+2;
  6218. WFIFOL(fd,4)=amount;
  6219. WFIFOSET(fd,packet_len(0x125));
  6220. }
  6221. /// Opens the shop creation menu (ZC_OPENSTORE).
  6222. /// 012d <num>.W
  6223. /// num:
  6224. /// number of allowed item slots
  6225. void clif_openvendingreq(struct map_session_data* sd, int num)
  6226. {
  6227. int fd;
  6228. nullpo_retv(sd);
  6229. fd = sd->fd;
  6230. WFIFOHEAD(fd,packet_len(0x12d));
  6231. WFIFOW(fd,0) = 0x12d;
  6232. WFIFOW(fd,2) = num;
  6233. WFIFOSET(fd,packet_len(0x12d));
  6234. }
  6235. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6236. /// 0131 <owner id>.L <message>.80B
  6237. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6238. {
  6239. unsigned char buf[128];
  6240. nullpo_retv(bl);
  6241. WBUFW(buf,0) = 0x131;
  6242. WBUFL(buf,2) = bl->id;
  6243. safestrncpy(WBUFCP(buf,6), message, 80);
  6244. if( fd ) {
  6245. WFIFOHEAD(fd,packet_len(0x131));
  6246. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6247. WFIFOSET(fd,packet_len(0x131));
  6248. } else {
  6249. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6250. }
  6251. }
  6252. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6253. /// 0132 <owner id>.L
  6254. void clif_closevendingboard(struct block_list* bl, int fd)
  6255. {
  6256. unsigned char buf[16];
  6257. nullpo_retv(bl);
  6258. WBUFW(buf,0) = 0x132;
  6259. WBUFL(buf,2) = bl->id;
  6260. if( fd ) {
  6261. WFIFOHEAD(fd,packet_len(0x132));
  6262. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6263. WFIFOSET(fd,packet_len(0x132));
  6264. } else {
  6265. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6266. }
  6267. }
  6268. /// Sends a list of items in a shop.
  6269. /// 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)
  6270. /// 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)
  6271. void clif_vendinglist( struct map_session_data* sd, struct map_session_data* vsd ){
  6272. nullpo_retv( sd );
  6273. nullpo_retv( vsd );
  6274. nullpo_retv( vsd->vending );
  6275. int fd = sd->fd;
  6276. if( !session_isActive( fd ) ){
  6277. return;
  6278. }
  6279. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6280. WFIFOHEAD( fd, len );
  6281. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6282. p->packetType = vendinglistType;
  6283. p->packetLength = len;
  6284. p->AID = vsd->status.account_id;
  6285. #if PACKETVER >= 20100105
  6286. p->venderId = vsd->vender_id;
  6287. #endif
  6288. for( int i = 0; i < vsd->vend_num; i++ ){
  6289. int index = vsd->vending[i].index;
  6290. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6291. p->items[i].price = vsd->vending[i].value;
  6292. p->items[i].amount = vsd->vending[i].amount;
  6293. p->items[i].index = client_index( index );
  6294. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6295. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6296. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6297. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6298. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6299. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6300. #if PACKETVER >= 20150226
  6301. clif_add_random_options( p->items[i].option_data, &vsd->cart.u.items_cart[index] );
  6302. #if PACKETVER >= 20160921
  6303. p->items[i].location = pc_equippoint_sub( sd, data );
  6304. p->items[i].viewSprite = data->look;
  6305. #endif
  6306. #endif
  6307. }
  6308. WFIFOSET( fd, len );
  6309. }
  6310. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6311. /// 0135 <index>.W <amount>.W <result>.B
  6312. /// result:
  6313. /// 0 = success
  6314. /// 1 = not enough zeny
  6315. /// 2 = overweight
  6316. /// 4 = out of stock
  6317. /// 5 = "cannot use an npc shop while in a trade"
  6318. /// 6 = Because the store information was incorrect the item was not purchased.
  6319. /// 7 = No sales information.
  6320. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6321. {
  6322. int fd;
  6323. nullpo_retv(sd);
  6324. fd = sd->fd;
  6325. WFIFOHEAD(fd,packet_len(0x135));
  6326. WFIFOW(fd,0) = 0x135;
  6327. WFIFOW(fd,2) = index+2;
  6328. WFIFOW(fd,4) = amount;
  6329. WFIFOB(fd,6) = fail;
  6330. WFIFOSET(fd,packet_len(0x135));
  6331. }
  6332. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6333. /// 0a28 <Result>.B
  6334. /// result:
  6335. /// 0 = Successed
  6336. /// 1 = Failed
  6337. void clif_openvending_ack(struct map_session_data* sd, int result)
  6338. {
  6339. int fd;
  6340. nullpo_retv(sd);
  6341. fd = sd->fd;
  6342. WFIFOHEAD(fd, 3);
  6343. WFIFOW(fd,0) = 0xa28;
  6344. WFIFOB(fd,2) = result;
  6345. WFIFOSET(fd, 3);
  6346. }
  6347. /// Shop creation success.
  6348. /// 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)
  6349. void clif_openvending( struct map_session_data* sd, int id, struct s_vending* vending ){
  6350. nullpo_retv( sd );
  6351. nullpo_retv( vending );
  6352. int fd = sd->fd;
  6353. if( !session_isActive( fd ) ){
  6354. return;
  6355. }
  6356. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6357. WFIFOHEAD( fd, len );
  6358. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6359. p->packetType = 0x136;
  6360. p->packetLength = len;
  6361. p->AID = id;
  6362. for( int i = 0; i < sd->vend_num; i++ ) {
  6363. int index = vending[i].index;
  6364. p->items[i].price = vending[i].value;
  6365. p->items[i].index = client_index( index );
  6366. p->items[i].amount = vending[i].amount;
  6367. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6368. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6369. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6370. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6371. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6372. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6373. #if PACKETVER >= 20150226
  6374. clif_add_random_options( p->items[i].option_data, &sd->cart.u.items_cart[index] );
  6375. #endif
  6376. }
  6377. WFIFOSET( fd, len );
  6378. #if PACKETVER >= 20141022
  6379. /// 0 = Successed
  6380. /// 1 = Failed
  6381. clif_openvending_ack( sd, 0 );
  6382. #endif
  6383. }
  6384. /// Inform merchant that someone has bought an item.
  6385. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6386. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6387. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6388. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6389. const int cmd = 0x137;
  6390. #else
  6391. const int cmd = 0x9e5;
  6392. #endif
  6393. int fd = sd->fd;
  6394. nullpo_retv(sd);
  6395. WFIFOHEAD(fd,packet_len(cmd));
  6396. WFIFOW(fd,0) = cmd;
  6397. WFIFOW(fd,2) = index+2;
  6398. WFIFOW(fd,4) = amount;
  6399. #if PACKETVER >= 20141016
  6400. WFIFOL(fd,6) = char_id; // GID
  6401. WFIFOL(fd,10) = (int)time(NULL); // Date
  6402. WFIFOL(fd,14) = zeny; // zeny
  6403. #endif
  6404. WFIFOSET(fd,packet_len(cmd));
  6405. }
  6406. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6407. /// 00fa <result>.B
  6408. /// result:
  6409. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6410. /// 1 = MsgStringTable[78]="party name already exists"
  6411. /// 2 = MsgStringTable[79]="already in a party"
  6412. /// 3 = cannot organize parties on this map
  6413. /// ? = nothing
  6414. void clif_party_created(struct map_session_data *sd,int result)
  6415. {
  6416. int fd;
  6417. nullpo_retv(sd);
  6418. fd=sd->fd;
  6419. WFIFOHEAD(fd,packet_len(0xfa));
  6420. WFIFOW(fd,0)=0xfa;
  6421. WFIFOB(fd,2)=result;
  6422. WFIFOSET(fd,packet_len(0xfa));
  6423. }
  6424. /// Adds new member to a party.
  6425. /// 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)
  6426. /// 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)
  6427. /// 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)
  6428. /// role:
  6429. /// 0 = leader
  6430. /// 1 = normal
  6431. /// state:
  6432. /// 0 = connected
  6433. /// 1 = disconnected
  6434. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6435. {
  6436. int i;
  6437. #if PACKETVER < 20170502
  6438. unsigned char buf[81];
  6439. int cmd = 0x1e9;
  6440. int offset = 0;
  6441. #else
  6442. unsigned char buf[85];
  6443. int cmd = 0xa43;
  6444. int offset = 4;
  6445. #endif
  6446. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6447. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6448. } else {
  6449. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6450. }
  6451. if (i >= MAX_PARTY) return; //Should never happen...
  6452. sd = p->data[i].sd;
  6453. WBUFW(buf, 0) = cmd;
  6454. WBUFL(buf, 2) = sd->status.account_id;
  6455. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6456. #if PACKETVER >= 20170502
  6457. WBUFW(buf,10) = sd->status.class_;
  6458. WBUFW(buf,12) = sd->status.base_level;
  6459. #endif
  6460. WBUFW(buf,offset+10) = sd->bl.x;
  6461. WBUFW(buf,offset+12) = sd->bl.y;
  6462. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6463. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6464. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6465. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6466. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6467. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6468. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6469. }
  6470. /// Sends party information (ZC_GROUP_LIST).
  6471. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6472. /// role:
  6473. /// 0 = leader
  6474. /// 1 = normal
  6475. /// state:
  6476. /// 0 = connected
  6477. /// 1 = disconnected
  6478. /// 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
  6479. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6480. {
  6481. struct map_session_data* party_sd = NULL;
  6482. int i, c;
  6483. #if PACKETVER < 20170502
  6484. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6485. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6486. int cmd = 0xfb;
  6487. #else
  6488. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6489. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6490. int cmd = 0xa44;
  6491. #endif
  6492. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6493. nullpo_retv(p);
  6494. WBUFW(buf,0) = cmd;
  6495. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6496. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6497. {
  6498. struct party_member* m = &p->party.member[i];
  6499. if(!m->account_id) continue;
  6500. if(party_sd == NULL) party_sd = p->data[i].sd;
  6501. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6502. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6503. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6504. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6505. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6506. #if PACKETVER >= 20170502
  6507. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6508. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6509. #endif
  6510. c++;
  6511. }
  6512. #if PACKETVER < 20170502
  6513. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6514. #else
  6515. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6516. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6517. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6518. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6519. #endif
  6520. if(sd) { // send only to self
  6521. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6522. } else if (party_sd) { // send to whole party
  6523. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6524. }
  6525. }
  6526. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6527. /// 02c9 <flag>.B
  6528. /// flag:
  6529. /// 0 = allow party invites
  6530. /// 1 = auto-deny party invites
  6531. void clif_partyinvitationstate(struct map_session_data* sd)
  6532. {
  6533. int fd;
  6534. nullpo_retv(sd);
  6535. fd = sd->fd;
  6536. WFIFOHEAD(fd, packet_len(0x2c9));
  6537. WFIFOW(fd, 0) = 0x2c9;
  6538. WFIFOB(fd, 2) = 0; // not implemented
  6539. WFIFOSET(fd, packet_len(0x2c9));
  6540. }
  6541. /// Party invitation request.
  6542. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6543. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6544. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6545. {
  6546. #if PACKETVER < 20070821
  6547. const int cmd = 0xfe;
  6548. #else
  6549. const int cmd = 0x2c6;
  6550. #endif
  6551. int fd;
  6552. struct party_data *p;
  6553. nullpo_retv(sd);
  6554. nullpo_retv(tsd);
  6555. fd=tsd->fd;
  6556. if( (p=party_search(sd->status.party_id))==NULL )
  6557. return;
  6558. WFIFOHEAD(fd,packet_len(cmd));
  6559. WFIFOW(fd,0)=cmd;
  6560. WFIFOL(fd,2)=sd->status.party_id;
  6561. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6562. WFIFOSET(fd,packet_len(cmd));
  6563. }
  6564. /// Party invite result.
  6565. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6566. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6567. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6568. {
  6569. int fd;
  6570. nullpo_retv(sd);
  6571. fd=sd->fd;
  6572. #if PACKETVER < 20070904
  6573. if( reply == PARTY_REPLY_OFFLINE ) {
  6574. clif_displaymessage(fd, msg_txt(sd,3));
  6575. return;
  6576. }
  6577. #endif
  6578. #if PACKETVER < 20070821
  6579. WFIFOHEAD(fd,packet_len(0xfd));
  6580. WFIFOW(fd,0) = 0xfd;
  6581. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6582. WFIFOB(fd,26) = reply;
  6583. WFIFOSET(fd,packet_len(0xfd));
  6584. #else
  6585. WFIFOHEAD(fd,packet_len(0x2c5));
  6586. WFIFOW(fd,0) = 0x2c5;
  6587. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6588. WFIFOL(fd,26) = reply;
  6589. WFIFOSET(fd,packet_len(0x2c5));
  6590. #endif
  6591. }
  6592. /// Updates party settings.
  6593. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6594. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6595. /// exp option:
  6596. /// 0 = exp sharing disabled
  6597. /// 1 = exp sharing enabled
  6598. /// 2 = cannot change exp sharing
  6599. ///
  6600. /// flag:
  6601. /// 0 = send to party
  6602. /// 1 = send to sd
  6603. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6604. {
  6605. unsigned char buf[16];
  6606. #if PACKETVER < 20090603
  6607. const int cmd = 0x101;
  6608. #else
  6609. const int cmd = 0x7d8;
  6610. #endif
  6611. nullpo_retv(p);
  6612. if(!sd && flag==0){
  6613. int i;
  6614. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6615. if (i < MAX_PARTY)
  6616. sd = p->data[i].sd;
  6617. }
  6618. if(!sd) return;
  6619. WBUFW(buf,0)=cmd;
  6620. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6621. #if PACKETVER >= 20090603
  6622. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6623. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6624. #endif
  6625. if(flag==0)
  6626. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6627. else
  6628. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6629. }
  6630. /**
  6631. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6632. * @param sd Send the notification for this player
  6633. * @param account_id Account ID of kicked member
  6634. * @param name Name of kicked member
  6635. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6636. * @param target Send target
  6637. **/
  6638. 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) {
  6639. unsigned char buf[2+4+NAME_LENGTH+1];
  6640. if (!sd)
  6641. return;
  6642. WBUFW(buf,0) = 0x0105;
  6643. WBUFL(buf,2) = account_id;
  6644. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6645. WBUFB(buf,6+NAME_LENGTH) = result;
  6646. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6647. }
  6648. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6649. /// 0109 <packet len>.W <account id>.L <message>.?B
  6650. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6651. {
  6652. struct map_session_data *sd;
  6653. int i;
  6654. nullpo_retv(p);
  6655. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6656. if(i < MAX_PARTY){
  6657. unsigned char buf[1024];
  6658. if( len > sizeof(buf)-8 )
  6659. {
  6660. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6661. len = sizeof(buf)-8;
  6662. }
  6663. sd = p->data[i].sd;
  6664. WBUFW(buf,0)=0x109;
  6665. WBUFW(buf,2)=len+8;
  6666. WBUFL(buf,4)=account_id;
  6667. safestrncpy(WBUFCP(buf,8), mes, len);
  6668. clif_send(buf,len+8,&sd->bl,PARTY);
  6669. }
  6670. }
  6671. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6672. /// 0107 <account id>.L <x>.W <y>.W
  6673. void clif_party_xy(struct map_session_data *sd)
  6674. {
  6675. unsigned char buf[16];
  6676. nullpo_retv(sd);
  6677. WBUFW(buf,0)=0x107;
  6678. WBUFL(buf,2)=sd->status.account_id;
  6679. WBUFW(buf,6)=sd->bl.x;
  6680. WBUFW(buf,8)=sd->bl.y;
  6681. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6682. }
  6683. /*==========================================
  6684. * Sends x/y dot to a single fd. [Skotlex]
  6685. *------------------------------------------*/
  6686. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6687. {
  6688. WFIFOHEAD(fd,packet_len(0x107));
  6689. WFIFOW(fd,0)=0x107;
  6690. WFIFOL(fd,2)=sd->status.account_id;
  6691. WFIFOW(fd,6)=sd->bl.x;
  6692. WFIFOW(fd,8)=sd->bl.y;
  6693. WFIFOSET(fd,packet_len(0x107));
  6694. }
  6695. /// Updates HP bar of a party member.
  6696. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6697. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6698. void clif_party_hp(struct map_session_data *sd)
  6699. {
  6700. unsigned char buf[16];
  6701. #if PACKETVER < 20100126
  6702. const int cmd = 0x106;
  6703. #else
  6704. const int cmd = 0x80e;
  6705. #endif
  6706. nullpo_retv(sd);
  6707. WBUFW(buf,0)=cmd;
  6708. WBUFL(buf,2)=sd->status.account_id;
  6709. #if PACKETVER < 20100126
  6710. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6711. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6712. WBUFW(buf,8) = 100;
  6713. } else {
  6714. WBUFW(buf,6) = sd->battle_status.hp;
  6715. WBUFW(buf,8) = sd->battle_status.max_hp;
  6716. }
  6717. #else
  6718. WBUFL(buf,6) = sd->battle_status.hp;
  6719. WBUFL(buf,10) = sd->battle_status.max_hp;
  6720. #endif
  6721. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6722. }
  6723. /// Notifies the party members of a character's death or revival.
  6724. /// 0AB2 <GID>.L <dead>.B
  6725. void clif_party_dead( struct map_session_data *sd ){
  6726. #if PACKETVER >= 20170502
  6727. unsigned char buf[7];
  6728. nullpo_retv(sd);
  6729. WBUFW(buf, 0) = 0xab2;
  6730. WBUFL(buf, 2) = sd->status.account_id;
  6731. WBUFB(buf, 6) = pc_isdead(sd);
  6732. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6733. #endif
  6734. }
  6735. /// Updates the job and level of a party member
  6736. /// 0abd <account id>.L <job>.W <level>.W
  6737. void clif_party_job_and_level(struct map_session_data *sd){
  6738. #if PACKETVER >= 20170502
  6739. unsigned char buf[10];
  6740. nullpo_retv(sd);
  6741. WBUFW(buf, 0) = 0xabd;
  6742. WBUFL(buf, 2) = sd->status.account_id;
  6743. WBUFW(buf, 6) = sd->status.class_;
  6744. WBUFW(buf, 8) = sd->status.base_level;
  6745. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6746. #endif
  6747. }
  6748. /*==========================================
  6749. * Sends HP bar to a single fd. [Skotlex]
  6750. *------------------------------------------*/
  6751. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6752. {
  6753. #if PACKETVER < 20100126
  6754. const int cmd = 0x106;
  6755. #else
  6756. const int cmd = 0x80e;
  6757. #endif
  6758. WFIFOHEAD(fd,packet_len(cmd));
  6759. WFIFOW(fd,0) = cmd;
  6760. WFIFOL(fd,2) = id;
  6761. #if PACKETVER < 20100126
  6762. if( maxhp > INT16_MAX )
  6763. {// To correctly display the %hp bar. [Skotlex]
  6764. WFIFOW(fd,6) = hp/(maxhp/100);
  6765. WFIFOW(fd,8) = 100;
  6766. } else {
  6767. WFIFOW(fd,6) = hp;
  6768. WFIFOW(fd,8) = maxhp;
  6769. }
  6770. #else
  6771. WFIFOL(fd,6) = hp;
  6772. WFIFOL(fd,10) = maxhp;
  6773. #endif
  6774. WFIFOSET(fd, packet_len(cmd));
  6775. }
  6776. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6777. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6778. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6779. {
  6780. int fd;
  6781. nullpo_retv(sd);
  6782. nullpo_retv(bl);
  6783. fd=sd->fd;
  6784. WFIFOHEAD(fd,packet_len(0x139));
  6785. WFIFOW(fd, 0)=0x139;
  6786. WFIFOL(fd, 2)=bl->id;
  6787. WFIFOW(fd, 6)=bl->x;
  6788. WFIFOW(fd, 8)=bl->y;
  6789. WFIFOW(fd,10)=sd->bl.x;
  6790. WFIFOW(fd,12)=sd->bl.y;
  6791. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6792. WFIFOSET(fd,packet_len(0x139));
  6793. }
  6794. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6795. /// 018f <result>.W <name id>.W
  6796. /// result:
  6797. /// 0 = success
  6798. /// 1 = failure
  6799. /// 2 = success (alchemist)
  6800. /// 3 = failure (alchemist)
  6801. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid){
  6802. nullpo_retv( sd );
  6803. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6804. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6805. p.packetType = 0x18f;
  6806. p.result = flag;
  6807. p.itemId = client_nameid( nameid );
  6808. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6809. }
  6810. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6811. /// 019e
  6812. void clif_catch_process(struct map_session_data *sd)
  6813. {
  6814. int fd;
  6815. nullpo_retv(sd);
  6816. fd=sd->fd;
  6817. WFIFOHEAD(fd,packet_len(0x19e));
  6818. WFIFOW(fd,0)=0x19e;
  6819. WFIFOSET(fd,packet_len(0x19e));
  6820. }
  6821. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6822. /// 01a0 <result>.B
  6823. /// 0 = failure
  6824. /// 1 = success
  6825. void clif_pet_roulette(struct map_session_data *sd,int data)
  6826. {
  6827. int fd;
  6828. nullpo_retv(sd);
  6829. fd=sd->fd;
  6830. WFIFOHEAD(fd,packet_len(0x1a0));
  6831. WFIFOW(fd,0)=0x1a0;
  6832. WFIFOB(fd,2)=data;
  6833. WFIFOSET(fd,packet_len(0x1a0));
  6834. }
  6835. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6836. /// 01a6 <packet len>.W { <index>.W }*
  6837. void clif_sendegg(struct map_session_data *sd)
  6838. {
  6839. int i,n=0,fd;
  6840. nullpo_retv(sd);
  6841. fd=sd->fd;
  6842. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6843. clif_displaymessage(fd, msg_txt(sd,666));
  6844. return;
  6845. }
  6846. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6847. WFIFOW(fd,0)=0x1a6;
  6848. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6849. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6850. sd->inventory_data[i]->type != IT_PETEGG ||
  6851. sd->inventory.u.items_inventory[i].amount <= 0)
  6852. continue;
  6853. WFIFOW(fd,n*2+4)=i+2;
  6854. n++;
  6855. }
  6856. WFIFOW(fd,2)=4+n*2;
  6857. WFIFOSET(fd,WFIFOW(fd,2));
  6858. sd->menuskill_id = SA_TAMINGMONSTER;
  6859. sd->menuskill_val = -1;
  6860. }
  6861. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6862. /// 01a4 <type>.B <id>.L <data>.L
  6863. /// type:
  6864. /// 0 = pre-init (data = 0)
  6865. /// 1 = intimacy (data = 0~4)
  6866. /// 2 = hunger (data = 0~4)
  6867. /// 3 = accessory
  6868. /// 4 = performance (data = 1~3: normal, 4: special)
  6869. /// 5 = hairstyle
  6870. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6871. ///
  6872. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6873. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6874. {
  6875. uint8 buf[16];
  6876. nullpo_retv(pd);
  6877. WBUFW(buf,0) = 0x1a4;
  6878. WBUFB(buf,2) = type;
  6879. WBUFL(buf,3) = pd->bl.id;
  6880. WBUFL(buf,7) = param;
  6881. if (sd)
  6882. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6883. else
  6884. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6885. }
  6886. /// Pet's base data (ZC_PROPERTY_PET).
  6887. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6888. void clif_send_petstatus(struct map_session_data *sd)
  6889. {
  6890. int fd;
  6891. struct s_pet *pet;
  6892. nullpo_retv(sd);
  6893. nullpo_retv(sd->pd);
  6894. fd=sd->fd;
  6895. pet = &sd->pd->pet;
  6896. WFIFOHEAD(fd,packet_len(0x1a2));
  6897. WFIFOW(fd,0)=0x1a2;
  6898. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6899. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6900. WFIFOW(fd,27)=pet->level;
  6901. WFIFOW(fd,29)=pet->hungry;
  6902. WFIFOW(fd,31)=pet->intimate;
  6903. WFIFOW(fd,33)=pet->equip;
  6904. #if PACKETVER >= 20081126
  6905. WFIFOW(fd,35)=pet->class_;
  6906. #endif
  6907. WFIFOSET(fd,packet_len(0x1a2));
  6908. }
  6909. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6910. /// 01aa <id>.L <data>.L
  6911. /// data:
  6912. /// @see CZ_PET_ACT.
  6913. void clif_pet_emotion(struct pet_data *pd,int param)
  6914. {
  6915. unsigned char buf[16];
  6916. nullpo_retv(pd);
  6917. memset(buf,0,packet_len(0x1aa));
  6918. WBUFW(buf,0)=0x1aa;
  6919. WBUFL(buf,2)=pd->bl.id;
  6920. WBUFL(buf,6)=param;
  6921. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6922. }
  6923. /// Result of request to feed a pet (ZC_FEED_PET).
  6924. /// 01a3 <result>.B <name id>.W
  6925. /// result:
  6926. /// 0 = failure
  6927. /// 1 = success
  6928. void clif_pet_food( struct map_session_data *sd, int foodid,int fail ){
  6929. nullpo_retv( sd );
  6930. struct PACKET_ZC_FEED_PET p;
  6931. p.packetType = 0x1a3;
  6932. p.result = fail;
  6933. p.itemId = client_nameid( foodid );
  6934. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6935. }
  6936. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6937. /// 01cd { <skill id>.L }*7
  6938. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6939. {
  6940. nullpo_retv(sd);
  6941. int fd = sd->fd;
  6942. #ifdef RENEWAL
  6943. uint16 autospell_skill[][2] = {
  6944. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  6945. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  6946. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  6947. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  6948. };
  6949. int count = 0;
  6950. WFIFOHEAD(fd, 2 * 6 + 4);
  6951. WFIFOW(fd, 0) = 0x442;
  6952. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  6953. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  6954. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  6955. count++;
  6956. }
  6957. }
  6958. WFIFOW(fd, 2) = 8 + count * 2;
  6959. WFIFOL(fd, 4) = count;
  6960. WFIFOSET(fd, WFIFOW(fd, 2));
  6961. #else
  6962. WFIFOHEAD(fd,packet_len(0x1cd));
  6963. WFIFOW(fd, 0)=0x1cd;
  6964. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6965. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6966. else
  6967. WFIFOL(fd,2)= 0x00000000;
  6968. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6969. WFIFOL(fd,6)= MG_COLDBOLT;
  6970. else
  6971. WFIFOL(fd,6)= 0x00000000;
  6972. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6973. WFIFOL(fd,10)= MG_FIREBOLT;
  6974. else
  6975. WFIFOL(fd,10)= 0x00000000;
  6976. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6977. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6978. else
  6979. WFIFOL(fd,14)= 0x00000000;
  6980. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6981. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6982. else
  6983. WFIFOL(fd,18)= 0x00000000;
  6984. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6985. WFIFOL(fd,22)= MG_FIREBALL;
  6986. else
  6987. WFIFOL(fd,22)= 0x00000000;
  6988. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6989. WFIFOL(fd,26)= MG_FROSTDIVER;
  6990. else
  6991. WFIFOL(fd,26)= 0x00000000;
  6992. WFIFOSET(fd,packet_len(0x1cd));
  6993. #endif
  6994. sd->menuskill_id = SA_AUTOSPELL;
  6995. sd->menuskill_val = skill_lv;
  6996. }
  6997. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6998. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6999. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7000. {
  7001. unsigned char buf[56];
  7002. nullpo_retv(src);
  7003. memset(buf,0,packet_len(0x1cf));
  7004. WBUFW(buf,0) = 0x1cf;
  7005. WBUFL(buf,2) = src->id;
  7006. if( src->type == BL_MER )
  7007. {
  7008. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7009. if( md && md->master && md->devotion_flag )
  7010. WBUFL(buf,6) = md->master->bl.id;
  7011. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7012. }
  7013. else
  7014. {
  7015. int i;
  7016. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7017. if( sd == NULL )
  7018. return;
  7019. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7020. WBUFL(buf,6+4*i) = sd->devotion[i];
  7021. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7022. }
  7023. if( tsd )
  7024. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7025. else
  7026. clif_send(buf, packet_len(0x1cf), src, AREA);
  7027. }
  7028. /*==========================================
  7029. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  7030. * Notifies clients in an area of an object's spirits.
  7031. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7032. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7033. *------------------------------------------*/
  7034. void clif_spiritball(struct block_list *bl) {
  7035. unsigned char buf[16];
  7036. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7037. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7038. nullpo_retv(bl);
  7039. WBUFW(buf, 0) = 0x1d0;
  7040. WBUFL(buf, 2) = bl->id;
  7041. WBUFW(buf, 6) = 0; //init to 0
  7042. switch(bl->type){
  7043. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7044. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7045. }
  7046. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7047. }
  7048. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7049. /// 01d2 <account id>.L <delay>.L
  7050. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7051. {
  7052. unsigned char buf[32];
  7053. nullpo_retv(bl);
  7054. WBUFW(buf,0)=0x1d2;
  7055. WBUFL(buf,2)=bl->id;
  7056. WBUFL(buf,6)=client_tick(wait);
  7057. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7058. }
  7059. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7060. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7061. /// flag:
  7062. /// 0 = inactive
  7063. /// 1 = active
  7064. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7065. {
  7066. unsigned char buf[32];
  7067. nullpo_retv(src);
  7068. WBUFW(buf,0)=0x1d1;
  7069. WBUFL(buf,2)=src->id;
  7070. WBUFL(buf,6)=dst_id;
  7071. WBUFL(buf,10)=active;
  7072. clif_send(buf,packet_len(0x1d1),src,AREA);
  7073. }
  7074. /// MVP effect (ZC_MVP).
  7075. /// 010c <account id>.L
  7076. void clif_mvp_effect(struct map_session_data *sd)
  7077. {
  7078. unsigned char buf[16];
  7079. nullpo_retv(sd);
  7080. WBUFW(buf,0)=0x10c;
  7081. WBUFL(buf,2)=sd->bl.id;
  7082. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7083. }
  7084. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7085. /// 010a <name id>.W
  7086. void clif_mvp_item( struct map_session_data *sd, unsigned short nameid ){
  7087. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7088. p.packetType = 0x10a;
  7089. p.itemId = client_nameid( nameid );
  7090. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7091. }
  7092. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7093. /// 010b <exp>.L
  7094. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7095. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7096. if (battle_config.mvp_exp_reward_message) {
  7097. char e_msg[CHAT_SIZE_MAX];
  7098. sprintf(e_msg, msg_txt(sd, 717), exp);
  7099. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7100. }
  7101. #else
  7102. int fd;
  7103. nullpo_retv(sd);
  7104. fd = sd->fd;
  7105. WFIFOHEAD(fd, packet_len(0x10b));
  7106. WFIFOW(fd,0) = 0x10b;
  7107. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7108. WFIFOSET(fd, packet_len(0x10b));
  7109. #endif
  7110. }
  7111. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7112. /// 010d
  7113. ///
  7114. /// "You are the MVP, but cannot obtain the reward because
  7115. /// you are overweight."
  7116. void clif_mvp_noitem(struct map_session_data* sd)
  7117. {
  7118. int fd = sd->fd;
  7119. WFIFOHEAD(fd,packet_len(0x10d));
  7120. WFIFOW(fd,0) = 0x10d;
  7121. WFIFOSET(fd,packet_len(0x10d));
  7122. }
  7123. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7124. /// 0167 <result>.B
  7125. /// result:
  7126. /// 0 = "Guild has been created."
  7127. /// 1 = "You are already in a Guild."
  7128. /// 2 = "That Guild Name already exists."
  7129. /// 3 = "You need the neccessary item to create a Guild."
  7130. void clif_guild_created(struct map_session_data *sd,int flag)
  7131. {
  7132. int fd;
  7133. nullpo_retv(sd);
  7134. fd=sd->fd;
  7135. WFIFOHEAD(fd,packet_len(0x167));
  7136. WFIFOW(fd,0)=0x167;
  7137. WFIFOB(fd,2)=flag;
  7138. WFIFOSET(fd,packet_len(0x167));
  7139. }
  7140. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7141. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7142. /// mode:
  7143. /// &0x01 = allow invite
  7144. /// &0x10 = allow expel
  7145. void clif_guild_belonginfo(struct map_session_data *sd)
  7146. {
  7147. int ps,fd;
  7148. struct guild* g;
  7149. nullpo_retv(sd);
  7150. nullpo_retv(g = sd->guild);
  7151. fd=sd->fd;
  7152. ps=guild_getposition(sd);
  7153. WFIFOHEAD(fd,packet_len(0x16c));
  7154. WFIFOW(fd,0)=0x16c;
  7155. WFIFOL(fd,2)=g->guild_id;
  7156. WFIFOL(fd,6)=g->emblem_id;
  7157. WFIFOL(fd,10)=g->position[ps].mode;
  7158. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7159. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7160. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7161. WFIFOSET(fd,packet_len(0x16c));
  7162. }
  7163. /// Guild member login notice.
  7164. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7165. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7166. /// status:
  7167. /// 0 = offline
  7168. /// 1 = online
  7169. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7170. {
  7171. unsigned char buf[64];
  7172. struct map_session_data* sd;
  7173. nullpo_retv(g);
  7174. WBUFW(buf, 0)=0x1f2;
  7175. WBUFL(buf, 2)=g->member[idx].account_id;
  7176. WBUFL(buf, 6)=g->member[idx].char_id;
  7177. WBUFL(buf,10)=flag;
  7178. if( ( sd = g->member[idx].sd ) != NULL )
  7179. {
  7180. WBUFW(buf,14) = sd->status.sex;
  7181. WBUFW(buf,16) = sd->status.hair;
  7182. WBUFW(buf,18) = sd->status.hair_color;
  7183. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7184. }
  7185. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7186. {
  7187. WBUFW(buf,14) = 0;
  7188. WBUFW(buf,16) = 0;
  7189. WBUFW(buf,18) = 0;
  7190. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7191. }
  7192. }
  7193. // Function `clif_guild_memberlogin_notice` sends info about
  7194. // logins and logouts of a guild member to the rest members.
  7195. // But at the 1st time (after a player login or map changing)
  7196. // the client won't show the message.
  7197. // So I suggest use this function for sending "first-time-info"
  7198. // to some player on entering the game or changing location.
  7199. // At next time the client would always show the message.
  7200. // The function sends all the statuses in the single packet
  7201. // to economize traffic. [LuzZza]
  7202. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7203. {
  7204. struct guild *g;
  7205. unsigned char buf[14*128];
  7206. int i, count=0, p_len;
  7207. nullpo_retv(sd);
  7208. p_len = packet_len(0x16d);
  7209. if(!(g = sd->guild))
  7210. return;
  7211. for(i=0; i<g->max_member; i++) {
  7212. if(g->member[i].account_id > 0 &&
  7213. g->member[i].account_id != sd->status.account_id) {
  7214. WBUFW(buf,count*p_len) = 0x16d;
  7215. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7216. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7217. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7218. count++;
  7219. }
  7220. }
  7221. clif_send(buf, p_len*count, &sd->bl, SELF);
  7222. }
  7223. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7224. /// 014e <menu flag>.L
  7225. /// menu flag:
  7226. /// 0x00 = Basic Info (always on)
  7227. /// &0x01 = Member manager
  7228. /// &0x02 = Positions
  7229. /// &0x04 = Skills
  7230. /// &0x10 = Expulsion list
  7231. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7232. /// &0x80 = Notice
  7233. void clif_guild_masterormember(struct map_session_data *sd)
  7234. {
  7235. int fd;
  7236. nullpo_retv(sd);
  7237. fd=sd->fd;
  7238. WFIFOHEAD(fd,packet_len(0x14e));
  7239. WFIFOW(fd,0) = 0x14e;
  7240. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7241. WFIFOSET(fd,packet_len(0x14e));
  7242. }
  7243. /// Guild basic information (Territories [Valaris])
  7244. /// 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)
  7245. /// 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)
  7246. /// 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)
  7247. void clif_guild_basicinfo(struct map_session_data *sd) {
  7248. int fd;
  7249. struct guild *g;
  7250. #if PACKETVER < 20160622
  7251. int cmd = 0x1b6;
  7252. int offset = NAME_LENGTH;
  7253. #else
  7254. int cmd = 0xa84;
  7255. int offset = 0;
  7256. #endif
  7257. nullpo_retv(sd);
  7258. fd = sd->fd;
  7259. if( (g = sd->guild) == NULL )
  7260. return;
  7261. WFIFOHEAD(fd,packet_len(cmd));
  7262. WFIFOW(fd, 0)=cmd;
  7263. WFIFOL(fd, 2)=g->guild_id;
  7264. WFIFOL(fd, 6)=g->guild_lv;
  7265. WFIFOL(fd,10)=g->connect_member;
  7266. WFIFOL(fd,14)=g->max_member;
  7267. WFIFOL(fd,18)=g->average_lv;
  7268. WFIFOL(fd,22)=(uint32)cap_value(g->exp, 0, MAX_GUILD_EXP);
  7269. WFIFOL(fd,26)=(uint32)cap_value(g->next_exp, 0, MAX_GUILD_EXP);
  7270. WFIFOL(fd,30)=0; // Tax Points
  7271. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7272. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7273. WFIFOL(fd,42)=g->emblem_id;
  7274. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7275. #if PACKETVER < 20160622
  7276. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7277. #endif
  7278. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7279. WFIFOL(fd,70+offset+16) = 0; // zeny
  7280. #if PACKETVER >= 20160622
  7281. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7282. #endif
  7283. WFIFOSET(fd,packet_len(cmd));
  7284. }
  7285. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7286. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7287. void clif_guild_allianceinfo(struct map_session_data *sd)
  7288. {
  7289. int fd,i,c;
  7290. struct guild *g;
  7291. nullpo_retv(sd);
  7292. if( (g = sd->guild) == NULL )
  7293. return;
  7294. fd = sd->fd;
  7295. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7296. WFIFOW(fd, 0)=0x14c;
  7297. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7298. struct guild_alliance *a=&g->alliance[i];
  7299. if(a->guild_id>0){
  7300. WFIFOL(fd,c*32+4)=a->opposition;
  7301. WFIFOL(fd,c*32+8)=a->guild_id;
  7302. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7303. c++;
  7304. }
  7305. }
  7306. WFIFOW(fd, 2)=c*32+4;
  7307. WFIFOSET(fd,WFIFOW(fd,2));
  7308. }
  7309. /// Guild member manager information
  7310. /// 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)
  7311. /// state:
  7312. /// 0 = offline
  7313. /// 1 = online
  7314. /// memo:
  7315. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7316. /// 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)
  7317. void clif_guild_memberlist(struct map_session_data *sd)
  7318. {
  7319. int fd;
  7320. int i,c;
  7321. struct guild *g;
  7322. #if PACKETVER < 20161026
  7323. int cmd = 0x154;
  7324. int size = 104;
  7325. #else
  7326. int cmd = 0xaa5;
  7327. int size = 34;
  7328. #endif
  7329. nullpo_retv(sd);
  7330. if( (fd = sd->fd) == 0 )
  7331. return;
  7332. if( (g = sd->guild) == NULL )
  7333. return;
  7334. WFIFOHEAD(fd, g->max_member * size + 4);
  7335. WFIFOW(fd, 0)=cmd;
  7336. for(i=0,c=0;i<g->max_member;i++){
  7337. struct guild_member *m=&g->member[i];
  7338. if(m->account_id==0)
  7339. continue;
  7340. WFIFOL(fd,c*size+ 4)=m->account_id;
  7341. WFIFOL(fd,c*size+ 8)=m->char_id;
  7342. WFIFOW(fd,c*size+12)=m->hair;
  7343. WFIFOW(fd,c*size+14)=m->hair_color;
  7344. WFIFOW(fd,c*size+16)=m->gender;
  7345. WFIFOW(fd,c*size+18)=m->class_;
  7346. WFIFOW(fd,c*size+20)=m->lv;
  7347. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7348. WFIFOL(fd,c*size+26)=m->online;
  7349. WFIFOL(fd,c*size+30)=m->position;
  7350. #if PACKETVER < 20161026
  7351. 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.
  7352. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7353. #else
  7354. WFIFOL(fd,c*size+34)=m->last_login;
  7355. #endif
  7356. c++;
  7357. }
  7358. WFIFOW(fd, 2)=c*size+4;
  7359. WFIFOSET(fd,WFIFOW(fd,2));
  7360. }
  7361. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7362. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7363. void clif_guild_positionnamelist(struct map_session_data *sd)
  7364. {
  7365. int i,fd;
  7366. struct guild *g;
  7367. nullpo_retv(sd);
  7368. if( (g = sd->guild) == NULL )
  7369. return;
  7370. fd = sd->fd;
  7371. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7372. WFIFOW(fd, 0)=0x166;
  7373. for(i=0;i<MAX_GUILDPOSITION;i++){
  7374. WFIFOL(fd,i*28+4)=i;
  7375. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7376. }
  7377. WFIFOW(fd,2)=i*28+4;
  7378. WFIFOSET(fd,WFIFOW(fd,2));
  7379. }
  7380. /// Guild position information (ZC_POSITION_INFO).
  7381. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7382. /// mode:
  7383. /// &0x01 = allow invite
  7384. /// &0x10 = allow expel
  7385. /// ranking:
  7386. /// TODO
  7387. void clif_guild_positioninfolist(struct map_session_data *sd)
  7388. {
  7389. int i,fd;
  7390. struct guild *g;
  7391. nullpo_retv(sd);
  7392. if( (g = sd->guild) == NULL )
  7393. return;
  7394. fd = sd->fd;
  7395. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7396. WFIFOW(fd, 0)=0x160;
  7397. for(i=0;i<MAX_GUILDPOSITION;i++){
  7398. struct guild_position *p=&g->position[i];
  7399. WFIFOL(fd,i*16+ 4)=i;
  7400. WFIFOL(fd,i*16+ 8)=p->mode;
  7401. WFIFOL(fd,i*16+12)=i;
  7402. WFIFOL(fd,i*16+16)=p->exp_mode;
  7403. }
  7404. WFIFOW(fd, 2)=i*16+4;
  7405. WFIFOSET(fd,WFIFOW(fd,2));
  7406. }
  7407. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7408. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7409. /// mode:
  7410. /// &0x01 = allow invite
  7411. /// &0x10 = allow expel
  7412. /// ranking:
  7413. /// TODO
  7414. void clif_guild_positionchanged(struct guild *g,int idx)
  7415. {
  7416. // FIXME: This packet is intended to update the clients after a
  7417. // commit of position info changes, not sending one packet per
  7418. // position.
  7419. struct map_session_data *sd;
  7420. unsigned char buf[128];
  7421. nullpo_retv(g);
  7422. WBUFW(buf, 0)=0x174;
  7423. WBUFW(buf, 2)=44; // packet len
  7424. // GUILD_REG_POSITION_INFO{
  7425. WBUFL(buf, 4)=idx;
  7426. WBUFL(buf, 8)=g->position[idx].mode;
  7427. WBUFL(buf,12)=idx;
  7428. WBUFL(buf,16)=g->position[idx].exp_mode;
  7429. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7430. // }*
  7431. if( (sd=guild_getavailablesd(g))!=NULL )
  7432. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7433. }
  7434. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7435. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7436. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7437. {
  7438. // FIXME: This packet is intended to update the clients after a
  7439. // commit of member position assignment changes, not sending one
  7440. // packet per position.
  7441. struct map_session_data *sd;
  7442. unsigned char buf[64];
  7443. nullpo_retv(g);
  7444. WBUFW(buf, 0)=0x156;
  7445. WBUFW(buf, 2)=16; // packet len
  7446. // MEMBER_POSITION_INFO{
  7447. WBUFL(buf, 4)=g->member[idx].account_id;
  7448. WBUFL(buf, 8)=g->member[idx].char_id;
  7449. WBUFL(buf,12)=g->member[idx].position;
  7450. // }*
  7451. if( (sd=guild_getavailablesd(g))!=NULL )
  7452. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7453. }
  7454. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7455. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7456. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7457. {
  7458. int fd;
  7459. nullpo_retv(sd);
  7460. nullpo_retv(g);
  7461. fd = sd->fd;
  7462. if( g->emblem_len <= 0 )
  7463. return;
  7464. WFIFOHEAD(fd,g->emblem_len+12);
  7465. WFIFOW(fd,0)=0x152;
  7466. WFIFOW(fd,2)=g->emblem_len+12;
  7467. WFIFOL(fd,4)=g->guild_id;
  7468. WFIFOL(fd,8)=g->emblem_id;
  7469. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7470. WFIFOSET(fd,WFIFOW(fd,2));
  7471. }
  7472. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7473. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7474. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7475. void clif_guild_emblem_area(struct block_list* bl)
  7476. {
  7477. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7478. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7479. PACKET_ZC_CHANGE_GUILD p{};
  7480. p.packetType = changeGuildEmblem;
  7481. p.guild_id = status_get_guild_id(bl);
  7482. p.emblem_id = status_get_emblem_id(bl);
  7483. #if PACKETVER < 20190724
  7484. p.aid = bl->id;
  7485. #else
  7486. p.unknown = 0;
  7487. #endif
  7488. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7489. }
  7490. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7491. /// 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 }*
  7492. void clif_guild_skillinfo(struct map_session_data* sd)
  7493. {
  7494. int fd;
  7495. struct guild* g;
  7496. int i,c;
  7497. nullpo_retv(sd);
  7498. if( (g = sd->guild) == NULL )
  7499. return;
  7500. fd = sd->fd;
  7501. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7502. WFIFOW(fd,0) = 0x0162;
  7503. WFIFOW(fd,4) = g->skill_point;
  7504. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7505. {
  7506. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7507. {
  7508. int id = g->skill[i].id;
  7509. int p = 6 + c*37;
  7510. WFIFOW(fd,p+0) = id;
  7511. WFIFOL(fd,p+2) = skill_get_inf(id);
  7512. WFIFOW(fd,p+6) = g->skill[i].lv;
  7513. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7514. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7515. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7516. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7517. c++;
  7518. }
  7519. }
  7520. WFIFOW(fd,2) = 6 + c*37;
  7521. WFIFOSET(fd,WFIFOW(fd,2));
  7522. }
  7523. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7524. /// 016f <subject>.60B <notice>.120B
  7525. void clif_guild_notice(struct map_session_data* sd)
  7526. {
  7527. int fd;
  7528. struct guild* g;
  7529. nullpo_retv(sd);
  7530. nullpo_retv(g = sd->guild);
  7531. fd = sd->fd;
  7532. if ( !session_isActive(fd) )
  7533. return;
  7534. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7535. return;
  7536. WFIFOHEAD(fd,packet_len(0x16f));
  7537. WFIFOW(fd,0) = 0x16f;
  7538. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7539. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7540. WFIFOSET(fd,packet_len(0x16f));
  7541. }
  7542. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7543. /// 016a <guild id>.L <guild name>.24B
  7544. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7545. {
  7546. int fd;
  7547. nullpo_retv(sd);
  7548. nullpo_retv(g);
  7549. fd=sd->fd;
  7550. WFIFOHEAD(fd,packet_len(0x16a));
  7551. WFIFOW(fd,0)=0x16a;
  7552. WFIFOL(fd,2)=g->guild_id;
  7553. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7554. WFIFOSET(fd,packet_len(0x16a));
  7555. }
  7556. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7557. /// 0169 <answer>.B
  7558. /// answer:
  7559. /// 0 = Already in guild.
  7560. /// 1 = Offer rejected.
  7561. /// 2 = Offer accepted.
  7562. /// 3 = Guild full.
  7563. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7564. {
  7565. int fd;
  7566. nullpo_retv(sd);
  7567. fd=sd->fd;
  7568. WFIFOHEAD(fd,packet_len(0x169));
  7569. WFIFOW(fd,0)=0x169;
  7570. WFIFOB(fd,2)=flag;
  7571. WFIFOSET(fd,packet_len(0x169));
  7572. }
  7573. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7574. /// 015a <char name>.24B <reason>.40B
  7575. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7576. {
  7577. unsigned char buf[128];
  7578. nullpo_retv(sd);
  7579. WBUFW(buf, 0)=0x15a;
  7580. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7581. memcpy(WBUFP(buf,26),mes,40);
  7582. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7583. }
  7584. /// Notifies clients of a guild of an expelled member.
  7585. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7586. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7587. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7588. {
  7589. unsigned char buf[128];
  7590. #if PACKETVER < 20100803
  7591. const unsigned short cmd = 0x15c;
  7592. #else
  7593. const unsigned short cmd = 0x839;
  7594. #endif
  7595. nullpo_retv(sd);
  7596. WBUFW(buf,0) = cmd;
  7597. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7598. safestrncpy(WBUFCP(buf,26), mes, 40);
  7599. #if PACKETVER < 20100803
  7600. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7601. #endif
  7602. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7603. }
  7604. /// Guild expulsion list (ZC_BAN_LIST).
  7605. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7606. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7607. void clif_guild_expulsionlist(struct map_session_data* sd)
  7608. {
  7609. #if PACKETVER < 20100803
  7610. const int offset = NAME_LENGTH*2+40;
  7611. #else
  7612. const int offset = NAME_LENGTH+40;
  7613. #endif
  7614. int fd, i, c = 0;
  7615. struct guild* g;
  7616. nullpo_retv(sd);
  7617. if( (g = sd->guild) == NULL )
  7618. return;
  7619. fd = sd->fd;
  7620. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7621. WFIFOW(fd,0) = 0x163;
  7622. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7623. {
  7624. struct guild_expulsion* e = &g->expulsion[i];
  7625. if( e->account_id > 0 )
  7626. {
  7627. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7628. #if PACKETVER < 20100803
  7629. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7630. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7631. #else
  7632. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7633. #endif
  7634. c++;
  7635. }
  7636. }
  7637. WFIFOW(fd,2) = 4 + c*offset;
  7638. WFIFOSET(fd,WFIFOW(fd,2));
  7639. }
  7640. /// Guild chat message (ZC_GUILD_CHAT).
  7641. /// 017f <packet len>.W <message>.?B
  7642. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7643. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7644. struct map_session_data *sd;
  7645. uint8 buf[256];
  7646. if( len == 0 )
  7647. {
  7648. return;
  7649. }
  7650. else if( len > sizeof(buf)-5 )
  7651. {
  7652. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7653. len = sizeof(buf)-5;
  7654. }
  7655. WBUFW(buf, 0) = 0x17f;
  7656. WBUFW(buf, 2) = len + 5;
  7657. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7658. if ((sd = guild_getavailablesd(g)) != NULL)
  7659. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7660. }
  7661. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7662. /// 0171 <inviter account id>.L <guild name>.24B
  7663. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7664. {
  7665. int fd;
  7666. nullpo_retv(sd);
  7667. fd=sd->fd;
  7668. WFIFOHEAD(fd,packet_len(0x171));
  7669. WFIFOW(fd,0)=0x171;
  7670. WFIFOL(fd,2)=account_id;
  7671. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7672. WFIFOSET(fd,packet_len(0x171));
  7673. }
  7674. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7675. /// 0173 <answer>.B
  7676. /// answer:
  7677. /// 0 = Already allied.
  7678. /// 1 = You rejected the offer.
  7679. /// 2 = You accepted the offer.
  7680. /// 3 = They have too any alliances.
  7681. /// 4 = You have too many alliances.
  7682. /// 5 = Alliances are disabled.
  7683. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7684. {
  7685. int fd;
  7686. nullpo_retv(sd);
  7687. fd=sd->fd;
  7688. WFIFOHEAD(fd,packet_len(0x173));
  7689. WFIFOW(fd,0)=0x173;
  7690. WFIFOL(fd,2)=flag;
  7691. WFIFOSET(fd,packet_len(0x173));
  7692. }
  7693. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7694. /// 0184 <other guild id>.L <relation>.L
  7695. /// relation:
  7696. /// 0 = Ally
  7697. /// 1 = Enemy
  7698. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7699. {
  7700. int fd;
  7701. nullpo_retv(sd);
  7702. fd = sd->fd;
  7703. if (fd <= 0)
  7704. return;
  7705. WFIFOHEAD(fd,packet_len(0x184));
  7706. WFIFOW(fd,0)=0x184;
  7707. WFIFOL(fd,2)=guild_id;
  7708. WFIFOL(fd,6)=flag;
  7709. WFIFOSET(fd,packet_len(0x184));
  7710. }
  7711. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7712. /// 0181 <result>.B
  7713. /// result:
  7714. /// 0 = Antagonist has been set.
  7715. /// 1 = Guild has too many Antagonists.
  7716. /// 2 = Already set as an Antagonist.
  7717. /// 3 = Antagonists are disabled.
  7718. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7719. {
  7720. int fd;
  7721. nullpo_retv(sd);
  7722. fd=sd->fd;
  7723. WFIFOHEAD(fd,packet_len(0x181));
  7724. WFIFOW(fd,0)=0x181;
  7725. WFIFOB(fd,2)=flag;
  7726. WFIFOSET(fd,packet_len(0x181));
  7727. }
  7728. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7729. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7730. /*
  7731. void clif_guild_allianceadded(struct guild *g,int idx)
  7732. {
  7733. unsigned char buf[64];
  7734. WBUFW(buf,0)=0x185;
  7735. WBUFL(buf,2)=g->alliance[idx].opposition;
  7736. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7737. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7738. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7739. }
  7740. */
  7741. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7742. /// 015e <reason>.L
  7743. /// 0 = success
  7744. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7745. /// 2 = there are still members in the guild
  7746. void clif_guild_broken(struct map_session_data *sd,int flag)
  7747. {
  7748. int fd;
  7749. nullpo_retv(sd);
  7750. fd=sd->fd;
  7751. WFIFOHEAD(fd,packet_len(0x15e));
  7752. WFIFOW(fd,0)=0x15e;
  7753. WFIFOL(fd,2)=flag;
  7754. WFIFOSET(fd,packet_len(0x15e));
  7755. }
  7756. /// Displays emotion on an object (ZC_EMOTION).
  7757. /// 00c0 <id>.L <type>.B
  7758. /// type:
  7759. /// enum emotion_type
  7760. void clif_emotion(struct block_list *bl,int type)
  7761. {
  7762. unsigned char buf[8];
  7763. nullpo_retv(bl);
  7764. WBUFW(buf,0)=0xc0;
  7765. WBUFL(buf,2)=bl->id;
  7766. WBUFB(buf,6)=type;
  7767. clif_send(buf,packet_len(0xc0),bl,AREA);
  7768. }
  7769. /// Displays the contents of a talkiebox trap.
  7770. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7771. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7772. nullpo_retv( bl );
  7773. nullpo_retv( talkie );
  7774. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7775. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7776. p.aid = bl->id;
  7777. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7778. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7779. }
  7780. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7781. /// 01ea <id>.L
  7782. void clif_wedding_effect(struct block_list *bl)
  7783. {
  7784. unsigned char buf[6];
  7785. nullpo_retv(bl);
  7786. WBUFW(buf,0) = 0x1ea;
  7787. WBUFL(buf,2) = bl->id;
  7788. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7789. }
  7790. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7791. /// 01e6 <partner name>.24B
  7792. void clif_callpartner(struct map_session_data *sd)
  7793. {
  7794. unsigned char buf[26];
  7795. nullpo_retv(sd);
  7796. WBUFW(buf,0) = 0x1e6;
  7797. if( sd->status.partner_id ) {
  7798. const char *p = map_charid2nick(sd->status.partner_id);
  7799. struct map_session_data *p_sd = pc_get_partner(sd);
  7800. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7801. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7802. else
  7803. WBUFB(buf,2) = 0;
  7804. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7805. WBUFB(buf,2) = 0;
  7806. }
  7807. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7808. }
  7809. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7810. /// 01e4
  7811. /// This packet while still implemented by the client is no longer being officially used.
  7812. /*
  7813. void clif_marriage_process(struct map_session_data *sd)
  7814. {
  7815. int fd;
  7816. nullpo_retv(sd);
  7817. fd=sd->fd;
  7818. WFIFOHEAD(fd,packet_len(0x1e4));
  7819. WFIFOW(fd,0)=0x1e4;
  7820. WFIFOSET(fd,packet_len(0x1e4));
  7821. }
  7822. */
  7823. /// Notice of divorce (ZC_DIVORCE).
  7824. /// 0205 <partner name>.24B
  7825. void clif_divorced(struct map_session_data* sd, const char* name)
  7826. {
  7827. int fd;
  7828. nullpo_retv(sd);
  7829. fd=sd->fd;
  7830. WFIFOHEAD(fd,packet_len(0x205));
  7831. WFIFOW(fd,0)=0x205;
  7832. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7833. WFIFOSET(fd, packet_len(0x205));
  7834. }
  7835. /// Marriage proposal (ZC_REQ_COUPLE).
  7836. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7837. /// This packet while still implemented by the client is no longer being officially used.
  7838. /*
  7839. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7840. {
  7841. nullpo_retv(sd);
  7842. WFIFOHEAD(fd,packet_len(0x1e2));
  7843. WFIFOW(fd,0) = 0x1e2;
  7844. WFIFOL(fd,2) = ssd->status.account_id;
  7845. WFIFOL(fd,6) = ssd->status.char_id;
  7846. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7847. WFIFOSET(fd, packet_len(0x1e2));
  7848. }
  7849. */
  7850. /*==========================================
  7851. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7852. *------------------------------------------*/
  7853. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7854. {
  7855. unsigned char buf[256];
  7856. if( len == 0 ) {
  7857. return;
  7858. } else if( len > sizeof(buf)-5 ) {
  7859. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7860. len = sizeof(buf)-5;
  7861. }
  7862. WBUFW(buf, 0) = 0x17f;
  7863. WBUFW(buf, 2) = len + 5;
  7864. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7865. clif_send(buf, WBUFW(buf,2), src, target);
  7866. }
  7867. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7868. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7869. /// 00cd <result>.B
  7870. /// result:
  7871. /// 0 = failure
  7872. /// 1 = success
  7873. void clif_GM_kickack(struct map_session_data *sd, int id)
  7874. {
  7875. int fd;
  7876. nullpo_retv(sd);
  7877. fd = sd->fd;
  7878. WFIFOHEAD(fd,packet_len(0xcd));
  7879. WFIFOW(fd,0) = 0xcd;
  7880. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7881. WFIFOSET(fd, packet_len(0xcd));
  7882. }
  7883. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7884. {
  7885. int fd;
  7886. nullpo_retv(tsd);
  7887. fd = tsd->fd;
  7888. if (sd == NULL)
  7889. tsd->state.keepshop = true;
  7890. if (fd > 0)
  7891. clif_authfail_fd(fd, 15);
  7892. else
  7893. map_quit(tsd);
  7894. if (sd)
  7895. clif_GM_kickack(sd, tsd->status.account_id);
  7896. }
  7897. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7898. /// 014a <result>.L
  7899. /// result:
  7900. /// 0 = "A manner point has been successfully aligned."
  7901. /// 1 = MP_FAILURE_EXHAUST
  7902. /// 2 = MP_FAILURE_ALREADY_GIVING
  7903. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7904. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7905. /// 5 = "You got a good point from %s."
  7906. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7907. {
  7908. int fd;
  7909. nullpo_retv(sd);
  7910. fd = sd->fd;
  7911. WFIFOHEAD(fd,packet_len(0x14a));
  7912. WFIFOW(fd,0) = 0x14a;
  7913. WFIFOL(fd,2) = type;
  7914. WFIFOSET(fd, packet_len(0x14a));
  7915. }
  7916. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7917. /// 014b <type>.B <GM name>.24B
  7918. /// type:
  7919. /// 0 = positive (unmute)
  7920. /// 1 = negative (mute)
  7921. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7922. {
  7923. int fd;
  7924. nullpo_retv(sd);
  7925. nullpo_retv(tsd);
  7926. fd = tsd->fd;
  7927. WFIFOHEAD(fd,packet_len(0x14b));
  7928. WFIFOW(fd,0) = 0x14b;
  7929. WFIFOB(fd,2) = type;
  7930. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7931. WFIFOSET(fd, packet_len(0x14b));
  7932. }
  7933. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7934. /// 00d1 <type>.B <result>.B
  7935. /// type:
  7936. /// 0 = /ex (deny)
  7937. /// 1 = /in (allow)
  7938. /// result:
  7939. /// 0 = success
  7940. /// 1 = failure
  7941. /// 2 = too many blocks
  7942. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7943. {
  7944. int fd;
  7945. nullpo_retv(sd);
  7946. fd=sd->fd;
  7947. WFIFOHEAD(fd,packet_len(0xd1));
  7948. WFIFOW(fd,0)=0xd1;
  7949. WFIFOB(fd,2)=type;
  7950. WFIFOB(fd,3)=flag;
  7951. WFIFOSET(fd,packet_len(0xd1));
  7952. }
  7953. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7954. /// 00d2 <type>.B <result>.B
  7955. /// type:
  7956. /// 0 = /exall (deny)
  7957. /// 1 = /inall (allow)
  7958. /// result:
  7959. /// 0 = success
  7960. /// 1 = failure
  7961. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7962. {
  7963. int fd;
  7964. nullpo_retv(sd);
  7965. fd=sd->fd;
  7966. WFIFOHEAD(fd,packet_len(0xd2));
  7967. WFIFOW(fd,0)=0xd2;
  7968. WFIFOB(fd,2)=type;
  7969. WFIFOB(fd,3)=flag;
  7970. WFIFOSET(fd,packet_len(0xd2));
  7971. }
  7972. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7973. /// 07fe <bgm>.24B
  7974. void clif_playBGM(struct map_session_data* sd, const char* name)
  7975. {
  7976. int fd;
  7977. nullpo_retv(sd);
  7978. fd = sd->fd;
  7979. WFIFOHEAD(fd,packet_len(0x7fe));
  7980. WFIFOW(fd,0) = 0x7fe;
  7981. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7982. WFIFOSET(fd,packet_len(0x7fe));
  7983. }
  7984. /// Plays/stops a wave sound (ZC_SOUND).
  7985. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7986. /// file name:
  7987. /// relative to data\wav
  7988. /// act:
  7989. /// 0 = play (once)
  7990. /// 1 = play (repeat, does not work)
  7991. /// 2 = stops all sound instances of file name (does not work)
  7992. /// term:
  7993. /// unknown purpose, only relevant to act = 1
  7994. /// npc id:
  7995. /// The accustic direction of the sound is determined by the
  7996. /// relative position of the NPC to the player (3D sound).
  7997. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7998. {
  7999. int fd;
  8000. nullpo_retv(sd);
  8001. nullpo_retv(bl);
  8002. fd = sd->fd;
  8003. WFIFOHEAD(fd,packet_len(0x1d3));
  8004. WFIFOW(fd,0) = 0x1d3;
  8005. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8006. WFIFOB(fd,26) = type;
  8007. WFIFOL(fd,27) = 0;
  8008. WFIFOL(fd,31) = bl->id;
  8009. WFIFOSET(fd,packet_len(0x1d3));
  8010. }
  8011. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8012. {
  8013. unsigned char buf[40];
  8014. nullpo_retv(bl);
  8015. WBUFW(buf,0) = 0x1d3;
  8016. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8017. WBUFB(buf,26) = type;
  8018. WBUFL(buf,27) = 0;
  8019. WBUFL(buf,31) = bl->id;
  8020. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8021. }
  8022. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8023. /// 01f3 <id>.L <effect id>.L
  8024. /// effect id:
  8025. /// @see doc/effect_list.txt
  8026. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8027. {
  8028. unsigned char buf[24];
  8029. nullpo_retv(bl);
  8030. memset(buf, 0, packet_len(0x1f3));
  8031. WBUFW(buf,0) = 0x1f3;
  8032. WBUFL(buf,2) = bl->id;
  8033. WBUFL(buf,6) = type;
  8034. clif_send(buf, packet_len(0x1f3), bl, target);
  8035. if (disguised(bl)) {
  8036. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8037. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8038. }
  8039. }
  8040. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8041. {
  8042. WFIFOHEAD(fd,10);
  8043. WFIFOW(fd,0) = 0x1f3;
  8044. WFIFOL(fd,2) = bl->id;
  8045. WFIFOL(fd,6) = type;
  8046. WFIFOSET(fd,10);
  8047. }
  8048. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8049. /// 0284 <id>.L <effect id>.L <num data>.L
  8050. /// effect id:
  8051. /// @see doc/effect_list.txt
  8052. /// num data:
  8053. /// effect-dependent value
  8054. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8055. {
  8056. uint8 buf[14];
  8057. WBUFW(buf,0) = 0x284;
  8058. WBUFL(buf,2) = bl->id;
  8059. WBUFL(buf,6) = effect_id;
  8060. WBUFL(buf,10) = num;
  8061. clif_send(buf, packet_len(0x284), bl, target);
  8062. if( disguised(bl) )
  8063. {
  8064. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8065. clif_send(buf, packet_len(0x284), bl, SELF);
  8066. }
  8067. }
  8068. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8069. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8070. 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) {
  8071. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8072. uint8 buf[CHAT_SIZE_MAX];
  8073. nullpo_retv(bl);
  8074. if (msg_len > sizeof(buf) - 12) {
  8075. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8076. msg_len = sizeof(buf) - 12;
  8077. }
  8078. if (rgb2bgr)
  8079. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8080. WBUFW(buf,0) = 0x2C1;
  8081. WBUFW(buf,2) = msg_len + 12;
  8082. WBUFL(buf,4) = bl->id;
  8083. WBUFL(buf,8) = color;
  8084. memcpy(WBUFCP(buf,12), msg, msg_len);
  8085. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8086. }
  8087. /**
  8088. * Notifies the client that the storage window is still open
  8089. *
  8090. * Should only be used in cases where the client closed the
  8091. * storage window without server's consent
  8092. */
  8093. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8094. // Notify the client that the storage is open
  8095. if( sd->state.storage_flag == 1 ) {
  8096. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8097. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8098. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8099. }
  8100. // Notify the client that the gstorage is open otherwise it will
  8101. // remain locked forever and nobody will be able to access it
  8102. if( sd->state.storage_flag == 2 ) {
  8103. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8104. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8105. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8106. else {
  8107. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8108. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8109. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8110. }
  8111. }
  8112. }
  8113. // refresh the client's screen, getting rid of any effects
  8114. void clif_refresh(struct map_session_data *sd)
  8115. {
  8116. nullpo_retv(sd);
  8117. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8118. clif_inventorylist(sd);
  8119. clif_equipswitch_list(sd);
  8120. if(pc_iscarton(sd)) {
  8121. clif_cartlist(sd);
  8122. clif_updatestatus(sd,SP_CARTINFO);
  8123. }
  8124. clif_updatestatus(sd,SP_WEIGHT);
  8125. clif_updatestatus(sd,SP_MAXWEIGHT);
  8126. clif_updatestatus(sd,SP_STR);
  8127. clif_updatestatus(sd,SP_AGI);
  8128. clif_updatestatus(sd,SP_VIT);
  8129. clif_updatestatus(sd,SP_INT);
  8130. clif_updatestatus(sd,SP_DEX);
  8131. clif_updatestatus(sd,SP_LUK);
  8132. if (sd->spiritball)
  8133. clif_spiritball_single(sd->fd, sd);
  8134. if (sd->sc.data[SC_MILLENNIUMSHIELD])
  8135. clif_millenniumshield_single(sd->fd, sd);
  8136. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8137. clif_spiritcharm_single(sd->fd, sd);
  8138. if (sd->soulball)
  8139. clif_soulball_single(sd->fd, sd);
  8140. if (sd->vd.cloth_color)
  8141. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8142. if (sd->vd.body_style)
  8143. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8144. if(hom_is_active(sd->hd))
  8145. clif_send_homdata(sd,SP_ACK,0);
  8146. if( sd->md ) {
  8147. clif_mercenary_info(sd);
  8148. clif_mercenary_skillblock(sd);
  8149. }
  8150. if( sd->ed )
  8151. clif_elemental_info(sd);
  8152. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8153. clif_weather_check(sd);
  8154. if( sd->chatID )
  8155. chat_leavechat(sd,0);
  8156. if( sd->state.vending )
  8157. clif_openvending(sd, sd->bl.id, sd->vending);
  8158. if( pc_issit(sd) )
  8159. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8160. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8161. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8162. else
  8163. clif_changed_dir(&sd->bl, SELF);
  8164. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8165. //Issue #2143
  8166. //Cancel Trading State
  8167. if (sd->state.trading)
  8168. trade_tradecancel(sd);
  8169. //Cancel Buying/Selling State
  8170. if (sd->state.buyingstore)
  8171. buyingstore_close(sd);
  8172. mail_clear(sd);
  8173. clif_loadConfirm( sd );
  8174. if( disguised(&sd->bl) ) {/* refresh-da */
  8175. short disguise = sd->disguise;
  8176. pc_disguise(sd, 0);
  8177. pc_disguise(sd, disguise);
  8178. }
  8179. clif_refresh_storagewindow(sd);
  8180. }
  8181. /// Updates the object's (bl) name on client.
  8182. /// Used to update when a char leaves a party/guild. [Skotlex]
  8183. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8184. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8185. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8186. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8187. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8188. nullpo_retv( src );
  8189. nullpo_retv( bl );
  8190. switch( bl->type ){
  8191. case BL_PC: {
  8192. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8193. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8194. packet.gid = bl->id;
  8195. map_session_data *sd = (map_session_data *)bl;
  8196. //Requesting your own "shadow" name. [Skotlex]
  8197. if( src == bl && target == SELF && sd->disguise ){
  8198. packet.gid = -bl->id;
  8199. }
  8200. if( sd->fakename[0] ) {
  8201. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8202. clif_send( &packet, sizeof(packet), src, target );
  8203. return;
  8204. }
  8205. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8206. party_data *p = nullptr;
  8207. if( sd->status.party_id ){
  8208. p = party_search( sd->status.party_id );
  8209. }
  8210. // do not display party unless the player is also in a guild
  8211. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8212. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8213. }
  8214. if( sd->guild ){
  8215. int position;
  8216. // Will get the position of the guild the player is in
  8217. position = guild_getposition( sd );
  8218. safestrncpy( packet.guild_name, sd->guild->name, NAME_LENGTH );
  8219. safestrncpy( packet.position_name, sd->guild->position[position].name, NAME_LENGTH );
  8220. }else if( sd->clan ){
  8221. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8222. }
  8223. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8224. packet.title_id = sd->status.title_id; // Title ID
  8225. #endif
  8226. clif_send(&packet, sizeof(packet), src, target);
  8227. }
  8228. break;
  8229. //[blackhole89]
  8230. case BL_HOM:
  8231. case BL_MER:
  8232. case BL_PET:
  8233. case BL_NPC:
  8234. case BL_ELEM: {
  8235. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8236. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8237. packet.gid = bl->id;
  8238. switch (bl->type) {
  8239. case BL_HOM:
  8240. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8241. break;
  8242. case BL_MER:
  8243. memcpy(packet.name, ((TBL_MER *)bl)->db->name, NAME_LENGTH);
  8244. break;
  8245. case BL_PET:
  8246. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8247. break;
  8248. case BL_NPC:
  8249. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8250. break;
  8251. case BL_ELEM:
  8252. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name, NAME_LENGTH);
  8253. break;
  8254. }
  8255. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8256. unit_data *ud = unit_bl2ud(bl);
  8257. if (ud != nullptr) {
  8258. memcpy(packet.title, ud->title, NAME_LENGTH);
  8259. packet.groupId = ud->group_id;
  8260. }
  8261. #endif
  8262. clif_send(&packet, sizeof(packet), src, target);
  8263. }
  8264. break;
  8265. case BL_MOB: {
  8266. mob_data *md = (mob_data *)bl;
  8267. if( md->guardian_data && md->guardian_data->guild_id ){
  8268. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8269. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8270. packet.gid = bl->id;
  8271. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8272. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8273. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8274. clif_send(&packet, sizeof(packet), src, target);
  8275. }else if( battle_config.show_mob_info ){
  8276. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8277. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8278. packet.gid = bl->id;
  8279. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8280. char mobhp[50], *str_p = mobhp;
  8281. if( battle_config.show_mob_info&4 ){
  8282. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8283. }
  8284. if( battle_config.show_mob_info&1 ){
  8285. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8286. }
  8287. if( battle_config.show_mob_info&2 ){
  8288. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8289. }
  8290. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8291. if( str_p != mobhp ){
  8292. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8293. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8294. }
  8295. clif_send(&packet, sizeof(packet), src, target);
  8296. } else {
  8297. PACKET_ZC_ACK_REQNAME_TITLE packet = { 0 };
  8298. packet.packet_id = HEADER_ZC_ACK_REQNAME_TITLE;
  8299. packet.gid = bl->id;
  8300. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8301. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8302. unit_data *ud = unit_bl2ud(bl);
  8303. if (ud != nullptr) {
  8304. memcpy(packet.title, ud->title, NAME_LENGTH);
  8305. packet.groupId = ud->group_id;
  8306. }
  8307. #endif
  8308. clif_send(&packet, sizeof(packet), src, target);
  8309. }
  8310. }
  8311. break;
  8312. case BL_CHAT:
  8313. case BL_SKILL:
  8314. // Newer clients request this, but do not need an answer
  8315. return;
  8316. default:
  8317. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8318. return;
  8319. }
  8320. }
  8321. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8322. /// 01ff <id>.L <x>.W <y>.W
  8323. ///
  8324. /// Visually moves(instant) a character to x,y. The char moves even
  8325. /// when the target cell isn't walkable. If the char is sitting it
  8326. /// stays that way.
  8327. void clif_slide(struct block_list *bl, int x, int y)
  8328. {
  8329. unsigned char buf[10];
  8330. nullpo_retv(bl);
  8331. WBUFW(buf, 0) = 0x01ff;
  8332. WBUFL(buf, 2) = bl->id;
  8333. WBUFW(buf, 6) = x;
  8334. WBUFW(buf, 8) = y;
  8335. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8336. if( disguised(bl) )
  8337. {
  8338. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8339. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8340. }
  8341. }
  8342. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8343. /// 008d <packet len>.W <id>.L <message>.?B
  8344. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8345. {
  8346. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8347. int len_mes = strlen(mes)+1; //Account for \0
  8348. if (len_mes > sizeof(buf)-8) {
  8349. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8350. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8351. }
  8352. // send message to others
  8353. if (flag == AREA) {
  8354. WBUFW(buf,0) = 0x8d;
  8355. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8356. WBUFL(buf,4) = bl->id;
  8357. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8358. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8359. }
  8360. // send back message to the speaker
  8361. if( bl->type == BL_PC ) {
  8362. WBUFW(buf,0) = 0x8e;
  8363. WBUFW(buf, 2) = len_mes + 4;
  8364. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8365. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8366. }
  8367. }
  8368. /*==========================
  8369. * Minimap fix [Kevin]
  8370. * Remove dot from minimap
  8371. *--------------------------*/
  8372. void clif_party_xy_remove(struct map_session_data *sd)
  8373. {
  8374. unsigned char buf[16];
  8375. nullpo_retv(sd);
  8376. WBUFW(buf,0)=0x107;
  8377. WBUFL(buf,2)=sd->status.account_id;
  8378. WBUFW(buf,6)=-1;
  8379. WBUFW(buf,8)=-1;
  8380. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8381. }
  8382. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8383. /// 0215 <msg id>.L
  8384. /// msg id:
  8385. /// 0x15 = End all negative status (PA_GOSPEL)
  8386. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8387. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8388. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8389. /// 0x19 = All stats +20 (PA_GOSPEL)
  8390. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8391. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8392. /// 0x1e = DEF +25% (PA_GOSPEL)
  8393. /// 0x1f = ATK +100% (PA_GOSPEL)
  8394. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8395. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8396. /// ? = nothing
  8397. void clif_gospel_info(struct map_session_data *sd, int type)
  8398. {
  8399. int fd=sd->fd;
  8400. WFIFOHEAD(fd,packet_len(0x215));
  8401. WFIFOW(fd,0)=0x215;
  8402. WFIFOL(fd,2)=type;
  8403. WFIFOSET(fd, packet_len(0x215));
  8404. }
  8405. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8406. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8407. /// result:
  8408. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8409. /// star:
  8410. /// 0 = Place of the Sun
  8411. /// 1 = Place of the Moon
  8412. /// 2 = Place of the Stars
  8413. /// 1 = Star Gladiator %s's %s: <mapname>
  8414. /// star:
  8415. /// 0 = Place of the Sun
  8416. /// 1 = Place of the Moon
  8417. /// 2 = Place of the Stars
  8418. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8419. /// star:
  8420. /// 0 = Target of the Sun
  8421. /// 1 = Target of the Moon
  8422. /// 2 = Target of the Stars
  8423. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8424. /// star:
  8425. /// 0 = Monster of the Sun
  8426. /// 1 = Monster of the Moon
  8427. /// 2 = Monster of the Stars
  8428. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8429. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8430. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8431. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8432. /// 40 = Target HP : <monster_id used as HP>
  8433. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8434. {
  8435. int fd = sd->fd;
  8436. WFIFOHEAD(fd,packet_len(0x20e));
  8437. WFIFOW(fd,0) = 0x20e;
  8438. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8439. WFIFOL(fd,26) = monster_id;
  8440. WFIFOB(fd,30) = star;
  8441. WFIFOB(fd,31) = result;
  8442. WFIFOSET(fd,packet_len(0x20e));
  8443. }
  8444. /*==========================================
  8445. * Info about Star Glaldiator save map [Komurka]
  8446. * type: 1: Information, 0: Map registered
  8447. *------------------------------------------*/
  8448. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8449. {
  8450. char mapname[MAP_NAME_LENGTH_EXT];
  8451. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8452. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8453. }
  8454. /*==========================================
  8455. * Info about Star Glaldiator hate mob [Komurka]
  8456. * type: 1: Register mob, 0: Information.
  8457. *------------------------------------------*/
  8458. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8459. {
  8460. if( pcdb_checkid(class_) ) {
  8461. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8462. } else if( mobdb_checkid(class_) ) {
  8463. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8464. } else {
  8465. 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);
  8466. }
  8467. }
  8468. /*==========================================
  8469. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8470. *------------------------------------------*/
  8471. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8472. {
  8473. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8474. }
  8475. /*==========================================
  8476. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8477. *------------------------------------------*/
  8478. void clif_feel_hate_reset(struct map_session_data *sd)
  8479. {
  8480. clif_starskill(sd, "", 0, 0, 30);
  8481. }
  8482. /// Send out reply to configuration change
  8483. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8484. /// type: see enum e_config_type
  8485. /// value:
  8486. /// false = disabled
  8487. /// true = enabled
  8488. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8489. int fd;
  8490. nullpo_retv(sd);
  8491. fd = sd->fd;
  8492. WFIFOHEAD(fd, packet_len(0x2d9));
  8493. WFIFOW(fd, 0) = 0x2d9;
  8494. WFIFOL(fd, 2) = type;
  8495. WFIFOL(fd, 6) = enabled;
  8496. WFIFOSET(fd, packet_len(0x2d9));
  8497. }
  8498. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8499. /// 02da <open equip window>.B
  8500. /// open equip window:
  8501. /// 0 = disabled
  8502. /// 1 = enabled
  8503. void clif_equipcheckbox(struct map_session_data* sd)
  8504. {
  8505. int fd;
  8506. nullpo_retv(sd);
  8507. fd = sd->fd;
  8508. WFIFOHEAD(fd, packet_len(0x2da));
  8509. WFIFOW(fd, 0) = 0x2da;
  8510. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8511. WFIFOSET(fd, packet_len(0x2da));
  8512. }
  8513. /// Sends info about a player's equipped items.
  8514. /// 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)
  8515. /// 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)
  8516. /// 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)
  8517. /// 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)
  8518. /// 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)
  8519. /// 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)
  8520. void clif_viewequip_ack( struct map_session_data* sd, struct map_session_data* tsd ){
  8521. nullpo_retv( sd );
  8522. nullpo_retv( tsd );
  8523. struct packet_viewequip_ack packet;
  8524. int equip = 0;
  8525. for( int i = 0; i < EQI_MAX; i++ ){
  8526. int k = tsd->equip_index[i];
  8527. if( k >= 0 ){
  8528. if( tsd->inventory.u.items_inventory[k].nameid <= 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8529. continue;
  8530. }
  8531. if( !tsd->inventory.u.items_inventory[k].equip ){
  8532. continue;
  8533. }
  8534. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8535. continue;
  8536. }
  8537. clif_item_equip( client_index( k ), &packet.list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8538. }
  8539. }
  8540. packet.PacketType = viewequipackType;
  8541. packet.PacketLength = ( sizeof( packet ) - sizeof( packet.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  8542. safestrncpy( packet.characterName, tsd->status.name, NAME_LENGTH );
  8543. packet.job = tsd->status.class_;
  8544. packet.head = tsd->vd.hair_style;
  8545. packet.accessory = tsd->vd.head_bottom;
  8546. packet.accessory2 = tsd->vd.head_mid;
  8547. packet.accessory3 = tsd->vd.head_top;
  8548. #if PACKETVER >= 20110111
  8549. packet.robe = tsd->vd.robe;
  8550. #endif
  8551. packet.headpalette = tsd->vd.hair_color;
  8552. packet.bodypalette = tsd->vd.cloth_color;
  8553. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8554. packet.body2 = tsd->vd.body_style;
  8555. #endif
  8556. packet.sex = tsd->vd.sex;
  8557. clif_send( &packet, packet.PacketLength, &sd->bl, SELF );
  8558. }
  8559. /// Display msgstringtable.txt string (ZC_MSG).
  8560. /// 0291 <message>.W
  8561. void clif_msg(struct map_session_data* sd, unsigned short id)
  8562. {
  8563. int fd;
  8564. nullpo_retv(sd);
  8565. fd = sd->fd;
  8566. WFIFOHEAD(fd, packet_len(0x291));
  8567. WFIFOW(fd, 0) = 0x291;
  8568. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8569. WFIFOSET(fd, packet_len(0x291));
  8570. }
  8571. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8572. /// 0x7e2 <message>.W <value>.L
  8573. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8574. {
  8575. int fd = sd->fd;
  8576. WFIFOHEAD(fd, packet_len(0x7e2));
  8577. WFIFOW(fd,0) = 0x7e2;
  8578. WFIFOW(fd,2) = id;
  8579. WFIFOL(fd,4) = value;
  8580. WFIFOSET(fd, packet_len(0x7e2));
  8581. }
  8582. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8583. /// 07e6 <skill id>.W <msg id>.L
  8584. ///
  8585. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8586. /// "[SkillName] Message"
  8587. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8588. {
  8589. int fd = sd->fd;
  8590. WFIFOHEAD(fd, packet_len(0x7e6));
  8591. WFIFOW(fd,0) = 0x7e6;
  8592. WFIFOW(fd,2) = skill_id;
  8593. WFIFOL(fd,4) = msg_id;
  8594. WFIFOSET(fd, packet_len(0x7e6));
  8595. }
  8596. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8597. /// 09cd <msg id>.W <color>.L
  8598. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8599. nullpo_retv(sd);
  8600. int fd = sd->fd;
  8601. WFIFOHEAD(fd, packet_len(0x9cd));
  8602. WFIFOW(fd, 0) = 0x9cd;
  8603. WFIFOW(fd, 2) = msg_id;
  8604. WFIFOL(fd, 4) = color;
  8605. WFIFOSET(fd, packet_len(0x9cd));
  8606. }
  8607. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8608. /// Returns true if the packet was parsed successfully.
  8609. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8610. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8611. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8612. const char* seperator = " : ";
  8613. int fd;
  8614. struct s_packet_db* info;
  8615. uint16 packetLength, inputLength;
  8616. const char *input, *name, *message;
  8617. size_t nameLength, messageLength;
  8618. fd = sd->fd;
  8619. info = &packet_db[RFIFOW(fd,0)];
  8620. packetLength = RFIFOW(fd,info->pos[0]);
  8621. input = RFIFOCP(fd,info->pos[1]);
  8622. // basic structure check for the 4-byte header
  8623. if( packetLength < 4 ){
  8624. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8625. return false;
  8626. }else{
  8627. inputLength = packetLength - 4;
  8628. }
  8629. // process <name> part of the packet
  8630. if( whisperFormat ) {
  8631. // name has fixed width
  8632. if( inputLength < NAME_LENGTH + 1 ) {
  8633. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8634. return false;
  8635. }
  8636. name = input;
  8637. // validate name
  8638. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8639. // only restriction is that the name must be zero-terminated
  8640. if( name[nameLength] != '\0' ) {
  8641. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8642. return false;
  8643. }
  8644. message = input + NAME_LENGTH;
  8645. messageLength = inputLength - NAME_LENGTH;
  8646. }else{
  8647. // name and message are separated by ' : '
  8648. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8649. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8650. // check if there's enough data provided
  8651. if( inputLength < nameLength + seperatorLength + 1 ){
  8652. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8653. return false;
  8654. }
  8655. name = input;
  8656. // validate name
  8657. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8658. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8659. {
  8660. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8661. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8662. set_eof(sd->fd); // Just kick them out to correct it.
  8663. return false;
  8664. }
  8665. message = input + nameLength + seperatorLength;
  8666. messageLength = inputLength - nameLength - seperatorLength;
  8667. }
  8668. #if PACKETVER < 20151001
  8669. // the declared length must match real length
  8670. if( messageLength != strnlen(message, messageLength)+1 ) {
  8671. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8672. return false;
  8673. }
  8674. // verify <message> part of the packet
  8675. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8676. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8677. return false;
  8678. }
  8679. #else
  8680. // No zero termination anymore
  8681. messageLength += 1;
  8682. #endif
  8683. // messages mustn't be too long
  8684. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8685. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8686. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8687. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8688. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8689. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8690. return false;
  8691. }
  8692. // If it is not a whisper message, set the name to the fakename of the player
  8693. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8694. strcpy( out_name, sd->fakename );
  8695. }else{
  8696. safestrncpy( out_name, name, nameLength + 1 );
  8697. }
  8698. safestrncpy( out_message, message, messageLength );
  8699. if( whisperFormat ){
  8700. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8701. out_full_message[nameLength] = '\0';
  8702. }else{
  8703. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8704. }
  8705. if( is_atcommand( fd, sd, out_message, 1 ) )
  8706. return false;
  8707. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8708. return false; //no "chatting" while muted.
  8709. if( battle_config.min_chat_delay ) { //[Skotlex]
  8710. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8711. return false;
  8712. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8713. }
  8714. if (battle_config.idletime_option&IDLE_CHAT)
  8715. sd->idletime = last_tick;
  8716. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8717. sd->idletime_hom = last_tick;
  8718. return true;
  8719. }
  8720. /**
  8721. * Displays a message if the player enters a PK Zone (during pk_mode)
  8722. * @param sd: Player data
  8723. */
  8724. inline void clif_pk_mode_message(struct map_session_data * sd)
  8725. {
  8726. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8727. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8728. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8729. char output[CHAT_SIZE_MAX];
  8730. // 1504: You've entered a PK Zone (safe until level %d).
  8731. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8732. battle_config.pk_min_level);
  8733. clif_showscript(&sd->bl, output, SELF);
  8734. } else {
  8735. // 1503: You've entered a PK Zone.
  8736. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8737. }
  8738. }
  8739. return;
  8740. }
  8741. // ---------------------
  8742. // clif_parse_wanttoconnect
  8743. // ---------------------
  8744. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8745. // error codes:
  8746. // 0 - Success
  8747. // 1 - Unknown packet_ver
  8748. // 2 - Invalid account_id
  8749. // 3 - Invalid char_id
  8750. // 4 - Invalid login_id1 (reserved)
  8751. // 5 - Invalid client_tick (reserved)
  8752. // 6 - Invalid sex
  8753. // Only the first 'invalid' error that appears is used.
  8754. static int clif_parse_WantToConnection_sub(int fd)
  8755. {
  8756. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8757. unsigned short cmd;
  8758. //By default, start searching on the default one.
  8759. cmd = RFIFOW(fd, 0);
  8760. packet_len = RFIFOREST(fd);
  8761. // FIXME: If the packet is not received at once, this will FAIL.
  8762. // Figure out, when it happens, that only part of the packet is
  8763. // received, or fix the function to be able to deal with that
  8764. // case.
  8765. if( packet_len != packet_db[cmd].len )
  8766. return 1; /* wrong length */
  8767. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8768. return 2; /* invalid account_id */
  8769. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8770. return 3; /* invalid char_id */
  8771. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8772. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8773. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8774. return 6; /* invalid sex */
  8775. else
  8776. return 0;
  8777. }
  8778. /// Request to connect to map-server.
  8779. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8780. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8781. /// There are various variants of this packet, some of them have padding between fields.
  8782. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8783. {
  8784. struct block_list* bl;
  8785. struct auth_node* node;
  8786. int cmd, account_id, char_id, login_id1, sex, err;
  8787. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8788. if (sd) {
  8789. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8790. return;
  8791. }
  8792. cmd = RFIFOW(fd, 0);
  8793. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8794. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8795. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8796. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8797. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8798. err = clif_parse_WantToConnection_sub(fd);
  8799. if( err ){ // connection rejected
  8800. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8801. err == 1 ? "." :
  8802. err == 2 ? ", possibly for having an invalid account_id." :
  8803. err == 3 ? ", possibly for having an invalid char_id." :
  8804. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8805. err == 4 ? ", possibly for having an invalid login_id1." :
  8806. err == 5 ? ", possibly for having an invalid client_tick." :
  8807. */
  8808. err == 6 ? ", possibly for having an invalid sex." :
  8809. ". ERROR invalid error code"));
  8810. WFIFOHEAD(fd,packet_len(0x6a));
  8811. WFIFOW(fd,0) = 0x6a;
  8812. WFIFOB(fd,2) = err;
  8813. WFIFOSET(fd,packet_len(0x6a));
  8814. #ifdef DUMP_INVALID_PACKET
  8815. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8816. #endif
  8817. RFIFOSKIP(fd, RFIFOREST(fd));
  8818. set_eof(fd);
  8819. return;
  8820. }
  8821. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8822. clif_authfail_fd(fd,1);// server closed
  8823. return;
  8824. }
  8825. //Check for double login.
  8826. bl = map_id2bl(account_id);
  8827. if(bl && bl->type != BL_PC) {
  8828. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8829. WFIFOHEAD(fd,packet_len(0x6a));
  8830. WFIFOW(fd,0) = 0x6a;
  8831. WFIFOB(fd,2) = 3; // Rejected by server
  8832. WFIFOSET(fd,packet_len(0x6a));
  8833. set_eof(fd);
  8834. return;
  8835. }
  8836. if (bl ||
  8837. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8838. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8839. {
  8840. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8841. return;
  8842. }
  8843. CREATE(sd, TBL_PC, 1);
  8844. sd->fd = fd;
  8845. #ifdef PACKET_OBFUSCATION
  8846. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8847. #endif
  8848. session[fd]->session_data = sd;
  8849. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8850. #if PACKETVER < 20070521
  8851. WFIFOHEAD(fd,4);
  8852. WFIFOL(fd,0) = sd->bl.id;
  8853. WFIFOSET(fd,4);
  8854. #else
  8855. WFIFOHEAD(fd,packet_len(0x283));
  8856. WFIFOW(fd,0) = 0x283;
  8857. WFIFOL(fd,2) = sd->bl.id;
  8858. WFIFOSET(fd,packet_len(0x283));
  8859. #endif
  8860. chrif_authreq(sd,false);
  8861. }
  8862. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8863. /// 007d
  8864. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8865. {
  8866. bool guild_notice = false;
  8867. if(sd->bl.prev != NULL)
  8868. return;
  8869. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8870. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8871. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8872. sd->state.connect_new = 0;
  8873. return;
  8874. }
  8875. if (sd->state.rewarp) { //Rewarp player.
  8876. sd->state.rewarp = 0;
  8877. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8878. return;
  8879. }
  8880. sd->state.warping = 0;
  8881. // look
  8882. #if PACKETVER < 4
  8883. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8884. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8885. #else
  8886. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8887. #endif
  8888. pc_set_costume_view(sd);
  8889. if(sd->vd.cloth_color)
  8890. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8891. if(sd->vd.body_style)
  8892. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8893. // item
  8894. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8895. pc_checkitem(sd);
  8896. clif_equipswitch_list(sd);
  8897. // cart
  8898. if(pc_iscarton(sd)) {
  8899. clif_cartlist(sd);
  8900. clif_updatestatus(sd,SP_CARTINFO);
  8901. }
  8902. // weight
  8903. clif_updatestatus(sd,SP_WEIGHT);
  8904. clif_updatestatus(sd,SP_MAXWEIGHT);
  8905. // guild
  8906. // (needs to go before clif_spawn() to show guild emblems correctly)
  8907. if(sd->status.guild_id)
  8908. guild_send_memberinfoshort(sd,1);
  8909. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8910. if(battle_config.pc_invincible_time > 0) {
  8911. if(mapdata_flag_gvg(mapdata))
  8912. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8913. else
  8914. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8915. }
  8916. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8917. map_spawnmobs(sd->bl.m);
  8918. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8919. mapdata->users_pvp++;
  8920. }
  8921. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8922. // reset the callshop flag if the player changes map
  8923. sd->state.callshop = 0;
  8924. if(map_addblock(&sd->bl))
  8925. return;
  8926. clif_spawn(&sd->bl);
  8927. // Party
  8928. // (needs to go after clif_spawn() to show hp bars correctly)
  8929. if(sd->status.party_id) {
  8930. party_send_movemap(sd);
  8931. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8932. }
  8933. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8934. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8935. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8936. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8937. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8938. sd->pvp_rank = 0;
  8939. sd->pvp_lastusers = 0;
  8940. sd->pvp_point = 5;
  8941. sd->pvp_won = 0;
  8942. sd->pvp_lost = 0;
  8943. }
  8944. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8945. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8946. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8947. else if (mapdata->flag[MF_GVG_DUNGEON])
  8948. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8949. else if( mapdata_flag_gvg(mapdata) )
  8950. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8951. else
  8952. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8953. // info about nearby objects
  8954. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8955. 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);
  8956. // pet
  8957. if( sd->pd ) {
  8958. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8959. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8960. pet_return_egg( sd, sd->pd );
  8961. } else {
  8962. if(map_addblock(&sd->pd->bl))
  8963. return;
  8964. clif_spawn(&sd->pd->bl);
  8965. clif_send_petdata(sd,sd->pd,0,0);
  8966. clif_send_petstatus(sd);
  8967. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8968. }
  8969. }
  8970. //homunculus [blackhole89]
  8971. if( hom_is_active(sd->hd) ) {
  8972. if(map_addblock(&sd->hd->bl))
  8973. return;
  8974. clif_spawn(&sd->hd->bl);
  8975. clif_send_homdata(sd,SP_ACK,0);
  8976. clif_hominfo(sd,sd->hd,1);
  8977. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8978. clif_homskillinfoblock(sd);
  8979. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8980. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8981. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8982. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8983. }
  8984. if( sd->md ) {
  8985. if(map_addblock(&sd->md->bl))
  8986. return;
  8987. clif_spawn(&sd->md->bl);
  8988. clif_mercenary_info(sd);
  8989. clif_mercenary_skillblock(sd);
  8990. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8991. }
  8992. if( sd->ed ) {
  8993. if (map_addblock(&sd->ed->bl))
  8994. return;
  8995. clif_spawn(&sd->ed->bl);
  8996. clif_elemental_info(sd);
  8997. clif_elemental_updatestatus(sd,SP_HP);
  8998. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8999. clif_elemental_updatestatus(sd,SP_SP);
  9000. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9001. }
  9002. if(sd->state.connect_new) {
  9003. int lv;
  9004. guild_notice = true;
  9005. clif_skillinfoblock(sd);
  9006. clif_hotkeys_send(sd,0);
  9007. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9008. clif_hotkeys_send(sd,1);
  9009. #endif
  9010. clif_updatestatus(sd,SP_BASEEXP);
  9011. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9012. clif_updatestatus(sd,SP_JOBEXP);
  9013. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9014. clif_updatestatus(sd,SP_SKILLPOINT);
  9015. clif_initialstatus(sd);
  9016. if (sd->sc.option&OPTION_FALCON)
  9017. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9018. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9019. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9020. else if (sd->sc.option&OPTION_WUGRIDER)
  9021. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9022. else if (sd->sc.option&OPTION_MADOGEAR)
  9023. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106
  9024. clif_status_load( &sd->bl, EFST_MADOGEAR, 1 );
  9025. #else
  9026. clif_status_load( &sd->bl, EFST_RIDING, 1 );
  9027. #endif
  9028. else if (sd->sc.data[SC_ALL_RIDING])
  9029. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9030. if(sd->status.manner < 0)
  9031. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9032. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9033. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9034. if(sd->bl.m == sd->feel_map[0].m
  9035. || sd->bl.m == sd->feel_map[1].m
  9036. || sd->bl.m == sd->feel_map[2].m)
  9037. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9038. }
  9039. if(sd->pd && sd->pd->pet.intimate > 900)
  9040. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9041. if(hom_is_active(sd->hd))
  9042. hom_init_timers(sd->hd);
  9043. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9044. sd->state.night = 1;
  9045. clif_status_load(&sd->bl, EFST_SKE, 1);
  9046. }
  9047. // Notify everyone that this char logged in [Skotlex].
  9048. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9049. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9050. //Login Event
  9051. npc_script_event(sd, NPCE_LOGIN);
  9052. }
  9053. } else {
  9054. //For some reason the client "loses" these on warp/map-change.
  9055. clif_updatestatus(sd,SP_STR);
  9056. clif_updatestatus(sd,SP_AGI);
  9057. clif_updatestatus(sd,SP_VIT);
  9058. clif_updatestatus(sd,SP_INT);
  9059. clif_updatestatus(sd,SP_DEX);
  9060. clif_updatestatus(sd,SP_LUK);
  9061. // abort currently running script
  9062. sd->state.using_fake_npc = 0;
  9063. sd->state.menu_or_input = 0;
  9064. sd->npc_menu = 0;
  9065. if(sd->npc_id)
  9066. npc_event_dequeue(sd);
  9067. }
  9068. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9069. #if PACKETVER >= 20070918
  9070. clif_partyinvitationstate(sd);
  9071. clif_equipcheckbox(sd);
  9072. #endif
  9073. #if PACKETVER >= 20141008
  9074. if( battle_config.pet_autofeed_always ){
  9075. // Always send ON or OFF
  9076. if( sd->pd && battle_config.feature_pet_autofeed ){
  9077. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  9078. }else{
  9079. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  9080. }
  9081. }else{
  9082. // Only send when enabled
  9083. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9084. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9085. }
  9086. }
  9087. #endif
  9088. #if PACKETVER >= 20170920
  9089. if( battle_config.homunculus_autofeed_always ){
  9090. // Always send ON or OFF
  9091. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9092. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9093. }else{
  9094. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9095. }
  9096. }else{
  9097. // Only send when enabled
  9098. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9099. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9100. }
  9101. }
  9102. #endif
  9103. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9104. clif_guild_notice(sd); // Displays after VIP
  9105. guild_notice = false; // Do not display it twice
  9106. }
  9107. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9108. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9109. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9110. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9111. }
  9112. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9113. { //Display night.
  9114. if( !sd->state.night )
  9115. {
  9116. sd->state.night = 1;
  9117. clif_status_load(&sd->bl, EFST_SKE, 1);
  9118. }
  9119. }
  9120. else if( sd->state.night )
  9121. { //Clear night display.
  9122. sd->state.night = 0;
  9123. clif_status_load(&sd->bl, EFST_SKE, 0);
  9124. }
  9125. if( mapdata->flag[MF_BATTLEGROUND] )
  9126. {
  9127. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9128. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9129. clif_bg_updatescore_single(sd);
  9130. }
  9131. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9132. {
  9133. char output[128];
  9134. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9135. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9136. }
  9137. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9138. mapdata->hpmeter_visible++;
  9139. sd->state.hpmeter_visible = 1;
  9140. }
  9141. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9142. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9143. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9144. #ifdef VIP_ENABLE
  9145. if (!sd->state.connect_new &&
  9146. !sd->vip.disableshowrate &&
  9147. sd->state.pmap != sd->bl.m &&
  9148. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9149. )
  9150. {
  9151. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9152. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9153. }
  9154. #endif
  9155. // Instances do not need their own channels
  9156. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9157. channel_mjoin(sd); //join new map
  9158. clif_pk_mode_message(sd);
  9159. }
  9160. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9161. clif_guild_notice(sd); // Displays at end
  9162. }
  9163. mail_clear(sd);
  9164. /* Guild Aura Init */
  9165. if( sd->guild && sd->state.gmaster_flag ) {
  9166. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9167. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9168. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9169. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9170. }
  9171. if( sd->state.vending ) { /* show we have a vending */
  9172. clif_openvending(sd,sd->bl.id,sd->vending);
  9173. clif_showvendingboard(&sd->bl,sd->message,0);
  9174. }
  9175. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9176. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9177. npc_script_event(sd, NPCE_LOADMAP);
  9178. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9179. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9180. if (sd->sc.opt2) //Client loses these on warp.
  9181. clif_changeoption(&sd->bl);
  9182. 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)) {
  9183. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9184. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9185. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9186. }
  9187. clif_weather_check(sd);
  9188. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9189. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9190. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9191. else
  9192. sd->areanpc.clear();
  9193. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9194. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9195. pc_setdead(sd);
  9196. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9197. if(pc_isdead(sd))
  9198. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9199. else {
  9200. skill_usave_trigger(sd);
  9201. if (battle_config.spawn_direction)
  9202. clif_changed_dir(&sd->bl, SELF);
  9203. }
  9204. // Trigger skill effects if you appear standing on them
  9205. if(!battle_config.pc_invincible_time)
  9206. skill_unit_move(&sd->bl,gettick(),1);
  9207. pc_show_questinfo_reinit(sd);
  9208. pc_show_questinfo(sd);
  9209. #if PACKETVER >= 20150513
  9210. if( sd->mail.inbox.unread ){
  9211. clif_Mail_new(sd, 0, NULL, NULL);
  9212. }
  9213. #endif
  9214. sd->state.connect_new = 0;
  9215. sd->state.changemap = false;
  9216. }
  9217. /// Server's tick (ZC_NOTIFY_TIME).
  9218. /// 007f <time>.L
  9219. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9220. {
  9221. int fd = sd->fd;
  9222. WFIFOHEAD(fd,packet_len(0x7f));
  9223. WFIFOW(fd,0) = 0x7f;
  9224. WFIFOL(fd,2) = client_tick(time);
  9225. WFIFOSET(fd,packet_len(0x7f));
  9226. }
  9227. /// Request for server's tick.
  9228. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9229. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9230. /// There are various variants of this packet, some of them have padding between fields.
  9231. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9232. {
  9233. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9234. clif_notify_time(sd, gettick());
  9235. }
  9236. /// Sends hotkey bar.
  9237. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9238. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9239. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9240. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9241. void clif_hotkeys_send( struct map_session_data *sd, int tab ){
  9242. #ifdef HOTKEY_SAVING
  9243. nullpo_retv( sd );
  9244. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9245. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9246. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9247. if( tab == 0 ){
  9248. p.rotate = sd->status.hotkey_rowshift;
  9249. }else{
  9250. p.rotate = sd->status.hotkey_rowshift2;
  9251. }
  9252. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9253. p.tab = tab;
  9254. #endif
  9255. #endif
  9256. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9257. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9258. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9259. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9260. }
  9261. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9262. #endif
  9263. }
  9264. /// Request to update a position on the hotkey row bar
  9265. void clif_parse_HotkeyRowShift( int fd, struct map_session_data *sd ){
  9266. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9267. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9268. if( p->tab == 0 ){
  9269. sd->status.hotkey_rowshift = p->rowshift;
  9270. }else{
  9271. sd->status.hotkey_rowshift2 = p->rowshift;
  9272. }
  9273. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9274. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9275. sd->status.hotkey_rowshift = p->rowshift;
  9276. #endif
  9277. }
  9278. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9279. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9280. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9281. #ifdef HOTKEY_SAVING
  9282. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9283. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9284. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9285. if( idx >= MAX_HOTKEYS_DB ){
  9286. return;
  9287. }
  9288. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9289. sd->status.hotkeys[idx].id = p->hotkey.id;
  9290. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9291. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9292. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9293. const unsigned short idx = p->index;
  9294. if( idx >= MAX_HOTKEYS_DB ){
  9295. return;
  9296. }
  9297. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9298. sd->status.hotkeys[idx].id = p->hotkey.id;
  9299. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9300. #endif
  9301. #endif
  9302. }
  9303. /// Displays cast-like progress bar (ZC_PROGRESS).
  9304. /// 02f0 <color>.L <time>.L
  9305. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9306. {
  9307. int fd = sd->fd;
  9308. WFIFOHEAD(fd,packet_len(0x2f0));
  9309. WFIFOW(fd,0) = 0x2f0;
  9310. WFIFOL(fd,2) = color;
  9311. WFIFOL(fd,6) = second;
  9312. WFIFOSET(fd,packet_len(0x2f0));
  9313. }
  9314. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9315. /// 02f2
  9316. void clif_progressbar_abort(struct map_session_data * sd)
  9317. {
  9318. int fd = sd->fd;
  9319. WFIFOHEAD(fd,packet_len(0x2f2));
  9320. WFIFOW(fd,0) = 0x2f2;
  9321. WFIFOSET(fd,packet_len(0x2f2));
  9322. }
  9323. /// Notification from the client, that the progress bar has reached 100%.
  9324. /// 02f1 (CZ_PROGRESS)
  9325. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9326. // No progressbar active, ignore it
  9327. if( !sd->progressbar.npc_id ){
  9328. return;
  9329. }
  9330. int npc_id = sd->progressbar.npc_id;
  9331. bool closing = false;
  9332. // Check if the progress was canceled
  9333. if( gettick() < sd->progressbar.timeout && sd->st ){
  9334. closing = true;
  9335. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9336. // If a message window was open, offer a close button to the user
  9337. if( sd->st->mes_active ){
  9338. clif_scriptclose( sd, npc_id );
  9339. }
  9340. }
  9341. sd->progressbar.npc_id = 0;
  9342. sd->progressbar.timeout = 0;
  9343. sd->state.workinprogress = WIP_DISABLE_NONE;
  9344. npc_scriptcont(sd, npc_id, closing);
  9345. }
  9346. /// Displays cast-like progress bar on a NPC
  9347. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9348. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9349. #if PACKETVER >= 20130821
  9350. unsigned char buf[14];
  9351. if( nd->progressbar.timeout > 0 ){
  9352. WBUFW(buf,0) = 0x9d1;
  9353. WBUFL(buf,2) = nd->bl.id;
  9354. WBUFL(buf,6) = nd->progressbar.color;
  9355. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9356. if( sd ){
  9357. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9358. }else{
  9359. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9360. }
  9361. }
  9362. #endif
  9363. }
  9364. /// Request to walk to a certain position on the current map.
  9365. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9366. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9367. /// There are various variants of this packet, some of them have padding between fields.
  9368. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9369. {
  9370. short x, y;
  9371. if (pc_isdead(sd)) {
  9372. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9373. return;
  9374. }
  9375. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9376. ; //You CAN walk on this OPT1 value.
  9377. else if (sd->progressbar.npc_id) {
  9378. clif_progressbar_abort(sd);
  9379. return; // First walk attempt cancels the progress bar
  9380. } else if (pc_cant_act(sd))
  9381. return;
  9382. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9383. return;
  9384. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9385. //A move command one cell west is only valid if the target cell is free
  9386. if(battle_config.official_cell_stack_limit > 0
  9387. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9388. return;
  9389. // Cloaking wall check is actually updated when you click to process next movement
  9390. // not when you move each cell. This is official behaviour.
  9391. if (sd->sc.data[SC_CLOAKING])
  9392. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9393. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9394. pc_delinvincibletimer(sd);
  9395. //Set last idle time... [Skotlex]
  9396. if (battle_config.idletime_option&IDLE_WALK)
  9397. sd->idletime = last_tick;
  9398. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9399. sd->idletime_hom = last_tick;
  9400. unit_walktoxy(&sd->bl, x, y, 4);
  9401. }
  9402. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9403. /// 018b <result>.W
  9404. /// result:
  9405. /// 0 = disconnect (quit)
  9406. /// 1 = cannot disconnect (wait 10 seconds)
  9407. /// ? = ignored
  9408. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9409. {
  9410. int fd = sd->fd;
  9411. WFIFOHEAD(fd,packet_len(0x18b));
  9412. WFIFOW(fd,0) = 0x18b;
  9413. WFIFOW(fd,2) = result;
  9414. WFIFOSET(fd,packet_len(0x18b));
  9415. }
  9416. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9417. /// 018a <type>.W
  9418. /// type:
  9419. /// 0 = quit
  9420. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9421. {
  9422. /* Rovert's prevent logout option fixed [Valaris] */
  9423. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9424. 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] &&
  9425. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9426. {
  9427. set_eof(fd);
  9428. pc_damage_log_clear(sd,0);
  9429. clif_disconnect_ack(sd, 0);
  9430. } else {
  9431. clif_disconnect_ack(sd, 1);
  9432. }
  9433. }
  9434. /// Requesting unit's name.
  9435. /// 0094 <id>.L (CZ_REQNAME)
  9436. /// 0368 <id>.L (CZ_REQNAME2)
  9437. /// There are various variants of this packet, some of them have padding between fields.
  9438. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9439. {
  9440. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9441. struct block_list* bl;
  9442. //struct status_change *sc;
  9443. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9444. id = sd->bl.id;
  9445. bl = map_id2bl(id);
  9446. if( bl == NULL )
  9447. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9448. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9449. return; // Block namerequests past view range
  9450. // 'see people in GM hide' cheat detection
  9451. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9452. sc = status_get_sc(bl);
  9453. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9454. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9455. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9456. ) {
  9457. char gm_msg[256];
  9458. 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);
  9459. ShowWarning(gm_msg);
  9460. // information is sent to all online GMs
  9461. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9462. return;
  9463. }
  9464. */
  9465. clif_name(&sd->bl,bl,SELF);
  9466. }
  9467. /// Validates and processes global messages
  9468. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9469. /// There are various variants of this packet.
  9470. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9471. {
  9472. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9473. size_t length;
  9474. // validate packet and retrieve name and message
  9475. if( !clif_process_message(sd, false, name, message, output ) )
  9476. return;
  9477. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9478. channel_send(sd->gcbind,sd,message);
  9479. return;
  9480. }
  9481. // send message to others (using the send buffer for temp. storage)
  9482. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9483. length = strlen(output) + 1;
  9484. // send back message to the speaker
  9485. WFIFOHEAD(fd,4+length);
  9486. WFIFOW(fd,0) = 0x8e;
  9487. WFIFOW(fd,2) = (uint16)(4+length);
  9488. safestrncpy(WFIFOCP(fd,4), output, length );
  9489. WFIFOSET(fd, WFIFOW(fd,2));
  9490. #ifdef PCRE_SUPPORT
  9491. // trigger listening npcs
  9492. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9493. #endif
  9494. // Chat logging type 'O' / Global Chat
  9495. 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);
  9496. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9497. }
  9498. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9499. /// Request to warp to a map on given coordinates.
  9500. /// 0140 <map name>.16B <x>.W <y>.W
  9501. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9502. {
  9503. char command[MAP_NAME_LENGTH_EXT+25];
  9504. char* map_name;
  9505. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9506. map_name = RFIFOCP(fd,info->pos[0]);
  9507. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9508. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9509. RFIFOW(fd,info->pos[1]), //x
  9510. RFIFOW(fd,info->pos[2])); //y
  9511. is_atcommand(fd, sd, command, 1);
  9512. }
  9513. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9514. /// 009c <id>.L <head dir>.W <dir>.B
  9515. /// head dir:
  9516. /// 0 = straight
  9517. /// 1 = turned CW
  9518. /// 2 = turned CCW
  9519. /// dir:
  9520. /// 0 = north
  9521. /// 1 = northwest
  9522. /// 2 = west
  9523. /// 3 = southwest
  9524. /// 4 = south
  9525. /// 5 = southeast
  9526. /// 6 = east
  9527. /// 7 = northeast
  9528. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9529. {
  9530. unsigned char buf[64];
  9531. WBUFW(buf,0) = 0x9c;
  9532. WBUFL(buf,2) = bl->id;
  9533. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9534. WBUFB(buf,8) = unit_getdir(bl);
  9535. clif_send(buf, packet_len(0x9c), bl, target);
  9536. if (disguised(bl)) {
  9537. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9538. WBUFW(buf,6) = 0;
  9539. clif_send(buf, packet_len(0x9c), bl, SELF);
  9540. }
  9541. }
  9542. /// Request to change own body and head direction.
  9543. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9544. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9545. /// There are various variants of this packet, some of them have padding between fields.
  9546. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9547. {
  9548. unsigned char headdir, dir;
  9549. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9550. headdir = RFIFOB(fd,info->pos[0]);
  9551. dir = RFIFOB(fd,info->pos[1]);
  9552. pc_setdir(sd, dir, headdir);
  9553. clif_changed_dir(&sd->bl, AREA_WOS);
  9554. }
  9555. /// Request to show an emotion (CZ_REQ_EMOTION).
  9556. /// 00bf <type>.B
  9557. /// type:
  9558. /// @see enum emotion_type
  9559. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9560. {
  9561. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9562. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9563. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9564. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9565. return;
  9566. }
  9567. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9568. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9569. sd->emotionlasttime = time(NULL);
  9570. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9571. return;
  9572. }
  9573. sd->emotionlasttime = time(NULL);
  9574. if (battle_config.idletime_option&IDLE_EMOTION)
  9575. sd->idletime = last_tick;
  9576. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9577. sd->idletime_hom = last_tick;
  9578. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9579. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9580. return;
  9581. }
  9582. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9583. emoticon = rnd()%6+ET_DICE1;
  9584. }
  9585. clif_emotion(&sd->bl, emoticon);
  9586. } else
  9587. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9588. }
  9589. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9590. /// 00c2 <count>.L
  9591. void clif_user_count(struct map_session_data* sd, int count)
  9592. {
  9593. int fd = sd->fd;
  9594. WFIFOHEAD(fd,packet_len(0xc2));
  9595. WFIFOW(fd,0) = 0xc2;
  9596. WFIFOL(fd,2) = count;
  9597. WFIFOSET(fd,packet_len(0xc2));
  9598. }
  9599. /// /w /who (CZ_REQ_USER_COUNT).
  9600. /// Request to display amount of currently connected players.
  9601. /// 00c1
  9602. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9603. {
  9604. clif_user_count(sd, map_getusers());
  9605. }
  9606. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9607. {
  9608. if (pc_isdead(sd)) {
  9609. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9610. return;
  9611. }
  9612. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9613. // (not all are included in pc_can_attack)
  9614. if (sd->sc.count &&
  9615. (sd->sc.data[SC_TRICKDEAD] ||
  9616. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9617. sd->sc.data[SC_BLADESTOP] ||
  9618. sd->sc.data[SC__MANHOLE] ||
  9619. sd->sc.data[SC_SUHIDE] ||
  9620. sd->sc.data[SC_GRAVITYCONTROL]))
  9621. return;
  9622. if(action_type != 0x00 && action_type != 0x07)
  9623. pc_stop_walking(sd, 1);
  9624. pc_stop_attack(sd);
  9625. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9626. target_id = sd->bl.id;
  9627. switch(action_type)
  9628. {
  9629. case 0x00: // once attack
  9630. case 0x07: // continuous attack
  9631. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9632. return;
  9633. if( sd->sc.option&OPTION_COSTUME )
  9634. return;
  9635. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9636. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9637. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9638. return;
  9639. }
  9640. }
  9641. pc_delinvincibletimer(sd);
  9642. if (battle_config.idletime_option&IDLE_ATTACK)
  9643. sd->idletime = last_tick;
  9644. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9645. sd->idletime_hom = last_tick;
  9646. unit_attack(&sd->bl, target_id, action_type != 0);
  9647. break;
  9648. case 0x02: // sitdown
  9649. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9650. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9651. break;
  9652. }
  9653. if(pc_issit(sd)) {
  9654. //Bugged client? Just refresh them.
  9655. clif_sitting(&sd->bl);
  9656. return;
  9657. }
  9658. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9659. break;
  9660. if (sd->sc.count && (
  9661. sd->sc.data[SC_DANCING] ||
  9662. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9663. )) //No sitting during these states either.
  9664. break;
  9665. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9666. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9667. break;
  9668. }
  9669. if (battle_config.idletime_option&IDLE_SIT)
  9670. sd->idletime = last_tick;
  9671. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9672. sd->idletime_hom = last_tick;
  9673. pc_setsit(sd);
  9674. skill_sit(sd, true);
  9675. clif_sitting(&sd->bl);
  9676. break;
  9677. case 0x03: // standup
  9678. if (!pc_issit(sd)) {
  9679. //Bugged client? Just refresh them.
  9680. clif_standing(&sd->bl);
  9681. return;
  9682. }
  9683. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9684. break;
  9685. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9686. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9687. break;
  9688. }
  9689. if (pc_setstand(sd, false)) {
  9690. if (battle_config.idletime_option&IDLE_SIT)
  9691. sd->idletime = last_tick;
  9692. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9693. sd->idletime_hom = last_tick;
  9694. skill_sit(sd, false);
  9695. clif_standing(&sd->bl);
  9696. }
  9697. break;
  9698. }
  9699. }
  9700. /// Request for an action.
  9701. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9702. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9703. /// action:
  9704. /// 0 = attack
  9705. /// 1 = pick up item
  9706. /// 2 = sit down
  9707. /// 3 = stand up
  9708. /// 7 = continous attack
  9709. /// 12 = (touch skill?)
  9710. /// There are various variants of this packet, some of them have padding between fields.
  9711. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9712. {
  9713. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9714. clif_parse_ActionRequest_sub(sd,
  9715. RFIFOB(fd,info->pos[1]),
  9716. RFIFOL(fd,info->pos[0]),
  9717. gettick()
  9718. );
  9719. }
  9720. /// Response to the death/system menu (CZ_RESTART).
  9721. /// 00b2 <type>.B
  9722. /// type:
  9723. /// 0 = restart (respawn)
  9724. /// 1 = char-select (disconnect)
  9725. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9726. {
  9727. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9728. case 0x00:
  9729. pc_respawn(sd,CLR_OUTSIGHT);
  9730. break;
  9731. case 0x01:
  9732. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9733. 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] &&
  9734. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9735. { //Send to char-server for character selection.
  9736. pc_damage_log_clear(sd,0);
  9737. chrif_charselectreq(sd, session[fd]->client_addr);
  9738. } else {
  9739. clif_disconnect_ack(sd, 1);
  9740. }
  9741. break;
  9742. }
  9743. }
  9744. /// Validates and processes whispered messages (CZ_WHISPER).
  9745. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9746. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9747. {
  9748. struct map_session_data* dstsd;
  9749. int i;
  9750. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9751. // validate packet and retrieve name and message
  9752. if( !clif_process_message( sd, true, target, message, output ) )
  9753. return;
  9754. // Chat logging type 'W' / Whisper
  9755. 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);
  9756. //-------------------------------------------------------//
  9757. // Lordalfa - Paperboy - To whisper NPC commands //
  9758. //-------------------------------------------------------//
  9759. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9760. {
  9761. char* str = target+4; //Skip the NPC: string part.
  9762. struct npc_data* npc;
  9763. if ((npc = npc_name2id(str))) {
  9764. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9765. char *split;
  9766. char event[EVENT_NAME_LENGTH];
  9767. str = message;
  9768. // skip codepage indicator, if detected
  9769. if( str[0] == '|' && strlen(str) >= 4 )
  9770. str += 3;
  9771. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9772. split = strchr(str,'#');
  9773. if( split == NULL ) { // use the remaining string
  9774. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9775. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9776. split_data[i][0] = '\0';
  9777. break;
  9778. }
  9779. *split = '\0';
  9780. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9781. str = split+1;
  9782. }
  9783. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9784. char variablename[CHAT_SIZE_MAX];
  9785. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9786. set_var_str( sd, variablename, split_data[i] );
  9787. }
  9788. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9789. npc_event(sd,event,0); // Calls the NPC label
  9790. return;
  9791. }
  9792. } else if( target[0] == '#' ) {
  9793. struct Channel *channel = NULL;
  9794. char* chname = target;
  9795. channel = channel_name2channel(chname,sd,3);
  9796. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9797. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9798. channel_send(channel,sd,message);
  9799. }
  9800. else if( channel->pass[0] == '\0') { //no pass needed
  9801. if (channel_join(channel,sd)==0)
  9802. channel_send(channel,sd,message); //join success
  9803. }
  9804. else {
  9805. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9806. }
  9807. return;
  9808. }
  9809. }
  9810. // searching destination character
  9811. dstsd = map_nick2sd(target,false);
  9812. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9813. // player is not on this map-server
  9814. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9815. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9816. // and if we ask for 'Test', we must not contact 'test' player
  9817. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9818. intif_wis_message(sd, target, message, strlen(message) + 1);
  9819. return;
  9820. }
  9821. // if player ignores everyone
  9822. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9823. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9824. clif_wis_end(fd, 1); // 1: target character is not logged in
  9825. else
  9826. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9827. return;
  9828. }
  9829. // if player is autotrading
  9830. if (dstsd->state.autotrade == 1){
  9831. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9832. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9833. return;
  9834. }
  9835. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9836. // if player ignores the source character
  9837. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9838. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9839. clif_wis_end(fd, 2); // 2: ignored by target
  9840. return;
  9841. }
  9842. }
  9843. // notify sender of success
  9844. clif_wis_end(fd, 0); // 0: success to send wisper
  9845. // Normal message
  9846. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9847. }
  9848. /// /b /nb (CZ_BROADCAST).
  9849. /// Request to broadcast a message on whole server.
  9850. /// 0099 <packet len>.W <text>.?B 00
  9851. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9852. char command[CHAT_SIZE_MAX+11];
  9853. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9854. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9855. char* msg = RFIFOCP(fd,info->pos[1]);
  9856. // as the length varies depending on the command used, just block unreasonably long strings
  9857. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9858. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9859. is_atcommand(fd, sd, command, 1);
  9860. }
  9861. /// Request to pick up an item.
  9862. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9863. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9864. /// There are various variants of this packet, some of them have padding between fields.
  9865. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9866. {
  9867. struct flooritem_data *fitem;
  9868. int map_object_id;
  9869. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9870. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9871. do {
  9872. if (pc_isdead(sd)) {
  9873. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9874. break;
  9875. }
  9876. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9877. break;
  9878. if (pc_cant_act(sd))
  9879. break;
  9880. if (!pc_takeitem(sd, fitem))
  9881. break;
  9882. return;
  9883. } while (0);
  9884. // Client REQUIRES a fail packet or you can no longer pick items.
  9885. clif_additem(sd,0,0,6);
  9886. }
  9887. /// Request to drop an item.
  9888. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9889. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9890. /// There are various variants of this packet, some of them have padding between fields.
  9891. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9892. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9893. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9894. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9895. for(;;) {
  9896. if (pc_isdead(sd))
  9897. break;
  9898. if (pc_cant_act2(sd) || sd->npc_id)
  9899. break;
  9900. if (sd->sc.count && (
  9901. sd->sc.data[SC_AUTOCOUNTER] ||
  9902. sd->sc.data[SC_BLADESTOP] ||
  9903. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9904. ))
  9905. break;
  9906. if (!pc_dropitem(sd, item_index, item_amount))
  9907. break;
  9908. if (battle_config.idletime_option&IDLE_DROPITEM)
  9909. sd->idletime = last_tick;
  9910. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9911. sd->idletime_hom = last_tick;
  9912. return;
  9913. }
  9914. //Because the client does not like being ignored.
  9915. clif_dropitem(sd, item_index,0);
  9916. }
  9917. /// Request to use an item.
  9918. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9919. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9920. /// There are various variants of this packet, some of them have padding between fields.
  9921. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9922. {
  9923. int n;
  9924. if (pc_isdead(sd)) {
  9925. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9926. return;
  9927. }
  9928. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9929. clif_msg(sd, WORK_IN_PROGRESS);
  9930. return;
  9931. }
  9932. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9933. if (battle_config.idletime_option&IDLE_USEITEM)
  9934. sd->idletime = last_tick;
  9935. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9936. sd->idletime_hom = last_tick;
  9937. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9938. if(n <0 || n >= MAX_INVENTORY)
  9939. return;
  9940. if (!pc_useitem(sd,n))
  9941. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9942. }
  9943. /// Request to equip an item
  9944. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9945. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9946. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9947. {
  9948. int index;
  9949. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9950. if(pc_isdead(sd)) {
  9951. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9952. return;
  9953. }
  9954. index = RFIFOW(fd,info->pos[0])-2;
  9955. if (index < 0 || index >= MAX_INVENTORY)
  9956. return; //Out of bounds check.
  9957. if(sd->npc_id && !sd->npc_item_flag) {
  9958. return;
  9959. } else if (sd->state.storage_flag || sd->sc.opt1)
  9960. ; //You can equip/unequip stuff while storage is open/under status changes
  9961. else if (pc_cant_act2(sd))
  9962. return;
  9963. if(!sd->inventory.u.items_inventory[index].identify) {
  9964. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9965. return;
  9966. }
  9967. if(!sd->inventory_data[index])
  9968. return;
  9969. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9970. pet_equipitem(sd,index);
  9971. return;
  9972. }
  9973. if (battle_config.idletime_option&IDLE_USEITEM)
  9974. sd->idletime = last_tick;
  9975. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9976. sd->idletime_hom = last_tick;
  9977. //Client doesn't send the position for ammo.
  9978. if(sd->inventory_data[index]->type == IT_AMMO)
  9979. pc_equipitem(sd,index,EQP_AMMO);
  9980. else {
  9981. int req_pos;
  9982. #if PACKETVER >= 20120925
  9983. req_pos = RFIFOL(fd,info->pos[1]);
  9984. #else
  9985. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9986. #endif
  9987. pc_equipitem(sd,index,req_pos);
  9988. }
  9989. }
  9990. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9991. /// 00ab <index>.W
  9992. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9993. {
  9994. int index;
  9995. if(pc_isdead(sd)) {
  9996. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9997. return;
  9998. }
  9999. if (sd->npc_id && !sd->npc_item_flag) {
  10000. return;
  10001. } else if (sd->state.storage_flag || sd->sc.opt1)
  10002. ; //You can equip/unequip stuff while storage is open/under status changes
  10003. else if (pc_cant_act2(sd))
  10004. return;
  10005. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10006. if (battle_config.idletime_option&IDLE_USEITEM)
  10007. sd->idletime = last_tick;
  10008. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10009. sd->idletime_hom = last_tick;
  10010. pc_unequipitem(sd,index,1);
  10011. }
  10012. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10013. /// 0090 <id>.L <type>.B
  10014. /// type:
  10015. /// 1 = click
  10016. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10017. {
  10018. struct block_list *bl;
  10019. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10020. if(pc_isdead(sd)) {
  10021. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10022. return;
  10023. }
  10024. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10025. #ifdef RENEWAL
  10026. clif_msg( sd, WORK_IN_PROGRESS );
  10027. #endif
  10028. return;
  10029. }
  10030. if( sd->state.mail_writing )
  10031. return;
  10032. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10033. //type = RFIFOB(fd,info->pos[1]);
  10034. if (!bl) return;
  10035. switch (bl->type) {
  10036. case BL_MOB:
  10037. case BL_PC:
  10038. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10039. break;
  10040. case BL_NPC:
  10041. #ifdef RENEWAL
  10042. 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
  10043. clif_msg(sd, WORK_IN_PROGRESS);
  10044. break;
  10045. }
  10046. #endif
  10047. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10048. struct npc_data* nd = (struct npc_data*)bl;
  10049. // Progressbar is running
  10050. if( nd->progressbar.timeout > 0 ){
  10051. return;
  10052. }
  10053. npc_click(sd,nd);
  10054. }
  10055. break;
  10056. }
  10057. }
  10058. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10059. /// 00c5 <id>.L <type>.B
  10060. /// type:
  10061. /// 0 = buy
  10062. /// 1 = sell
  10063. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10064. {
  10065. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10066. if (sd->state.trading)
  10067. return;
  10068. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10069. }
  10070. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10071. /// 00ca <result>.B
  10072. /// result:
  10073. /// 0 = "The deal has successfully completed."
  10074. /// 1 = "You do not have enough zeny."
  10075. /// 2 = "You are over your Weight Limit."
  10076. /// 3 = "Out of the maximum capacity, you have too many items."
  10077. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10078. /// 10 = "Props open-air store sales will be traded in RODEX"
  10079. /// 11 = "The exchange failed."
  10080. /// 12 = "The exchange was well done."
  10081. /// 13 = "The item is already sold and out of stock."
  10082. /// 14 = "There is not enough goods to exchange."
  10083. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10084. {
  10085. int fd = sd->fd;
  10086. WFIFOHEAD(fd,packet_len(0xca));
  10087. WFIFOW(fd,0) = 0xca;
  10088. WFIFOB(fd,2) = result;
  10089. WFIFOSET(fd,packet_len(0xca));
  10090. }
  10091. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10092. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10093. void clif_parse_NpcBuyListSend( int fd, struct map_session_data* sd ){
  10094. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10095. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10096. int result;
  10097. if( sd->state.trading || !sd->npc_shopid )
  10098. result = 1;
  10099. else
  10100. result = npc_buylist( sd, n, (struct s_npc_buy_list*)p->items );
  10101. sd->npc_shopid = 0; //Clear shop data.
  10102. clif_npc_buy_result(sd, result);
  10103. }
  10104. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10105. /// 00cb <result>.B
  10106. /// result:
  10107. /// 0 = "The deal has successfully completed."
  10108. /// 1 = "The deal has failed."
  10109. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10110. {
  10111. int fd = sd->fd;
  10112. WFIFOHEAD(fd,packet_len(0xcb));
  10113. WFIFOW(fd,0) = 0xcb;
  10114. WFIFOB(fd,2) = result;
  10115. WFIFOSET(fd,packet_len(0xcb));
  10116. }
  10117. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10118. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10119. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10120. {
  10121. int fail=0,n;
  10122. unsigned short *item_list;
  10123. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10124. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10125. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10126. if (sd->state.trading || !sd->npc_shopid)
  10127. fail = 1;
  10128. else
  10129. fail = npc_selllist(sd,n,item_list);
  10130. sd->npc_shopid = 0; //Clear shop data.
  10131. clif_npc_sell_result(sd, fail);
  10132. }
  10133. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10134. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10135. /// type:
  10136. /// 0 = private
  10137. /// 1 = public
  10138. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10139. {
  10140. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10141. int len = RFIFOW(fd,info->pos[0])-15;
  10142. int limit = RFIFOW(fd,info->pos[1]);
  10143. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10144. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10145. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10146. char s_password[CHATROOM_PASS_SIZE];
  10147. char s_title[CHATROOM_TITLE_SIZE];
  10148. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10149. return;
  10150. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10151. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10152. return;
  10153. }
  10154. if( npc_isnear(&sd->bl) ) {
  10155. // uncomment to send msg_txt.
  10156. //char output[150];
  10157. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10158. //clif_displaymessage(sd->fd, output);
  10159. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10160. return;
  10161. }
  10162. if( len <= 0 )
  10163. return; // invalid input
  10164. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10165. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10166. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10167. }
  10168. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10169. /// 00d9 <chat ID>.L <passwd>.8B
  10170. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10171. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10172. int chatid = RFIFOL(fd,info->pos[0]);
  10173. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10174. chat_joinchat(sd,chatid,password);
  10175. }
  10176. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10177. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10178. /// type:
  10179. /// 0 = private
  10180. /// 1 = public
  10181. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10182. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10183. int len = RFIFOW(fd,info->pos[0])-15;
  10184. int limit = RFIFOW(fd,info->pos[1]);
  10185. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10186. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10187. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10188. char s_password[CHATROOM_PASS_SIZE];
  10189. char s_title[CHATROOM_TITLE_SIZE];
  10190. if( len <= 0 )
  10191. return; // invalid input
  10192. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10193. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10194. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10195. }
  10196. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10197. /// 00e0 <role>.L <nick>.24B
  10198. /// role:
  10199. /// 0 = owner
  10200. /// 1 = normal
  10201. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10202. {
  10203. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10204. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10205. }
  10206. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10207. /// 00e2 <name>.24B
  10208. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10209. {
  10210. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10211. }
  10212. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10213. /// 00e3
  10214. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10215. {
  10216. chat_leavechat(sd,0);
  10217. }
  10218. //Handles notifying asker and rejecter of what has just ocurred.
  10219. //Type is used to determine the correct msg_txt to use:
  10220. //0:
  10221. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10222. {
  10223. const char* msg;
  10224. char output[256];
  10225. // Your request has been rejected by autoreject option.
  10226. msg = msg_txt(sd,392);
  10227. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10228. //Notice that a request was rejected.
  10229. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10230. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10231. }
  10232. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10233. /// 00e4 <account id>.L
  10234. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10235. {
  10236. struct map_session_data *t_sd;
  10237. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10238. if(!sd->chatID && pc_cant_act(sd))
  10239. return; //You can trade while in a chatroom.
  10240. if(t_sd){
  10241. // @noask [LuzZza]
  10242. if(t_sd->state.noask) {
  10243. clif_noask_sub(sd, t_sd, 0);
  10244. return;
  10245. }
  10246. if (t_sd->state.mail_writing) {
  10247. int old = sd->trade_partner;
  10248. // Fake trading
  10249. sd->trade_partner = t_sd->status.account_id;
  10250. clif_tradestart(sd, 5);
  10251. // Restore old state
  10252. sd->trade_partner = old;
  10253. return;
  10254. }
  10255. }
  10256. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10257. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10258. return;
  10259. }
  10260. trade_traderequest(sd,t_sd);
  10261. }
  10262. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10263. /// 00e6 <result>.B
  10264. /// result:
  10265. /// 3 = accepted
  10266. /// 4 = rejected
  10267. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10268. {
  10269. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10270. }
  10271. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10272. /// 00e8 <index>.W <amount>.L
  10273. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10274. {
  10275. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10276. short index = RFIFOW(fd,info->pos[0]);
  10277. int amount = RFIFOL(fd,info->pos[1]);
  10278. if( index == 0 )
  10279. trade_tradeaddzeny(sd, amount);
  10280. else
  10281. trade_tradeadditem(sd, index, (short)amount);
  10282. }
  10283. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10284. /// 00eb
  10285. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10286. {
  10287. trade_tradeok(sd);
  10288. }
  10289. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10290. /// 00ed
  10291. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10292. {
  10293. trade_tradecancel(sd);
  10294. }
  10295. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10296. /// 00ef
  10297. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10298. {
  10299. trade_tradecommit(sd);
  10300. }
  10301. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10302. /// 0118
  10303. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10304. {
  10305. pc_stop_attack(sd);
  10306. if (sd) sd->ud.state.attack_continue = 0;
  10307. }
  10308. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10309. /// 0126 <index>.W <amount>.L
  10310. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10311. {
  10312. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10313. if (pc_istrading(sd))
  10314. return;
  10315. if (!pc_iscarton(sd))
  10316. return;
  10317. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10318. }
  10319. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10320. /// 0127 <index>.W <amount>.L
  10321. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10322. {
  10323. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10324. if (!pc_iscarton(sd))
  10325. return;
  10326. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10327. }
  10328. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10329. /// 012a
  10330. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10331. {
  10332. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10333. #ifdef NEW_CARTS
  10334. && sd->sc.data[SC_PUSH_CART] )
  10335. pc_setcart(sd,0);
  10336. #else
  10337. )
  10338. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10339. #endif
  10340. else // priority to remove this option before we can clear cart
  10341. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10342. }
  10343. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10344. /// 097f <Length>.W <identity>.L <type>.B
  10345. void clif_SelectCart(struct map_session_data *sd) {
  10346. #if PACKETVER >= 20150826
  10347. int i = 0, carts = 3;
  10348. int fd = sd->fd;
  10349. WFIFOHEAD(fd,8 + carts);
  10350. WFIFOW(fd,0) = 0x97f;
  10351. WFIFOW(fd,2) = 8 + carts;
  10352. WFIFOL(fd,4) = sd->status.account_id;
  10353. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10354. for( i = 0; i < carts; i++ ) {
  10355. WFIFOB(fd,8 + i) = 10 + i;
  10356. }
  10357. WFIFOSET(fd,8 + carts);
  10358. #endif
  10359. }
  10360. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10361. /// 0980 <identity>.L <type>.B
  10362. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10363. #if PACKETVER >= 20150826
  10364. int type;
  10365. // Check identity
  10366. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10367. return;
  10368. type = (int)RFIFOB(fd,6);
  10369. // Check type
  10370. if( type < 10 || type > MAX_CARTS )
  10371. return;
  10372. pc_setcart(sd, type);
  10373. #endif
  10374. }
  10375. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10376. /// 01af <num>.W
  10377. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10378. {// TODO: State tracking?
  10379. int type;
  10380. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10381. return;
  10382. #ifdef RENEWAL
  10383. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10384. clif_msg(sd, WORK_IN_PROGRESS);
  10385. return;
  10386. }
  10387. #endif
  10388. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10389. if(
  10390. #ifdef NEW_CARTS
  10391. (type == 9 && sd->status.base_level > 130) ||
  10392. (type == 8 && sd->status.base_level > 120) ||
  10393. (type == 7 && sd->status.base_level > 110) ||
  10394. (type == 6 && sd->status.base_level > 100) ||
  10395. #endif
  10396. (type == 5 && sd->status.base_level > 90) ||
  10397. (type == 4 && sd->status.base_level > 80) ||
  10398. (type == 3 && sd->status.base_level > 65) ||
  10399. (type == 2 && sd->status.base_level > 40) ||
  10400. (type == 1))
  10401. pc_setcart(sd, type);
  10402. }
  10403. /// Request to increase status (CZ_STATUS_CHANGE).
  10404. /// 00bb <status id>.W <amount>.B
  10405. /// status id:
  10406. /// SP_STR ~ SP_LUK
  10407. /// amount:
  10408. /// Old clients always send 1 for this, even when using /str+ and the like.
  10409. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10410. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10411. {
  10412. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10413. if( increase_amount < 0 ) {
  10414. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10415. fd, increase_amount);
  10416. }
  10417. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10418. }
  10419. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10420. /// 0112 <skill id>.W
  10421. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10422. {
  10423. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10424. }
  10425. 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)
  10426. {
  10427. int lv;
  10428. if( !hd )
  10429. return;
  10430. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10431. clif_emotion(&hd->bl, ET_THINK);
  10432. return;
  10433. }
  10434. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10435. target_id = hd->bl.id;
  10436. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10437. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10438. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10439. clif_emotion(&hd->bl, ET_THINK);
  10440. if (hd->master)
  10441. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10442. return;
  10443. }
  10444. lv = hom_checkskill(hd, skill_id);
  10445. if( skill_lv > lv )
  10446. skill_lv = lv;
  10447. if( skill_lv )
  10448. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10449. }
  10450. 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)
  10451. {
  10452. int lv;
  10453. if( !hd )
  10454. return;
  10455. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10456. clif_emotion(&hd->bl, ET_THINK);
  10457. return;
  10458. }
  10459. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10460. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10461. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10462. clif_emotion(&hd->bl, ET_THINK);
  10463. if (hd->master)
  10464. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10465. return;
  10466. }
  10467. #ifdef RENEWAL
  10468. if (hd->sc.data[SC_BASILICA_CELL])
  10469. #else
  10470. if (hd->sc.data[SC_BASILICA])
  10471. #endif
  10472. return;
  10473. lv = hom_checkskill(hd, skill_id);
  10474. if( skill_lv > lv )
  10475. skill_lv = lv;
  10476. if( skill_lv )
  10477. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10478. }
  10479. 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)
  10480. {
  10481. int lv;
  10482. if( !md )
  10483. return;
  10484. if( skill_isNotOk_mercenary(skill_id, md) )
  10485. return;
  10486. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10487. target_id = md->bl.id;
  10488. if( md->ud.skilltimer != INVALID_TIMER )
  10489. {
  10490. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10491. }
  10492. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10493. return;
  10494. lv = mercenary_checkskill(md, skill_id);
  10495. if( skill_lv > lv )
  10496. skill_lv = lv;
  10497. if( skill_lv )
  10498. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10499. }
  10500. 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)
  10501. {
  10502. int lv;
  10503. if( !md )
  10504. return;
  10505. if( skill_isNotOk_mercenary(skill_id, md) )
  10506. return;
  10507. if( md->ud.skilltimer != INVALID_TIMER )
  10508. return;
  10509. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10510. {
  10511. if (md->master)
  10512. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10513. return;
  10514. }
  10515. #ifdef RENEWAL
  10516. if (md->sc.data[SC_BASILICA_CELL])
  10517. #else
  10518. if (md->sc.data[SC_BASILICA])
  10519. #endif
  10520. return;
  10521. lv = mercenary_checkskill(md, skill_id);
  10522. if( skill_lv > lv )
  10523. skill_lv = lv;
  10524. if( skill_lv )
  10525. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10526. }
  10527. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10528. t_tick tick = gettick();
  10529. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10530. int inf = skill_get_inf(skill_id);
  10531. if (inf&INF_GROUND_SKILL || !inf)
  10532. return; //Using a ground/passive skill on a target? WRONG.
  10533. if (sd->state.block_action & PCBLOCK_SKILL) {
  10534. clif_msg(sd, WORK_IN_PROGRESS);
  10535. return;
  10536. }
  10537. if( SKILL_CHK_HOMUN(skill_id) ) {
  10538. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10539. return;
  10540. }
  10541. if( SKILL_CHK_MERC(skill_id) ) {
  10542. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10543. return;
  10544. }
  10545. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10546. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10547. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10548. sd->idletime = last_tick;
  10549. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10550. sd->idletime_hom = last_tick;
  10551. if( sd->npc_id ){
  10552. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10553. #ifdef RENEWAL
  10554. clif_msg( sd, WORK_IN_PROGRESS );
  10555. #endif
  10556. return;
  10557. }
  10558. }
  10559. if ((pc_cant_act2(sd) || sd->chatID) &&
  10560. skill_id != RK_REFRESH &&
  10561. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10562. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10563. return;
  10564. if( pc_issit(sd) )
  10565. return;
  10566. if( skill_isNotOk(skill_id, sd) )
  10567. return;
  10568. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10569. target_id = sd->bl.id; // never trust the client
  10570. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10571. target_id = sd->bl.id;
  10572. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10573. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10574. return;
  10575. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10576. if( sd->skillitem != skill_id ) {
  10577. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10578. return;
  10579. }
  10580. }
  10581. if( sd->sc.option&OPTION_COSTUME )
  10582. return;
  10583. #ifndef RENEWAL
  10584. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10585. return; // On basilica only caster can use Basilica again to stop it.
  10586. #endif
  10587. if( sd->menuskill_id ) {
  10588. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10589. clif_menuskill_clear(sd); //Cancel pet capture.
  10590. }else if( sd->menuskill_id == SG_FEEL ){
  10591. clif_menuskill_clear( sd ); // Cancel selection
  10592. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10593. return; //Can't use skills while a menu is open.
  10594. }
  10595. if( sd->skillitem == skill_id ) {
  10596. if( skill_lv != sd->skillitemlv )
  10597. skill_lv = sd->skillitemlv;
  10598. if( !(inf&INF_SELF_SKILL) )
  10599. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10600. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10601. return;
  10602. }
  10603. sd->skillitem = sd->skillitemlv = 0;
  10604. if( SKILL_CHK_GUILD(skill_id) ) {
  10605. if( sd->state.gmaster_flag )
  10606. skill_lv = guild_checkskill(sd->guild, skill_id);
  10607. else
  10608. skill_lv = 0;
  10609. } else {
  10610. if( skill_id != ALL_EQSWITCH ){
  10611. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10612. }
  10613. }
  10614. pc_delinvincibletimer(sd);
  10615. if( skill_lv )
  10616. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10617. }
  10618. /// Request to use a targeted skill.
  10619. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10620. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10621. /// There are various variants of this packet, some of them have padding between fields.
  10622. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10623. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10624. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10625. }
  10626. /*==========================================
  10627. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10628. *------------------------------------------*/
  10629. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10630. {
  10631. t_tick tick = gettick();
  10632. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10633. return; //Using a target skill on the ground? WRONG.
  10634. if (sd->state.block_action & PCBLOCK_SKILL) {
  10635. clif_msg(sd, WORK_IN_PROGRESS);
  10636. return;
  10637. }
  10638. if( SKILL_CHK_HOMUN(skill_id) ) {
  10639. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10640. return;
  10641. }
  10642. if( SKILL_CHK_MERC(skill_id) ) {
  10643. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10644. return;
  10645. }
  10646. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10647. #ifdef RENEWAL
  10648. clif_msg( sd, WORK_IN_PROGRESS );
  10649. #endif
  10650. return;
  10651. }
  10652. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10653. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10654. sd->idletime = last_tick;
  10655. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10656. sd->idletime_hom = last_tick;
  10657. if( skill_isNotOk(skill_id, sd) )
  10658. return;
  10659. if( skillmoreinfo != -1 ) {
  10660. if( pc_issit(sd) ) {
  10661. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10662. return;
  10663. }
  10664. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10665. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10666. }
  10667. if( sd->ud.skilltimer != INVALID_TIMER )
  10668. return;
  10669. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10670. if( sd->skillitem != skill_id ) {
  10671. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10672. return;
  10673. }
  10674. }
  10675. if( sd->sc.option&OPTION_COSTUME )
  10676. return;
  10677. #ifndef RENEWAL
  10678. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10679. return; // On basilica only caster can use Basilica again to stop it.
  10680. #endif
  10681. if( sd->menuskill_id ) {
  10682. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10683. clif_menuskill_clear(sd); //Cancel pet capture.
  10684. }else if( sd->menuskill_id == SG_FEEL ){
  10685. clif_menuskill_clear( sd ); // Cancel selection
  10686. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10687. return; //Can't use skills while a menu is open.
  10688. }
  10689. pc_delinvincibletimer(sd);
  10690. if( sd->skillitem == skill_id ) {
  10691. if( skill_lv != sd->skillitemlv )
  10692. skill_lv = sd->skillitemlv;
  10693. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10694. } else {
  10695. int lv;
  10696. sd->skillitem = sd->skillitemlv = 0;
  10697. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10698. if( skill_lv > lv )
  10699. skill_lv = lv;
  10700. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10701. }
  10702. }
  10703. }
  10704. /// Request to use a ground skill.
  10705. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10706. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10707. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10708. /// There are various variants of this packet, some of them have padding between fields.
  10709. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10710. {
  10711. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10712. if (pc_cant_act(sd))
  10713. return;
  10714. if (pc_issit(sd))
  10715. return;
  10716. clif_parse_UseSkillToPosSub(fd, sd,
  10717. RFIFOW(fd,info->pos[0]), //skill lv
  10718. RFIFOW(fd,info->pos[1]), //skill num
  10719. RFIFOW(fd,info->pos[2]), //pos x
  10720. RFIFOW(fd,info->pos[3]), //pos y
  10721. // TODO: find out what this is intended to do
  10722. //RFIFOB(fd, info->pos[4])
  10723. -1 //Skill more info.
  10724. );
  10725. }
  10726. /// Request to use a ground skill with text.
  10727. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10728. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10729. /// There are various variants of this packet, some of them have padding between fields.
  10730. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10731. {
  10732. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10733. if (pc_cant_act(sd))
  10734. return;
  10735. if (pc_issit(sd))
  10736. return;
  10737. clif_parse_UseSkillToPosSub(fd, sd,
  10738. RFIFOW(fd,info->pos[0]), //Skill lv
  10739. RFIFOW(fd,info->pos[1]), //Skill num
  10740. RFIFOW(fd,info->pos[2]), //pos x
  10741. RFIFOW(fd,info->pos[3]), //pos y
  10742. info->pos[4] //skill more info
  10743. );
  10744. }
  10745. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10746. /// 011b <skill id>.W <map name>.16B
  10747. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10748. {
  10749. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10750. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10751. char map_name[MAP_NAME_LENGTH];
  10752. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10753. sd->state.workinprogress = WIP_DISABLE_NONE;
  10754. if(skill_id != sd->menuskill_id)
  10755. return;
  10756. //It is possible to use teleport with the storage window open bugreport:8027
  10757. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10758. clif_menuskill_clear(sd);
  10759. return;
  10760. }
  10761. pc_delinvincibletimer(sd);
  10762. skill_castend_map(sd,skill_id,map_name);
  10763. }
  10764. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10765. /// 011d
  10766. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10767. {
  10768. if (!pc_isdead(sd))
  10769. pc_memo(sd,-1);
  10770. }
  10771. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10772. /// 018e <name id>.W { <material id>.W }*3
  10773. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10774. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10775. switch( sd->menuskill_id ) {
  10776. case -1:
  10777. case AM_PHARMACY:
  10778. case RK_RUNEMASTERY:
  10779. case GC_RESEARCHNEWPOISON:
  10780. break;
  10781. default:
  10782. return;
  10783. }
  10784. if (pc_istrading(sd)) {
  10785. //Make it fail to avoid shop exploits where you sell something different than you see.
  10786. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10787. clif_menuskill_clear(sd);
  10788. return;
  10789. }
  10790. int produce_idx;
  10791. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10792. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10793. clif_menuskill_clear(sd);
  10794. }
  10795. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10796. /// 025b <mk type>.W <name id>.W
  10797. /// mk type:
  10798. /// 1 = cooking
  10799. /// 2 = arrow
  10800. /// 3 = elemental
  10801. /// 4 = GN_MIX_COOKING
  10802. /// 5 = GN_MAKEBOMB
  10803. /// 6 = GN_S_PHARMACY
  10804. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10805. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10806. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10807. short food_idx = -1;
  10808. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10809. return;
  10810. if (pc_istrading(sd)) {
  10811. //Make it fail to avoid shop exploits where you sell something different than you see.
  10812. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10813. clif_menuskill_clear(sd);
  10814. return;
  10815. }
  10816. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10817. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10818. clif_menuskill_clear(sd);
  10819. }
  10820. /// Answer to repair weapon item selection dialog
  10821. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10822. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10823. void clif_parse_RepairItem( int fd, struct map_session_data *sd ){
  10824. const struct PACKET_CZ_REQ_ITEMREPAIR *p = (struct PACKET_CZ_REQ_ITEMREPAIR *)RFIFOP( fd, 0 );
  10825. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10826. return;
  10827. if (pc_istrading(sd)) {
  10828. //Make it fail to avoid shop exploits where you sell something different than you see.
  10829. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10830. clif_menuskill_clear(sd);
  10831. return;
  10832. }
  10833. skill_repairweapon( sd, p->index );
  10834. clif_menuskill_clear(sd);
  10835. }
  10836. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10837. /// 0222 <index>.L
  10838. void clif_parse_WeaponRefine( int fd, struct map_session_data *sd ){
  10839. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10840. return;
  10841. if (pc_istrading(sd)) {
  10842. //Make it fail to avoid shop exploits where you sell something different than you see.
  10843. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10844. clif_menuskill_clear(sd);
  10845. return;
  10846. }
  10847. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  10848. clif_menuskill_clear(sd);
  10849. }
  10850. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10851. /// 00b8 <npc id>.L <choice>.B
  10852. /// choice:
  10853. /// 1~254 = menu item
  10854. /// 255 = cancel
  10855. /// NOTE: If there were more than 254 items in the list, choice
  10856. /// overflows to choice%256.
  10857. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10858. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10859. int npc_id = RFIFOL(fd,info->pos[0]);
  10860. uint8 select = RFIFOB(fd,info->pos[1]);
  10861. #ifdef SECURE_NPCTIMEOUT
  10862. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  10863. return;
  10864. #endif
  10865. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10866. TBL_NPC* nd = map_id2nd(npc_id);
  10867. 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);
  10868. clif_GM_kick(NULL,sd);
  10869. return;
  10870. }
  10871. sd->npc_menu = select;
  10872. npc_scriptcont(sd,npc_id, false);
  10873. }
  10874. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10875. /// 00b9 <npc id>.L
  10876. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10877. {
  10878. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10879. }
  10880. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10881. /// 0143 <npc id>.L <value>.L
  10882. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10883. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10884. int npcid = RFIFOL(fd,info->pos[0]);
  10885. int amount = (int)RFIFOL(fd,info->pos[1]);
  10886. sd->npc_amount = amount;
  10887. npc_scriptcont(sd, npcid, false);
  10888. }
  10889. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10890. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10891. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10892. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10893. int message_len = RFIFOW(fd,info->pos[0])-8;
  10894. int npcid = RFIFOL(fd,info->pos[1]);
  10895. const char* message = RFIFOCP(fd,info->pos[2]);
  10896. if( message_len <= 0 )
  10897. return; // invalid input
  10898. #if PACKETVER >= 20151001
  10899. message_len++;
  10900. #endif
  10901. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10902. npc_scriptcont(sd, npcid, false);
  10903. }
  10904. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10905. /// 0146 <npc id>.L
  10906. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10907. {
  10908. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10909. return;
  10910. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10911. }
  10912. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10913. /// 0178 <index>.W
  10914. /// index:
  10915. /// -1 = cancel
  10916. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10917. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10918. if (sd->menuskill_id != MC_IDENTIFY)
  10919. return;
  10920. // Ignore the request
  10921. // - Invalid item index
  10922. // - Invalid item ID or item doesn't exist
  10923. // - Item is already identified
  10924. if (idx < 0 || idx >= MAX_INVENTORY ||
  10925. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10926. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10927. sd->state.workinprogress = WIP_DISABLE_NONE;
  10928. clif_menuskill_clear(sd);
  10929. return;
  10930. }
  10931. skill_identify(sd, idx);
  10932. clif_menuskill_clear(sd);
  10933. }
  10934. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10935. /// 01ae <name id>.W
  10936. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10937. if (pc_istrading(sd)) {
  10938. //Make it fail to avoid shop exploits where you sell something different than you see.
  10939. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10940. clif_menuskill_clear(sd);
  10941. return;
  10942. }
  10943. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  10944. switch (sd->menuskill_id) {
  10945. case AC_MAKINGARROW:
  10946. skill_arrow_create(sd,p->itemId);
  10947. break;
  10948. case SA_CREATECON:
  10949. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  10950. break;
  10951. case WL_READING_SB:
  10952. skill_spellbook(sd,p->itemId);
  10953. break;
  10954. case GC_POISONINGWEAPON:
  10955. skill_poisoningweapon(sd,p->itemId);
  10956. break;
  10957. case NC_MAGICDECOY:
  10958. skill_magicdecoy(sd,p->itemId);
  10959. break;
  10960. }
  10961. clif_menuskill_clear(sd);
  10962. }
  10963. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10964. /// 01ce <skill id>.L
  10965. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10966. {
  10967. if (sd->menuskill_id != SA_AUTOSPELL)
  10968. return;
  10969. sd->state.workinprogress = WIP_DISABLE_NONE;
  10970. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10971. clif_menuskill_clear(sd);
  10972. }
  10973. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10974. /// 017a <card index>.W
  10975. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10976. {
  10977. if (sd->state.trading != 0)
  10978. return;
  10979. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10980. }
  10981. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10982. /// 017c <card index>.W <equip index>.W
  10983. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10984. {
  10985. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10986. if (sd->state.trading != 0)
  10987. return;
  10988. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10989. }
  10990. /// Request of character's name by char ID.
  10991. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10992. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10993. /// There are various variants of this packet, some of them have padding between fields.
  10994. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10995. {
  10996. int charid;
  10997. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10998. map_reqnickdb(sd, charid);
  10999. }
  11000. /// /resetskill /resetstate (CZ_RESET).
  11001. /// Request to reset stats or skills.
  11002. /// 0197 <type>.W
  11003. /// type:
  11004. /// 0 = state
  11005. /// 1 = skill
  11006. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  11007. char cmd[15];
  11008. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11009. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11010. else
  11011. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11012. is_atcommand(fd, sd, cmd, 1);
  11013. }
  11014. /// /lb /nlb (CZ_LOCALBROADCAST).
  11015. /// Request to broadcast a message on current map.
  11016. /// 019c <packet len>.W <text>.?B
  11017. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  11018. {
  11019. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11020. char command[CHAT_SIZE_MAX+16];
  11021. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11022. char* msg = RFIFOCP(fd,info->pos[1]);
  11023. // as the length varies depending on the command used, just block unreasonably long strings
  11024. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11025. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11026. is_atcommand(fd, sd, command, 1);
  11027. }
  11028. /// Request to move an item from inventory to storage.
  11029. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11030. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11031. /// There are various variants of this packet, some of them have padding between fields.
  11032. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11033. {
  11034. int item_index, item_amount;
  11035. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11036. if (pc_istrading(sd))
  11037. return;
  11038. item_index = RFIFOW(fd,info->pos[0])-2;
  11039. item_amount = RFIFOL(fd,info->pos[1]);
  11040. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11041. return;
  11042. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11043. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11044. return;
  11045. }
  11046. if (sd->state.storage_flag == 1)
  11047. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11048. else
  11049. if (sd->state.storage_flag == 2)
  11050. storage_guild_storageadd(sd, item_index, item_amount);
  11051. else if (sd->state.storage_flag == 3)
  11052. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11053. }
  11054. /// Request to move an item from storage to inventory.
  11055. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11056. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11057. /// There are various variants of this packet, some of them have padding between fields.
  11058. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11059. {
  11060. int item_index, item_amount;
  11061. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11062. item_index = RFIFOW(fd,info->pos[0])-1;
  11063. item_amount = RFIFOL(fd,info->pos[1]);
  11064. if (sd->state.storage_flag == 1)
  11065. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11066. else if(sd->state.storage_flag == 2)
  11067. storage_guild_storageget(sd, item_index, item_amount);
  11068. else if(sd->state.storage_flag == 3)
  11069. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11070. }
  11071. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11072. /// 0129 <index>.W <amount>.L
  11073. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11074. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11075. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11076. int amount = RFIFOL(fd,info->pos[1]);
  11077. if( sd->state.vending )
  11078. return;
  11079. if (!pc_iscarton(sd))
  11080. return;
  11081. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11082. return;
  11083. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11084. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11085. return;
  11086. }
  11087. if (sd->state.storage_flag == 1)
  11088. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11089. else if (sd->state.storage_flag == 2)
  11090. storage_guild_storageaddfromcart(sd, idx, amount);
  11091. else if (sd->state.storage_flag == 3)
  11092. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11093. }
  11094. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11095. /// 0128 <index>.W <amount>.L
  11096. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11097. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11098. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11099. int amount = RFIFOL(fd,info->pos[1]);
  11100. if( sd->state.vending )
  11101. return;
  11102. if (!pc_iscarton(sd))
  11103. return;
  11104. if (sd->state.storage_flag == 1)
  11105. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11106. else
  11107. if (sd->state.storage_flag == 2)
  11108. storage_guild_storagegettocart(sd, idx, amount);
  11109. else if (sd->state.storage_flag == 3)
  11110. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11111. }
  11112. /// Request to close storage (CZ_CLOSE_STORE).
  11113. /// 00f7
  11114. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11115. {
  11116. if( sd->state.storage_flag == 1 )
  11117. storage_storageclose(sd);
  11118. else
  11119. if( sd->state.storage_flag == 2 )
  11120. storage_guild_storageclose(sd);
  11121. else if( sd->state.storage_flag == 3 )
  11122. storage_premiumStorage_close(sd);
  11123. }
  11124. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11125. /// 023a <info>.W
  11126. /// info:
  11127. /// 0 = password has not been set yet
  11128. /// 1 = storage is password-protected
  11129. /// 8 = too many wrong passwords
  11130. /// ? = ignored
  11131. /// NOTE: This packet is only available on certain non-kRO clients.
  11132. void clif_storagepassword(struct map_session_data* sd, short info)
  11133. {
  11134. int fd = sd->fd;
  11135. WFIFOHEAD(fd,packet_len(0x23a));
  11136. WFIFOW(fd,0) = 0x23a;
  11137. WFIFOW(fd,2) = info;
  11138. WFIFOSET(fd,packet_len(0x23a));
  11139. }
  11140. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11141. /// 023b <type>.W <password>.16B <new password>.16B
  11142. /// type:
  11143. /// 2 = change password
  11144. /// 3 = check password
  11145. /// NOTE: This packet is only available on certain non-kRO clients.
  11146. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11147. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11148. // int type = RFIFOW(fd,info->pos[0]);
  11149. // char* password = RFIFOP(fd,info->pos[1]);
  11150. // char* new_password = RFIFOP(fd,info->pos[2]);
  11151. // storage_changepass(sd,password,new_password);
  11152. }
  11153. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11154. /// 023c <result>.W <error count>.W
  11155. /// result:
  11156. /// 4 = password change success
  11157. /// 5 = password change failure
  11158. /// 6 = password check success
  11159. /// 7 = password check failure
  11160. /// 8 = too many wrong passwords
  11161. /// ? = ignored
  11162. /// NOTE: This packet is only available on certain non-kRO clients.
  11163. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11164. {
  11165. int fd = sd->fd;
  11166. WFIFOHEAD(fd,packet_len(0x23c));
  11167. WFIFOW(fd,0) = 0x23c;
  11168. WFIFOW(fd,2) = result;
  11169. WFIFOW(fd,4) = error_count;
  11170. WFIFOSET(fd,packet_len(0x23c));
  11171. }
  11172. /// Party creation request
  11173. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11174. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11175. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11176. name[NAME_LENGTH-1] = '\0';
  11177. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11178. clif_displaymessage(fd, msg_txt(sd,227));
  11179. return;
  11180. }
  11181. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11182. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11183. return;
  11184. }
  11185. party_create(sd,name,0,0);
  11186. }
  11187. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11188. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11189. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11190. char* name = RFIFOCP(fd,info->pos[0]);
  11191. int item1 = RFIFOB(fd,info->pos[1]);
  11192. int item2 = RFIFOB(fd,info->pos[2]);
  11193. name[NAME_LENGTH-1] = '\0';
  11194. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11195. clif_displaymessage(fd, msg_txt(sd,227));
  11196. return;
  11197. }
  11198. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11199. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11200. return;
  11201. }
  11202. party_create(sd,name,item1,item2);
  11203. }
  11204. /// Party invitation request
  11205. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11206. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11207. {
  11208. struct map_session_data *t_sd;
  11209. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11210. clif_displaymessage(fd, msg_txt(sd,227));
  11211. return;
  11212. }
  11213. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11214. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11215. clif_noask_sub(sd, t_sd, 1);
  11216. return;
  11217. }
  11218. party_invite(sd, t_sd);
  11219. }
  11220. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11221. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11222. struct map_session_data *t_sd;
  11223. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11224. name[NAME_LENGTH-1] = '\0';
  11225. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11226. clif_displaymessage(fd, msg_txt(sd,227));
  11227. return;
  11228. }
  11229. t_sd = map_nick2sd(name,false);
  11230. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11231. clif_noask_sub(sd, t_sd, 1);
  11232. return;
  11233. }
  11234. party_invite(sd, t_sd);
  11235. }
  11236. /// Party invitation reply
  11237. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11238. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11239. /// flag:
  11240. /// 0 = reject
  11241. /// 1 = accept
  11242. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11243. {
  11244. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11245. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11246. RFIFOL(fd,info->pos[1]));
  11247. }
  11248. //(CZ_PARTY_JOIN_REQ_ACK)
  11249. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11250. {
  11251. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11252. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11253. RFIFOB(fd,info->pos[1]));
  11254. }
  11255. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11256. /// 0100
  11257. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11258. {
  11259. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11260. clif_displaymessage(fd, msg_txt(sd,227));
  11261. return;
  11262. }
  11263. party_leave(sd);
  11264. }
  11265. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11266. /// 0103 <account id>.L <char name>.24B
  11267. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11268. {
  11269. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11270. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11271. clif_displaymessage(fd, msg_txt(sd,227));
  11272. return;
  11273. }
  11274. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11275. RFIFOCP(fd,info->pos[1]));
  11276. }
  11277. /// Request to change party options.
  11278. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11279. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11280. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11281. {
  11282. struct party_data *p;
  11283. int i,expflag;
  11284. int cmd = RFIFOW(fd,0);
  11285. struct s_packet_db* info = &packet_db[cmd];
  11286. if( !sd->status.party_id )
  11287. return;
  11288. p = party_search(sd->status.party_id);
  11289. if( p == NULL )
  11290. return;
  11291. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11292. if( i == MAX_PARTY )
  11293. return; //Shouldn't happen
  11294. if( !p->party.member[i].leader )
  11295. return;
  11296. expflag = RFIFOL(fd,info->pos[0]);
  11297. if(cmd == 0x0102){ //Client can't change the item-field
  11298. party_changeoption(sd, expflag, p->party.item);
  11299. }
  11300. else {
  11301. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11302. party_changeoption(sd, expflag, itemflag);
  11303. }
  11304. }
  11305. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11306. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11307. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11308. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11309. // validate packet and retrieve name and message
  11310. if( !clif_process_message( sd, false, name, message, output ) )
  11311. return;
  11312. party_send_message(sd, output, strlen(output) + 1 );
  11313. }
  11314. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11315. /// 07da <account id>.L
  11316. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11317. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11318. }
  11319. /// Party Booking in KRO [Spiria]
  11320. ///
  11321. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11322. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11323. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11324. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11325. short level = RFIFOW(fd,info->pos[0]);
  11326. short mapid = RFIFOW(fd,info->pos[1]);
  11327. int idxpbj = info->pos[2];
  11328. short job[MAX_PARTY_BOOKING_JOBS];
  11329. int i;
  11330. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11331. job[i] = RFIFOB(fd,idxpbj+i*2);
  11332. party_booking_register(sd, level, mapid, job);
  11333. }
  11334. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11335. /// 0803 <result>.W
  11336. /// result:
  11337. /// 0 = success
  11338. /// 1 = failure
  11339. /// 2 = already registered
  11340. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11341. {
  11342. int fd = sd->fd;
  11343. WFIFOHEAD(fd,packet_len(0x803));
  11344. WFIFOW(fd,0) = 0x803;
  11345. WFIFOW(fd,2) = flag;
  11346. WFIFOSET(fd,packet_len(0x803));
  11347. }
  11348. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11349. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11350. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11351. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11352. short level = RFIFOW(fd,info->pos[0]);
  11353. short mapid = RFIFOW(fd,info->pos[1]);
  11354. short job = RFIFOW(fd,info->pos[2]);
  11355. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11356. short resultcount = RFIFOW(fd,info->pos[4]);
  11357. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11358. }
  11359. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11360. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11361. /// more results:
  11362. /// 0 = no
  11363. /// 1 = yes
  11364. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11365. {
  11366. int i, j;
  11367. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11368. struct party_booking_ad_info *pb_ad;
  11369. WFIFOHEAD(fd,size*count + 5);
  11370. WFIFOW(fd,0) = 0x805;
  11371. WFIFOW(fd,2) = size*count + 5;
  11372. WFIFOB(fd,4) = more_result;
  11373. for(i=0; i<count; i++)
  11374. {
  11375. pb_ad = results[i];
  11376. WFIFOL(fd,i*size+5) = pb_ad->index;
  11377. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11378. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11379. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11380. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11381. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11382. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11383. }
  11384. WFIFOSET(fd,WFIFOW(fd,2));
  11385. }
  11386. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11387. /// 0806
  11388. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11389. {
  11390. if(party_booking_delete(sd))
  11391. clif_PartyBookingDeleteAck(sd, 0);
  11392. }
  11393. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11394. /// 0807 <result>.W
  11395. /// result:
  11396. /// 0 = success
  11397. /// 1 = success (auto-removed expired ad)
  11398. /// 2 = failure
  11399. /// 3 = nothing registered
  11400. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11401. {
  11402. int fd = sd->fd;
  11403. WFIFOHEAD(fd,packet_len(0x807));
  11404. WFIFOW(fd,0) = 0x807;
  11405. WFIFOW(fd,2) = flag;
  11406. WFIFOSET(fd,packet_len(0x807));
  11407. }
  11408. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11409. /// 0808 { <job>.W }*6
  11410. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11411. {
  11412. short job[MAX_PARTY_BOOKING_JOBS];
  11413. int i;
  11414. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11415. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11416. job[i] = RFIFOW(fd,idxpbu+i*2);
  11417. party_booking_update(sd, job);
  11418. }
  11419. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11420. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11421. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11422. {
  11423. int i;
  11424. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11425. if(pb_ad == NULL) return;
  11426. WBUFW(buf,0) = 0x809;
  11427. WBUFL(buf,2) = pb_ad->index;
  11428. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11429. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11430. WBUFW(buf,34) = pb_ad->p_detail.level;
  11431. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11432. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11433. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11434. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11435. }
  11436. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11437. /// 080a <index>.L { <job>.W }*6
  11438. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11439. {
  11440. int i;
  11441. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11442. if(pb_ad == NULL) return;
  11443. WBUFW(buf,0) = 0x80a;
  11444. WBUFL(buf,2) = pb_ad->index;
  11445. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11446. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11447. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11448. }
  11449. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11450. /// 080b <index>.L
  11451. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11452. {
  11453. uint8 buf[6];
  11454. WBUFW(buf,0) = 0x80b;
  11455. WBUFL(buf,2) = index;
  11456. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11457. }
  11458. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11459. /// 012e
  11460. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11461. {
  11462. vending_closevending(sd);
  11463. }
  11464. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11465. /// 0130 <account id>.L
  11466. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11467. {
  11468. if( sd->npc_id ) {// using an NPC
  11469. return;
  11470. }
  11471. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11472. }
  11473. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11474. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11475. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11476. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11477. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11478. int id = (int)RFIFOL(fd,info->pos[1]);
  11479. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11480. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11481. // whether it fails or not, the buy window is closed
  11482. sd->vended_id = 0;
  11483. }
  11484. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11485. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11486. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11487. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11488. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11489. int aid = (int)RFIFOL(fd,info->pos[1]);
  11490. int uid = (int)RFIFOL(fd,info->pos[2]);
  11491. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11492. vending_purchasereq(sd, aid, uid, data, len/4);
  11493. // whether it fails or not, the buy window is closed
  11494. sd->vended_id = 0;
  11495. }
  11496. /// Confirm or cancel the shop preparation window.
  11497. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11498. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11499. /// result:
  11500. /// 0 = canceled
  11501. /// 1 = open
  11502. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11503. int cmd = RFIFOW(fd,0);
  11504. struct s_packet_db* info = &packet_db[cmd];
  11505. short len = (short)RFIFOW(fd,info->pos[0]);
  11506. const char* message = RFIFOCP(fd,info->pos[1]);
  11507. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11508. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11509. len -= 84;
  11510. }
  11511. else { //(CZ_REQ_OPENSTORE2)
  11512. bool flag;
  11513. len -= 85;
  11514. flag = RFIFOB(fd,info->pos[2]) != 0;
  11515. if (!flag) {
  11516. sd->state.prevend = 0;
  11517. sd->state.workinprogress = WIP_DISABLE_NONE;
  11518. }
  11519. }
  11520. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11521. return;
  11522. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11523. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11524. return;
  11525. }
  11526. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11527. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11528. return;
  11529. }
  11530. if( message[0] == '\0' ) // invalid input
  11531. return;
  11532. vending_openvending(sd, message, data, len/8, NULL);
  11533. }
  11534. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11535. /// 0165 <char id>.L <guild name>.24B
  11536. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11537. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11538. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11539. name[NAME_LENGTH-1] = '\0';
  11540. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11541. clif_displaymessage(fd, msg_txt(sd,228));
  11542. return;
  11543. }
  11544. if(sd->clan){
  11545. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11546. return;
  11547. }
  11548. guild_create(sd, name);
  11549. }
  11550. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11551. /// 014d
  11552. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11553. {
  11554. clif_guild_masterormember(sd);
  11555. }
  11556. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11557. /// 014f <type>.L
  11558. /// type:
  11559. /// 0 = basic info
  11560. /// 1 = member manager
  11561. /// 2 = positions
  11562. /// 3 = skills
  11563. /// 4 = expulsion list
  11564. /// 5 = unknown (GM_ALLGUILDLIST)
  11565. /// 6 = notice
  11566. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11567. {
  11568. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11569. if( !sd->status.guild_id && !sd->bg_id )
  11570. return;
  11571. switch( type )
  11572. {
  11573. case 0: // Basic Information Guild, hostile alliance information
  11574. clif_guild_basicinfo(sd);
  11575. clif_guild_allianceinfo(sd);
  11576. break;
  11577. case 1: // Members list, list job title
  11578. clif_guild_positionnamelist(sd);
  11579. clif_guild_memberlist(sd);
  11580. break;
  11581. case 2: // List job title, title information list
  11582. clif_guild_positionnamelist(sd);
  11583. clif_guild_positioninfolist(sd);
  11584. break;
  11585. case 3: // Skill list
  11586. clif_guild_skillinfo(sd);
  11587. break;
  11588. case 4: // Expulsion list
  11589. clif_guild_expulsionlist(sd);
  11590. break;
  11591. default:
  11592. ShowError("clif: guild request info: unknown type %d\n", type);
  11593. break;
  11594. }
  11595. }
  11596. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11597. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11598. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11599. {
  11600. int i;
  11601. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11602. int len = RFIFOW(fd,info->pos[0]);
  11603. int idxgpos = info->pos[1];
  11604. if(!sd->state.gmaster_flag)
  11605. return;
  11606. for(i = idxgpos; i < len; i += 40 ){
  11607. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11608. }
  11609. }
  11610. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11611. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11612. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11613. {
  11614. int i;
  11615. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11616. int len = RFIFOW(fd,info->pos[0]);
  11617. int idxgpos = info->pos[1];
  11618. if(!sd->state.gmaster_flag)
  11619. return;
  11620. // Guild leadership change
  11621. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11622. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11623. clif_msg(sd, GUILD_MASTER_WOE);
  11624. return;
  11625. }
  11626. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11627. clif_msg(sd, GUILD_MASTER_DELAY);
  11628. return;
  11629. }
  11630. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11631. return;
  11632. }
  11633. for(i=idxgpos;i<len;i+=12){
  11634. int position = RFIFOL(fd,i+8);
  11635. if( position > 0 ){
  11636. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11637. }
  11638. }
  11639. }
  11640. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11641. /// 0151 <guild id>.L
  11642. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11643. {
  11644. struct guild* g;
  11645. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11646. if( (g = guild_search(guild_id)) != NULL )
  11647. clif_guild_emblem(sd,g);
  11648. }
  11649. /// Validates data of a guild emblem (compressed bitmap)
  11650. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11651. EMBVALIDATE_SUCCESS = 0,
  11652. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11653. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11654. };
  11655. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11656. {
  11657. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11658. unsigned long buf_len = sizeof(buf);
  11659. int offset = 0;
  11660. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11661. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11662. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11663. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11664. ))
  11665. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11666. if(battle_config.emblem_transparency_limit != 100) {
  11667. int i, transcount = 1, tmp[3];
  11668. for(i = offset; i < buf_len-1; i++) {
  11669. int j = i%3;
  11670. tmp[j] = RBUFL(buf,i);
  11671. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11672. transcount++;
  11673. }
  11674. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11675. return EMBVALIDATE_ERR_TRANSPARENCY;
  11676. }
  11677. return EMBVALIDATE_SUCCESS;
  11678. }
  11679. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11680. /// 0153 <packet len>.W <emblem data>.?B
  11681. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11682. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11683. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11684. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11685. int emb_val=0;
  11686. if( !emblem_len || !sd->state.gmaster_flag )
  11687. return;
  11688. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11689. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11690. return;
  11691. }
  11692. emb_val = clif_validate_emblem(emblem, emblem_len);
  11693. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11694. 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);
  11695. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11696. return;
  11697. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11698. char output[128];
  11699. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11700. 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"
  11701. return;
  11702. }
  11703. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11704. }
  11705. /// Request to update the guild emblem id (version, according to Gravity)
  11706. /// 0b46 <guild id>.L <version>.L
  11707. void clif_parse_GuildChangeEmblem2(int fd, struct map_session_data* sd) {
  11708. nullpo_retv(sd);
  11709. #if PACKETVER >= 20190724
  11710. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  11711. guild* g = sd->guild;
  11712. if (g == nullptr || g->guild_id != p->guild_id)
  11713. return;
  11714. if (!sd->state.gmaster_flag)
  11715. return;
  11716. if (!battle_config.emblem_woe_change && is_agit_start()) {
  11717. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11718. return;
  11719. }
  11720. guild_change_emblem_version(sd, p->version);
  11721. #endif
  11722. }
  11723. /// Guild notice update request (CZ_GUILD_NOTICE).
  11724. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11725. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11726. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11727. int guild_id = RFIFOL(fd,info->pos[0]);
  11728. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11729. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11730. if(!sd->state.gmaster_flag)
  11731. return;
  11732. // compensate for some client defects when using multilanguage mode
  11733. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11734. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11735. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11736. guild_change_notice(sd, guild_id, msg1, msg2);
  11737. }
  11738. // Helper function for guild invite functions
  11739. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11740. {
  11741. if (t_sd == NULL) // not online or does not exist
  11742. return 1;
  11743. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11744. clif_displaymessage(fd, msg_txt(sd,228));
  11745. return 1;
  11746. }
  11747. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11748. clif_noask_sub(sd, t_sd, 2);
  11749. return 1;
  11750. }
  11751. // Players in a clan can not join a guild
  11752. if(t_sd && t_sd->clan){
  11753. return 1;
  11754. }
  11755. guild_invite(sd, t_sd);
  11756. return 0;
  11757. }
  11758. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11759. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11760. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11761. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11762. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11763. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11764. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11765. if (clif_sub_guild_invite(fd, sd, t_sd))
  11766. return;
  11767. }
  11768. /// Guild invite request (/guildinvite)
  11769. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11770. void
  11771. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11772. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11773. if (clif_sub_guild_invite(fd, sd, t_sd))
  11774. return;
  11775. }
  11776. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11777. /// 016b <guild id>.L <answer>.L
  11778. /// answer:
  11779. /// 0 = refuse
  11780. /// 1 = accept
  11781. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11782. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11783. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11784. RFIFOL(fd,info->pos[1]));
  11785. }
  11786. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11787. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11788. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11789. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11790. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11791. clif_displaymessage(fd, msg_txt(sd,228));
  11792. return;
  11793. }
  11794. if( sd->bg_id ) {
  11795. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11796. return;
  11797. }
  11798. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11799. RFIFOL(fd,info->pos[1]),
  11800. RFIFOL(fd,info->pos[2]),
  11801. RFIFOCP(fd,info->pos[3]));
  11802. }
  11803. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11804. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11805. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11806. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11807. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11808. { // Guild locked.
  11809. clif_displaymessage(fd, msg_txt(sd,228));
  11810. return;
  11811. }
  11812. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11813. RFIFOL(fd,info->pos[1]),
  11814. RFIFOL(fd,info->pos[2]),
  11815. RFIFOCP(fd,info->pos[3]));
  11816. }
  11817. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11818. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11819. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11820. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11821. // validate packet and retrieve name and message
  11822. if( !clif_process_message( sd, false, name, message, output ) )
  11823. return;
  11824. if( sd->bg_id )
  11825. bg_send_message(sd, output, strlen(output) );
  11826. else
  11827. guild_send_message(sd, output, strlen(output) );
  11828. }
  11829. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11830. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11831. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11832. {
  11833. struct map_session_data *t_sd;
  11834. if(!sd->state.gmaster_flag)
  11835. return;
  11836. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11837. clif_displaymessage(fd, msg_txt(sd,228));
  11838. return;
  11839. }
  11840. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11841. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11842. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11843. // @noask [LuzZza]
  11844. if(t_sd && t_sd->state.noask) {
  11845. clif_noask_sub(sd, t_sd, 3);
  11846. return;
  11847. }
  11848. guild_reqalliance(sd,t_sd);
  11849. }
  11850. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11851. /// 0172 <inviter account id>.L <answer>.L
  11852. /// answer:
  11853. /// 0 = refuse
  11854. /// 1 = accept
  11855. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11856. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11857. guild_reply_reqalliance(sd,
  11858. RFIFOL(fd,info->pos[0]),
  11859. RFIFOL(fd,info->pos[1]));
  11860. }
  11861. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11862. /// 0183 <opponent guild id>.L <relation>.L
  11863. /// relation:
  11864. /// 0 = Ally
  11865. /// 1 = Enemy
  11866. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11867. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11868. if(!sd->state.gmaster_flag)
  11869. return;
  11870. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11871. clif_displaymessage(fd, msg_txt(sd,228));
  11872. return;
  11873. }
  11874. guild_delalliance(sd,
  11875. RFIFOL(fd,info->pos[0]),
  11876. RFIFOL(fd,info->pos[1]));
  11877. }
  11878. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11879. /// 0180 <account id>.L
  11880. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11881. {
  11882. struct map_session_data *t_sd;
  11883. if(!sd->state.gmaster_flag)
  11884. return;
  11885. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11886. clif_displaymessage(fd, msg_txt(sd,228));
  11887. return;
  11888. }
  11889. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11890. // @noask [LuzZza]
  11891. if(t_sd && t_sd->state.noask) {
  11892. clif_noask_sub(sd, t_sd, 4);
  11893. return;
  11894. }
  11895. guild_opposition(sd,t_sd);
  11896. }
  11897. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11898. /// 015d <key>.40B
  11899. /// key:
  11900. /// now guild name; might have been (intended) email, since the
  11901. /// field name and size is same as the one in CH_DELETE_CHAR.
  11902. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11903. {
  11904. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11905. clif_displaymessage(fd, msg_txt(sd,228));
  11906. return;
  11907. }
  11908. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11909. }
  11910. /// Pet
  11911. ///
  11912. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11913. /// 01a1 <type>.B
  11914. /// type:
  11915. /// 0 = pet information
  11916. /// 1 = feed
  11917. /// 2 = performance
  11918. /// 3 = return to egg
  11919. /// 4 = unequip accessory
  11920. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11921. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11922. }
  11923. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11924. /// 019f <id>.L
  11925. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11926. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11927. }
  11928. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11929. /// 01a7 <index>.W
  11930. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11931. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11932. return;
  11933. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11934. clif_menuskill_clear(sd);
  11935. }
  11936. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11937. /// 01a9 <data>.L
  11938. /// data:
  11939. /// is either emotion (@see enum emotion_type) or a compound value
  11940. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11941. /// entry (given in parentheses) in data\pettalktable.xml
  11942. /// act id:
  11943. /// 0 = feeding
  11944. /// 1 = hunting
  11945. /// 2 = danger
  11946. /// 3 = dead
  11947. /// 4 = normal (stand)
  11948. /// 5 = special performance (perfor_s)
  11949. /// 6 = level up (levelup)
  11950. /// 7 = performance 1 (perfor_1)
  11951. /// 8 = performance 2 (perfor_2)
  11952. /// 9 = performance 3 (perfor_3)
  11953. /// 10 = log-in greeting (connect)
  11954. /// hungry value:
  11955. /// 0 = very hungry (hungry)
  11956. /// 1 = hungry (bit_hungry)
  11957. /// 2 = satisfied (noting)
  11958. /// 3 = stuffed (full)
  11959. /// 4 = full (so_full)
  11960. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11961. {
  11962. if(sd->pd)
  11963. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11964. }
  11965. /// Request to change pet's name (CZ_RENAME_PET).
  11966. /// 01a5 <name>.24B
  11967. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11968. {
  11969. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11970. }
  11971. /// /kill (CZ_DISCONNECT_CHARACTER).
  11972. /// Request to disconnect a character.
  11973. /// 00cc <account id>.L
  11974. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11975. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11976. {
  11977. struct block_list *target;
  11978. int tid;
  11979. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11980. target = map_id2bl(tid);
  11981. if (!target) {
  11982. clif_GM_kickack(sd, 0);
  11983. return;
  11984. }
  11985. switch (target->type) {
  11986. case BL_PC:
  11987. {
  11988. char command[NAME_LENGTH+6];
  11989. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11990. is_atcommand(fd, sd, command, 1);
  11991. }
  11992. break;
  11993. /**
  11994. * This one does not invoke any atcommand, so we need to check for permissions.
  11995. */
  11996. case BL_MOB:
  11997. {
  11998. char command[100];
  11999. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12000. clif_GM_kickack(sd, 0);
  12001. return;
  12002. }
  12003. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12004. log_atcommand(sd, command);
  12005. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12006. }
  12007. break;
  12008. case BL_NPC:
  12009. {
  12010. struct npc_data* nd = (struct npc_data *)target;
  12011. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12012. npc_unload_duplicates(nd);
  12013. npc_unload(nd,true);
  12014. npc_read_event_script();
  12015. }
  12016. }
  12017. break;
  12018. default:
  12019. clif_GM_kickack(sd, 0);
  12020. }
  12021. }
  12022. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12023. /// Request to disconnect all characters.
  12024. /// 00ce
  12025. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  12026. char cmd[15];
  12027. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12028. is_atcommand(fd, sd, cmd, 1);
  12029. }
  12030. /// /remove (CZ_REMOVE_AID).
  12031. /// Request to warp to a character with given login ID.
  12032. /// 01ba <account name>.24B
  12033. /// /shift (CZ_SHIFT).
  12034. /// Request to warp to a character with given name.
  12035. /// 01bb <char name>.24B
  12036. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  12037. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12038. char *player_name;
  12039. char command[NAME_LENGTH+8];
  12040. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12041. player_name[NAME_LENGTH-1] = '\0';
  12042. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12043. is_atcommand(fd, sd, command, 1);
  12044. }
  12045. /// /remove (CZ_REMOVE_AID_SSO).
  12046. /// Request to warp to a character with given account ID.
  12047. /// 0843 <account id>.L
  12048. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12049. {
  12050. uint32 account_id;
  12051. struct map_session_data* pl_sd;
  12052. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12053. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12054. char command[NAME_LENGTH+8];
  12055. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12056. is_atcommand(fd, sd, command, 1);
  12057. }
  12058. }
  12059. /// /recall (CZ_RECALL).
  12060. /// Request to summon a player with given login ID to own position.
  12061. /// 01bc <account name>.24B
  12062. /// /summon (CZ_RECALL_GID).
  12063. /// Request to summon a player with given name to own position.
  12064. /// 01bd <char name>.24B
  12065. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12066. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12067. char *player_name;
  12068. char command [NAME_LENGTH+8];
  12069. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12070. player_name[NAME_LENGTH-1] = '\0';
  12071. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12072. is_atcommand(fd, sd, command, 1);
  12073. }
  12074. /// /recall (CZ_RECALL_SSO).
  12075. /// Request to summon a player with given account ID to own position.
  12076. /// 0842 <account id>.L
  12077. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12078. {
  12079. uint32 account_id;
  12080. struct map_session_data* pl_sd;
  12081. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12082. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12083. char command[NAME_LENGTH+8];
  12084. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12085. is_atcommand(fd, sd, command, 1);
  12086. }
  12087. }
  12088. /// /item /monster (CZ_ITEM_CREATE).
  12089. /// Request to execute GM commands.
  12090. /// Usage:
  12091. /// /item n - summon n monster or acquire n item/s
  12092. /// /item money - grants 2147483647 zenies
  12093. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12094. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12095. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12096. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12097. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12098. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12099. /// 013f <item/mob name>.24B
  12100. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12101. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12102. {
  12103. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12104. int mob_id = 0;
  12105. struct item_data *id = NULL;
  12106. struct mob_db *mob = NULL;
  12107. StringBuf command;
  12108. char *str;
  12109. //#if PACKETVER >= 20131218
  12110. // char str[100];
  12111. //#else
  12112. // char str[24];
  12113. //#endif
  12114. str = RFIFOCP(fd,info->pos[0]);
  12115. if (!str || str[0] == '\0')
  12116. return;
  12117. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12118. return;
  12119. trim(str);
  12120. // Zeny
  12121. if( strcmpi(str, "money") == 0 ) {
  12122. StringBuf_Init(&command);
  12123. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12124. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12125. StringBuf_Destroy(&command);
  12126. return;
  12127. }
  12128. // Item
  12129. if( (id = itemdb_searchname(str)) ) {
  12130. StringBuf_Init(&command);
  12131. if( !itemdb_isstackable2(id) ) //Nonstackable
  12132. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12133. else {
  12134. if (id->flag.guid)
  12135. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12136. else
  12137. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12138. }
  12139. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12140. StringBuf_Destroy(&command);
  12141. return;
  12142. }
  12143. // Monster
  12144. if ((mob_id = mobdb_searchname(str)) == 0)
  12145. mob_id = mobdb_checkid(atoi(str));
  12146. if( (mob = mob_db(mob_id)) ) {
  12147. StringBuf_Init(&command);
  12148. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12149. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12150. StringBuf_Destroy(&command);
  12151. return;
  12152. }
  12153. }
  12154. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12155. /// 019d <effect state>.L
  12156. /// effect state:
  12157. /// TODO: Any OPTION_* ?
  12158. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12159. char cmd[6];
  12160. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12161. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12162. is_atcommand(fd, sd, cmd, 1);
  12163. }
  12164. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12165. /// 0149 <account id>.L <type>.B <value>.W
  12166. /// type:
  12167. /// 0 = positive points
  12168. /// 1 = negative points
  12169. /// 2 = self mute (+10 minutes)
  12170. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12171. {
  12172. int id, type, value;
  12173. struct map_session_data *dstsd;
  12174. char command[NAME_LENGTH+15];
  12175. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12176. id = RFIFOL(fd,info->pos[0]);
  12177. type = RFIFOB(fd,info->pos[1]);
  12178. value = RFIFOW(fd,info->pos[2]);
  12179. if( type == 0 )
  12180. value = -value;
  12181. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12182. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12183. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12184. return;
  12185. dstsd = map_id2sd(id);
  12186. if( dstsd == NULL )
  12187. return;
  12188. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12189. is_atcommand(fd, sd, command, 1);
  12190. }
  12191. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12192. /// GM adjustment of a player's manner value by -60.
  12193. /// 0212 <char name>.24B
  12194. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12195. {
  12196. char command[NAME_LENGTH+15];
  12197. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12198. name[NAME_LENGTH-1] = '\0';
  12199. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12200. is_atcommand(fd, sd, command, 1);
  12201. }
  12202. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12203. /// 01e0 <account id>.L <account name>.24B
  12204. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12205. {
  12206. WFIFOHEAD(fd,packet_len(0x1e0));
  12207. WFIFOW(fd,0) = 0x1e0;
  12208. WFIFOL(fd,2) = account_id;
  12209. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12210. WFIFOSET(fd,packet_len(0x1e0));
  12211. }
  12212. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12213. /// 01df <account id>.L
  12214. //! TODO: Figure out how does this actually work
  12215. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12216. {
  12217. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12218. /*
  12219. char query[30];
  12220. safesnprintf(query,sizeof(query),"%d", account_id);
  12221. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12222. */
  12223. clif_account_name(fd, account_id, "");
  12224. }
  12225. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12226. /// GM single cell type change request.
  12227. /// 0198 <x>.W <y>.W <type>.W
  12228. /// type:
  12229. /// 0 = not walkable
  12230. /// 1 = walkable
  12231. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12232. {
  12233. int x,y,type;
  12234. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12235. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12236. return;
  12237. x = RFIFOW(fd,info->pos[0]);
  12238. y = RFIFOW(fd,info->pos[1]);
  12239. type = RFIFOW(fd,info->pos[2]);
  12240. map_setgatcell(sd->bl.m,x,y,type);
  12241. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12242. //FIXME: once players leave the map, the client 'forgets' this information.
  12243. }
  12244. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12245. /// Request to allow/deny whispers from a nick.
  12246. /// 00cf <nick>.24B <type>.B
  12247. /// type:
  12248. /// 0 = (/ex nick) deny speech from nick
  12249. /// 1 = (/in nick) allow speech from nick
  12250. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12251. {
  12252. char* nick;
  12253. uint8 type;
  12254. int i;
  12255. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12256. nick = RFIFOCP(fd,info->pos[0]);
  12257. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12258. type = RFIFOB(fd,info->pos[1]);
  12259. if( type == 0 ) { // Add name to ignore list (block)
  12260. if (strcmp(wisp_server_name, nick) == 0) {
  12261. clif_wisexin(sd, type, 1); // fail
  12262. return;
  12263. }
  12264. // try to find a free spot, while checking for duplicates at the same time
  12265. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12266. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12267. clif_wisexin(sd, type, 2); // too many blocks
  12268. return;
  12269. }
  12270. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12271. clif_wisexin(sd, type, 0); // Aegis reports success.
  12272. return;
  12273. }
  12274. //Insert in position i
  12275. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12276. } else { // Remove name from ignore list (unblock)
  12277. // find entry
  12278. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12279. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12280. clif_wisexin(sd, type, 1); // fail
  12281. return;
  12282. }
  12283. // move everything one place down to overwrite removed entry
  12284. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12285. // wipe last entry
  12286. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12287. }
  12288. clif_wisexin(sd, type, 0); // success
  12289. }
  12290. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12291. /// Request to allow/deny all whispers.
  12292. /// 00d0 <type>.B
  12293. /// type:
  12294. /// 0 = (/exall) deny all speech
  12295. /// 1 = (/inall) allow all speech
  12296. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12297. {
  12298. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12299. if( type == 0 ) {// Deny all
  12300. if( sd->state.ignoreAll ) {
  12301. flag = 1; // fail
  12302. } else {
  12303. sd->state.ignoreAll = 1;
  12304. flag = 0; // success
  12305. }
  12306. } else {//Unblock everyone
  12307. if( sd->state.ignoreAll ) {
  12308. sd->state.ignoreAll = 0;
  12309. flag = 0; // success
  12310. } else {
  12311. if (sd->ignore[0].name[0] != '\0')
  12312. { //Wipe the ignore list.
  12313. memset(sd->ignore, 0, sizeof(sd->ignore));
  12314. flag = 0; // success
  12315. } else {
  12316. flag = 1; // fail
  12317. }
  12318. }
  12319. }
  12320. clif_wisall(sd, type, flag);
  12321. }
  12322. /// Whisper ignore list (ZC_WHISPER_LIST).
  12323. /// 00d4 <packet len>.W { <char name>.24B }*
  12324. void clif_PMIgnoreList(struct map_session_data* sd)
  12325. {
  12326. int i, fd = sd->fd;
  12327. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12328. WFIFOW(fd,0) = 0xd4;
  12329. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12330. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12331. }
  12332. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12333. WFIFOSET(fd,WFIFOW(fd,2));
  12334. }
  12335. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12336. /// 00d3
  12337. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12338. {
  12339. clif_PMIgnoreList(sd);
  12340. }
  12341. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12342. /// 01e7
  12343. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12344. {
  12345. if (sd->state.doridori) return;
  12346. switch (sd->class_&MAPID_UPPERMASK) {
  12347. case MAPID_SOUL_LINKER:
  12348. case MAPID_STAR_GLADIATOR:
  12349. case MAPID_TAEKWON:
  12350. if (!sd->state.rest)
  12351. break;
  12352. case MAPID_SUPER_NOVICE:
  12353. case MAPID_SUPER_BABY:
  12354. case MAPID_SUPER_NOVICE_E:
  12355. case MAPID_SUPER_BABY_E:
  12356. sd->state.doridori=1;
  12357. break;
  12358. }
  12359. }
  12360. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12361. /// 01ed
  12362. /// Note: This packet is caused by 7 lines of any text, followed by
  12363. /// the prayer and an another line of any text. The prayer is
  12364. /// defined by lines 790~793 in data\msgstringtable.txt
  12365. /// "Dear angel, can you hear my voice?"
  12366. /// "I am" (space separated player name) "Super Novice~"
  12367. /// "Help me out~ Please~ T_T"
  12368. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12369. {
  12370. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12371. t_exp next = pc_nextbaseexp(sd);
  12372. if( next ) {
  12373. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12374. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12375. 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]
  12376. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12377. }
  12378. }
  12379. }
  12380. }
  12381. /// Friends List
  12382. ///
  12383. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12384. /// 0206 <account id>.L <char id>.L <state>.B
  12385. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12386. /// state:
  12387. /// 0 = online
  12388. /// 1 = offline
  12389. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12390. {
  12391. int i, fd = sd->fd;
  12392. //Seek friend.
  12393. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12394. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12395. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12396. return; //Not found
  12397. WFIFOHEAD(fd,packet_len(0x206));
  12398. WFIFOW(fd, 0) = 0x206;
  12399. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12400. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12401. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12402. #if PACKETVER >= 20180221
  12403. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12404. #endif
  12405. WFIFOSET(fd, packet_len(0x206));
  12406. }
  12407. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12408. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12409. {
  12410. uint32 account_id, char_id, online;
  12411. account_id = va_arg(ap, int);
  12412. char_id = va_arg(ap, int);
  12413. online = va_arg(ap, int);
  12414. clif_friendslist_toggle(sd, account_id, char_id, online);
  12415. return 0;
  12416. }
  12417. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12418. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12419. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12420. void clif_friendslist_send(struct map_session_data *sd)
  12421. {
  12422. int i = 0, n, fd = sd->fd;
  12423. #if PACKETVER >= 20180221
  12424. const int size = 8;
  12425. #else
  12426. const int size = 8 + NAME_LENGTH;
  12427. #endif
  12428. // Send friends list
  12429. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12430. WFIFOW(fd, 0) = 0x201;
  12431. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12432. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12433. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12434. #if PACKETVER < 20180221
  12435. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12436. #endif
  12437. }
  12438. if (i) {
  12439. WFIFOW(fd,2) = 4 + size * i;
  12440. WFIFOSET(fd, WFIFOW(fd,2));
  12441. }
  12442. for (n = 0; n < i; n++) { //Sending the online players
  12443. if (map_charid2sd(sd->status.friends[n].char_id))
  12444. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12445. }
  12446. }
  12447. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12448. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12449. /// result:
  12450. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12451. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12452. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12453. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12454. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12455. {
  12456. int fd;
  12457. nullpo_retv(sd);
  12458. fd = sd->fd;
  12459. WFIFOHEAD(fd,packet_len(0x209));
  12460. WFIFOW(fd,0) = 0x209;
  12461. WFIFOW(fd,2) = type;
  12462. if (f_sd) {
  12463. WFIFOL(fd,4) = f_sd->status.account_id;
  12464. WFIFOL(fd,8) = f_sd->status.char_id;
  12465. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12466. }
  12467. WFIFOSET(fd, packet_len(0x209));
  12468. }
  12469. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12470. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12471. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12472. {
  12473. int fd = sd->fd;
  12474. WFIFOHEAD(fd,packet_len(0x207));
  12475. WFIFOW(fd,0) = 0x207;
  12476. WFIFOL(fd,2) = account_id;
  12477. WFIFOL(fd,6) = char_id;
  12478. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12479. WFIFOSET(fd,packet_len(0x207));
  12480. }
  12481. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12482. /// 0202 <name>.24B
  12483. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12484. {
  12485. struct map_session_data *f_sd;
  12486. int i;
  12487. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12488. // Friend doesn't exist (no player with this name)
  12489. if (f_sd == NULL) {
  12490. clif_displaymessage(fd, msg_txt(sd,3));
  12491. return;
  12492. }
  12493. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12494. return;
  12495. }
  12496. // ensure that the request player's friend list is not full
  12497. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12498. if( i == MAX_FRIENDS ){
  12499. clif_friendslist_reqack(sd, f_sd, 2);
  12500. return;
  12501. }
  12502. // @noask [LuzZza]
  12503. if(f_sd->state.noask) {
  12504. clif_noask_sub(sd, f_sd, 5);
  12505. return;
  12506. }
  12507. // Friend already exists
  12508. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12509. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12510. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12511. return;
  12512. }
  12513. }
  12514. f_sd->friend_req = sd->status.char_id;
  12515. sd->friend_req = f_sd->status.char_id;
  12516. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12517. }
  12518. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12519. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12520. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12521. /// reply:
  12522. /// 0 = rejected
  12523. /// 1 = accepted
  12524. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12525. {
  12526. struct map_session_data *f_sd;
  12527. uint32 account_id;
  12528. char reply;
  12529. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12530. account_id = RFIFOL(fd,info->pos[0]);
  12531. //char_id = RFIFOL(fd,info->pos[1]);
  12532. #if PACKETVER < 6
  12533. reply = RFIFOB(fd,info->pos[2]);
  12534. #else
  12535. reply = RFIFOL(fd,info->pos[2]);
  12536. #endif
  12537. if( sd->bl.id == account_id ) {// adding oneself as friend
  12538. return;
  12539. }
  12540. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12541. if (f_sd == NULL)
  12542. return;
  12543. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12544. clif_friendslist_reqack(f_sd, sd, 1);
  12545. else {
  12546. int i;
  12547. // Find an empty slot
  12548. for (i = 0; i < MAX_FRIENDS; i++)
  12549. if (f_sd->status.friends[i].char_id == 0)
  12550. break;
  12551. if (i == MAX_FRIENDS) {
  12552. clif_friendslist_reqack(f_sd, sd, 2);
  12553. return;
  12554. }
  12555. f_sd->status.friends[i].account_id = sd->status.account_id;
  12556. f_sd->status.friends[i].char_id = sd->status.char_id;
  12557. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12558. clif_friendslist_reqack(f_sd, sd, 0);
  12559. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12560. if (battle_config.friend_auto_add) {
  12561. // Also add f_sd to sd's friendlist.
  12562. for (i = 0; i < MAX_FRIENDS; i++) {
  12563. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12564. return; //No need to add anything.
  12565. if (sd->status.friends[i].char_id == 0)
  12566. break;
  12567. }
  12568. if (i == MAX_FRIENDS) {
  12569. clif_friendslist_reqack(sd, f_sd, 2);
  12570. return;
  12571. }
  12572. sd->status.friends[i].account_id = f_sd->status.account_id;
  12573. sd->status.friends[i].char_id = f_sd->status.char_id;
  12574. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12575. clif_friendslist_reqack(sd, f_sd, 0);
  12576. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12577. }
  12578. }
  12579. }
  12580. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12581. /// 0203 <account id>.L <char id>.L
  12582. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12583. {
  12584. struct map_session_data *f_sd = NULL;
  12585. uint32 account_id, char_id;
  12586. int i, j;
  12587. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12588. account_id = RFIFOL(fd,info->pos[0]);
  12589. char_id = RFIFOL(fd,info->pos[1]);
  12590. // Search friend
  12591. for (i = 0; i < MAX_FRIENDS &&
  12592. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12593. if (i == MAX_FRIENDS) {
  12594. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12595. return;
  12596. }
  12597. //remove from friend's list first
  12598. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12599. for (i = 0; i < MAX_FRIENDS &&
  12600. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12601. if (i != MAX_FRIENDS) {
  12602. // move all chars up
  12603. for(j = i + 1; j < MAX_FRIENDS; j++)
  12604. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12605. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12606. //should the guy be notified of some message? we should add it here if so
  12607. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12608. WFIFOW(f_sd->fd,0) = 0x20a;
  12609. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12610. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12611. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12612. }
  12613. } else { //friend not online -- ask char server to delete from his friendlist
  12614. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12615. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12616. return;
  12617. }
  12618. }
  12619. // We can now delete from original requester
  12620. for (i = 0; i < MAX_FRIENDS &&
  12621. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12622. // move all chars up
  12623. for(j = i + 1; j < MAX_FRIENDS; j++)
  12624. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12625. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12626. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12627. WFIFOHEAD(fd,packet_len(0x20a));
  12628. WFIFOW(fd,0) = 0x20a;
  12629. WFIFOL(fd,2) = account_id;
  12630. WFIFOL(fd,6) = char_id;
  12631. WFIFOSET(fd, packet_len(0x20a));
  12632. }
  12633. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12634. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12635. void clif_PVPInfo(struct map_session_data* sd)
  12636. {
  12637. int fd = sd->fd;
  12638. WFIFOHEAD(fd,packet_len(0x210));
  12639. WFIFOW(fd,0) = 0x210;
  12640. WFIFOL(fd,2) = sd->status.char_id;
  12641. WFIFOL(fd,6) = sd->status.account_id;
  12642. WFIFOL(fd,10) = sd->pvp_won; // times won
  12643. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12644. WFIFOL(fd,18) = sd->pvp_point;
  12645. WFIFOSET(fd, packet_len(0x210));
  12646. }
  12647. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12648. /// 020f <char id>.L <account id>.L
  12649. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12650. {
  12651. // TODO: Is there a way to use this on an another player (char/acc id)?
  12652. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12653. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12654. clif_PVPInfo(sd);
  12655. }
  12656. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12657. /// 0254 <which>.B
  12658. /// which: (unused atm for security purpose)
  12659. /// 0 = sun
  12660. /// 1 = moon
  12661. /// 2 = star
  12662. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12663. {
  12664. int i;
  12665. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12666. if (sd->menuskill_id != SG_FEEL)
  12667. return;
  12668. i = sd->menuskill_val-1;
  12669. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12670. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12671. sd->feel_map[i].m = sd->bl.m;
  12672. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12673. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12674. // clif_misceffect2(&sd->bl, 0x1b0);
  12675. // clif_misceffect2(&sd->bl, 0x21f);
  12676. clif_feel_info(sd, i, 0);
  12677. clif_menuskill_clear(sd);
  12678. }
  12679. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12680. /// 0253 <which>.B
  12681. /// which:
  12682. /// 0 = sun
  12683. /// 1 = moon
  12684. /// 2 = star
  12685. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12686. {
  12687. WFIFOHEAD(fd,packet_len(0x253));
  12688. WFIFOW(fd,0)=0x253;
  12689. WFIFOB(fd,2)=TOB(skill_lv-1);
  12690. WFIFOSET(fd, packet_len(0x253));
  12691. sd->menuskill_id = SG_FEEL;
  12692. sd->menuskill_val = skill_lv;
  12693. }
  12694. /// Request to change homunculus' name (CZ_RENAME_MER).
  12695. /// 0231 <name>.24B
  12696. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12697. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12698. }
  12699. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12700. /// 0234 <id>.L
  12701. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12702. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12703. struct block_list *bl = NULL;
  12704. struct unit_data *ud = NULL;
  12705. if( sd->md && sd->md->bl.id == id )
  12706. bl = &sd->md->bl;
  12707. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12708. bl = &sd->hd->bl; // Moving Homunculus
  12709. else
  12710. return;
  12711. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12712. ud = unit_bl2ud(bl);
  12713. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12714. }
  12715. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12716. /// 0232 <id>.L <position data>.3B
  12717. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12718. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12719. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12720. struct block_list *bl = NULL;
  12721. short x, y;
  12722. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12723. if( sd->md && sd->md->bl.id == id )
  12724. bl = &sd->md->bl; // Moving Mercenary
  12725. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12726. bl = &sd->hd->bl; // Moving Homunculus
  12727. else
  12728. return;
  12729. unit_walktoxy(bl, x, y, 4);
  12730. }
  12731. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12732. /// 0233 <id>.L <target id>.L <action>.B
  12733. /// action:
  12734. /// always 0
  12735. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12736. {
  12737. struct block_list *bl = NULL;
  12738. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12739. int id = RFIFOL(fd,info->pos[0]);
  12740. int target_id = RFIFOL(fd,info->pos[1]);
  12741. int action_type = RFIFOB(fd,info->pos[2]);
  12742. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12743. bl = &sd->hd->bl;
  12744. else if( sd->md && sd->md->bl.id == id )
  12745. bl = &sd->md->bl;
  12746. else return;
  12747. unit_stop_attack(bl);
  12748. unit_attack(bl, target_id, action_type != 0);
  12749. }
  12750. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12751. /// 022d <type>.W <command>.B
  12752. /// type:
  12753. /// always 0
  12754. /// command:
  12755. /// 0 = homunculus information
  12756. /// 1 = feed
  12757. /// 2 = delete
  12758. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12759. { //[orn]
  12760. int cmd = RFIFOW(fd,0);
  12761. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12762. if(!hom_is_active(sd->hd))
  12763. return;
  12764. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12765. }
  12766. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12767. /// 0292
  12768. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12769. {
  12770. pc_revive_item(sd);
  12771. }
  12772. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12773. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12774. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12775. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12776. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12777. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12778. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12779. void clif_check(int fd, struct map_session_data* pl_sd)
  12780. {
  12781. WFIFOHEAD(fd,packet_len(0x214));
  12782. WFIFOW(fd, 0) = 0x214;
  12783. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12784. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12785. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12786. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12787. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12788. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12789. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12790. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12791. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12792. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12793. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12794. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12795. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12796. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12797. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12798. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12799. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12800. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12801. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12802. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12803. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12804. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12805. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12806. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12807. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12808. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12809. WFIFOSET(fd,packet_len(0x214));
  12810. }
  12811. /// /check (CZ_REQ_STATUS_GM).
  12812. /// Request character's status values.
  12813. /// 0213 <char name>.24B
  12814. void clif_parse_Check(int fd, struct map_session_data *sd)
  12815. {
  12816. char charname[NAME_LENGTH];
  12817. struct map_session_data* pl_sd;
  12818. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12819. return;
  12820. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12821. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12822. {
  12823. return;
  12824. }
  12825. clif_check(fd, pl_sd);
  12826. }
  12827. /// MAIL SYSTEM
  12828. /// By Zephyrus
  12829. ///
  12830. /// Notification about the result of adding an item to mail
  12831. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12832. /// result:
  12833. /// 0 = success
  12834. /// 1 = failure
  12835. /// 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)
  12836. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12837. /// result:
  12838. /// 0 = success
  12839. /// 1 = over weight
  12840. /// 2 = fatal error
  12841. void clif_Mail_setattachment( struct map_session_data* sd, int index, int amount, uint8 flag ){
  12842. int fd = sd->fd;
  12843. #if PACKETVER < 20150513
  12844. WFIFOHEAD(fd,packet_len(0x255));
  12845. WFIFOW(fd,0) = 0x255;
  12846. WFIFOW(fd,2) = index;
  12847. WFIFOB(fd,4) = flag;
  12848. WFIFOSET(fd,packet_len(0x255));
  12849. #else
  12850. struct PACKET_ZC_ADD_ITEM_TO_MAIL p;
  12851. if( flag ){
  12852. memset( &p, 0, sizeof( p ) );
  12853. }else{
  12854. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  12855. p.index = index;
  12856. p.count = amount;
  12857. p.itemId = client_nameid( item->nameid );
  12858. p.type = itemtype( item->nameid );
  12859. p.IsIdentified = item->identify ? 1 : 0;
  12860. p.IsDamaged = item->attribute ? 1 : 0;
  12861. p.refiningLevel = item->refine;
  12862. clif_addcards( &p.slot, item );
  12863. clif_add_random_options( p.optionData, item );
  12864. p.weight = 0;
  12865. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  12866. if( sd->mail.item[i].nameid == 0 ){
  12867. continue;
  12868. }
  12869. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12870. }
  12871. p.favorite = item->favorite;
  12872. p.location = pc_equippoint( sd, server_index( index ) );
  12873. }
  12874. p.PacketType = rodexadditem;
  12875. p.result = flag;
  12876. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  12877. #endif
  12878. }
  12879. /// Notification about the result of retrieving a mail attachment
  12880. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12881. /// result:
  12882. /// 0 = success
  12883. /// 1 = failure
  12884. /// 2 = too many items
  12885. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12886. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12887. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12888. #if PACKETVER < 20150513
  12889. int fd = sd->fd;
  12890. WFIFOHEAD(fd,packet_len(0x245));
  12891. WFIFOW(fd,0) = 0x245;
  12892. WFIFOB(fd,2) = result;
  12893. WFIFOSET(fd,packet_len(0x245));
  12894. #else
  12895. switch( type ){
  12896. case MAIL_ATT_ITEM:
  12897. case MAIL_ATT_ZENY:
  12898. break;
  12899. default:
  12900. return;
  12901. }
  12902. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  12903. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  12904. p.MailID = msg->id;
  12905. p.opentype = msg->type;
  12906. p.result = result;
  12907. clif_send(&p, sizeof(p), &sd->bl, SELF);
  12908. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12909. #endif
  12910. }
  12911. /// Notification about the result of sending a mail
  12912. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12913. /// result:
  12914. /// 0 = success
  12915. /// 1 = recipinent does not exist
  12916. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12917. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12918. #if PACKETVER < 20150513
  12919. int fd = sd->fd;
  12920. WFIFOHEAD(fd,packet_len(0x249));
  12921. WFIFOW(fd,0) = 0x249;
  12922. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12923. WFIFOSET(fd,packet_len(0x249));
  12924. #else
  12925. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  12926. p.PacketType = rodexwriteresult;
  12927. p.result = result;
  12928. clif_send(&p, sizeof(p), &sd->bl, SELF);
  12929. #endif
  12930. }
  12931. /// Notification about the result of deleting a mail.
  12932. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12933. /// result:
  12934. /// 0 = success
  12935. /// 1 = failure
  12936. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12937. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12938. #if PACKETVER < 20150513
  12939. int fd = sd->fd;
  12940. WFIFOHEAD(fd, packet_len(0x257));
  12941. WFIFOW(fd,0) = 0x257;
  12942. WFIFOL(fd,2) = msg->id;
  12943. WFIFOW(fd,6) = !success;
  12944. WFIFOSET(fd, packet_len(0x257));
  12945. #else
  12946. // This is only a success notification
  12947. if( success ){
  12948. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  12949. p.PacketType = rodexdelete;
  12950. p.opentype = msg->type;
  12951. p.MailID = msg->id;
  12952. clif_send(&p, sizeof(p), &sd->bl, SELF);
  12953. }
  12954. #endif
  12955. }
  12956. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12957. /// 0274 <mail id>.L <result>.W
  12958. /// result:
  12959. /// 0 = success
  12960. /// 1 = failure
  12961. void clif_Mail_return(int fd, int mail_id, short fail)
  12962. {
  12963. WFIFOHEAD(fd,packet_len(0x274));
  12964. WFIFOW(fd,0) = 0x274;
  12965. WFIFOL(fd,2) = mail_id;
  12966. WFIFOW(fd,6) = fail;
  12967. WFIFOSET(fd,packet_len(0x274));
  12968. }
  12969. /// Notification about new mail.
  12970. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12971. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12972. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12973. #if PACKETVER < 20150513
  12974. int fd = sd->fd;
  12975. WFIFOHEAD(fd,packet_len(0x24a));
  12976. WFIFOW(fd,0) = 0x24a;
  12977. WFIFOL(fd,2) = mail_id;
  12978. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12979. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12980. WFIFOSET(fd,packet_len(0x24a));
  12981. #else
  12982. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  12983. p.PacketType = rodexicon;
  12984. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12985. clif_send(&p, sizeof(p), &sd->bl, SELF);
  12986. #endif
  12987. }
  12988. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12989. /// 0260 <type>.L
  12990. /// type:
  12991. /// 0 = open
  12992. /// 1 = close
  12993. void clif_Mail_window(int fd, int flag)
  12994. {
  12995. WFIFOHEAD(fd,packet_len(0x260));
  12996. WFIFOW(fd,0) = 0x260;
  12997. WFIFOL(fd,2) = flag;
  12998. WFIFOSET(fd,packet_len(0x260));
  12999. }
  13000. /// Lists mails stored in inbox.
  13001. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13002. /// read:
  13003. /// 0 = unread
  13004. /// 1 = read
  13005. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13006. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13007. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13008. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13009. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13010. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13011. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13012. #if PACKETVER < 20150513
  13013. int fd = sd->fd;
  13014. struct mail_data *md = &sd->mail.inbox;
  13015. struct mail_message *msg;
  13016. int len, i, j;
  13017. len = 8 + (73 * md->amount);
  13018. WFIFOHEAD(fd,len);
  13019. WFIFOW(fd,0) = 0x240;
  13020. WFIFOW(fd,2) = len;
  13021. WFIFOL(fd,4) = md->amount;
  13022. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13023. {
  13024. msg = &md->msg[i];
  13025. if (msg->id < 1)
  13026. continue;
  13027. WFIFOL(fd,8+73*j) = msg->id;
  13028. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13029. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13030. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13031. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13032. j++;
  13033. }
  13034. WFIFOSET(fd,len);
  13035. if( md->full ) {// TODO: is this official?
  13036. char output[100];
  13037. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13038. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13039. }
  13040. #else
  13041. int fd = sd->fd;
  13042. struct mail_data *md = &sd->mail.inbox;
  13043. struct mail_message *msg;
  13044. int i, j, k, offset, titleLength;
  13045. uint8 mailType, amount, remaining;
  13046. uint32 now = (uint32)time(NULL);
  13047. #if PACKETVER >= 20170419
  13048. int cmd = 0xac2;
  13049. #elif PACKETVER >= 20160601
  13050. int cmd = 0xa7d;
  13051. #else
  13052. int cmd = 0x9f0;
  13053. #endif
  13054. if( battle_config.mail_daily_count ){
  13055. mail_refresh_remaining_amount(sd);
  13056. }
  13057. #if PACKETVER >= 20170419
  13058. // Always send all
  13059. i = md->amount;
  13060. #else
  13061. // If a starting mail id was sent
  13062. if( mailID != 0 ){
  13063. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13064. // Unknown mail
  13065. if( i == md->amount ){
  13066. // Ignore the request for now
  13067. return; // TODO: Should we just show the first page instead?
  13068. }
  13069. // It was actually the oldest/first mail, there is no further page
  13070. if( i == 0 ){
  13071. return;
  13072. }
  13073. // We actually want the next/older mail
  13074. i -= 1;
  13075. }else{
  13076. i = md->amount;
  13077. }
  13078. #endif
  13079. // Count the remaining mails from the starting mail or the beginning
  13080. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13081. for( j = i, remaining = 0; j >= 0; j-- ){
  13082. msg = &md->msg[j];
  13083. if (msg->id < 1)
  13084. continue;
  13085. #if PACKETVER < 20170419
  13086. if (msg->type != type)
  13087. continue;
  13088. #endif
  13089. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13090. continue;
  13091. remaining++;
  13092. }
  13093. #if PACKETVER >= 20170419
  13094. // Always send all
  13095. amount = remaining;
  13096. #else
  13097. if( remaining > MAIL_PAGE_SIZE ){
  13098. amount = MAIL_PAGE_SIZE;
  13099. }else{
  13100. amount = remaining;
  13101. }
  13102. #endif
  13103. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13104. WFIFOW(fd, 0) = cmd;
  13105. #if PACKETVER >= 20170419
  13106. WFIFOB(fd, 4) = 1; // Unknown
  13107. offset = 5;
  13108. #else
  13109. WFIFOB(fd, 4) = type;
  13110. WFIFOB(fd, 5) = amount;
  13111. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13112. offset = 7;
  13113. #endif
  13114. for( amount = 0; i >= 0; i-- ){
  13115. msg = &md->msg[i];
  13116. if (msg->id < 1)
  13117. continue;
  13118. #if PACKETVER < 20170419
  13119. if (msg->type != type)
  13120. continue;
  13121. #endif
  13122. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13123. continue;
  13124. #if PACKETVER >= 20170419
  13125. WFIFOB(fd, offset) = msg->type;
  13126. offset += 1;
  13127. #endif
  13128. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13129. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13130. mailType = MAIL_TYPE_TEXT; // Normal letter
  13131. if( msg->zeny > 0 ){
  13132. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13133. }
  13134. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13135. if( msg->item[k].nameid > 0 ){
  13136. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13137. break;
  13138. }
  13139. }
  13140. #if PACKETVER >= 20170419
  13141. // If it came from an npc?
  13142. if( !msg->send_id ){
  13143. mailType |= MAIL_TYPE_NPC;
  13144. }
  13145. #endif
  13146. WFIFOB(fd, offset + 9) = mailType;
  13147. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13148. #if PACKETVER < 20170419
  13149. // How much time has passed since you received the mail
  13150. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13151. offset += 4;
  13152. #endif
  13153. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13154. if( msg->scheduled_deletion > 0 ){
  13155. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13156. }else{
  13157. // Fake the scheduled deletion to one year in the future
  13158. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13159. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13160. }
  13161. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13162. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13163. offset += 40 + titleLength;
  13164. }
  13165. WFIFOW(fd, 2) = (int16)offset;
  13166. WFIFOSET(fd, offset);
  13167. #endif
  13168. }
  13169. /// Mail inbox list request.
  13170. /// 023f (CZ_MAIL_GET_LIST)
  13171. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13172. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13173. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13174. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13175. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13176. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13177. #if PACKETVER < 20150513
  13178. struct mail_data* md = &sd->mail.inbox;
  13179. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13180. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13181. else
  13182. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13183. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13184. mail_removezeny(sd, false);
  13185. #else
  13186. int cmd = RFIFOW(fd, 0);
  13187. #if PACKETVER < 20170419
  13188. uint8 openType = RFIFOB(fd, 2);
  13189. uint64 mailId = RFIFOQ(fd, 3);
  13190. #else
  13191. uint8 openType;
  13192. uint64 mailId = RFIFOQ(fd, 2);
  13193. int i;
  13194. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13195. if( i == MAIL_MAX_INBOX ){
  13196. openType = MAIL_INBOX_NORMAL;
  13197. mailId = 0;
  13198. }else{
  13199. openType = sd->mail.inbox.msg[i].type;
  13200. mailId = 0;
  13201. }
  13202. #endif
  13203. switch( openType ){
  13204. case MAIL_INBOX_NORMAL:
  13205. case MAIL_INBOX_ACCOUNT:
  13206. case MAIL_INBOX_RETURNED:
  13207. break;
  13208. default:
  13209. // Unknown type: ignore request
  13210. return;
  13211. }
  13212. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13213. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13214. return;
  13215. }
  13216. // If it is not a next page request
  13217. if( cmd != 0x9ee ){
  13218. mailId = 0;
  13219. }
  13220. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13221. #endif
  13222. }
  13223. /// Opens a mail
  13224. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13225. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13226. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13227. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13228. /// { }*n
  13229. // TODO: Packet description => for repeated block
  13230. void clif_Mail_read( struct map_session_data *sd, int mail_id ){
  13231. int i, fd = sd->fd;
  13232. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13233. if( i == MAIL_MAX_INBOX ) {
  13234. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13235. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13236. return;
  13237. } else {
  13238. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13239. struct item *item;
  13240. struct item_data *data;
  13241. int msg_len = strlen(msg->body);
  13242. if( msg_len == 0 ) {
  13243. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13244. msg_len = strlen(msg->body);
  13245. }
  13246. #if PACKETVER < 20150513
  13247. item = &msg->item[0];
  13248. int len = 101 + msg_len;
  13249. WFIFOHEAD(fd,len);
  13250. WFIFOW(fd,0) = 0x242;
  13251. WFIFOW(fd,2) = len;
  13252. WFIFOL(fd,4) = msg->id;
  13253. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13254. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13255. WFIFOL(fd,72) = 0;
  13256. WFIFOL(fd,76) = msg->zeny;
  13257. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13258. WFIFOL(fd,80) = item->amount;
  13259. WFIFOW(fd,84) = client_nameid( item->nameid );
  13260. WFIFOW(fd,86) = itemtype( item->nameid );
  13261. WFIFOB(fd,88) = item->identify;
  13262. WFIFOB(fd,89) = item->attribute;
  13263. WFIFOB(fd,90) = item->refine;
  13264. WFIFOW(fd,91) = item->card[0];
  13265. WFIFOW(fd,93) = item->card[1];
  13266. WFIFOW(fd,95) = item->card[2];
  13267. WFIFOW(fd,97) = item->card[3];
  13268. } else // no item, set all to zero
  13269. memset(WFIFOP(fd,80), 0x00, 19);
  13270. WFIFOB(fd,99) = (unsigned char)msg_len;
  13271. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13272. WFIFOSET(fd,len);
  13273. #else
  13274. msg_len += 1; // Zero Termination
  13275. int length = sizeof( struct PACKET_ZC_READ_MAIL ) + MAIL_BODY_LENGTH + sizeof( struct mail_item ) * MAIL_MAX_ITEM;
  13276. WFIFOHEAD( fd, length );
  13277. struct PACKET_ZC_READ_MAIL *p = (struct PACKET_ZC_READ_MAIL *)WFIFOP( fd, 0 );
  13278. p->PacketType = rodexread;
  13279. p->PacketLength = length;
  13280. p->opentype = msg->type;
  13281. p->MailID = msg->id;
  13282. p->TextcontentsLength = msg_len;
  13283. p->zeny = msg->zeny;
  13284. int offset = sizeof( struct PACKET_ZC_READ_MAIL );
  13285. safestrncpy( WFIFOCP( fd, offset ), msg->body, msg_len );
  13286. offset += msg_len;
  13287. int count = 0;
  13288. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13289. item = &msg->item[j];
  13290. if( item->nameid > 0 && item->amount > 0 && ( data = itemdb_exists( item->nameid ) ) != NULL ){
  13291. struct mail_item* mailitem = (struct mail_item *)WFIFOP( fd, offset );
  13292. mailitem->ITID = client_nameid( item->nameid );
  13293. mailitem->count = item->amount;
  13294. mailitem->type = itemtype( item->nameid );
  13295. mailitem->IsIdentified = item->identify ? 1 : 0;
  13296. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13297. mailitem->refiningLevel = item->refine;
  13298. mailitem->location = pc_equippoint_sub( sd, data );
  13299. mailitem->viewSprite = data->look;
  13300. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13301. clif_addcards( &mailitem->slot, item );
  13302. clif_add_random_options( mailitem->optionData, item );
  13303. offset += sizeof( struct mail_item );
  13304. count++;
  13305. }
  13306. }
  13307. p->ItemCnt = count;
  13308. p->PacketLength = sizeof( struct PACKET_ZC_READ_MAIL ) + p->TextcontentsLength + sizeof( struct mail_item ) * p->ItemCnt;
  13309. WFIFOSET( fd, p->PacketLength );
  13310. #endif
  13311. if (msg->status == MAIL_UNREAD) {
  13312. msg->status = MAIL_READ;
  13313. intif_Mail_read(mail_id);
  13314. clif_parse_Mail_refreshinbox(fd, sd);
  13315. sd->mail.inbox.unread--;
  13316. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13317. }
  13318. }
  13319. }
  13320. /// Request to open a mail.
  13321. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13322. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13323. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13324. #if PACKETVER < 20150513
  13325. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13326. #else
  13327. //uint8 openType = RFIFOB(fd, 2);
  13328. int mail_id = (int)RFIFOQ(fd, 3);
  13329. #endif
  13330. if( mail_id <= 0 )
  13331. return;
  13332. if( mail_invalid_operation(sd) )
  13333. return;
  13334. clif_Mail_read(sd, mail_id);
  13335. }
  13336. /// Allow a player to begin writing a mail
  13337. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13338. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13339. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13340. p.PacketType = rodexopenwrite;
  13341. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13342. p.result = success;
  13343. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13344. }
  13345. /// Request to start writing a mail
  13346. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13347. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13348. char name[NAME_LENGTH];
  13349. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13350. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13351. clif_send_Mail_beginwrite_ack(sd, name, false);
  13352. return;
  13353. }
  13354. mail_clear(sd);
  13355. sd->state.mail_writing = true;
  13356. clif_send_Mail_beginwrite_ack(sd, name,true);
  13357. }
  13358. /// Notification that the client cancelled writing a mail
  13359. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13360. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13361. sd->state.mail_writing = false;
  13362. }
  13363. /// Give the client information about the recipient, if available
  13364. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13365. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13366. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13367. PACKET_ZC_CHECKNAME p = { 0 };
  13368. p.PacketType = rodexcheckplayer;
  13369. p.CharId = char_id;
  13370. p.Class = class_;
  13371. p.BaseLevel = level;
  13372. #if PACKETVER >= 20160302
  13373. strncpy(p.Name, name, NAME_LENGTH);
  13374. #endif
  13375. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13376. }
  13377. /// Request information about the recipient
  13378. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13379. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13380. static char name[NAME_LENGTH];
  13381. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13382. intif_mail_checkreceiver(sd, name);
  13383. }
  13384. /// Request to receive mail's attachment.
  13385. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13386. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13387. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13388. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13389. int i;
  13390. struct mail_message* msg;
  13391. #if PACKETVER < 20150513
  13392. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13393. int attachment = MAIL_ATT_ALL;
  13394. #else
  13395. uint16 packet_id = RFIFOW(fd, 0);
  13396. int mail_id = (int)RFIFOQ(fd, 2);
  13397. //int openType = RFIFOB(fd, 10);
  13398. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13399. #endif
  13400. if( !chrif_isconnected() )
  13401. return;
  13402. if( mail_id <= 0 )
  13403. return;
  13404. if( mail_invalid_operation(sd) )
  13405. return;
  13406. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13407. if( i == MAIL_MAX_INBOX )
  13408. return;
  13409. msg = &sd->mail.inbox.msg[i];
  13410. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13411. attachment &= ~MAIL_ATT_ZENY;
  13412. }
  13413. if( attachment&MAIL_ATT_ITEM ){
  13414. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13415. // No items were found
  13416. if( i == MAIL_MAX_ITEM ){
  13417. attachment &= ~MAIL_ATT_ITEM;
  13418. }
  13419. }
  13420. // Either no attachment requested at all or there are no zeny or items in the mail
  13421. if( attachment == MAIL_ATT_NONE ){
  13422. return;
  13423. }
  13424. if( attachment&MAIL_ATT_ZENY ){
  13425. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13426. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13427. return;
  13428. }else{
  13429. // To make sure another request fails
  13430. msg->zeny = 0;
  13431. }
  13432. }
  13433. if( attachment&MAIL_ATT_ITEM ){
  13434. int new_ = 0, totalweight = 0;
  13435. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13436. struct item* item = &msg->item[i];
  13437. if( item->nameid > 0 && item->amount > 0 ){
  13438. struct item_data *data;
  13439. if((data = itemdb_exists(item->nameid)) == NULL)
  13440. continue;
  13441. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13442. case CHKADDITEM_NEW:
  13443. new_++;
  13444. break;
  13445. case CHKADDITEM_OVERAMOUNT:
  13446. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13447. return;
  13448. }
  13449. totalweight += data->weight * item->amount;
  13450. }
  13451. }
  13452. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13453. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13454. return;
  13455. }else if( pc_inventoryblank(sd) < new_ ){
  13456. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13457. return;
  13458. }
  13459. // To make sure another request fails
  13460. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13461. }
  13462. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13463. }
  13464. /// Request to delete a mail.
  13465. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13466. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13467. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13468. #if PACKETVER < 20150513
  13469. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13470. #else
  13471. //int openType = RFIFOB(fd, 2);
  13472. int mail_id = (int)RFIFOQ(fd, 3);
  13473. #endif
  13474. int i, j;
  13475. if( !chrif_isconnected() )
  13476. return;
  13477. if( mail_id <= 0 )
  13478. return;
  13479. if( mail_invalid_operation(sd) )
  13480. return;
  13481. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13482. if (i < MAIL_MAX_INBOX) {
  13483. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13484. // can't delete mail without removing zeny first
  13485. if( msg->zeny > 0 ){
  13486. clif_mail_delete(sd, msg, false);
  13487. return;
  13488. }
  13489. // can't delete mail without removing attachment(s) first
  13490. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13491. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13492. clif_mail_delete(sd, msg, false);
  13493. return;
  13494. }
  13495. }
  13496. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13497. sd->mail.inbox.unread--;
  13498. clif_Mail_new(sd,0,NULL,NULL);
  13499. }
  13500. }
  13501. }
  13502. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13503. /// 0273 <mail id>.L <receive name>.24B
  13504. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13505. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13506. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13507. int i;
  13508. if( mail_id <= 0 )
  13509. return;
  13510. if( mail_invalid_operation(sd) )
  13511. return;
  13512. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13513. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13514. intif_Mail_return(sd->status.char_id, mail_id);
  13515. else
  13516. clif_Mail_return(sd->fd, mail_id, 1);
  13517. }
  13518. /// Request to add an item or Zeny to mail.
  13519. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13520. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13521. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13522. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13523. int idx = RFIFOW(fd,info->pos[0]);
  13524. #if PACKETVER < 20150513
  13525. int amount = RFIFOL(fd,info->pos[1]);
  13526. #else
  13527. int amount = RFIFOW(fd,info->pos[1]);
  13528. #endif
  13529. unsigned char flag;
  13530. if( !chrif_isconnected() )
  13531. return;
  13532. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13533. return;
  13534. flag = mail_setitem(sd, idx, amount);
  13535. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13536. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13537. }else{
  13538. clif_Mail_setattachment(sd,idx,amount,flag);
  13539. }
  13540. }
  13541. /// Remove an item from a mail
  13542. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13543. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13544. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13545. p.PacketType = rodexremoveitem;
  13546. p.result = success;
  13547. p.index = index;
  13548. p.cnt = amount;
  13549. int total = 0;
  13550. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13551. if( sd->mail.item[i].nameid == 0 ){
  13552. break;
  13553. }
  13554. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13555. }
  13556. p.weight = total;
  13557. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13558. }
  13559. /// Request to reset mail item and/or Zeny
  13560. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13561. /// type:
  13562. /// 0 = reset all
  13563. /// 1 = remove item
  13564. /// 2 = remove zeny
  13565. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13566. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13567. {
  13568. #if PACKETVER < 20150513
  13569. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13570. if (type == 0 || type == 1)
  13571. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13572. if (type == 0 || type == 2)
  13573. mail_removezeny(sd, false);
  13574. #else
  13575. uint16 index = RFIFOW(fd, 2);
  13576. uint16 count = RFIFOW(fd, 4);
  13577. mail_removeitem(sd,0,index,count);
  13578. #endif
  13579. }
  13580. /// Request to send mail
  13581. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13582. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13583. /// 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)
  13584. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13585. #if PACKETVER < 20150513
  13586. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13587. if( !chrif_isconnected() )
  13588. return;
  13589. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13590. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13591. return;
  13592. }
  13593. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13594. #else
  13595. uint16 length = RFIFOW(fd, 2);
  13596. if( length < 0x3e ){
  13597. ShowWarning("Too short...\n");
  13598. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13599. return;
  13600. }
  13601. // Forged request without a begin writing packet?
  13602. if( !sd->state.mail_writing ){
  13603. return; // Ignore it
  13604. }
  13605. char receiver[NAME_LENGTH];
  13606. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13607. // char sender[NAME_LENGTH];
  13608. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13609. uint64 zeny = RFIFOQ(fd, 52);
  13610. uint16 titleLength = RFIFOW(fd, 60);
  13611. uint16 textLength = RFIFOW(fd, 62);
  13612. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13613. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13614. char title[MAIL_TITLE_LENGTH];
  13615. char text[MAIL_BODY_LENGTH];
  13616. #if PACKETVER <= 20160330
  13617. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13618. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13619. #else
  13620. // 64 = <char id>.L
  13621. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13622. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13623. #endif
  13624. if( zeny > 0 ){
  13625. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13626. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13627. return;
  13628. }
  13629. }
  13630. mail_send(sd, receiver, title, text, realTextLength);
  13631. #endif
  13632. }
  13633. /// AUCTION SYSTEM
  13634. /// By Zephyrus
  13635. ///
  13636. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13637. /// 025f <type>.L
  13638. /// type:
  13639. /// 0 = open
  13640. /// 1 = close
  13641. void clif_Auction_openwindow(struct map_session_data *sd)
  13642. {
  13643. int fd = sd->fd;
  13644. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13645. return;
  13646. if( !battle_config.feature_auction )
  13647. return;
  13648. WFIFOHEAD(fd,packet_len(0x25f));
  13649. WFIFOW(fd,0) = 0x25f;
  13650. WFIFOL(fd,2) = 0;
  13651. WFIFOSET(fd,packet_len(0x25f));
  13652. }
  13653. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13654. /// 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 }*
  13655. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13656. {
  13657. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13658. struct auction_data auction;
  13659. WFIFOHEAD(fd,12 + (count * 83));
  13660. WFIFOW(fd,0) = 0x252;
  13661. WFIFOW(fd,2) = 12 + (count * 83);
  13662. WFIFOL(fd,4) = pages;
  13663. WFIFOL(fd,8) = count;
  13664. for( i = 0; i < count; i++ ) {
  13665. int k = 12 + (i * 83);
  13666. memcpy(&auction, RBUFP(buf,i * len), len);
  13667. WFIFOL(fd,k) = auction.auction_id;
  13668. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13669. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13670. WFIFOL(fd,30+k) = auction.type;
  13671. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13672. WFIFOB(fd,36+k) = auction.item.identify;
  13673. WFIFOB(fd,37+k) = auction.item.attribute;
  13674. WFIFOB(fd,38+k) = auction.item.refine;
  13675. WFIFOW(fd,39+k) = auction.item.card[0];
  13676. WFIFOW(fd,41+k) = auction.item.card[1];
  13677. WFIFOW(fd,43+k) = auction.item.card[2];
  13678. WFIFOW(fd,45+k) = auction.item.card[3];
  13679. WFIFOL(fd,47+k) = auction.price;
  13680. WFIFOL(fd,51+k) = auction.buynow;
  13681. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13682. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13683. }
  13684. WFIFOSET(fd,WFIFOW(fd,2));
  13685. }
  13686. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13687. /// 0256 <index>.W <result>.B
  13688. /// result:
  13689. /// 0 = success
  13690. /// 1 = failure
  13691. static void clif_Auction_setitem(int fd, int index, bool fail)
  13692. {
  13693. WFIFOHEAD(fd,packet_len(0x256));
  13694. WFIFOW(fd,0) = 0x256;
  13695. WFIFOW(fd,2) = index;
  13696. WFIFOB(fd,4) = fail;
  13697. WFIFOSET(fd,packet_len(0x256));
  13698. }
  13699. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13700. /// 024b <type>.W
  13701. /// type:
  13702. /// 0 = create (any other action in auction window)
  13703. /// 1 = cancel (cancel pressed on register tab)
  13704. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13705. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13706. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13707. if( sd->auction.amount > 0 )
  13708. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13709. sd->auction.amount = 0;
  13710. }
  13711. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13712. /// 024c <index>.W <count>.L
  13713. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13714. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13715. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13716. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13717. struct item_data *item;
  13718. if( !battle_config.feature_auction )
  13719. return;
  13720. if( sd->auction.amount > 0 )
  13721. sd->auction.amount = 0;
  13722. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13723. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13724. return;
  13725. }
  13726. 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.
  13727. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13728. return;
  13729. }
  13730. 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) )
  13731. { // Consumable or pets are not allowed
  13732. clif_Auction_setitem(sd->fd, idx, true);
  13733. return;
  13734. }
  13735. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13736. !sd->inventory.u.items_inventory[idx].identify ||
  13737. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13738. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13739. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13740. clif_Auction_setitem(sd->fd, idx, true);
  13741. return;
  13742. }
  13743. sd->auction.index = idx;
  13744. sd->auction.amount = amount;
  13745. clif_Auction_setitem(fd, idx + 2, false);
  13746. }
  13747. /// Result from an auction action (ZC_AUCTION_RESULT).
  13748. /// 0250 <result>.B
  13749. /// result:
  13750. /// 0 = You have failed to bid into the auction
  13751. /// 1 = You have successfully bid in the auction
  13752. /// 2 = The auction has been canceled
  13753. /// 3 = An auction with at least one bidder cannot be canceled
  13754. /// 4 = You cannot register more than 5 items in an auction at a time
  13755. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13756. /// 6 = You have won the auction
  13757. /// 7 = You have failed to win the auction
  13758. /// 8 = You do not have enough Zeny
  13759. /// 9 = You cannot place more than 5 bids at a time
  13760. void clif_Auction_message(int fd, unsigned char flag)
  13761. {
  13762. WFIFOHEAD(fd,packet_len(0x250));
  13763. WFIFOW(fd,0) = 0x250;
  13764. WFIFOB(fd,2) = flag;
  13765. WFIFOSET(fd,packet_len(0x250));
  13766. }
  13767. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13768. /// 025e <result>.W
  13769. /// result:
  13770. /// 0 = You have ended the auction
  13771. /// 1 = You cannot end the auction
  13772. /// 2 = Auction ID is incorrect
  13773. void clif_Auction_close(int fd, unsigned char flag)
  13774. {
  13775. WFIFOHEAD(fd,packet_len(0x25e));
  13776. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13777. WFIFOW(fd,2) = flag;
  13778. WFIFOSET(fd,packet_len(0x25e));
  13779. }
  13780. /// Request to add an auction (CZ_AUCTION_ADD).
  13781. /// 024d <now money>.L <max money>.L <delete hour>.W
  13782. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13783. {
  13784. struct auction_data auction;
  13785. struct item_data *item;
  13786. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13787. if( !battle_config.feature_auction )
  13788. return;
  13789. auction.price = RFIFOL(fd,info->pos[0]);
  13790. auction.buynow = RFIFOL(fd,info->pos[1]);
  13791. auction.hours = RFIFOW(fd,info->pos[2]);
  13792. // Invalid Situations...
  13793. if( sd->auction.amount < 1 ) {
  13794. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13795. return;
  13796. }
  13797. if( auction.price >= auction.buynow ) {
  13798. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13799. return;
  13800. }
  13801. if( auction.hours < 1 || auction.hours > 48 ) {
  13802. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13803. return;
  13804. }
  13805. // Auction checks...
  13806. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13807. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13808. clif_Auction_message(fd, 2); // The auction has been canceled
  13809. return;
  13810. }
  13811. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13812. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13813. return;
  13814. }
  13815. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13816. auction.buynow = battle_config.auction_maximumprice;
  13817. if( auction.price >= auction.buynow )
  13818. auction.price = auction.buynow - 1;
  13819. }
  13820. auction.auction_id = 0;
  13821. auction.seller_id = sd->status.char_id;
  13822. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13823. auction.buyer_id = 0;
  13824. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13825. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13826. {
  13827. clif_Auction_message(fd, 2); // The auction has been canceled
  13828. return;
  13829. }
  13830. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13831. { // Just in case
  13832. clif_Auction_message(fd, 2); // The auction has been canceled
  13833. return;
  13834. }
  13835. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13836. auction.type = item->type;
  13837. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13838. auction.item.amount = 1;
  13839. auction.timestamp = 0;
  13840. if( !intif_Auction_register(&auction) )
  13841. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13842. else
  13843. {
  13844. int zeny = auction.hours*battle_config.auction_feeperhour;
  13845. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13846. sd->auction.amount = 0;
  13847. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13848. }
  13849. }
  13850. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13851. /// 024e <auction id>.L
  13852. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13853. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13854. intif_Auction_cancel(sd->status.char_id, auction_id);
  13855. }
  13856. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13857. /// 025d <auction id>.L
  13858. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13859. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13860. intif_Auction_close(sd->status.char_id, auction_id);
  13861. }
  13862. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13863. /// 024f <auction id>.L <money>.L
  13864. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13865. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13866. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13867. int bid = RFIFOL(fd,info->pos[1]);
  13868. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13869. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13870. return;
  13871. }
  13872. if( bid <= 0 )
  13873. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13874. else if( bid > sd->status.zeny )
  13875. clif_Auction_message(fd, 8); // You do not have enough zeny
  13876. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13877. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13878. else {
  13879. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13880. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13881. }
  13882. }
  13883. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13884. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13885. /// search type:
  13886. /// 0 = armor
  13887. /// 1 = weapon
  13888. /// 2 = card
  13889. /// 3 = misc
  13890. /// 4 = name search
  13891. /// 5 = auction id search
  13892. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13893. char search_text[NAME_LENGTH];
  13894. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13895. short type = RFIFOW(fd,info->pos[0]);
  13896. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13897. int page = RFIFOW(fd,info->pos[3]);
  13898. if( !battle_config.feature_auction )
  13899. return;
  13900. clif_parse_Auction_cancelreg(fd, sd);
  13901. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13902. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13903. }
  13904. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13905. /// 025c <type>.W
  13906. /// type:
  13907. /// 0 = sell (own auctions)
  13908. /// 1 = buy (own bids)
  13909. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13910. {
  13911. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13912. if( !battle_config.feature_auction )
  13913. return;
  13914. clif_parse_Auction_cancelreg(fd, sd);
  13915. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13916. }
  13917. /// CASH/POINT SHOP
  13918. ///
  13919. void clif_cashshop_open( struct map_session_data* sd, int tab ){
  13920. nullpo_retv( sd );
  13921. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  13922. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  13923. p.cashPoints = sd->cashPoints;
  13924. p.kafraPoints = sd->kafraPoints;
  13925. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  13926. p.tab = tab;
  13927. #endif
  13928. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13929. }
  13930. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13931. nullpo_retv( sd );
  13932. int tab = 0;
  13933. #if PACKETVER >= 20191224
  13934. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  13935. tab = p->tab;
  13936. #endif
  13937. sd->state.cashshop_open = true;
  13938. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13939. clif_cashshop_open( sd, tab );
  13940. }
  13941. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13942. sd->state.cashshop_open = false;
  13943. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13944. // No need to do anything here
  13945. }
  13946. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13947. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13948. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13949. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13950. int j;
  13951. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13952. return;
  13953. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13954. WFIFOW(fd, 0) = 0x8c0;
  13955. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13956. WFIFOL(fd, 4) = tab;
  13957. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13958. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13959. WFIFOW(fd, 10 + ( 6 * j ) ) = client_nameid( cash_shop_items[tab].item[j]->nameid );
  13960. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13961. }
  13962. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13963. }
  13964. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13965. void clif_cashshop_list( struct map_session_data* sd ){
  13966. nullpo_retv( sd );
  13967. int fd = sd->fd;
  13968. if( !session_isActive( fd ) ){
  13969. return;
  13970. }
  13971. for( int tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13972. // Skip empty tabs, the client only expects filled ones
  13973. if( cash_shop_items[tab].count == 0 ){
  13974. continue;
  13975. }
  13976. int len = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM ) + ( cash_shop_items[tab].count * sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM_sub ) );
  13977. WFIFOHEAD( fd, len );
  13978. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)WFIFOP( fd, 0 );
  13979. p->packetType = 0x8ca;
  13980. p->packetLength = len;
  13981. p->count = cash_shop_items[tab].count;
  13982. p->tabNum = tab;
  13983. for( int i = 0; i < cash_shop_items[tab].count; i++ ){
  13984. p->items[i].itemId = client_nameid( cash_shop_items[tab].item[i]->nameid );
  13985. p->items[i].price = cash_shop_items[tab].item[i]->price;
  13986. }
  13987. WFIFOSET( fd, len );
  13988. }
  13989. }
  13990. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13991. if( !sd->status.cashshop_sent ) {
  13992. clif_cashshop_list( sd );
  13993. #if PACKETVER_SUPPORTS_SALES
  13994. sale_notify_login(sd);
  13995. #endif
  13996. sd->status.cashshop_sent = true;
  13997. }
  13998. }
  13999. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14000. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14001. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14002. void clif_cashshop_show( struct map_session_data *sd, struct npc_data *nd ){
  14003. nullpo_retv( sd );
  14004. nullpo_retv( nd );
  14005. int fd = sd->fd;
  14006. if( !session_isActive( fd ) ){
  14007. return;
  14008. }
  14009. sd->npc_shopid = nd->bl.id;
  14010. int cost[2] = { 0, 0 };
  14011. npc_shop_currency_type( sd, nd, cost, true );
  14012. uint16 len = sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_CASH_POINT_ITEMLIST_sub );
  14013. WFIFOHEAD( fd, len );
  14014. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST *)WFIFOP( fd, 0 );
  14015. p->packetType = 0x287;
  14016. p->packetLength = len;
  14017. p->cashPoints = cost[0];
  14018. #if PACKETVER >= 20070711
  14019. p->kafraPoints = cost[1];
  14020. #endif
  14021. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14022. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14023. p->items[i].price = nd->u.shop.shop_item[i].value;
  14024. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14025. p->items[i].itemType = itemtype( id->nameid );
  14026. p->items[i].itemId = client_nameid( id->nameid );
  14027. }
  14028. WFIFOSET( fd, len );
  14029. }
  14030. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14031. /// 0289 <cash point>.L <error>.W
  14032. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14033. /// error:
  14034. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14035. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14036. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14037. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14038. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14039. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14040. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14041. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14042. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14043. void clif_cashshop_ack(struct map_session_data* sd, int error)
  14044. {
  14045. int fd, cost[2] = { 0, 0 };
  14046. struct npc_data *nd;
  14047. nullpo_retv(sd);
  14048. fd = sd->fd;
  14049. nd = map_id2nd(sd->npc_shopid);
  14050. npc_shop_currency_type(sd, nd, cost, false);
  14051. WFIFOHEAD(fd, packet_len(0x289));
  14052. WFIFOW(fd,0) = 0x289;
  14053. WFIFOL(fd,2) = cost[0];
  14054. #if PACKETVER < 20070711
  14055. WFIFOW(fd,6) = TOW(error);
  14056. #else
  14057. WFIFOL(fd,6) = cost[1];
  14058. WFIFOW(fd,10) = TOW(error);
  14059. #endif
  14060. WFIFOSET(fd, packet_len(0x289));
  14061. }
  14062. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  14063. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14064. nullpo_retv( sd );
  14065. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet;
  14066. packet.packetType = 0x849;
  14067. packet.itemId = client_nameid( item_id );
  14068. packet.result = result;
  14069. packet.cashPoints = sd->cashPoints;
  14070. packet.kafraPoints = sd->kafraPoints;
  14071. clif_send( &packet, sizeof( struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT ), &sd->bl, SELF );
  14072. #endif
  14073. }
  14074. /// Request to buy item(s) from cash shop.
  14075. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14076. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14077. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14078. void clif_parse_npccashshop_buy( int fd, struct map_session_data *sd ){
  14079. nullpo_retv( sd );
  14080. if( sd->state.trading || !sd->npc_shopid ){
  14081. clif_cashshop_ack( sd, 1 );
  14082. return;
  14083. }
  14084. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14085. #if PACKETVER < 20070711
  14086. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14087. #elif PACKETVER < 20101116
  14088. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14089. #else
  14090. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14091. 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 ){
  14092. 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 );
  14093. return;
  14094. }
  14095. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, p->count, p->items ) );
  14096. #endif
  14097. }
  14098. /// Request to buy item(s) from cash shop.
  14099. /// 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)
  14100. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  14101. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14102. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14103. 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 ){
  14104. 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 );
  14105. return;
  14106. }
  14107. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14108. }
  14109. /// Adoption System
  14110. ///
  14111. /// Adoption message (ZC_BABYMSG).
  14112. /// 0216 <msg>.L
  14113. /// msg:
  14114. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14115. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14116. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14117. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14118. {
  14119. int fd = sd->fd;
  14120. WFIFOHEAD(fd,6);
  14121. WFIFOW(fd,0) = 0x216;
  14122. WFIFOL(fd,2) = type;
  14123. WFIFOSET(fd,6);
  14124. }
  14125. /// Adoption confirmation (ZC_REQ_BABY).
  14126. /// 01f6 <account id>.L <char id>.L <name>.B
  14127. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14128. {
  14129. int fd = sd->fd;
  14130. WFIFOHEAD(fd,34);
  14131. WFIFOW(fd,0) = 0x1f6;
  14132. WFIFOL(fd,2) = src->status.account_id;
  14133. WFIFOL(fd,6) = p_id;
  14134. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14135. WFIFOSET(fd,34);
  14136. }
  14137. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14138. /// 01f9 <account id>.L
  14139. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14140. {
  14141. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14142. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14143. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14144. {
  14145. tsd->adopt_invite = sd->status.account_id;
  14146. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14147. }
  14148. }
  14149. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14150. /// 01f7 <account id>.L <char id>.L <answer>.L
  14151. /// answer:
  14152. /// 0 = rejected
  14153. /// 1 = accepted
  14154. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14155. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14156. int p1_id = RFIFOL(fd,info->pos[0]);
  14157. int p2_id = RFIFOL(fd,info->pos[1]);
  14158. int result = RFIFOL(fd,info->pos[2]);
  14159. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14160. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14161. int pid = sd->adopt_invite;
  14162. sd->adopt_invite = 0;
  14163. if( p1_sd == NULL || p2_sd == NULL )
  14164. return; // Both players need to be online
  14165. if( pid != p1_sd->status.account_id )
  14166. return; // Incorrect values
  14167. if( result == 0 )
  14168. return; // Rejected
  14169. pc_adoption(p1_sd, p2_sd, sd);
  14170. }
  14171. /// Convex Mirror (ZC_BOSS_INFO).
  14172. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14173. /// infoType:
  14174. /// BOSS_INFO_NOT = No boss on this map.
  14175. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14176. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14177. /// BOSS_INFO_DEAD = Boss is dead.
  14178. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14179. {
  14180. int fd = sd->fd;
  14181. WFIFOHEAD(fd,70);
  14182. memset(WFIFOP(fd,0),0,70);
  14183. WFIFOW(fd,0) = 0x293;
  14184. switch (flag) {
  14185. case BOSS_INFO_NOT:
  14186. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14187. // No data required
  14188. break;
  14189. case BOSS_INFO_ALIVE:
  14190. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14191. // Update X/Y
  14192. WFIFOL(fd,3) = md->bl.x;
  14193. WFIFOL(fd,7) = md->bl.y;
  14194. break;
  14195. case BOSS_INFO_ALIVE_WITHMSG:
  14196. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14197. // Current X/Y
  14198. WFIFOL(fd,3) = md->bl.x;
  14199. WFIFOL(fd,7) = md->bl.y;
  14200. break;
  14201. case BOSS_INFO_DEAD:
  14202. {
  14203. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14204. unsigned int seconds;
  14205. int hours, minutes;
  14206. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14207. hours = seconds / (60 * 60);
  14208. seconds = seconds - (60 * 60 * hours);
  14209. minutes = seconds / 60;
  14210. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14211. // Add respawn info
  14212. WFIFOW(fd,11) = hours; // Hours
  14213. WFIFOW(fd,13) = minutes; // Minutes
  14214. }
  14215. break;
  14216. }
  14217. if (md != NULL)
  14218. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14219. WFIFOSET(fd,70);
  14220. }
  14221. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14222. /// 02d6 <account id>.L
  14223. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14224. {
  14225. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14226. struct map_session_data* tsd = map_id2sd(aid);
  14227. if (!tsd)
  14228. return;
  14229. if (sd->bl.m != tsd->bl.m)
  14230. return;
  14231. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14232. clif_viewequip_ack(sd, tsd);
  14233. else
  14234. clif_msg(sd, VIEW_EQUIP_FAIL);
  14235. }
  14236. /// Request to a configuration.
  14237. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14238. /// type: see enum e_config_type
  14239. /// flag:
  14240. /// false = disabled
  14241. /// true = enabled
  14242. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14243. int cmd = RFIFOW(fd,0);
  14244. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14245. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14246. switch( type ){
  14247. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14248. sd->status.show_equip = flag;
  14249. break;
  14250. case CONFIG_PET_AUTOFEED:
  14251. // Player can not click this if he does not have a pet
  14252. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14253. return;
  14254. }
  14255. sd->pd->pet.autofeed = flag;
  14256. break;
  14257. case CONFIG_HOMUNCULUS_AUTOFEED:
  14258. // Player can not click this if he does not have a homunculus or it is vaporized
  14259. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14260. return;
  14261. }
  14262. sd->hd->homunculus.autofeed = flag;
  14263. break;
  14264. default:
  14265. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14266. return;
  14267. }
  14268. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14269. }
  14270. /// Request to change party invitation tick.
  14271. /// value:
  14272. /// 0 = disabled
  14273. /// 1 = enabled
  14274. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14275. {
  14276. bool flag = RFIFOB(fd,6) ? true : false;
  14277. sd->status.allow_party = flag;
  14278. clif_partytickack(sd, flag);
  14279. }
  14280. /// Questlog System [Kevin] [Inkfish]
  14281. ///
  14282. /**
  14283. * Safe check to init packet len & quest num for player.
  14284. * @param def_len
  14285. * @param info_len Length of each quest info.
  14286. * @param avail_quests Avail quests that player has.
  14287. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14288. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14289. **/
  14290. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14291. (*limit_out) = (0xFFFF - def_len) / info_len;
  14292. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14293. (*len_out) = ((*limit_out) * info_len) + def_len;
  14294. }
  14295. std::string clif_mobtype_name(e_race race, e_size size, e_element element) {
  14296. std::string race_name, size_name, ele_name;
  14297. switch(race) {
  14298. case RC_FORMLESS: race_name = "Formless"; break;
  14299. case RC_UNDEAD: race_name = "Undead"; break;
  14300. case RC_BRUTE: race_name = "Brute"; break;
  14301. case RC_PLANT: race_name = "Plant"; break;
  14302. case RC_INSECT: race_name = "Insect"; break;
  14303. case RC_FISH: race_name = "Fish"; break;
  14304. case RC_DEMON: race_name = "Demon"; break;
  14305. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14306. case RC_ANGEL: race_name = "Angel"; break;
  14307. case RC_DRAGON: race_name = "Dragon"; break;
  14308. case RC_ALL: race_name = ""; break;
  14309. default: race_name = "unknown"; break;
  14310. }
  14311. switch(size) {
  14312. case SZ_SMALL: size_name = "Small"; break;
  14313. case SZ_MEDIUM: size_name = "Medium"; break;
  14314. case SZ_BIG: size_name = "Large"; break;
  14315. case SZ_ALL: size_name = ""; break;
  14316. default: size_name = "unknown"; break;
  14317. }
  14318. switch(element) {
  14319. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14320. case ELE_WATER: ele_name = "Water Element"; break;
  14321. case ELE_EARTH: ele_name = "Earth Element"; break;
  14322. case ELE_FIRE: ele_name = "Fire Element"; break;
  14323. case ELE_WIND: ele_name = "Wind Element"; break;
  14324. case ELE_POISON: ele_name = "Poison Element"; break;
  14325. case ELE_HOLY: ele_name = "Holy Element"; break;
  14326. case ELE_DARK: ele_name = "Shadow Element"; break;
  14327. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14328. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14329. case ELE_ALL: ele_name = ""; break;
  14330. default: ele_name = "unknown"; break;
  14331. }
  14332. return (race_name + (race_name.size() && size_name.size() ? ", " + size_name : size_name) + ((race_name.size() || size_name.size()) && ele_name.size() ? ", " + ele_name : ele_name));
  14333. }
  14334. /// Sends list of all quest states
  14335. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14336. /// 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)
  14337. /// 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)
  14338. void clif_quest_send_list(struct map_session_data *sd)
  14339. {
  14340. nullpo_retv(sd);
  14341. int fd = sd->fd;
  14342. int i;
  14343. int offset = 8;
  14344. int limit = 0;
  14345. #if PACKETVER >= 20141022
  14346. #if PACKETVER >= 20150513
  14347. int size = 22 + NAME_LENGTH;
  14348. #else
  14349. int size = 10 + NAME_LENGTH;
  14350. #endif
  14351. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14352. WFIFOHEAD(fd,i);
  14353. #if PACKETVER >= 20150513
  14354. WFIFOW(fd, 0) = 0x9f8;
  14355. #else
  14356. WFIFOW(fd, 0) = 0x97a;
  14357. #endif
  14358. WFIFOL(fd, 4) = limit;
  14359. for (i = 0; i < limit; i++) {
  14360. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14361. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14362. offset += 4;
  14363. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14364. offset++;
  14365. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14366. offset += 4;
  14367. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14368. offset += 4;
  14369. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14370. offset += 2;
  14371. if (!qi->objectives.empty()) {
  14372. struct mob_db *mob;
  14373. for (int j = 0; j < qi->objectives.size(); j++) {
  14374. mob = mob_db(qi->objectives[j]->mob_id);
  14375. e_race race = qi->objectives[j]->race;
  14376. e_size size = qi->objectives[j]->size;
  14377. e_element element = qi->objectives[j]->element;
  14378. #if PACKETVER >= 20150513
  14379. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14380. offset += 4;
  14381. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14382. offset += 4;
  14383. #endif
  14384. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14385. offset += 4;
  14386. #if PACKETVER >= 20150513
  14387. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14388. offset += 2;
  14389. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14390. offset += 2;
  14391. #endif
  14392. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14393. offset += 2;
  14394. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14395. offset += 2;
  14396. if (mob && qi->objectives[j]->mob_id > 0)
  14397. safestrncpy((char *)WFIFOP(fd,offset), mob->jname, NAME_LENGTH);
  14398. else
  14399. safestrncpy((char *)WFIFOP(fd,offset), clif_mobtype_name(race, size, element).c_str(), NAME_LENGTH);
  14400. offset += NAME_LENGTH;
  14401. }
  14402. }
  14403. }
  14404. WFIFOW(fd, 2) = offset;
  14405. WFIFOSET(fd, offset);
  14406. #else
  14407. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14408. WFIFOHEAD(fd,i);
  14409. WFIFOW(fd, 0) = 0x2b1;
  14410. WFIFOL(fd, 4) = limit;
  14411. for (i = 0; i < limit; i++) {
  14412. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14413. offset += 4;
  14414. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14415. offset += 1;
  14416. }
  14417. WFIFOW(fd, 2) = offset;
  14418. WFIFOSET(fd, offset);
  14419. #endif
  14420. }
  14421. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14422. /// 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
  14423. void clif_quest_send_mission(struct map_session_data *sd)
  14424. {
  14425. nullpo_retv(sd);
  14426. int fd = sd->fd;
  14427. int limit = 0;
  14428. int len = sd->avail_quests*104+8;
  14429. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14430. WFIFOHEAD(fd, len);
  14431. WFIFOW(fd, 0) = 0x2b2;
  14432. WFIFOW(fd, 2) = len;
  14433. WFIFOL(fd, 4) = limit;
  14434. for (int i = 0; i < limit; i++) {
  14435. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14436. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14437. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14438. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14439. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14440. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14441. struct mob_db *mob = mob_db(qi->objectives[j]->mob_id);
  14442. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14443. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14444. if (mob && qi->objectives[j]->mob_id > 0)
  14445. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14446. else
  14447. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_mobtype_name(qi->objectives[j]->race, qi->objectives[j]->size, qi->objectives[j]->element).c_str(), NAME_LENGTH);
  14448. }
  14449. }
  14450. WFIFOSET(fd, len);
  14451. }
  14452. /// Notification about a new quest
  14453. /// 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)
  14454. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14455. /// 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)
  14456. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14457. {
  14458. nullpo_retv(sd);
  14459. nullpo_retv(qd);
  14460. int fd = sd->fd;
  14461. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14462. if (!qi)
  14463. return;
  14464. #if PACKETVER >= 20150513
  14465. int cmd = 0x9f9;
  14466. #else
  14467. int cmd = 0x2b3;
  14468. #endif
  14469. WFIFOHEAD(fd, packet_len(cmd));
  14470. WFIFOW(fd, 0) = cmd;
  14471. WFIFOL(fd, 2) = qd->quest_id;
  14472. WFIFOB(fd, 6) = qd->state;
  14473. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14474. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14475. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14476. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14477. struct mob_db *mob = mob_db(qi->objectives[i]->mob_id);
  14478. e_race race = qi->objectives[i]->race;
  14479. e_size size = qi->objectives[i]->size;
  14480. e_element element = qi->objectives[i]->element;
  14481. #if PACKETVER >= 20150513
  14482. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14483. offset += 4;
  14484. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14485. offset += 4;
  14486. #endif
  14487. WFIFOL(fd, offset) = ((mob && qi->objectives[i]->mob_id > 0) ? qi->objectives[i]->mob_id : MOBID_PORING); // 0 can't be used as it displays "Novice" job regardless of the clif_mobtype_name
  14488. offset += 4;
  14489. #if PACKETVER >= 20150513
  14490. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14491. offset += 2;
  14492. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14493. offset += 2;
  14494. #endif
  14495. WFIFOW(fd, offset) = qd->count[i];
  14496. offset += 2;
  14497. if (mob && qi->objectives[i]->mob_id > 0)
  14498. safestrncpy((char *)WFIFOP(fd,offset), mob->jname, NAME_LENGTH);
  14499. else
  14500. safestrncpy((char *)WFIFOP(fd,offset), clif_mobtype_name(race, size, element).c_str(), NAME_LENGTH);
  14501. offset += NAME_LENGTH;
  14502. }
  14503. WFIFOSET(fd, packet_len(cmd));
  14504. #if PACKETVER >= 20150513
  14505. int len = 4 + qi->objectives.size() * 12;
  14506. WFIFOHEAD(fd, len);
  14507. WFIFOW(fd, 0) = 0x8fe;
  14508. WFIFOW(fd, 2) = len;
  14509. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14510. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14511. WFIFOL(fd, offset+4) = qi->objectives[i]->mob_id;
  14512. WFIFOW(fd, offset + 10) = qi->objectives[i]->count;
  14513. WFIFOW(fd, offset + 12) = qd->count[i];
  14514. }
  14515. WFIFOSET(fd, len);
  14516. #endif
  14517. }
  14518. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14519. /// 02b4 <quest id>.L
  14520. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14521. {
  14522. int fd = sd->fd;
  14523. WFIFOHEAD(fd, packet_len(0x2b4));
  14524. WFIFOW(fd, 0) = 0x2b4;
  14525. WFIFOL(fd, 2) = quest_id;
  14526. WFIFOSET(fd, packet_len(0x2b4));
  14527. }
  14528. /// Notification of an update to the hunting mission counter
  14529. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14530. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14531. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  14532. {
  14533. int fd = sd->fd;
  14534. int offset = 6;
  14535. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14536. int len = qi->objectives.size() * 12 + 6;
  14537. #if PACKETVER >= 20150513
  14538. int cmd = 0x9fa;
  14539. #else
  14540. int cmd = 0x2b5;
  14541. #endif
  14542. WFIFOHEAD(fd, len);
  14543. WFIFOW(fd, 0) = cmd;
  14544. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14545. for (int i = 0; i < qi->objectives.size(); i++) {
  14546. WFIFOL(fd, offset) = qd->quest_id;
  14547. offset += 4;
  14548. #if PACKETVER >= 20150513
  14549. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14550. offset += 4;
  14551. #else
  14552. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14553. offset += 4;
  14554. #endif
  14555. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14556. offset += 2;
  14557. WFIFOW(fd, offset) = qd->count[i];
  14558. offset += 2;
  14559. }
  14560. WFIFOW(fd, 2) = offset;
  14561. WFIFOSET(fd, offset);
  14562. }
  14563. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14564. /// 02b6 <quest id>.L <active>.B
  14565. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14566. {
  14567. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14568. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14569. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14570. }
  14571. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14572. /// 02b7 <quest id>.L <active>.B
  14573. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14574. {
  14575. int fd = sd->fd;
  14576. WFIFOHEAD(fd, packet_len(0x2b7));
  14577. WFIFOW(fd, 0) = 0x2b7;
  14578. WFIFOL(fd, 2) = quest_id;
  14579. WFIFOB(fd, 6) = active;
  14580. WFIFOSET(fd, packet_len(0x2b7));
  14581. }
  14582. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14583. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14584. /// effect:
  14585. /// 0 = none
  14586. /// 1 = exclamation mark icon
  14587. /// 2 = question mark icon
  14588. /// color:
  14589. /// 0 = yellow
  14590. /// 1 = orange
  14591. /// 2 = green
  14592. /// 3 = purple
  14593. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14594. {
  14595. #if PACKETVER >= 20090218
  14596. nullpo_retv(sd);
  14597. nullpo_retv(bl);
  14598. int fd = sd->fd;
  14599. WFIFOHEAD(fd, packet_len(0x446));
  14600. WFIFOW(fd, 0) = 0x446;
  14601. WFIFOL(fd, 2) = bl->id;
  14602. WFIFOW(fd, 6) = bl->x;
  14603. WFIFOW(fd, 8) = bl->y;
  14604. WFIFOW(fd, 10) = effect;
  14605. WFIFOW(fd, 12) = color;
  14606. WFIFOSET(fd, packet_len(0x446));
  14607. #endif
  14608. }
  14609. /// Mercenary System
  14610. ///
  14611. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14612. /// 02a2 <var id>.W <value>.L
  14613. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14614. {
  14615. struct mercenary_data *md;
  14616. struct status_data *status;
  14617. int fd;
  14618. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14619. return;
  14620. fd = sd->fd;
  14621. status = &md->battle_status;
  14622. WFIFOHEAD(fd,packet_len(0x2a2));
  14623. WFIFOW(fd,0) = 0x2a2;
  14624. WFIFOW(fd,2) = type;
  14625. switch( type ) {
  14626. case SP_ATK1:
  14627. {
  14628. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14629. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14630. }
  14631. break;
  14632. case SP_MATK1:
  14633. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14634. break;
  14635. case SP_HIT:
  14636. WFIFOL(fd,4) = status->hit;
  14637. break;
  14638. case SP_CRITICAL:
  14639. WFIFOL(fd,4) = status->cri/10;
  14640. break;
  14641. case SP_DEF1:
  14642. WFIFOL(fd,4) = status->def;
  14643. break;
  14644. case SP_MDEF1:
  14645. WFIFOL(fd,4) = status->mdef;
  14646. break;
  14647. case SP_MERCFLEE:
  14648. WFIFOL(fd,4) = status->flee;
  14649. break;
  14650. case SP_ASPD:
  14651. WFIFOL(fd,4) = status->amotion;
  14652. break;
  14653. case SP_HP:
  14654. WFIFOL(fd,4) = status->hp;
  14655. break;
  14656. case SP_MAXHP:
  14657. WFIFOL(fd,4) = status->max_hp;
  14658. break;
  14659. case SP_SP:
  14660. WFIFOL(fd,4) = status->sp;
  14661. break;
  14662. case SP_MAXSP:
  14663. WFIFOL(fd,4) = status->max_sp;
  14664. break;
  14665. case SP_MERCKILLS:
  14666. WFIFOL(fd,4) = md->mercenary.kill_count;
  14667. break;
  14668. case SP_MERCFAITH:
  14669. WFIFOL(fd,4) = mercenary_get_faith(md);
  14670. break;
  14671. }
  14672. WFIFOSET(fd,packet_len(0x2a2));
  14673. }
  14674. /// Mercenary base status data (ZC_MER_INIT).
  14675. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14676. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14677. /// <calls>.L <kills>.L <atk range>.W
  14678. void clif_mercenary_info(struct map_session_data *sd)
  14679. {
  14680. int fd;
  14681. struct mercenary_data *md;
  14682. struct status_data *status;
  14683. int atk;
  14684. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14685. return;
  14686. fd = sd->fd;
  14687. status = &md->battle_status;
  14688. WFIFOHEAD(fd,packet_len(0x29b));
  14689. WFIFOW(fd,0) = 0x29b;
  14690. WFIFOL(fd,2) = md->bl.id;
  14691. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14692. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14693. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14694. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14695. WFIFOW(fd,10) = status->hit;
  14696. WFIFOW(fd,12) = status->cri/10;
  14697. WFIFOW(fd,14) = status->def;
  14698. WFIFOW(fd,16) = status->mdef;
  14699. WFIFOW(fd,18) = status->flee;
  14700. WFIFOW(fd,20) = status->amotion;
  14701. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14702. WFIFOW(fd,46) = md->db->lv;
  14703. WFIFOL(fd,48) = status->hp;
  14704. WFIFOL(fd,52) = status->max_hp;
  14705. WFIFOL(fd,56) = status->sp;
  14706. WFIFOL(fd,60) = status->max_sp;
  14707. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14708. WFIFOW(fd,68) = mercenary_get_faith(md);
  14709. WFIFOL(fd,70) = mercenary_get_calls(md);
  14710. WFIFOL(fd,74) = md->mercenary.kill_count;
  14711. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14712. WFIFOSET(fd,packet_len(0x29b));
  14713. }
  14714. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14715. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14716. void clif_mercenary_skillblock(struct map_session_data *sd)
  14717. {
  14718. struct mercenary_data *md;
  14719. int fd, i, len = 4;
  14720. if( sd == NULL || (md = sd->md) == NULL )
  14721. return;
  14722. fd = sd->fd;
  14723. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14724. WFIFOW(fd,0) = 0x29d;
  14725. for( i = 0; i < MAX_MERCSKILL; i++ )
  14726. {
  14727. uint16 id;
  14728. short idx = -1;
  14729. if( (id = md->db->skill[i].id) == 0 )
  14730. continue;
  14731. if ((idx = mercenary_skill_get_index(id)) == -1)
  14732. continue;
  14733. WFIFOW(fd,len) = id;
  14734. WFIFOL(fd,len+2) = skill_get_inf(id);
  14735. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14736. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14737. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14738. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14739. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14740. len += 37;
  14741. }
  14742. WFIFOW(fd,2) = len;
  14743. WFIFOSET(fd,len);
  14744. }
  14745. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14746. /// 029f <command>.B
  14747. /// 1 = mercenary information
  14748. /// 2 = delete
  14749. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14750. {
  14751. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14752. if( sd->md == NULL )
  14753. return;
  14754. if( option == 2 ) mercenary_delete(sd->md, 2);
  14755. }
  14756. /// Mercenary Message
  14757. /// message:
  14758. /// 0 = Mercenary soldier's duty hour is over.
  14759. /// 1 = Your mercenary soldier has been killed.
  14760. /// 2 = Your mercenary soldier has been fired.
  14761. /// 3 = Your mercenary soldier has ran away.
  14762. void clif_mercenary_message(struct map_session_data* sd, int message){
  14763. clif_msg(sd, MERC_MSG_BASE + message);
  14764. }
  14765. /// Notification about the remaining time of a rental item.
  14766. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  14767. void clif_rental_time( struct map_session_data* sd, unsigned short nameid, int seconds ){
  14768. // '<ItemName>' item will disappear in <seconds/60> minutes.
  14769. struct PACKET_ZC_CASH_TIME_COUNTER p;
  14770. p.packetType = 0x298;
  14771. p.itemId = client_nameid( nameid );
  14772. p.seconds = seconds;
  14773. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14774. }
  14775. /// Deletes a rental item from client's inventory.
  14776. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  14777. void clif_rental_expired( struct map_session_data* sd, int index, unsigned short nameid ){
  14778. // '<ItemName>' item has been deleted from the Inventory
  14779. struct PACKET_ZC_CASH_ITEM_DELETE p;
  14780. p.packetType = 0x299;
  14781. p.index = client_index( index );
  14782. p.itemId = client_nameid( nameid );
  14783. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14784. }
  14785. /// Book Reading (ZC_READ_BOOK).
  14786. /// 0294 <book id>.L <page>.L
  14787. void clif_readbook(int fd, int book_id, int page)
  14788. {
  14789. WFIFOHEAD(fd,packet_len(0x294));
  14790. WFIFOW(fd,0) = 0x294;
  14791. WFIFOL(fd,2) = book_id;
  14792. WFIFOL(fd,6) = page;
  14793. WFIFOSET(fd,packet_len(0x294));
  14794. }
  14795. /// Battlegrounds
  14796. ///
  14797. /// Updates HP bar of a camp member.
  14798. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14799. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14800. void clif_bg_hp(struct map_session_data *sd) {
  14801. #if PACKETVER < 20140613
  14802. unsigned char buf[34];
  14803. const int cmd = 0x2e0;
  14804. #else
  14805. unsigned char buf[14];
  14806. const int cmd = 0xa0e;
  14807. #endif
  14808. nullpo_retv(sd);
  14809. WBUFW(buf,0) = cmd;
  14810. WBUFL(buf,2) = sd->status.account_id;
  14811. #if PACKETVER < 20140613
  14812. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14813. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14814. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14815. WBUFW(buf,32) = 100;
  14816. } else {
  14817. WBUFW(buf,30) = sd->battle_status.hp;
  14818. WBUFW(buf,32) = sd->battle_status.max_hp;
  14819. }
  14820. #else
  14821. if( sd->battle_status.max_hp > INT32_MAX ) {
  14822. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14823. WBUFL(buf,10) = 100;
  14824. } else {
  14825. WBUFL(buf,6) = sd->battle_status.hp;
  14826. WBUFL(buf,10) = sd->battle_status.max_hp;
  14827. }
  14828. #endif
  14829. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14830. }
  14831. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14832. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14833. void clif_bg_xy(struct map_session_data *sd)
  14834. {
  14835. unsigned char buf[36];
  14836. nullpo_retv(sd);
  14837. WBUFW(buf,0)=0x2df;
  14838. WBUFL(buf,2)=sd->status.account_id;
  14839. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14840. WBUFW(buf,30)=sd->status.class_;
  14841. WBUFW(buf,32)=sd->bl.x;
  14842. WBUFW(buf,34)=sd->bl.y;
  14843. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14844. }
  14845. void clif_bg_xy_remove(struct map_session_data *sd)
  14846. {
  14847. unsigned char buf[36];
  14848. nullpo_retv(sd);
  14849. WBUFW(buf,0)=0x2df;
  14850. WBUFL(buf,2)=sd->status.account_id;
  14851. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14852. WBUFW(buf,30)=0;
  14853. WBUFW(buf,32)=-1;
  14854. WBUFW(buf,34)=-1;
  14855. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14856. }
  14857. /// Notifies clients of a battleground message.
  14858. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14859. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14860. struct map_session_data *sd = bg_getavailablesd( bg );
  14861. if( sd == nullptr ){
  14862. return;
  14863. }
  14864. // limit length
  14865. len = min( len + 1, CHAT_SIZE_MAX );
  14866. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14867. WBUFW(buf,0) = 0x2dc;
  14868. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14869. WBUFL(buf,4) = src_id;
  14870. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14871. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14872. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14873. }
  14874. /// Validates and processes battlechat messages.
  14875. /// All messages that are sent after enabling battleground chat with /battlechat.
  14876. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14877. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14878. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14879. if( !clif_process_message( sd, false, name, message, output ) )
  14880. return;
  14881. bg_send_message(sd, output, strlen(output) );
  14882. }
  14883. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14884. /// 02de <camp A points>.W <camp B points>.W
  14885. void clif_bg_updatescore(int16 m)
  14886. {
  14887. struct block_list bl;
  14888. unsigned char buf[6];
  14889. struct map_data *mapdata = map_getmapdata(m);
  14890. bl.id = 0;
  14891. bl.type = BL_NUL;
  14892. bl.m = m;
  14893. WBUFW(buf,0) = 0x2de;
  14894. WBUFW(buf,2) = mapdata->bgscore_lion;
  14895. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14896. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14897. }
  14898. void clif_bg_updatescore_single(struct map_session_data *sd)
  14899. {
  14900. int fd;
  14901. nullpo_retv(sd);
  14902. fd = sd->fd;
  14903. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14904. WFIFOHEAD(fd,packet_len(0x2de));
  14905. WFIFOW(fd,0) = 0x2de;
  14906. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14907. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14908. WFIFOSET(fd,packet_len(0x2de));
  14909. }
  14910. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14911. /// 02dd <account id>.L <name>.24B <camp>.W
  14912. void clif_sendbgemblem_area(struct map_session_data *sd)
  14913. {
  14914. unsigned char buf[33];
  14915. nullpo_retv(sd);
  14916. WBUFW(buf, 0) = 0x2dd;
  14917. WBUFL(buf,2) = sd->bl.id;
  14918. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14919. WBUFW(buf,30) = sd->bg_id;
  14920. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14921. }
  14922. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14923. {
  14924. nullpo_retv(sd);
  14925. WFIFOHEAD(fd,32);
  14926. WFIFOW(fd,0) = 0x2dd;
  14927. WFIFOL(fd,2) = sd->bl.id;
  14928. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14929. WFIFOW(fd,30) = sd->bg_id;
  14930. WFIFOSET(fd,packet_len(0x2dd));
  14931. }
  14932. /// Battlegrounds queue incoming apply request from client.
  14933. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  14934. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  14935. void clif_parse_bg_queue_apply_request(int fd, struct map_session_data *sd)
  14936. {
  14937. if (!battle_config.feature_bgqueue)
  14938. return;
  14939. nullpo_retv(sd);
  14940. short type = RFIFOW(fd,2);
  14941. char name[NAME_LENGTH];
  14942. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  14943. if (sd->bg_queue_id > 0) {
  14944. //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);
  14945. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  14946. return;
  14947. } else if (type == 1) // Solo
  14948. bg_queue_join_solo(name, sd);
  14949. else if (type == 2) // Party
  14950. bg_queue_join_party(name, sd);
  14951. else if (type == 4) // Guild
  14952. bg_queue_join_guild(name, sd);
  14953. else {
  14954. 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);
  14955. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  14956. return;
  14957. }
  14958. }
  14959. /// Outgoing battlegrounds queue apply result.
  14960. /// Result types: @see e_bg_queue_apply_ack
  14961. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  14962. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, struct map_session_data *sd)
  14963. {
  14964. nullpo_retv(sd);
  14965. int fd = sd->fd;
  14966. WFIFOHEAD(fd, packet_len(0x8d8));
  14967. WFIFOW(fd,0) = 0x8d8;
  14968. WFIFOB(fd,2) = result;
  14969. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  14970. WFIFOSET(fd, packet_len(0x8d8));
  14971. }
  14972. /// Outgoing battlegrounds queue apply notification.
  14973. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  14974. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  14975. void clif_bg_queue_apply_notify(const char *name, struct map_session_data *sd)
  14976. {
  14977. nullpo_retv(sd);
  14978. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  14979. if (queue == nullptr) {
  14980. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  14981. return;
  14982. }
  14983. int fd = sd->fd;
  14984. WFIFOHEAD(fd, packet_len(0x8d9));
  14985. WFIFOW(fd,0) = 0x8d9;
  14986. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  14987. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  14988. WFIFOSET(fd, packet_len(0x8d9));
  14989. }
  14990. /// Battlegrounds queue outgoing cancel result.
  14991. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  14992. void clif_bg_queue_cancel_result(bool success, const char *name, struct map_session_data *sd)
  14993. {
  14994. nullpo_retv(sd);
  14995. int fd = sd->fd;
  14996. WFIFOHEAD(fd, packet_len(0x8d8));
  14997. WFIFOW(fd,0) = 0x8db;
  14998. WFIFOB(fd,2) = success;
  14999. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15000. WFIFOSET(fd, packet_len(0x8d8));
  15001. }
  15002. /// Battlegrounds queue incoming cancel request from client.
  15003. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15004. void clif_parse_bg_queue_cancel_request(int fd, struct map_session_data *sd)
  15005. {
  15006. if (!battle_config.feature_bgqueue)
  15007. return;
  15008. nullpo_retv(sd);
  15009. bool success;
  15010. if (sd->bg_queue_id > 0) {
  15011. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15012. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15013. 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.
  15014. else
  15015. success = bg_queue_leave(sd);
  15016. } else {
  15017. 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);
  15018. success = false;
  15019. }
  15020. char name[NAME_LENGTH];
  15021. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15022. clif_bg_queue_cancel_result(success, name, sd);
  15023. }
  15024. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15025. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15026. void clif_bg_queue_lobby_notify(const char *name, struct map_session_data *sd)
  15027. {
  15028. nullpo_retv(sd);
  15029. int fd = sd->fd;
  15030. WFIFOHEAD(fd, packet_len(0x8df));
  15031. WFIFOW(fd,0) = 0x8df;
  15032. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15033. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15034. WFIFOSET(fd, packet_len(0x8df));
  15035. }
  15036. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15037. /// Result types: 1(Accept), 2(Decline).
  15038. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15039. void clif_parse_bg_queue_lobby_reply(int fd, struct map_session_data *sd)
  15040. {
  15041. nullpo_retv(sd);
  15042. if(sd->bg_queue_id > 0) {
  15043. uint8 result = RFIFOB(fd, 2);
  15044. if(result == 1) { // Accept
  15045. bg_queue_on_accept_invite(sd);
  15046. } else if(result == 2) { // Decline
  15047. bg_queue_leave(sd);
  15048. clif_bg_queue_entry_init(sd);
  15049. }
  15050. }
  15051. }
  15052. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15053. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15054. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, struct map_session_data *sd)
  15055. {
  15056. nullpo_retv(sd);
  15057. int fd = sd->fd;
  15058. WFIFOHEAD(fd, packet_len(0x8e1));
  15059. WFIFOW(fd,0) = 0x8e1;
  15060. WFIFOB(fd,2) = result;
  15061. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15062. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15063. WFIFOSET(fd, packet_len(0x8e1));
  15064. }
  15065. /// Battlegrounds queue incoming queue number request from client.
  15066. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15067. void clif_parse_bg_queue_request_queue_number(int fd, struct map_session_data *sd)
  15068. {
  15069. nullpo_retv(sd);
  15070. char name[NAME_LENGTH];
  15071. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15072. clif_bg_queue_apply_notify(name, sd);
  15073. }
  15074. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15075. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15076. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15077. void clif_bg_queue_entry_init(struct map_session_data *sd)
  15078. {
  15079. nullpo_retv(sd);
  15080. int fd = sd->fd;
  15081. WFIFOHEAD(fd, packet_len(0x90e));
  15082. WFIFOW(fd,0) = 0x90e;
  15083. WFIFOSET(fd, packet_len(0x90e));
  15084. }
  15085. /// Custom Fonts (ZC_NOTIFY_FONT).
  15086. /// 02ef <account_id>.L <font id>.W
  15087. void clif_font(struct map_session_data *sd)
  15088. {
  15089. #if PACKETVER >= 20080102
  15090. unsigned char buf[8];
  15091. nullpo_retv(sd);
  15092. WBUFW(buf,0) = 0x2ef;
  15093. WBUFL(buf,2) = sd->bl.id;
  15094. WBUFW(buf,6) = sd->status.font;
  15095. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15096. #endif
  15097. }
  15098. /// Required to start the instancing information window on Client
  15099. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15100. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15101. void clif_instance_create(int instance_id, int num)
  15102. {
  15103. #if PACKETVER >= 20071128
  15104. struct map_session_data *sd = NULL;
  15105. enum send_target target = PARTY;
  15106. unsigned char buf[65];
  15107. instance_getsd(instance_id, sd, &target);
  15108. if (!sd)
  15109. return;
  15110. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15111. if (!db)
  15112. return;
  15113. WBUFW(buf,0) = 0x2cb;
  15114. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15115. WBUFW(buf,63) = num;
  15116. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15117. #endif
  15118. return;
  15119. }
  15120. /// To announce Instancing queue creation if no maps available
  15121. /// S 0x2cc <Standby Position>.W
  15122. void clif_instance_changewait(int instance_id, int num)
  15123. {
  15124. #if PACKETVER >= 20071128
  15125. struct map_session_data *sd = NULL;
  15126. enum send_target target = PARTY;
  15127. unsigned char buf[4];
  15128. instance_getsd(instance_id, sd, &target);
  15129. if (!sd)
  15130. return;
  15131. WBUFW(buf,0) = 0x2cc;
  15132. WBUFW(buf,2) = num;
  15133. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15134. #endif
  15135. return;
  15136. }
  15137. /// Notify the current status to members
  15138. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15139. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15140. {
  15141. #if PACKETVER >= 20071128
  15142. struct map_session_data *sd = NULL;
  15143. enum send_target target = PARTY;
  15144. unsigned char buf[71];
  15145. instance_getsd(instance_id, sd, &target);
  15146. if (!sd)
  15147. return;
  15148. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15149. if (!db)
  15150. return;
  15151. WBUFW(buf,0) = 0x2cd;
  15152. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15153. WBUFL(buf,63) = limit1;
  15154. WBUFL(buf,67) = limit2;
  15155. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15156. #endif
  15157. return;
  15158. }
  15159. /// Notify a status change to members
  15160. /// S 0x2ce <Message ID>.L
  15161. /// 0 = Notification (EnterLimitDate update?)
  15162. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15163. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15164. /// 3 = The Memorial Dungeon has been removed.
  15165. /// 4 = Create failure (removes the instance window)
  15166. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15167. {
  15168. #if PACKETVER >= 20071128
  15169. struct map_session_data *sd = NULL;
  15170. enum send_target target = PARTY;
  15171. unsigned char buf[10];
  15172. instance_getsd(instance_id, sd, &target);
  15173. if (!sd)
  15174. return;
  15175. WBUFW(buf,0) = 0x2ce;
  15176. WBUFL(buf,2) = type;
  15177. WBUFL(buf,6) = limit;
  15178. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15179. #endif
  15180. return;
  15181. }
  15182. /// Destroy an instance from the status window
  15183. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15184. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15185. {
  15186. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15187. return;
  15188. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15189. switch (p->command) {
  15190. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15191. instance_destroy_command(sd);
  15192. break;
  15193. }
  15194. }
  15195. /// Notifies clients about item picked up by a party member.
  15196. /// 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)
  15197. void clif_party_show_picker( struct map_session_data* sd, struct item* item_data ){
  15198. #if PACKETVER >= 20071002
  15199. nullpo_retv( sd );
  15200. nullpo_retv( item_data );
  15201. struct item_data* id = itemdb_search( item_data->nameid );
  15202. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15203. p.packetType = 0x2b8;
  15204. p.AID = sd->status.account_id;
  15205. p.itemId = item_data->nameid;
  15206. p.identified = item_data->identify;
  15207. p.damaged = item_data->attribute;
  15208. p.refine = item_data->refine;
  15209. clif_addcards( &p.slot, item_data );
  15210. p.location = id->equip; // equip location
  15211. p.itemType = itemtype( id->nameid ); // item type
  15212. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15213. #endif
  15214. }
  15215. /** Display gained exp.
  15216. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15217. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15218. * amount: INT32_MIN ~ INT32_MAX
  15219. * var id:
  15220. * SP_BASEEXP, SP_JOBEXP
  15221. * exp type:
  15222. * 0 = normal exp gained/lost
  15223. * 1 = quest exp gained/lost
  15224. * @param sd Player
  15225. * @param exp EXP value gained/loss
  15226. * @param type SP_BASEEXP, SP_JOBEXP
  15227. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15228. * @param lost True:if losing EXP
  15229. */
  15230. void clif_displayexp(struct map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15231. {
  15232. int fd;
  15233. int offset;
  15234. #if PACKETVER >= 20170830
  15235. int cmd = 0xacc;
  15236. #else
  15237. int cmd = 0x7f6;
  15238. #endif
  15239. nullpo_retv(sd);
  15240. fd = sd->fd;
  15241. WFIFOHEAD(fd, packet_len(cmd));
  15242. WFIFOW(fd,0) = cmd;
  15243. WFIFOL(fd,2) = sd->bl.id;
  15244. #if PACKETVER >= 20170830
  15245. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15246. offset = 4;
  15247. #else
  15248. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15249. offset = 0;
  15250. #endif
  15251. WFIFOW(fd,10+offset) = type;
  15252. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15253. WFIFOSET(fd,packet_len(cmd));
  15254. }
  15255. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15256. /// type:
  15257. /// 0 = Displays 'value' for 5 seconds.
  15258. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15259. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15260. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15261. /// value:
  15262. /// 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).
  15263. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15264. {
  15265. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15266. WFIFOW(sd->fd,0) = 0x1b1;
  15267. WFIFOB(sd->fd,2) = type;
  15268. WFIFOL(sd->fd,3) = value;
  15269. WFIFOSET(sd->fd, packet_len(0x1b1));
  15270. }
  15271. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15272. /// 021d <state>.L
  15273. /// state:
  15274. /// 0 = Full effects
  15275. /// 1 = Reduced effects
  15276. ///
  15277. /// NOTE: The state is used on Aegis for sending skill unit packet
  15278. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15279. /// whenever possible. Due to the way the decision check is
  15280. /// constructed, this state tracking was rendered useless,
  15281. /// as the only skill unit, that is sent with 0x1c9 is
  15282. /// Graffiti.
  15283. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15284. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15285. sd->state.lesseffect = ( isLess != 0 );
  15286. }
  15287. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15288. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15290. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15291. int type = RFIFOL(fd,info->pos[1]);
  15292. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15293. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15294. if( sd->state.trading || sd->npc_shopid )
  15295. return;
  15296. if( flag == 0 || n == 0) {
  15297. clif_menuskill_clear(sd);
  15298. return; // Canceled by player.
  15299. }
  15300. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15301. clif_menuskill_clear(sd);
  15302. return; // Prevent hacking.
  15303. }
  15304. switch( type ) {
  15305. case 0: // Change Material
  15306. skill_changematerial(sd,n,item_list);
  15307. break;
  15308. case 1: // Level 1: Pure to Rough
  15309. case 2: // Level 2: Rough to Pure
  15310. skill_elementalanalysis(sd,n,type,item_list);
  15311. break;
  15312. }
  15313. clif_menuskill_clear(sd);
  15314. return;
  15315. }
  15316. /*==========================================
  15317. * Elemental System
  15318. *==========================================*/
  15319. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15320. struct elemental_data *ed;
  15321. struct status_data *status;
  15322. int fd;
  15323. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15324. return;
  15325. fd = sd->fd;
  15326. status = &ed->battle_status;
  15327. WFIFOHEAD(fd,8);
  15328. WFIFOW(fd,0) = 0x81e;
  15329. WFIFOW(fd,2) = type;
  15330. switch( type ) {
  15331. case SP_HP:
  15332. WFIFOL(fd,4) = status->hp;
  15333. break;
  15334. case SP_MAXHP:
  15335. WFIFOL(fd,4) = status->max_hp;
  15336. break;
  15337. case SP_SP:
  15338. WFIFOL(fd,4) = status->sp;
  15339. break;
  15340. case SP_MAXSP:
  15341. WFIFOL(fd,4) = status->max_sp;
  15342. break;
  15343. }
  15344. WFIFOSET(fd,8);
  15345. }
  15346. void clif_elemental_info(struct map_session_data *sd) {
  15347. int fd;
  15348. struct elemental_data *ed;
  15349. struct status_data *status;
  15350. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15351. return;
  15352. fd = sd->fd;
  15353. status = &ed->battle_status;
  15354. WFIFOHEAD(fd,22);
  15355. WFIFOW(fd, 0) = 0x81d;
  15356. WFIFOL(fd, 2) = ed->bl.id;
  15357. WFIFOL(fd, 6) = status->hp;
  15358. WFIFOL(fd,10) = status->max_hp;
  15359. WFIFOL(fd,14) = status->sp;
  15360. WFIFOL(fd,18) = status->max_sp;
  15361. WFIFOSET(fd,22);
  15362. }
  15363. /// Buying Store System
  15364. ///
  15365. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15366. /// 0810 <slots>.B
  15367. void clif_buyingstore_open(struct map_session_data* sd)
  15368. {
  15369. int fd = sd->fd;
  15370. WFIFOHEAD(fd,packet_len(0x810));
  15371. WFIFOW(fd,0) = 0x810;
  15372. WFIFOB(fd,2) = sd->buyingstore.slots;
  15373. WFIFOSET(fd,packet_len(0x810));
  15374. }
  15375. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15376. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15377. /// result:
  15378. /// 0 = cancel
  15379. /// 1 = open
  15380. static void clif_parse_ReqOpenBuyingStore( int fd, struct map_session_data* sd ){
  15381. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15382. // TODO: Make this check global for all variable length packets.
  15383. // minimum packet length
  15384. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15385. 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 );
  15386. return;
  15387. }
  15388. char storename[MESSAGE_SIZE];
  15389. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15390. // so that buyingstore_create knows, how many elements it has access to
  15391. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15392. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15393. 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 ) );
  15394. return;
  15395. }
  15396. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15397. }
  15398. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15399. /// 0812 <result>.W <total weight>.L
  15400. /// result:
  15401. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15402. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15403. /// 8 = "No sale (purchase) information available." (0x705)
  15404. /// ? = nothing
  15405. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15406. {
  15407. int fd = sd->fd;
  15408. WFIFOHEAD(fd,packet_len(0x812));
  15409. WFIFOW(fd,0) = 0x812;
  15410. WFIFOW(fd,2) = result;
  15411. WFIFOL(fd,4) = weight;
  15412. WFIFOSET(fd,packet_len(0x812));
  15413. }
  15414. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15415. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15416. void clif_buyingstore_myitemlist( struct map_session_data* sd ){
  15417. nullpo_retv( sd );
  15418. int fd = sd->fd;
  15419. if( !session_isActive( fd ) ){
  15420. return;
  15421. }
  15422. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15423. WFIFOHEAD( fd, length );
  15424. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15425. p->packetType = 0x813;
  15426. p->packetLength = length;
  15427. p->AID = sd->bl.id;
  15428. p->zenyLimit = sd->buyingstore.zenylimit;
  15429. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15430. p->items[i].price = sd->buyingstore.items[i].price;
  15431. p->items[i].amount = sd->buyingstore.items[i].amount;
  15432. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15433. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15434. }
  15435. WFIFOSET( fd, p->packetLength );
  15436. }
  15437. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15438. /// 0814 <account id>.L <store name>.80B
  15439. void clif_buyingstore_entry(struct map_session_data* sd)
  15440. {
  15441. uint8 buf[MESSAGE_SIZE+6];
  15442. WBUFW(buf,0) = 0x814;
  15443. WBUFL(buf,2) = sd->bl.id;
  15444. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15445. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15446. }
  15447. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15448. {
  15449. int fd = sd->fd;
  15450. WFIFOHEAD(fd,packet_len(0x814));
  15451. WFIFOW(fd,0) = 0x814;
  15452. WFIFOL(fd,2) = pl_sd->bl.id;
  15453. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15454. WFIFOSET(fd,packet_len(0x814));
  15455. }
  15456. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15457. /// 0815
  15458. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15459. {
  15460. buyingstore_close(sd);
  15461. }
  15462. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15463. /// 0816 <account id>.L
  15464. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15465. {
  15466. uint8 buf[6];
  15467. WBUFW(buf,0) = 0x816;
  15468. WBUFL(buf,2) = sd->bl.id;
  15469. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15470. }
  15471. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15472. {
  15473. int fd = sd->fd;
  15474. WFIFOHEAD(fd,packet_len(0x816));
  15475. WFIFOW(fd,0) = 0x816;
  15476. WFIFOL(fd,2) = pl_sd->bl.id;
  15477. WFIFOSET(fd,packet_len(0x816));
  15478. }
  15479. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15480. /// 0817 <account id>.L
  15481. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15482. {
  15483. uint32 account_id;
  15484. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15485. buyingstore_open(sd, account_id);
  15486. }
  15487. /// Sends buying store item list.
  15488. /// 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)
  15489. void clif_buyingstore_itemlist( struct map_session_data* sd, struct map_session_data* pl_sd ){
  15490. nullpo_retv( sd );
  15491. nullpo_retv( pl_sd );
  15492. int fd = sd->fd;
  15493. if( !session_isActive( fd ) ){
  15494. return;
  15495. }
  15496. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15497. WFIFOHEAD( fd, length );
  15498. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15499. p->packetType = 0x818;
  15500. p->packetLength = length;
  15501. p->AID = pl_sd->bl.id;
  15502. p->storeId = pl_sd->buyer_id;
  15503. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15504. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15505. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15506. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15507. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15508. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15509. }
  15510. WFIFOSET( fd, p->packetLength );
  15511. }
  15512. /// Request to sell items to a buying store.
  15513. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15514. static void clif_parse_ReqTradeBuyingStore( int fd, struct map_session_data* sd ){
  15515. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15516. // minimum packet length
  15517. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15518. 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 );
  15519. return;
  15520. }
  15521. // so that buyingstore_trade knows, how many elements it has access to
  15522. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15523. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15524. 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 ) );
  15525. return;
  15526. }
  15527. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15528. }
  15529. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15530. /// 081a <result>.W
  15531. /// result:
  15532. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15533. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15534. /// ? = nothing
  15535. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15536. {
  15537. int fd = sd->fd;
  15538. WFIFOHEAD(fd,packet_len(0x81a));
  15539. WFIFOW(fd,0) = 0x81a;
  15540. WFIFOW(fd,2) = result;
  15541. WFIFOSET(fd,packet_len(0x81a));
  15542. }
  15543. /// Updates the zeny limit and an item in the buying store item list.
  15544. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15545. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15546. void clif_buyingstore_update_item( struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny ){
  15547. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15548. p.packetType = buyingStoreUpdateItemType;
  15549. p.itemId = nameid;
  15550. p.amount = amount;
  15551. p.zenyLimit = sd->buyingstore.zenylimit;
  15552. #if PACKETVER >= 20141016
  15553. p.zeny = zeny;
  15554. p.charId = char_id; // GID
  15555. p.updateTime = (int)time(NULL);
  15556. #endif
  15557. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15558. }
  15559. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15560. /// 081c <index>.W <amount>.W <price>.L
  15561. /// message:
  15562. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15563. ///
  15564. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15565. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15566. {
  15567. int fd = sd->fd;
  15568. WFIFOHEAD(fd,packet_len(0x81c));
  15569. WFIFOW(fd,0) = 0x81c;
  15570. WFIFOW(fd,2) = client_index( index );
  15571. WFIFOW(fd,4) = amount;
  15572. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15573. WFIFOSET(fd,packet_len(0x81c));
  15574. }
  15575. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15576. /// 0824 <result>.W <name id>.W
  15577. /// result:
  15578. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15579. /// 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)
  15580. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15581. /// ? = nothing
  15582. void clif_buyingstore_trade_failed_seller( struct map_session_data* sd, short result, unsigned short nameid ){
  15583. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15584. p.packetType = 0x824;
  15585. p.result = result;
  15586. p.itemId = client_nameid( nameid );
  15587. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15588. }
  15589. /// Search Store Info System
  15590. ///
  15591. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15592. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15593. /// type:
  15594. /// 0 = Vending
  15595. /// 1 = Buying Store
  15596. ///
  15597. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15598. /// amount of card slots. If the client does not know about the item it
  15599. /// cannot be searched.
  15600. static void clif_parse_SearchStoreInfo( int fd, struct map_session_data *sd ){
  15601. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15602. // minimum packet length
  15603. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15604. 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 );
  15605. return;
  15606. }
  15607. // check, if there is enough data for the claimed count of items
  15608. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15609. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15610. 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 ) );
  15611. return;
  15612. }
  15613. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15614. if( count < p->itemsCount + p->cardsCount ){
  15615. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15616. return;
  15617. }
  15618. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15619. }
  15620. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15621. /// 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 }*
  15622. /// is first page:
  15623. /// 0 = appends to existing results
  15624. /// 1 = clears previous results before displaying this result set
  15625. /// is next page:
  15626. /// 0 = no "next" label
  15627. /// 1 = "next" label to retrieve more results
  15628. void clif_search_store_info_ack( struct map_session_data* sd ){
  15629. nullpo_retv( sd );
  15630. int fd = sd->fd;
  15631. if( !session_isActive( fd ) ){
  15632. return;
  15633. }
  15634. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15635. unsigned int end = umin( sd->searchstore.count, start + SEARCHSTORE_RESULTS_PER_PAGE );
  15636. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15637. WFIFOHEAD( fd, len );
  15638. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15639. p->packetType = 0x836;
  15640. p->packetLength = len;
  15641. p->firstPage = !sd->searchstore.pages;
  15642. p->nextPage = searchstore_querynext( sd );
  15643. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15644. for( int i = start; i < end; i++ ) {
  15645. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15646. p->items[i].storeId = ssitem->store_id;
  15647. p->items[i].AID = ssitem->account_id;
  15648. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15649. p->items[i].itemId = client_nameid( ssitem->nameid );
  15650. p->items[i].itemType = itemtype( ssitem->nameid );
  15651. p->items[i].price = ssitem->price;
  15652. p->items[i].amount = ssitem->amount;
  15653. p->items[i].refine = ssitem->refine;
  15654. // make-up an item for clif_addcards
  15655. struct item it;
  15656. memset( &it, 0, sizeof( it ) );
  15657. memcpy( &it.card, &ssitem->card, sizeof( it.card ) );
  15658. it.nameid = ssitem->nameid;
  15659. it.amount = ssitem->amount;
  15660. clif_addcards( &p->items[i].slot, &it );
  15661. #if PACKETVER >= 20150226
  15662. clif_add_random_options( p->items[i].option_data, &it );
  15663. #endif
  15664. }
  15665. WFIFOSET( fd, len );
  15666. }
  15667. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15668. /// 0837 <reason>.B
  15669. /// reason:
  15670. /// 0 = "No matching stores were found." (0x70b)
  15671. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15672. /// 2 = "You cannot search anymore." (0x706)
  15673. /// 3 = "You cannot search yet." (0x708)
  15674. /// 4 = "No sale (purchase) information available." (0x705)
  15675. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15676. {
  15677. int fd = sd->fd;
  15678. WFIFOHEAD(fd,packet_len(0x837));
  15679. WFIFOW(fd,0) = 0x837;
  15680. WFIFOB(fd,2) = reason;
  15681. WFIFOSET(fd,packet_len(0x837));
  15682. }
  15683. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15684. /// 0838
  15685. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15686. {
  15687. searchstore_next(sd);
  15688. }
  15689. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15690. /// 083a <type>.W <remaining uses>.B
  15691. /// type:
  15692. /// 0 = Search Stores
  15693. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15694. void clif_open_search_store_info(struct map_session_data* sd)
  15695. {
  15696. int fd = sd->fd;
  15697. WFIFOHEAD(fd,packet_len(0x83a));
  15698. WFIFOW(fd,0) = 0x83a;
  15699. WFIFOW(fd,2) = sd->searchstore.effect;
  15700. #if PACKETVER > 20100701
  15701. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15702. #endif
  15703. WFIFOSET(fd,packet_len(0x83a));
  15704. }
  15705. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15706. /// 083b
  15707. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15708. {
  15709. searchstore_close(sd);
  15710. }
  15711. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15712. /// 083c <account id>.L <store id>.L <nameid>.W
  15713. static void clif_parse_SearchStoreInfoListItemClick( int fd, struct map_session_data* sd ){
  15714. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  15715. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  15716. }
  15717. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15718. /// 083d <xPos>.W <yPos>.W
  15719. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15720. {
  15721. int fd = sd->fd;
  15722. WFIFOHEAD(fd,packet_len(0x83d));
  15723. WFIFOW(fd,0) = 0x83d;
  15724. WFIFOW(fd,2) = x;
  15725. WFIFOW(fd,4) = y;
  15726. WFIFOSET(fd,packet_len(0x83d));
  15727. }
  15728. /// Parse function for packet debugging.
  15729. void clif_parse_debug(int fd,struct map_session_data *sd)
  15730. {
  15731. int cmd, packet_len;
  15732. // clif_parse ensures, that there is at least 2 bytes of data
  15733. cmd = RFIFOW(fd,0);
  15734. if( sd ) {
  15735. packet_len = packet_db[cmd].len;
  15736. if( packet_len == 0 )
  15737. {// unknown
  15738. packet_len = RFIFOREST(fd);
  15739. }
  15740. else if( packet_len == -1 )
  15741. {// variable length
  15742. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15743. }
  15744. 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);
  15745. }
  15746. else
  15747. {
  15748. packet_len = RFIFOREST(fd);
  15749. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15750. }
  15751. ShowDump(RFIFOP(fd,0), packet_len);
  15752. }
  15753. /*==========================================
  15754. * Server tells client to display a window similar to Magnifier (item) one
  15755. * Server populates the window with avilable elemental converter options according to player's inventory
  15756. *------------------------------------------*/
  15757. void clif_elementalconverter_list( struct map_session_data *sd ){
  15758. nullpo_retv( sd );
  15759. int fd = sd->fd;
  15760. if( !session_isActive( fd ) ){
  15761. return;
  15762. }
  15763. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_SKILL_ARROW_DB * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15764. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15765. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15766. int count = 0;
  15767. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  15768. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  15769. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  15770. count++;
  15771. }
  15772. }
  15773. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15774. WFIFOSET( fd, p->packetLength );
  15775. if( count > 0 ){
  15776. sd->menuskill_id = SA_CREATECON;
  15777. sd->menuskill_val = count;
  15778. }
  15779. }
  15780. /**
  15781. * Rune Knight
  15782. **/
  15783. void clif_millenniumshield(struct block_list *bl, short shields) {
  15784. #if PACKETVER >= 20081217
  15785. unsigned char buf[10];
  15786. WBUFW(buf,0) = 0x440;
  15787. WBUFL(buf,2) = bl->id;
  15788. WBUFW(buf,6) = shields;
  15789. WBUFW(buf,8) = 0;
  15790. clif_send(buf,packet_len(0x440),bl,AREA);
  15791. #endif
  15792. }
  15793. /**
  15794. * Warlock
  15795. **/
  15796. /*==========================================
  15797. * Spellbook list [LimitLine/3CeAM]
  15798. *------------------------------------------*/
  15799. void clif_spellbook_list( struct map_session_data *sd ){
  15800. nullpo_retv( sd );
  15801. int fd = sd->fd;
  15802. if( !session_isActive( fd ) ){
  15803. return;
  15804. }
  15805. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15806. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15807. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15808. int count = 0;
  15809. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15810. if( reading_spellbook_db.findBook( sd->inventory.u.items_inventory[i].nameid ) ){
  15811. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15812. count++;
  15813. }
  15814. }
  15815. if( count > 0 ){
  15816. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15817. WFIFOSET( fd, p->packetLength );
  15818. sd->menuskill_id = WL_READING_SB;
  15819. sd->menuskill_val = count;
  15820. }else{
  15821. status_change_end( &sd->bl, SC_STOP, INVALID_TIMER );
  15822. clif_skill_fail( sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0 );
  15823. }
  15824. }
  15825. /**
  15826. * Mechanic
  15827. **/
  15828. /*==========================================
  15829. * Magic Decoy Material List
  15830. *------------------------------------------*/
  15831. void clif_magicdecoy_list( struct map_session_data *sd, uint16 skill_lv, short x, short y ){
  15832. nullpo_retv( sd );
  15833. int fd = sd->fd;
  15834. if( !session_isActive( fd ) ){
  15835. return;
  15836. }
  15837. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15838. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  15839. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15840. int count = 0;
  15841. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15842. if( itemdb_group_item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  15843. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15844. count++;
  15845. }
  15846. }
  15847. if( count > 0 ) {
  15848. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15849. WFIFOSET( fd, p->packetLength );
  15850. sd->menuskill_id = NC_MAGICDECOY;
  15851. sd->menuskill_val = skill_lv;
  15852. sd->sc.comet_x = x;
  15853. sd->sc.comet_y = y;
  15854. }else{
  15855. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  15856. }
  15857. }
  15858. /*==========================================
  15859. * Guillotine Cross Poisons List
  15860. *------------------------------------------*/
  15861. void clif_poison_list( struct map_session_data *sd, uint16 skill_lv ){
  15862. nullpo_retv( sd );
  15863. int fd = sd->fd;
  15864. if( !session_isActive( fd ) ){
  15865. return;
  15866. }
  15867. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  15868. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  15869. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  15870. int count = 0;
  15871. for( int i = 0; i < MAX_INVENTORY; i++ ){
  15872. if( itemdb_group_item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  15873. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  15874. count++;
  15875. }
  15876. }
  15877. if( count > 0 ){
  15878. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  15879. WFIFOSET( fd, p->packetLength );
  15880. sd->menuskill_id = GC_POISONINGWEAPON;
  15881. sd->menuskill_val = skill_lv;
  15882. }else{
  15883. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  15884. }
  15885. }
  15886. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15887. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15888. int fd, i, c;
  15889. nullpo_ret(sd);
  15890. fd = sd->fd;
  15891. if( !fd )
  15892. return 0;
  15893. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15894. return 0;
  15895. WFIFOHEAD(fd, 2 * 6 + 4);
  15896. WFIFOW(fd,0) = 0x442;
  15897. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15898. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15899. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15900. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  15901. {
  15902. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15903. c++;
  15904. }
  15905. if( c > 0 ) {
  15906. WFIFOW(fd,2) = 8 + c * 2;
  15907. WFIFOL(fd,4) = c;
  15908. WFIFOSET(fd,WFIFOW(fd,2));
  15909. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15910. sd->menuskill_val = c;
  15911. } else {
  15912. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15913. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15914. }
  15915. return 1;
  15916. }
  15917. /*===========================================
  15918. * Skill list for Four Elemental Analysis
  15919. * and Change Material skills.
  15920. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15921. *------------------------------------------*/
  15922. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15923. #if PACKETVER >= 20090922
  15924. int fd = sd->fd;
  15925. nullpo_ret(sd);
  15926. sd->menuskill_id = skill_id; // To prevent hacking.
  15927. sd->menuskill_val = skill_lv;
  15928. if( skill_id == GN_CHANGEMATERIAL )
  15929. skill_lv = 0; // Changematerial
  15930. WFIFOHEAD(fd, packet_len(0x7e3));
  15931. WFIFOW(fd,0) = 0x7e3;
  15932. WFIFOL(fd,2) = skill_lv;
  15933. WFIFOL(fd,4) = 0;
  15934. WFIFOSET(fd, packet_len(0x7e3));
  15935. #endif
  15936. return 1;
  15937. }
  15938. /*==========================================
  15939. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  15940. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15941. * RFIFOL(fd,2) - type (currently not used)
  15942. *------------------------------------------*/
  15943. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15944. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15945. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15946. if (sd->menuskill_id == SA_AUTOSPELL) {
  15947. sd->state.workinprogress = WIP_DISABLE_NONE;
  15948. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  15949. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  15950. if (pc_istrading(sd)) {
  15951. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  15952. clif_menuskill_clear(sd);
  15953. return;
  15954. }
  15955. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  15956. } else
  15957. return;
  15958. clif_menuskill_clear(sd);
  15959. }
  15960. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15961. /// 08cf <id>.L <type>.W <num>.W
  15962. void clif_spiritcharm(struct map_session_data *sd) {
  15963. unsigned char buf[10];
  15964. nullpo_retv(sd);
  15965. WBUFW(buf,0) = 0x08cf;
  15966. WBUFL(buf,2) = sd->bl.id;
  15967. WBUFW(buf,6) = sd->spiritcharm_type;
  15968. WBUFW(buf,8) = sd->spiritcharm;
  15969. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15970. }
  15971. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15972. /// 0907 <index>.W
  15973. ///
  15974. /// R 0908 <index>.w <type>.b
  15975. /// type:
  15976. /// 0 = move item to personal tab
  15977. /// 1 = move item to normal tab
  15978. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15979. #if PACKETVER >= 20111122
  15980. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15981. int index = RFIFOW(fd,info->pos[0]) - 2;
  15982. int type = RFIFOB(fd, info->pos[1]);
  15983. /* can't move while dead. */
  15984. if(pc_isdead(sd)) {
  15985. return;
  15986. }
  15987. if (index < 0 || index >= MAX_INVENTORY)
  15988. return;
  15989. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15990. sd->inventory.u.items_inventory[index].favorite = 0;
  15991. else if( type == 0 )
  15992. sd->inventory.u.items_inventory[index].favorite = 1;
  15993. else
  15994. return;/* nothing to do. */
  15995. clif_favorite_item(sd, index);
  15996. #endif
  15997. }
  15998. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15999. /// 0900 <index>.W <favorite>.B
  16000. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  16001. int fd = sd->fd;
  16002. WFIFOHEAD(fd,packet_len(0x908));
  16003. WFIFOW(fd,0) = 0x908;
  16004. WFIFOW(fd,2) = index+2;
  16005. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16006. WFIFOSET(fd,packet_len(0x908));
  16007. }
  16008. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16009. void clif_snap( struct block_list *bl, short x, short y ) {
  16010. unsigned char buf[10];
  16011. WBUFW(buf,0) = 0x8d2;
  16012. WBUFL(buf,2) = bl->id;
  16013. WBUFW(buf,6) = x;
  16014. WBUFW(buf,8) = y;
  16015. if( disguised(bl) )
  16016. {
  16017. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16018. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16019. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16020. } else
  16021. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16022. }
  16023. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16024. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16025. #if PACKETVER >= 20120404
  16026. WFIFOHEAD(fd,packet_len(0x977));
  16027. WFIFOW(fd,0) = 0x977;
  16028. WFIFOL(fd,2) = md->bl.id;
  16029. WFIFOL(fd,6) = md->status.hp;
  16030. WFIFOL(fd,10) = md->status.max_hp;
  16031. WFIFOSET(fd,packet_len(0x977));
  16032. #endif
  16033. }
  16034. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16035. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  16036. return;
  16037. }
  16038. void clif_partytickack(struct map_session_data* sd, bool flag) {
  16039. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16040. WFIFOW(sd->fd,0) = 0x2c9;
  16041. WFIFOB(sd->fd,2) = flag;
  16042. WFIFOSET(sd->fd, packet_len(0x2c9));
  16043. }
  16044. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16045. /// 0979 <world name>.24B <char name>.24B
  16046. void clif_ackworldinfo(struct map_session_data* sd) {
  16047. int fd;
  16048. nullpo_retv(sd);
  16049. fd = sd->fd;
  16050. WFIFOHEAD(fd,packet_len(0x979));
  16051. WFIFOW(fd,0)=0x979;
  16052. //AID -> world name ?
  16053. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16054. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16055. WFIFOSET(fd,packet_len(0x979));
  16056. }
  16057. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16058. /// 0978 <AID>.L
  16059. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  16060. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16061. if(sd)
  16062. clif_ackworldinfo(sd);
  16063. }
  16064. static void clif_loadConfirm( struct map_session_data *sd ){
  16065. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16066. nullpo_retv( sd );
  16067. struct PACKET_ZC_LOAD_CONFIRM p;
  16068. p.packetType = HEADER_ZC_LOAD_CONFIRM;
  16069. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16070. if (sd->instance_id > 0)
  16071. instance_reqinfo(sd, sd->instance_id);
  16072. if (sd->status.party_id > 0)
  16073. party_member_joined(sd);
  16074. if (sd->status.guild_id > 0)
  16075. guild_member_joined(sd);
  16076. if (sd->status.clan_id > 0)
  16077. clan_member_joined(sd);
  16078. #endif
  16079. }
  16080. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16081. /// 0447
  16082. void clif_parse_blocking_playcancel( int fd, struct map_session_data *sd ){
  16083. clif_loadConfirm( sd );
  16084. }
  16085. /// req world info (CZ_CLIENT_VERSION)
  16086. /// 044A <version>.L
  16087. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  16088. //if(sd)
  16089. ;
  16090. }
  16091. /// Ranking list
  16092. /// ranking pointlist { <name>.24B <point>.L }*10
  16093. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  16094. struct fame_list* list;
  16095. int i, size = MAX_FAME_LIST;
  16096. switch(rankingtype) {
  16097. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16098. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16099. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16100. // PK currently unsupported
  16101. case RANK_KILLER: list = NULL; size = 0; break;
  16102. default:
  16103. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16104. return;
  16105. }
  16106. //Packet size limits this list to 10 elements. [Skotlex]
  16107. for (i = 0; i < min(10,size); i++) {
  16108. if (list[i].id > 0) {
  16109. const char* name;
  16110. if (strcmp(list[i].name, "-") == 0 &&
  16111. (name = map_charid2nick(list[i].id)) != NULL)
  16112. {
  16113. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16114. } else {
  16115. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16116. }
  16117. } else {
  16118. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16119. }
  16120. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16121. }
  16122. for(;i < 10; i++) { //In case the MAX is less than 10.
  16123. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16124. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16125. }
  16126. }
  16127. /// Request for the blacksmith ranklist.
  16128. /// /blacksmith command sends this packet to the server.
  16129. /// 0217 (CZ_BLACKSMITH_RANK)
  16130. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  16131. clif_ranklist(sd,RANK_BLACKSMITH);
  16132. }
  16133. /// Request for the alchemist ranklist.
  16134. /// /alchemist command sends this packet to the server.
  16135. /// 0218 (CZ_ALCHEMIST_RANK)
  16136. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  16137. clif_ranklist(sd,RANK_ALCHEMIST);
  16138. }
  16139. /// Request for the taekwon ranklist.
  16140. /// /taekwon command sends this packet to the server.
  16141. /// 0225 (CZ_TAEKWON_RANK)
  16142. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  16143. clif_ranklist(sd,RANK_TAEKWON);
  16144. }
  16145. /// Request for the killer ranklist.
  16146. /// /pk command sends this packet to the server.
  16147. /// 0237 (CZ_KILLER_RANK)
  16148. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  16149. clif_ranklist(sd,RANK_KILLER);
  16150. }
  16151. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16152. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16153. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16154. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16155. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16156. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  16157. enum e_rank rank;
  16158. #if PACKETVER < 20130710
  16159. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16160. short cmd;
  16161. switch( rankingType ){
  16162. case RANK_BLACKSMITH: cmd = 0x219; break;
  16163. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16164. case RANK_TAEKWON: cmd = 0x226; break;
  16165. case RANK_KILLER: cmd = 0x238; break;
  16166. default:
  16167. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16168. return;
  16169. }
  16170. // Can be safely casted here, since we validated it before
  16171. rank = (enum e_rank)rankingType;
  16172. WBUFW(buf,0) = cmd;
  16173. clif_sub_ranklist(buf,2,sd,rank);
  16174. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16175. #else
  16176. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16177. int mypoint = 0;
  16178. switch( rankingType ){
  16179. case RANK_BLACKSMITH:
  16180. case RANK_ALCHEMIST:
  16181. case RANK_TAEKWON:
  16182. case RANK_KILLER:
  16183. break;
  16184. default:
  16185. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16186. return;
  16187. }
  16188. // Can be safely casted here, since we validated it before
  16189. rank = (enum e_rank)rankingType;
  16190. WBUFW(buf,0) = 0x97d;
  16191. WBUFW(buf,2) = rank;
  16192. clif_sub_ranklist(buf,4,sd,rank);
  16193. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16194. case MAPID_BLACKSMITH:
  16195. case MAPID_ALCHEMIST:
  16196. case MAPID_TAEKWON:
  16197. mypoint = sd->status.fame;
  16198. }
  16199. WBUFL(buf,284) = mypoint; //mypoint
  16200. clif_send(buf, 288, &sd->bl, SELF);
  16201. #endif
  16202. }
  16203. /*
  16204. * 097c <type> (CZ_REQ_RANKING)
  16205. * type
  16206. * 0: /blacksmith
  16207. * 1: /alchemist
  16208. * 2: /taekwon
  16209. * 3: /pk
  16210. * */
  16211. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  16212. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16213. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16214. clif_ranklist(sd,rankingtype);
  16215. }
  16216. /// Updates the fame rank points for the given ranking.
  16217. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16218. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16219. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16220. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16221. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  16222. int fd=sd->fd;
  16223. #if PACKETVER < 20130710
  16224. short cmd;
  16225. switch(rankingtype){
  16226. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16227. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16228. case RANK_TAEKWON: cmd = 0x224; break;
  16229. default:
  16230. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16231. return;
  16232. }
  16233. WFIFOHEAD(fd,packet_len(cmd));
  16234. WFIFOW(fd,0) = cmd;
  16235. WFIFOL(fd,2) = point;
  16236. WFIFOL(fd,6) = sd->status.fame;
  16237. WFIFOSET(fd, packet_len(cmd));
  16238. #else
  16239. WFIFOHEAD(fd,packet_len(0x97e));
  16240. WFIFOW(fd,0) = 0x97e;
  16241. WFIFOW(fd,2) = rankingtype;
  16242. WFIFOL(fd,4) = point;
  16243. WFIFOL(fd,8) = sd->status.fame;
  16244. WFIFOSET(fd,packet_len(0x97e));
  16245. #endif
  16246. }
  16247. /**
  16248. * Transmit personal information to player. (rates)
  16249. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16250. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16251. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16252. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16253. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16254. * FIXME!
  16255. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16256. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16257. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16258. */
  16259. #ifdef VIP_ENABLE
  16260. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16261. if (sd) {
  16262. struct s_packet_db* info;
  16263. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16264. int cmd = 0, fd, i = 0;
  16265. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16266. int details_bexp[PINFO_MAX];
  16267. int details_drop[PINFO_MAX];
  16268. int details_penalty[PINFO_MAX];
  16269. /**
  16270. * Set for EXP
  16271. */
  16272. //0:PCRoom
  16273. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16274. if (details_bexp[0] == 100 || !details_bexp[0])
  16275. details_bexp[0] = 0;
  16276. else {
  16277. if (details_bexp[0] < 100) {
  16278. details_bexp[0] = 100 - details_bexp[0];
  16279. details_bexp[0] = 0 - details_bexp[0];
  16280. }
  16281. else
  16282. details_bexp[0] = details_bexp[0] - 100;
  16283. }
  16284. //1:Premium
  16285. if (pc_isvip(sd)) {
  16286. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16287. if (details_bexp[1] < 0)
  16288. details_bexp[1] = 0 - details_bexp[1];
  16289. }
  16290. else
  16291. details_bexp[1] = 0;
  16292. //2:Server
  16293. details_bexp[2] = battle_config.base_exp_rate;
  16294. if (details_bexp[2] == 100)
  16295. details_bexp[2] = 0;
  16296. else {
  16297. if (details_bexp[2] < 100) {
  16298. details_bexp[2] = 100 - details_bexp[2];
  16299. details_bexp[2] = 0 - details_bexp[2];
  16300. }
  16301. else
  16302. details_bexp[2] = details_bexp[2] - 100;
  16303. }
  16304. //3:TPLUS
  16305. details_bexp[3] = 0;
  16306. /* End - EXP set*/
  16307. /**
  16308. * Set for Drop rate
  16309. */
  16310. //0:PCRoom
  16311. details_drop[0] = 0;
  16312. //1:Premium
  16313. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16314. if (pc_isvip(sd)) {
  16315. if (details_drop[1] < 0)
  16316. details_drop[1] = 0 - details_drop[1];
  16317. }
  16318. else
  16319. details_drop[1] = 0;
  16320. //2:Server
  16321. details_drop[2] = battle_config.item_rate_common;
  16322. if (details_drop[2] == 100)
  16323. details_drop[2] = 0;
  16324. else {
  16325. if (details_drop[2] < 100) {
  16326. details_drop[2] = 100 - details_drop[2];
  16327. details_drop[2] = 0 - details_drop[2];
  16328. }
  16329. else
  16330. details_drop[2] = details_drop[2] - 100;
  16331. }
  16332. //3:TPLUS
  16333. details_drop[3] = 0;
  16334. /* End - Drop set*/
  16335. /**
  16336. * Set for Penalty rate
  16337. */
  16338. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16339. //0:PCRoom
  16340. details_penalty[0] = 0;
  16341. //1:Premium
  16342. if (pc_isvip(sd)) {
  16343. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16344. if (details_penalty[1] == 100)
  16345. details_penalty[1] = 0;
  16346. else {
  16347. if (details_penalty[1] < 100) {
  16348. details_penalty[1] = 100 - details_penalty[1];
  16349. details_penalty[1] = 0 - details_penalty[1];
  16350. }
  16351. else
  16352. details_penalty[1] = details_penalty[1] - 100;
  16353. }
  16354. }
  16355. else
  16356. details_penalty[1] = 0;
  16357. //2:Server
  16358. details_penalty[2] = battle_config.death_penalty_base;
  16359. if (details_penalty[2] == 100)
  16360. details_penalty[2] = 0;
  16361. else {
  16362. if (details_penalty[2] < 100) {
  16363. details_penalty[2] = 100 - details_penalty[2];
  16364. details_penalty[2] = 0 - details_penalty[2];
  16365. }
  16366. else
  16367. details_penalty[2] = details_penalty[2] - 100;
  16368. }
  16369. //3:TPLUS
  16370. details_penalty[3] = 0;
  16371. /* End - Penalty set*/
  16372. cmd = packet_db_ack[cmdtype];
  16373. info = &packet_db[cmd];
  16374. len = info->len; //this is the base len without details
  16375. if(!len) return; //version as packet disable
  16376. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16377. szdetails = 7;
  16378. factor = 1;
  16379. }
  16380. else if (cmd == 0x097b) {
  16381. tot_baseexp *= factor;
  16382. tot_drop *= factor;
  16383. tot_penalty *= factor;
  16384. }
  16385. fd = sd->fd;
  16386. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16387. WFIFOW(fd,0) = cmd;
  16388. for (i = 0; i < maxinfotype; i++) {
  16389. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16390. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16391. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16392. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16393. tot_baseexp += details_bexp[i]*factor;
  16394. tot_drop += details_penalty[i]*factor;
  16395. tot_penalty += details_drop[i]*factor;
  16396. len += szdetails;
  16397. }
  16398. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16399. if (cmd == 0x08cb) { //0x08cb version
  16400. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16401. WFIFOW(fd,info->pos[2]) = tot_drop;
  16402. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16403. }
  16404. else { //2013-08-07aRagexe uses 0x097b
  16405. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16406. WFIFOL(fd,info->pos[2]) = tot_drop;
  16407. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16408. }
  16409. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16410. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16411. WFIFOSET(fd,len);
  16412. }
  16413. }
  16414. #endif
  16415. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16416. char cmd[30];
  16417. int t_aid = RFIFOL(fd,2);
  16418. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16419. is_atcommand(fd, sd, cmd, 1);
  16420. }
  16421. /**
  16422. * Marks Crimson Marker target on mini-map to the caster
  16423. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16424. * @param fd
  16425. * @param bl Crimson Marker target
  16426. **/
  16427. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16428. struct s_packet_db* info;
  16429. int cmd = 0;
  16430. int16 len;
  16431. unsigned char buf[11];
  16432. nullpo_retv(sd);
  16433. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16434. if (!cmd)
  16435. cmd = 0x09C1; //default
  16436. info = &packet_db[cmd];
  16437. if (!(len = info->len))
  16438. return;
  16439. WBUFW(buf, 0) = cmd;
  16440. WBUFL(buf, info->pos[0]) = bl->id;
  16441. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16442. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16443. clif_send(buf, len, &sd->bl, SELF);
  16444. }
  16445. /**
  16446. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16447. **/
  16448. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16449. struct s_packet_db *info = NULL;
  16450. int cmd = 0;
  16451. nullpo_retv(sd);
  16452. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16453. info = &packet_db[cmd];
  16454. if (!cmd || !info->len)
  16455. return;
  16456. WFIFOHEAD(sd->fd, info->len);
  16457. WFIFOW(sd->fd, 0) = cmd;
  16458. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16459. WFIFOSET(sd->fd, info->len);
  16460. }
  16461. /**
  16462. * [Ind/Hercules]
  16463. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16464. **/
  16465. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16466. char buf[256];
  16467. size_t len;
  16468. nullpo_retv(bl);
  16469. if(!message)
  16470. return;
  16471. len = strlen(message)+1;
  16472. if( len > sizeof(buf)-8 ) {
  16473. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16474. len = sizeof(buf)-8;
  16475. }
  16476. WBUFW(buf,0) = 0x8b3;
  16477. WBUFW(buf,2) = (uint16)(len+8);
  16478. WBUFL(buf,4) = bl->id;
  16479. safestrncpy(WBUFCP(buf,8), message, len);
  16480. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16481. }
  16482. /**
  16483. * [Ind/Hercules]
  16484. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16485. **/
  16486. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16487. unsigned char buf[10];
  16488. nullpo_retv(sd);
  16489. WBUFW(buf,0) = 0x7fc;
  16490. WBUFL(buf,2) = prev_leader_aid;
  16491. WBUFL(buf,6) = new_leader_aid;
  16492. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16493. }
  16494. /**
  16495. * Sends a clan message to a player
  16496. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16497. **/
  16498. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16499. #if PACKETVER >= 20131223
  16500. struct map_session_data *sd;
  16501. uint8 buf[256];
  16502. if( len == 0 ){
  16503. return;
  16504. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16505. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16506. len = sizeof(buf)-5-NAME_LENGTH;
  16507. }
  16508. WBUFW(buf, 0) = 0x98e;
  16509. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16510. // 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
  16511. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16512. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16513. if((sd = clan_getavailablesd(clan)) != NULL)
  16514. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16515. #endif
  16516. }
  16517. /**
  16518. * Parses a clan message from a player.
  16519. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16520. **/
  16521. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16522. #if PACKETVER >= 20131223
  16523. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16524. // validate packet and retrieve name and message
  16525. if( !clif_process_message(sd, false, name, message, output ) )
  16526. return;
  16527. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16528. #endif
  16529. }
  16530. /**
  16531. * Sends the basic clan informations to the client.
  16532. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16533. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16534. **/
  16535. void clif_clan_basicinfo( struct map_session_data *sd ){
  16536. #if PACKETVER >= 20131223
  16537. int fd, offset, length, i, flag;
  16538. struct clan* clan;
  16539. char mapname[MAP_NAME_LENGTH_EXT];
  16540. nullpo_retv( sd );
  16541. nullpo_retv( clan = sd->clan );
  16542. // Check if the player has a valid session and is not autotrading
  16543. if( !clif_session_isValid( sd ) ){
  16544. return;
  16545. }
  16546. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16547. fd = sd->fd;
  16548. WFIFOHEAD(fd,length);
  16549. memset( WFIFOP(fd, 0), 0, length );
  16550. WFIFOW( fd, 0 ) = 0x98a;
  16551. WFIFOL( fd, 4 ) = clan->id;
  16552. offset = 8;
  16553. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16554. offset += NAME_LENGTH;
  16555. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16556. offset += NAME_LENGTH;
  16557. mapindex_getmapname_ext( clan->map, mapname );
  16558. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16559. offset += MAP_NAME_LENGTH_EXT;
  16560. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16561. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16562. for( flag = 0; flag < 2; flag++ ){
  16563. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16564. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16565. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16566. offset += NAME_LENGTH;
  16567. }
  16568. }
  16569. }
  16570. WFIFOW( fd, 2 ) = offset;
  16571. WFIFOSET(fd,offset);
  16572. #endif
  16573. }
  16574. /**
  16575. * Updates the online and maximum player count of a clan.
  16576. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16577. **/
  16578. void clif_clan_onlinecount( struct clan* clan ){
  16579. #if PACKETVER >= 20131223
  16580. uint8 buf[6];
  16581. struct map_session_data *sd;
  16582. WBUFW(buf,0) = 0x988;
  16583. WBUFW(buf,2) = clan->connect_member;
  16584. WBUFW(buf,4) = clan->max_member;
  16585. if((sd = clan_getavailablesd(clan)) != NULL)
  16586. clif_send(buf, 6, &sd->bl, CLAN);
  16587. #endif
  16588. }
  16589. /**
  16590. * Notifies the client that the player has left his clan.
  16591. * 0989 (ZC_ACK_CLAN_LEAVE)
  16592. **/
  16593. void clif_clan_leave( struct map_session_data* sd ){
  16594. #if PACKETVER >= 20131223
  16595. int fd;
  16596. nullpo_retv( sd );
  16597. if( !clif_session_isValid( sd ) ){
  16598. return;
  16599. }
  16600. fd = sd->fd;
  16601. WFIFOHEAD(fd,2);
  16602. WFIFOW(fd,0) = 0x989;
  16603. WFIFOSET(fd,2);
  16604. #endif
  16605. }
  16606. /**
  16607. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16608. * 0A2F <result>.B <title_id>.L
  16609. */
  16610. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16611. {
  16612. #if PACKETVER >= 20150513
  16613. int fd;
  16614. nullpo_retv(sd);
  16615. if (!clif_session_isValid(sd))
  16616. return;
  16617. fd = sd->fd;
  16618. WFIFOHEAD(fd, packet_len(0xa2f));
  16619. WFIFOW(fd, 0) = 0xa2f;
  16620. WFIFOB(fd, 2) = result;
  16621. WFIFOL(fd, 3) = title_id;
  16622. WFIFOSET(fd, packet_len(0xa2f));
  16623. #endif
  16624. }
  16625. /**
  16626. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16627. * 0A2E <title_id>.L
  16628. */
  16629. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16630. {
  16631. int title_id;
  16632. nullpo_retv(sd);
  16633. title_id = RFIFOL(fd, 2);
  16634. if( title_id == sd->status.title_id ){
  16635. // It is exactly the same as the old one
  16636. return;
  16637. }else if( title_id <= 0 ){
  16638. sd->status.title_id = 0;
  16639. }else{
  16640. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16641. clif_change_title_ack(sd, 1, title_id);
  16642. return;
  16643. }
  16644. sd->status.title_id = title_id;
  16645. }
  16646. clif_name_area(&sd->bl);
  16647. clif_change_title_ack(sd, 0, title_id);
  16648. }
  16649. #ifdef DUMP_UNKNOWN_PACKET
  16650. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16651. {
  16652. const char* packet_txt = "save/packet.txt";
  16653. FILE* fp;
  16654. time_t time_server;
  16655. struct tm *datetime;
  16656. char datestr[512];
  16657. time(&time_server); // get time in seconds since 1/1/1970
  16658. datetime = localtime(&time_server); // convert seconds in structure
  16659. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16660. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16661. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16662. if( sd ) {
  16663. 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);
  16664. } else {
  16665. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16666. }
  16667. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16668. fprintf(fp, "\n");
  16669. fclose(fp);
  16670. } else {
  16671. ShowError("Failed to write '%s'.\n", packet_txt);
  16672. // Dump on console instead
  16673. if( sd ) {
  16674. 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);
  16675. } else {
  16676. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16677. }
  16678. ShowDump(RFIFOP(fd,0), packet_len);
  16679. }
  16680. }
  16681. #endif
  16682. /// Roulette System
  16683. /// Author: Yommy
  16684. /// Opens the roulette window
  16685. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16686. void clif_roulette_open( struct map_session_data* sd ){
  16687. nullpo_retv( sd );
  16688. struct packet_roulette_open_ack p;
  16689. p.PacketType = 0xa1a;
  16690. p.Result = 0; // result
  16691. p.Serial = 0; // serial
  16692. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16693. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16694. p.AdditionItemID = -1; //! TODO: Display bonus item
  16695. p.GoldPoint = sd->roulette_point.gold;
  16696. p.SilverPoint = sd->roulette_point.silver;
  16697. p.BronzePoint = sd->roulette_point.bronze;
  16698. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16699. }
  16700. /// Request to open the roulette window
  16701. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16702. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16703. nullpo_retv(sd);
  16704. if (!battle_config.feature_roulette) {
  16705. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16706. return;
  16707. }
  16708. clif_roulette_open(sd);
  16709. }
  16710. /// Sends the info about the available roulette rewards to the client
  16711. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16712. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16713. void clif_roulette_info( struct map_session_data* sd ){
  16714. nullpo_retv(sd);
  16715. struct packet_roulette_info_ack p;
  16716. p.PacketType = rouletteinfoackType;
  16717. p.PacketLength = sizeof(p);
  16718. p.RouletteSerial = 1;
  16719. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16720. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16721. p.ItemInfo[count].Row = i;
  16722. p.ItemInfo[count].Position = j;
  16723. p.ItemInfo[count].ItemId = rd.nameid[i][j];
  16724. p.ItemInfo[count].Count = rd.qty[i][j];
  16725. #if PACKETVER >= 20180511
  16726. p.ItemInfo[count].unused = 0;
  16727. #endif
  16728. count++;
  16729. }
  16730. }
  16731. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16732. }
  16733. /// Request the roulette reward data
  16734. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16735. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16736. nullpo_retv(sd);
  16737. if (!battle_config.feature_roulette) {
  16738. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16739. return;
  16740. }
  16741. clif_roulette_info(sd);
  16742. }
  16743. /// Notification of the client that the roulette window was closed
  16744. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16745. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16746. nullpo_retv(sd);
  16747. if (!battle_config.feature_roulette) {
  16748. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16749. return;
  16750. }
  16751. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16752. }
  16753. /// Response to a item reward request
  16754. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16755. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16756. #if PACKETVER >= 20141016
  16757. nullpo_retv(sd);
  16758. struct packet_roulette_itemrecv_ack p;
  16759. p.PacketType = roulettercvitemackType;
  16760. p.Result = type;
  16761. p.AdditionItemID = 0; //! TODO: Additional item
  16762. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16763. #endif
  16764. }
  16765. /**
  16766. * Claim roulette reward
  16767. * @param sd Player
  16768. * @return 0:Success
  16769. **/
  16770. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16771. struct item it;
  16772. uint8 res = 1;
  16773. nullpo_retr(1, sd);
  16774. if (sd->roulette.prizeIdx < 0)
  16775. return RECV_ITEM_FAILED;
  16776. memset(&it, 0, sizeof(it));
  16777. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16778. it.identify = 1;
  16779. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16780. ; // onSuccess
  16781. }
  16782. sd->roulette.claimPrize = false;
  16783. sd->roulette.prizeStage = 0;
  16784. sd->roulette.prizeIdx = -1;
  16785. sd->roulette.stage = 0;
  16786. return res;
  16787. }
  16788. /// Update Roulette window with current stats
  16789. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16790. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16791. nullpo_retv( sd );
  16792. struct packet_roulette_generate_ack p;
  16793. p.PacketType = roulettgenerateackType;
  16794. p.Result = result;
  16795. p.Step = stage;
  16796. p.Idx = prizeIdx;
  16797. p.AdditionItemID = bonusItemID;
  16798. p.RemainGold = sd->roulette_point.gold;
  16799. p.RemainSilver = sd->roulette_point.silver;
  16800. p.RemainBronze = sd->roulette_point.bronze;
  16801. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16802. }
  16803. /// Request to start the roulette
  16804. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16805. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16806. enum GENERATE_ROULETTE_ACK result;
  16807. nullpo_retv(sd);
  16808. if (!battle_config.feature_roulette) {
  16809. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16810. return;
  16811. }
  16812. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16813. return;
  16814. }
  16815. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16816. sd->roulette.stage = 0;
  16817. sd->roulette.claimPrize = false;
  16818. sd->roulette.prizeStage = 0;
  16819. sd->roulette.prizeIdx = -1;
  16820. }
  16821. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16822. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16823. }else{
  16824. if (!sd->roulette.stage) {
  16825. if (sd->roulette_point.bronze > 0) {
  16826. sd->roulette_point.bronze -= 1;
  16827. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16828. } else if (sd->roulette_point.silver > 9) {
  16829. sd->roulette_point.silver -= 10;
  16830. sd->roulette.stage = 2;
  16831. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16832. } else if (sd->roulette_point.gold > 9) {
  16833. sd->roulette_point.gold -= 10;
  16834. sd->roulette.stage = 4;
  16835. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16836. }
  16837. }
  16838. sd->roulette.prizeStage = sd->roulette.stage;
  16839. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16840. sd->roulette.claimPrize = true;
  16841. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16842. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16843. result = GENERATE_ROULETTE_LOSING;
  16844. sd->roulette.stage = 0;
  16845. }else{
  16846. result = GENERATE_ROULETTE_SUCCESS;
  16847. sd->roulette.stage++;
  16848. }
  16849. }
  16850. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16851. }
  16852. /// Request to claim a prize
  16853. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16854. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16855. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16856. nullpo_retv(sd);
  16857. if (!battle_config.feature_roulette) {
  16858. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16859. return;
  16860. }
  16861. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16862. return;
  16863. }
  16864. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16865. switch (clif_roulette_getitem(sd)) {
  16866. case ADDITEM_SUCCESS:
  16867. type = RECV_ITEM_SUCCESS;
  16868. break;
  16869. case ADDITEM_INVALID:
  16870. case ADDITEM_OVERITEM:
  16871. case ADDITEM_OVERAMOUNT:
  16872. type = RECV_ITEM_OVERCOUNT;
  16873. break;
  16874. case ADDITEM_OVERWEIGHT:
  16875. type = RECV_ITEM_OVERWEIGHT;
  16876. break;
  16877. case ADDITEM_STACKLIMIT:
  16878. default:
  16879. type = RECV_ITEM_FAILED;
  16880. break;
  16881. }
  16882. }
  16883. clif_roulette_recvitem_ack(sd,type);
  16884. }
  16885. /// MERGE ITEM
  16886. /**
  16887. * Acknowledge the client about item merger result
  16888. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16889. * @param fd
  16890. * @param sd
  16891. **/
  16892. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16893. unsigned char buf[9];
  16894. struct s_packet_db *info = NULL;
  16895. short cmd = 0;
  16896. nullpo_retv(sd);
  16897. if (!clif_session_isValid(sd))
  16898. return;
  16899. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16900. return;
  16901. if (!(info = &packet_db[cmd]) || info->len == 0)
  16902. return;
  16903. WBUFW(buf, 0) = cmd;
  16904. WBUFW(buf, info->pos[0]) = index;
  16905. WBUFW(buf, info->pos[1]) = count;
  16906. WBUFB(buf, info->pos[2]) = type;
  16907. clif_send(buf, info->len, &sd->bl, SELF);
  16908. }
  16909. /**
  16910. * Check if item has the pair to be merged
  16911. * @param sd
  16912. * @param it Item
  16913. * @return True if has pair, False if not
  16914. **/
  16915. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16916. struct item *it_;
  16917. unsigned short i;
  16918. nullpo_retr(false, sd);
  16919. 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);
  16920. if (i < MAX_INVENTORY)
  16921. return true;
  16922. return false;
  16923. }
  16924. /**
  16925. * Check if item can be merged
  16926. * @param id Item Data
  16927. * @param it Item
  16928. * @return True if can be merged, False if not
  16929. **/
  16930. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16931. if (!id || !it)
  16932. return false;
  16933. if (id->type == IT_CASH)
  16934. return false;
  16935. if (!itemdb_isstackable2(id))
  16936. return false;
  16937. if (itemdb_isspecial(it->card[0]))
  16938. return false;
  16939. if (!it->unique_id)
  16940. return false;
  16941. return true;
  16942. }
  16943. /**
  16944. * Open available item to be merged.
  16945. * Only show 1 item in 1 process.
  16946. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16947. * @param sd
  16948. **/
  16949. void clif_merge_item_open(struct map_session_data *sd) {
  16950. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16951. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16952. int len = 0;
  16953. struct s_packet_db *info = NULL;
  16954. struct item *it;
  16955. nullpo_retv(sd);
  16956. if (!clif_session_isValid(sd))
  16957. return;
  16958. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16959. return;
  16960. if (!(info = &packet_db[cmd]) || info->len == 0)
  16961. return;
  16962. // Get entries
  16963. for (i = 0; i < MAX_INVENTORY; i++) {
  16964. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16965. continue;
  16966. if (clif_merge_item_has_pair(sd, it))
  16967. indexes[n++] = i;
  16968. }
  16969. if (n < 2) { // No item need to be merged
  16970. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16971. return;
  16972. }
  16973. WBUFW(buf, 0) = cmd;
  16974. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16975. for (i = 0; i < n; i++) {
  16976. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16977. }
  16978. clif_send(buf, len, &sd->bl, SELF);
  16979. }
  16980. /**
  16981. * Process item merger
  16982. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16983. * @param fd
  16984. * @param sd
  16985. **/
  16986. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16987. struct s_packet_db *info = NULL;
  16988. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16989. unsigned int count = 0;
  16990. struct item_data *id = NULL;
  16991. nullpo_retv(sd);
  16992. if (!clif_session_isValid(sd))
  16993. return;
  16994. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16995. return;
  16996. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16997. if (n < 2) { // No item need to be merged
  16998. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16999. return;
  17000. }
  17001. for (i = 0, j = 0; i < n; i++) {
  17002. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  17003. if( idx < 0 || idx >= MAX_INVENTORY ){
  17004. return;
  17005. }
  17006. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  17007. continue;
  17008. indexes[j] = idx;
  17009. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  17010. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  17011. return;
  17012. }
  17013. count += sd->inventory.u.items_inventory[idx].amount;
  17014. j++;
  17015. }
  17016. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  17017. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  17018. return;
  17019. }
  17020. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  17021. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  17022. return;
  17023. }
  17024. // Merrrrge!!!!
  17025. for (i = 1; i < n; i++) {
  17026. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  17027. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  17028. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  17029. sd->inventory_data[idx] = NULL;
  17030. clif_delitem(sd, idx, amt, 0);
  17031. }
  17032. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  17033. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  17034. }
  17035. /**
  17036. * Cancel item merge
  17037. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17038. * @param fd
  17039. * @param sd
  17040. **/
  17041. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  17042. return; // Nothing todo yet
  17043. }
  17044. /**
  17045. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17046. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17047. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17048. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17049. **/
  17050. void clif_broadcast_obtain_special_item( const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17051. char name[NAME_LENGTH];
  17052. if( battle_config.broadcast_hide_name ){
  17053. std::string dispname = std::string( char_name );
  17054. int hide = min( battle_config.broadcast_hide_name, dispname.length() - 1 );
  17055. dispname.replace( dispname.length() - hide, hide, hide, '*' );
  17056. safestrncpy( name, dispname.c_str(), sizeof( name ) );
  17057. }else{
  17058. safestrncpy( name, char_name, sizeof( name ) );
  17059. }
  17060. switch( type ){
  17061. case ITEMOBTAIN_TYPE_BOXITEM:
  17062. {
  17063. struct packet_package_item_announce p;
  17064. p.PacketType = package_item_announceType;
  17065. p.type = type;
  17066. p.ItemID = client_nameid( nameid );
  17067. p.len = NAME_LENGTH;
  17068. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17069. p.unknown = 0x2; // some strange byte, IDA shows.. BYTE3(BoxItemIDLength) = 2;
  17070. p.BoxItemID = client_nameid( container );
  17071. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17072. p.PacketLength = 15 + p.len;
  17073. #else
  17074. p.PacketLength = 11 + p.len;
  17075. #endif
  17076. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17077. }
  17078. break;
  17079. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17080. case ITEMOBTAIN_TYPE_NPC:
  17081. {
  17082. struct packet_item_drop_announce p;
  17083. p.PacketType = item_drop_announceType;
  17084. p.type = type;
  17085. p.ItemID = client_nameid( nameid );
  17086. p.len = NAME_LENGTH;
  17087. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17088. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17089. struct mob_db *db = mob_db( container );
  17090. p.monsterNameLen = NAME_LENGTH;
  17091. safestrncpy( p.monsterName, db->name, NAME_LENGTH );
  17092. }else{
  17093. p.monsterNameLen = 0;
  17094. p.monsterName[0] = '\0';
  17095. }
  17096. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17097. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17098. #else
  17099. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17100. #endif
  17101. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17102. }
  17103. break;
  17104. }
  17105. }
  17106. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17107. /// 0A02 <view>.W
  17108. /// Value <flag> has the following effects:
  17109. /// 1: Open a Dress Room window.
  17110. void clif_dressing_room(struct map_session_data *sd, int flag) {
  17111. #if PACKETVER >= 20150513
  17112. int fd = sd->fd;
  17113. nullpo_retv(sd);
  17114. WFIFOHEAD(fd, packet_len(0xa02));
  17115. WFIFOW(fd,0) = 0xa02;
  17116. WFIFOW(fd,2) = flag;
  17117. WFIFOSET(fd, packet_len(0xa02));
  17118. #endif
  17119. }
  17120. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17121. /// 0A35 <result>.W
  17122. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  17123. #if PACKETVER >= 20150513
  17124. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17125. // Ignore the request
  17126. // - Invalid item index
  17127. // - Invalid item ID or item doesn't exist
  17128. // - Item is already identified
  17129. if (idx < 0 || idx >= MAX_INVENTORY ||
  17130. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  17131. sd->inventory.u.items_inventory[idx].identify)
  17132. return;
  17133. // Ignore the request - No magnifiers in inventory
  17134. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17135. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17136. return;
  17137. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17138. return;
  17139. skill_identify(sd, idx);
  17140. #endif
  17141. }
  17142. /// Starts navigation to the given target on client side
  17143. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17144. #if PACKETVER >= 20111010
  17145. int fd = sd->fd;
  17146. WFIFOHEAD(fd,27);
  17147. WFIFOW(fd,0) = 0x08e2;
  17148. // How detailed will our navigation be?
  17149. if( mob_id > 0 ){
  17150. x = 0;
  17151. y = 0;
  17152. WFIFOB(fd,2) = 3; // monster with destination field
  17153. }else if( x > 0 && y > 0 ){
  17154. WFIFOB(fd,2) = 0; // with coordinates
  17155. }else{
  17156. x = 0;
  17157. y = 0;
  17158. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17159. }
  17160. // Which services can be used for transportation?
  17161. WFIFOB(fd,3) = flag;
  17162. // If this flag is set, the navigation window will not be opened up
  17163. WFIFOB(fd,4) = hideWindow;
  17164. // Target map
  17165. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17166. // Target x
  17167. WFIFOW(fd,21) = x;
  17168. // Target y
  17169. WFIFOW(fd,23) = y;
  17170. // Target monster ID
  17171. WFIFOW(fd,25) = mob_id;
  17172. WFIFOSET(fd,27);
  17173. #endif
  17174. }
  17175. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17176. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17177. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  17178. #if PACKETVER >= 20150513
  17179. unsigned char* buf;
  17180. int len,i;
  17181. struct map_session_data *tsd;
  17182. struct block_list* tbl;
  17183. if( target == SELF ){
  17184. tsd = BL_CAST(BL_PC,bl);
  17185. tbl = &sd->bl;
  17186. }else{
  17187. tsd = sd;
  17188. tbl = bl;
  17189. }
  17190. if( !tsd->hatEffectCount )
  17191. return;
  17192. len = 9 + tsd->hatEffectCount * 2;
  17193. buf = (unsigned char*)aMalloc( len );
  17194. WBUFW(buf,0) = 0xa3b;
  17195. WBUFW(buf,2) = len;
  17196. WBUFL(buf,4) = tsd->bl.id;
  17197. WBUFB(buf,8) = 1;
  17198. for( i = 0; i < tsd->hatEffectCount; i++ ){
  17199. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  17200. }
  17201. clif_send(buf, len,tbl,target);
  17202. aFree(buf);
  17203. #endif
  17204. }
  17205. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  17206. #if PACKETVER >= 20150513
  17207. unsigned char buf[13];
  17208. WBUFW(buf,0) = 0xa3b;
  17209. WBUFW(buf,2) = 13;
  17210. WBUFL(buf,4) = sd->bl.id;
  17211. WBUFB(buf,8) = enable;
  17212. WBUFL(buf,9) = effectId;
  17213. clif_send(buf,13,&sd->bl,AREA);
  17214. #endif
  17215. }
  17216. /// Notify the client that a sale has started
  17217. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17218. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17219. #if PACKETVER_SUPPORTS_SALES
  17220. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17221. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17222. p.itemId = client_nameid( sale_item->nameid );
  17223. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17224. clif_send( &p, sizeof( p ), bl, target );
  17225. #endif
  17226. }
  17227. /// Notify the clien that a sale has ended
  17228. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17229. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17230. #if PACKETVER_SUPPORTS_SALES
  17231. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17232. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17233. p.itemId = client_nameid( sale_item->nameid );
  17234. clif_send( &p, sizeof( p ), bl, target );
  17235. #endif
  17236. }
  17237. /// Update the remaining amount of a sale item.
  17238. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17239. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17240. #if PACKETVER_SUPPORTS_SALES
  17241. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17242. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17243. p.itemId = client_nameid( sale_item->nameid );
  17244. p.amount = sale_item->amount;
  17245. clif_send( &p, sizeof( p ), bl, target );
  17246. #endif
  17247. }
  17248. /// The client requested a refresh of the current remaining count of a sale item
  17249. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17250. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17251. #if PACKETVER_SUPPORTS_SALES
  17252. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17253. struct sale_item_data* sale;
  17254. if( p->AID != sd->status.account_id ){
  17255. return;
  17256. }
  17257. sale = sale_find_item( p->itemId, true );
  17258. if( sale == NULL ){
  17259. return;
  17260. }
  17261. clif_sale_amount(sale, &sd->bl, SELF);
  17262. #endif
  17263. }
  17264. /// Opens the sale administration window on the client
  17265. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17266. void clif_sale_open( struct map_session_data* sd ){
  17267. #if PACKETVER_SUPPORTS_SALES
  17268. nullpo_retv(sd);
  17269. if( sd->state.sale_open ){
  17270. return;
  17271. }
  17272. sd->state.sale_open = true;
  17273. int fd = sd->fd;
  17274. WFIFOHEAD(fd, 2);
  17275. WFIFOW(fd, 0) = 0x9b5;
  17276. WFIFOSET(fd, 2);
  17277. #endif
  17278. }
  17279. /// Client request to open the sale administration window.
  17280. /// This is sent by /limitedsale
  17281. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17282. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17283. #if PACKETVER_SUPPORTS_SALES
  17284. nullpo_retv(sd);
  17285. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17286. return;
  17287. }
  17288. char command[CHAT_SIZE_MAX];
  17289. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17290. is_atcommand(fd, sd, command, 1);
  17291. #endif
  17292. }
  17293. /// Closes the sale administration window on the client.
  17294. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17295. void clif_sale_close(struct map_session_data* sd) {
  17296. #if PACKETVER_SUPPORTS_SALES
  17297. nullpo_retv(sd);
  17298. if( !sd->state.sale_open ){
  17299. return;
  17300. }
  17301. sd->state.sale_open = false;
  17302. int fd = sd->fd;
  17303. WFIFOHEAD(fd, 2);
  17304. WFIFOW(fd, 0) = 0x9bd;
  17305. WFIFOSET(fd, 2);
  17306. #endif
  17307. }
  17308. /// Client request to close the sale administration window.
  17309. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17310. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17311. #if PACKETVER_SUPPORTS_SALES
  17312. nullpo_retv(sd);
  17313. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17314. return;
  17315. }
  17316. clif_sale_close(sd);
  17317. #endif
  17318. }
  17319. /// Reply to a item search request for item sale administration.
  17320. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17321. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17322. #if PACKETVER_SUPPORTS_SALES
  17323. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17324. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17325. if( item != NULL ){
  17326. p.result = 0;
  17327. p.itemId = client_nameid( item->nameid );
  17328. p.price = item->price;
  17329. }else{
  17330. p.result = 1;
  17331. p.itemId = 0;
  17332. p.price = 0;
  17333. }
  17334. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17335. #endif
  17336. }
  17337. /// Search request for an item sale administration.
  17338. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17339. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17340. #if PACKETVER_SUPPORTS_SALES
  17341. char item_name[ITEM_NAME_LENGTH];
  17342. struct item_data *id = NULL;
  17343. nullpo_retv(sd);
  17344. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17345. return;
  17346. }
  17347. if( !sd->state.sale_open ){
  17348. return;
  17349. }
  17350. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17351. id = itemdb_searchname(item_name);
  17352. if( id ){
  17353. int i;
  17354. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17355. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17356. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17357. return;
  17358. }
  17359. }
  17360. }
  17361. // not found
  17362. clif_sale_search_reply( sd, NULL );
  17363. #endif
  17364. }
  17365. /// Reply if an item was successfully put on sale or not.
  17366. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17367. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17368. #if PACKETVER_SUPPORTS_SALES
  17369. int fd = sd->fd;
  17370. WFIFOHEAD(fd, 4);
  17371. WFIFOW(fd, 0) = 0x9af;
  17372. WFIFOW(fd, 2) = (uint16)result;
  17373. WFIFOSET(fd, 4);
  17374. #endif
  17375. }
  17376. /// A client request to put an item on sale.
  17377. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17378. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17379. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17380. #if PACKETVER_SUPPORTS_SALES
  17381. nullpo_retv( sd );
  17382. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17383. if( p->AID != sd->status.account_id ){
  17384. return;
  17385. }
  17386. if( !sd->state.sale_open ){
  17387. return;
  17388. }
  17389. time_t endTime = p->startTime + p->hours * 60 * 60;
  17390. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17391. #endif
  17392. }
  17393. /// Reply to an item removal from sale.
  17394. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17395. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17396. #if PACKETVER_SUPPORTS_SALES
  17397. int fd = sd->fd;
  17398. WFIFOHEAD(fd, 4);
  17399. WFIFOW(fd, 0) = 0x9b1;
  17400. WFIFOW(fd, 2) = failed;
  17401. WFIFOSET(fd, 4);
  17402. #endif
  17403. }
  17404. /// Request to remove an item from sale.
  17405. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17406. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17407. #if PACKETVER_SUPPORTS_SALES
  17408. nullpo_retv( sd );
  17409. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17410. if( p->AID != sd->status.account_id ){
  17411. return;
  17412. }
  17413. if( !sd->state.sale_open ){
  17414. return;
  17415. }
  17416. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17417. #endif
  17418. }
  17419. /// Achievement System
  17420. /// Author: Luxuri, Aleos
  17421. /**
  17422. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17423. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17424. */
  17425. void clif_achievement_list_all(struct map_session_data *sd)
  17426. {
  17427. nullpo_retv(sd);
  17428. if (!battle_config.feature_achievement) {
  17429. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17430. return;
  17431. }
  17432. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17433. if (count == 0)
  17434. return;
  17435. int len = (50 * count) + 22;
  17436. int fd = sd->fd;
  17437. int *info = achievement_level(sd, true);
  17438. WFIFOHEAD(fd,len);
  17439. WFIFOW(fd, 0) = 0xa23;
  17440. WFIFOW(fd, 2) = len;
  17441. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17442. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17443. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17444. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17445. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17446. for (int i = 0; i < count; i++) {
  17447. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17448. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17449. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17450. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17451. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17452. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17453. }
  17454. WFIFOSET(fd, len);
  17455. }
  17456. /**
  17457. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17458. * 0a24 <packetType>.W <ACHPoint>.L
  17459. */
  17460. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17461. {
  17462. nullpo_retv(sd);
  17463. if (!battle_config.feature_achievement) {
  17464. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17465. return;
  17466. }
  17467. int fd = sd->fd;
  17468. int *info = achievement_level(sd, true);
  17469. WFIFOHEAD(fd, packet_len(0xa24));
  17470. WFIFOW(fd, 0) = 0xa24;
  17471. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17472. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17473. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17474. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17475. if (ach) {
  17476. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17477. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17478. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17479. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17480. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17481. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17482. } else
  17483. memset(WFIFOP(fd, 16), 0, 40);
  17484. WFIFOSET(fd, packet_len(0xa24));
  17485. }
  17486. /**
  17487. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17488. * 0a25 <packetType>.W <achievementID>.L
  17489. */
  17490. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17491. {
  17492. nullpo_retv(sd);
  17493. if( sd->achievement_data.save )
  17494. intif_achievement_save(sd);
  17495. achievement_check_reward(sd, RFIFOL(fd,2));
  17496. }
  17497. /**
  17498. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17499. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17500. */
  17501. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17502. {
  17503. WFIFOHEAD(fd, packet_len(0xa26));
  17504. WFIFOW(fd, 0) = 0xa26;
  17505. WFIFOB(fd, 2) = result;
  17506. WFIFOL(fd, 3) = achievement_id;
  17507. WFIFOSET(fd, packet_len(0xa26));
  17508. }
  17509. /// Process the pet evolution request
  17510. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17511. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17512. #if PACKETVER >= 20141008
  17513. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17514. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17515. if (!pet) {
  17516. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17517. return;
  17518. }
  17519. pet_evolution(sd, pet->class_);
  17520. #endif
  17521. }
  17522. /// Sends the result of the evolution to the client.
  17523. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17524. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17525. #if PACKETVER >= 20141008
  17526. int fd = sd->fd;
  17527. WFIFOHEAD(fd, packet_len(0x9fc));
  17528. WFIFOW(fd, 0) = 0x9fc;
  17529. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17530. WFIFOSET(fd, packet_len(0x9fc));
  17531. #endif
  17532. }
  17533. /*
  17534. * This packet is sent by /changedress or /nocosplay
  17535. *
  17536. * 0ae8
  17537. */
  17538. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17539. #if PACKETVER >= 20180103
  17540. char command[CHAT_SIZE_MAX];
  17541. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17542. is_atcommand( fd, sd, command, 1 );
  17543. #endif
  17544. }
  17545. /// Opens an UI window of the given type and initializes it with the given data
  17546. /// 0AE2 <type>.B <data>.L
  17547. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17548. nullpo_retv(sd);
  17549. int fd = sd->fd;
  17550. WFIFOHEAD(fd,packet_len(0xae2));
  17551. WFIFOW(fd,0) = 0xae2;
  17552. WFIFOB(fd,2) = ui_type;
  17553. WFIFOL(fd,3) = data;
  17554. WFIFOSET(fd,packet_len(0xae2));
  17555. }
  17556. /// Request to open an UI window of the given type
  17557. /// 0A68 <type>.B
  17558. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17559. switch( RFIFOB(fd,2) ){
  17560. case IN_UI_ATTENDANCE:
  17561. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17562. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17563. }else if( pc_attendance_enabled() ){
  17564. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17565. }else{
  17566. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17567. }
  17568. break;
  17569. }
  17570. }
  17571. /// Response for attedance request
  17572. /// 0AF0 <unknown>.L <data>.L
  17573. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17574. nullpo_retv(sd);
  17575. int fd = sd->fd;
  17576. WFIFOHEAD(fd,packet_len(0xAF0));
  17577. WFIFOW(fd,0) = 0xAF0;
  17578. WFIFOL(fd,2) = 0;
  17579. WFIFOL(fd,6) = data;
  17580. WFIFOSET(fd,packet_len(0xAF0));
  17581. }
  17582. /// Request from the client to retrieve today's attendance reward
  17583. /// 0AEF
  17584. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17585. pc_attendance_claim_reward(sd);
  17586. }
  17587. /// Send out the percentage of weight that causes it to be displayed in red.
  17588. /// 0ADE <percentage>.L
  17589. void clif_weight_limit( struct map_session_data* sd ){
  17590. #if PACKETVER >= 20171025
  17591. nullpo_retv(sd);
  17592. int fd = sd->fd;
  17593. WFIFOHEAD(fd, packet_len(0xADE));
  17594. WFIFOW(fd, 0) = 0xADE;
  17595. #ifdef RENEWAL
  17596. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17597. #else
  17598. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17599. #endif
  17600. WFIFOSET(fd, packet_len(0xADE));
  17601. #endif
  17602. }
  17603. enum e_private_airship_response : uint32{
  17604. PRIVATEAIRSHIP_OK,
  17605. PRIVATEAIRSHIP_RETRY,
  17606. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17607. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17608. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17609. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17610. };
  17611. /// Send out the response to a private airship request
  17612. /// 0A4A <response>.L
  17613. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17614. #if PACKETVER >= 20180321
  17615. nullpo_retv( sd );
  17616. int fd = sd->fd;
  17617. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17618. WFIFOW( fd, 0 ) = 0xA4A;
  17619. WFIFOL( fd, 2 ) = response;
  17620. WFIFOSET( fd, packet_len( 0xA4A ) );
  17621. #endif
  17622. }
  17623. /// Parses a request for a private airship
  17624. /// 0A49 <mapname>.16B <itemid>.W
  17625. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17626. #if PACKETVER >= 20180321
  17627. // Check if the feature is enabled
  17628. if( !battle_config.feature_privateairship ){
  17629. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17630. return;
  17631. }
  17632. // Check if the player is allowed to warp from the source map
  17633. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17634. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17635. return;
  17636. }
  17637. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17638. char mapname[MAP_NAME_LENGTH_EXT];
  17639. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17640. int16 mapindex = mapindex_name2id( mapname );
  17641. // Check if we know the mapname
  17642. if( mapindex < 0 ){
  17643. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17644. return;
  17645. }
  17646. int16 mapid = map_mapindex2mapid( mapindex );
  17647. // Check if the map is available on this server
  17648. if( mapid < 0 ){
  17649. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17650. return;
  17651. }
  17652. // Check if the player tried to warp to the map he is on
  17653. if( sd->bl.m == mapid ){
  17654. // This is blocked by the client, but just to be sure
  17655. return;
  17656. }
  17657. // This can only be a hack, so we prevent it
  17658. if( map_getmapdata( mapid )->instance_id ){
  17659. // Ignore requests to warp directly into a running instance
  17660. return;
  17661. }
  17662. // Check if the player is allowed to warp to the target map
  17663. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17664. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17665. return;
  17666. }
  17667. uint16 item_id = p->ItemID;
  17668. // Check if the item sent by the client is known to us
  17669. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17670. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17671. return;
  17672. }
  17673. int idx = pc_search_inventory( sd, item_id );
  17674. // Check if the player has the item at all
  17675. if( idx < 0 ){
  17676. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17677. return;
  17678. }
  17679. // Delete the chosen item
  17680. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17681. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17682. return;
  17683. }
  17684. // Warp the player to a random spot on the destination map
  17685. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17686. #endif
  17687. }
  17688. /// Sends out the usage history of the guild storage
  17689. /// 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
  17690. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17691. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17692. #if PACKETVER >= 20140205
  17693. nullpo_retv( sd );
  17694. int fd = sd->fd;
  17695. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17696. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17697. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17698. }else{
  17699. log.clear();
  17700. }
  17701. WFIFOHEAD( fd, size );
  17702. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17703. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17704. p->PacketLength = size;
  17705. p->result = result;
  17706. p->amount = (uint16)log.size();
  17707. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17708. for( int i = 0; i < log.size(); i++ ){
  17709. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  17710. struct guild_log_entry& entry = log[i];
  17711. item->id = entry.id;
  17712. item->itemId = client_nameid( entry.item.nameid );
  17713. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17714. item->action = entry.amount > 0; // action = true(put), false(get)
  17715. item->refine = entry.item.refine;
  17716. item->uniqueId = entry.item.unique_id;
  17717. item->IsIdentified = entry.item.identify;
  17718. item->itemType = itemtype( entry.item.nameid );
  17719. clif_addcards( &item->slot, &entry.item );
  17720. safestrncpy( item->name, entry.name, NAME_LENGTH );
  17721. safestrncpy( item->time, entry.time, NAME_LENGTH );
  17722. item->attribute = entry.item.attribute;
  17723. }
  17724. }
  17725. WFIFOSET( fd, p->PacketLength );
  17726. #endif
  17727. }
  17728. /// Activates the client camera info or updates the client camera with the given values.
  17729. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17730. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17731. #if PACKETVER >= 20160525
  17732. int fd = sd->fd;
  17733. WFIFOHEAD(fd, packet_len(0xa78));
  17734. WFIFOW(fd, 0) = 0xa78;
  17735. WFIFOB(fd, 2) = show;
  17736. WFIFOF(fd, 3) = range;
  17737. WFIFOF(fd, 7) = rotation;
  17738. WFIFOF(fd, 11) = latitude;
  17739. WFIFOSET(fd, packet_len(0xa78));
  17740. #endif
  17741. }
  17742. /// Activates or deactives the client camera info or updates the camera settings.
  17743. /// This packet is triggered by /viewpointvalue or /setcamera
  17744. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17745. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17746. char command[CHAT_SIZE_MAX];
  17747. // /viewpointvalue
  17748. if( RFIFOB( fd, 2 ) == 1 ){
  17749. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17750. // /setcamera
  17751. }else{
  17752. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17753. }
  17754. is_atcommand( fd, sd, command, 1 );
  17755. }
  17756. /// Send the full list of items in the equip switch window
  17757. /// 0a9b <length>.W { <index>.W <position>.L }*
  17758. void clif_equipswitch_list( struct map_session_data* sd ){
  17759. #if PACKETVER >= 20170208
  17760. int fd = sd->fd;
  17761. int offset, i, position;
  17762. WFIFOW(fd, 0) = 0xa9b;
  17763. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17764. short index = sd->equip_switch_index[i];
  17765. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17766. WFIFOW(fd, offset) = index + 2;
  17767. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17768. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17769. offset += 6;
  17770. }
  17771. }
  17772. WFIFOW(fd, 2) = offset;
  17773. WFIFOSET(fd, offset);
  17774. #endif
  17775. }
  17776. /// Acknowledgement for removing an equip to the equip switch window
  17777. /// 0a9a <index>.W <position.>.L <failure>.W
  17778. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17779. #if PACKETVER >= 20170208
  17780. int fd = sd->fd;
  17781. WFIFOHEAD(fd, packet_len(0xa9a));
  17782. WFIFOW(fd, 0) = 0xa9a;
  17783. WFIFOW(fd, 2) = index + 2;
  17784. WFIFOL(fd, 4) = pos;
  17785. WFIFOW(fd, 8) = failed;
  17786. WFIFOSET(fd, packet_len(0xa9a));
  17787. #endif
  17788. }
  17789. /// Request to remove an equip from the equip switch window
  17790. /// 0a99 <index>.W <position>.L <= 20170502
  17791. /// 0a99 <index>.W
  17792. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17793. #if PACKETVER >= 20170208
  17794. uint16 index = RFIFOW(fd, 2) - 2;
  17795. bool removed = false;
  17796. if( !battle_config.feature_equipswitch ){
  17797. return;
  17798. }
  17799. // Check if the index is valid
  17800. if( index >= MAX_INVENTORY ){
  17801. return;
  17802. }
  17803. pc_equipswitch_remove( sd, index );
  17804. #endif
  17805. }
  17806. /// Acknowledgement for adding an equip to the equip switch window
  17807. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17808. /// 0a98 <index>.W <position.>.L <flag>.W
  17809. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17810. #if PACKETVER >= 20170208
  17811. int fd = sd->fd;
  17812. WFIFOHEAD(fd, packet_len(0xa98));
  17813. WFIFOW(fd, 0) = 0xa98;
  17814. WFIFOW(fd, 2) = index + 2;
  17815. WFIFOL(fd, 4) = pos;
  17816. #if PACKETVER <= 20170502
  17817. WFIFOL(fd, 8) = flag;
  17818. #else
  17819. WFIFOW(fd, 8) = flag;
  17820. #endif
  17821. WFIFOSET(fd,packet_len(0xa98));
  17822. #endif
  17823. }
  17824. /// Request to add an equip to the equip switch window
  17825. /// 0a97 <index>.W <position>.L
  17826. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17827. #if PACKETVER >= 20170208
  17828. uint16 index = RFIFOW(fd, 2) - 2;
  17829. uint32 position = RFIFOL(fd, 4);
  17830. if( !battle_config.feature_equipswitch ){
  17831. return;
  17832. }
  17833. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17834. return;
  17835. }
  17836. if( sd->state.trading || sd->npc_shopid ){
  17837. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17838. return;
  17839. }
  17840. if( sd->inventory_data[index]->type == IT_AMMO ){
  17841. position = EQP_AMMO;
  17842. }
  17843. pc_equipitem( sd, index, position, true );
  17844. #endif
  17845. }
  17846. /// Acknowledgement packet for the full equip switch
  17847. /// 0a9d <failed>.W
  17848. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17849. #if PACKETVER >= 20170208
  17850. int fd = sd->fd;
  17851. WFIFOHEAD(fd, packet_len(0xa9d));
  17852. WFIFOW(fd, 0) = 0xa9d;
  17853. WFIFOW(fd, 2) = failed;
  17854. WFIFOSET(fd, packet_len(0xa9d));
  17855. #endif
  17856. }
  17857. /// Request to do a full equip switch
  17858. /// 0a9c
  17859. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17860. #if PACKETVER >= 20170208
  17861. int i;
  17862. t_tick tick = gettick();
  17863. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17864. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17865. // Client will not let you send a request
  17866. return;
  17867. }
  17868. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17869. if( !battle_config.feature_equipswitch ){
  17870. return;
  17871. }
  17872. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17873. if( i == EQI_MAX ){
  17874. // client will show: "There is no item to replace." and should not even come here
  17875. clif_equipswitch_reply( sd, false );
  17876. return;
  17877. }
  17878. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17879. return;
  17880. }
  17881. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17882. #endif
  17883. }
  17884. /// Request to do a single equip switch
  17885. /// 0ace <index>.W
  17886. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17887. #if PACKETVER >= 20170502
  17888. uint16 index = RFIFOW(fd, 2) - 2;
  17889. if( !battle_config.feature_equipswitch ){
  17890. return;
  17891. }
  17892. // Check if the index is valid
  17893. if( index >= MAX_INVENTORY ){
  17894. return;
  17895. }
  17896. // Check if the item exists
  17897. if (sd->inventory_data[index] == nullptr)
  17898. return;
  17899. // Check if the item was already added to equip switch
  17900. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17901. if( sd->npc_id ){
  17902. #ifdef RENEWAL
  17903. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17904. clif_msg( sd, WORK_IN_PROGRESS );
  17905. return;
  17906. }
  17907. #endif
  17908. if( !sd->npc_item_flag ){
  17909. return;
  17910. }
  17911. }
  17912. pc_equipswitch( sd, index );
  17913. return;
  17914. }
  17915. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  17916. #endif
  17917. }
  17918. void clif_parse_StartUseSkillToId( int fd, struct map_session_data* sd ){
  17919. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  17920. const struct PACKET_CZ_START_USE_SKILL *p = (struct PACKET_CZ_START_USE_SKILL *)RFIFOP( fd, 0 );
  17921. // Only rolling cutter is supported for now
  17922. if( p->skillId != GC_ROLLINGCUTTER ){
  17923. return;
  17924. }
  17925. // Already running - cant happen on officials, since only one skill is supported
  17926. if( sd->skill_keep_using.skill_id != 0 ){
  17927. return;
  17928. }
  17929. sd->skill_keep_using.tid = INVALID_TIMER;
  17930. sd->skill_keep_using.skill_id = p->skillId;
  17931. sd->skill_keep_using.level = p->skillLv;
  17932. sd->skill_keep_using.target = p->targetId;
  17933. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  17934. #endif
  17935. }
  17936. void clif_parse_StopUseSkillToId( int fd, struct map_session_data* sd ){
  17937. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  17938. const struct PACKET_CZ_STOP_USE_SKILL *p = (struct PACKET_CZ_STOP_USE_SKILL *)RFIFOP( fd, 0 );
  17939. // Not running
  17940. if( sd->skill_keep_using.skill_id == 0 ){
  17941. return;
  17942. }
  17943. #if 0
  17944. // Hack
  17945. if( p->skillId != sd->skill_keep_using.skill_id ){
  17946. return;
  17947. }
  17948. #endif
  17949. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  17950. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  17951. sd->skill_keep_using.tid = INVALID_TIMER;
  17952. }
  17953. sd->skill_keep_using.skill_id = 0;
  17954. sd->skill_keep_using.level = 0;
  17955. sd->skill_keep_using.target = 0;
  17956. #endif
  17957. }
  17958. void clif_ping( struct map_session_data* sd ){
  17959. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  17960. nullpo_retv( sd );
  17961. int fd = sd->fd;
  17962. if( !session_isActive( fd ) ){
  17963. return;
  17964. }
  17965. struct PACKET_ZC_PING p;
  17966. p.packetType = HEADER_ZC_PING;
  17967. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17968. #endif
  17969. }
  17970. int clif_ping_timer_sub( struct map_session_data *sd, va_list ap ){
  17971. nullpo_ret( sd );
  17972. int fd = sd->fd;
  17973. if( !session_isActive( fd ) ){
  17974. return 0;
  17975. }
  17976. t_tick tick = va_arg( ap, t_tick );
  17977. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  17978. clif_ping( sd );
  17979. }
  17980. return 0;
  17981. }
  17982. TIMER_FUNC( clif_ping_timer ){
  17983. map_foreachpc( clif_ping_timer_sub, gettick() );
  17984. return 0;
  17985. }
  17986. /*==========================================
  17987. * Main client packet processing function
  17988. *------------------------------------------*/
  17989. static int clif_parse(int fd)
  17990. {
  17991. int cmd, packet_len;
  17992. TBL_PC* sd;
  17993. int pnum;
  17994. #ifdef PACKET_OBFUSCATION
  17995. int cmd2;
  17996. #endif
  17997. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17998. // Note: "click masters" can do 80+ clicks in 10 seconds
  17999. 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]
  18000. { // begin main client packet processing loop
  18001. sd = (TBL_PC *)session[fd]->session_data;
  18002. if (session[fd]->flag.eof) {
  18003. if (sd) {
  18004. if (sd->state.autotrade) {
  18005. //Disassociate character from the socket connection.
  18006. session[fd]->session_data = NULL;
  18007. sd->fd = 0;
  18008. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  18009. } else
  18010. if (sd->state.active) {
  18011. // Player logout display [Valaris]
  18012. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  18013. clif_quitsave(fd, sd);
  18014. } else {
  18015. //Unusual logout (during log on/off/map-changer procedure)
  18016. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  18017. map_quit(sd);
  18018. }
  18019. } else {
  18020. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  18021. }
  18022. do_close(fd);
  18023. return 0;
  18024. }
  18025. if (RFIFOREST(fd) < 2)
  18026. return 0;
  18027. cmd = RFIFOW(fd, 0);
  18028. #ifdef PACKET_OBFUSCATION
  18029. // Check if it is a player that tries to connect to the map server.
  18030. if( sd ){
  18031. // Decrypt the current packet ID with the last key stored in the session.
  18032. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  18033. }else{
  18034. // Store the original value for checking
  18035. cmd2 = cmd;
  18036. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  18037. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  18038. }
  18039. #endif
  18040. // filter out invalid / unsupported packets
  18041. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  18042. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  18043. #ifdef DUMP_INVALID_PACKET
  18044. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  18045. #endif
  18046. #ifdef PACKET_OBFUSCATION_WARN
  18047. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  18048. if( !sd ){
  18049. #ifdef PACKET_OBFUSCATION
  18050. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  18051. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  18052. }
  18053. #else
  18054. // Try to use the initial keys for the decryption of the packet ID.
  18055. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  18056. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  18057. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  18058. }
  18059. #endif
  18060. }
  18061. #endif
  18062. set_eof(fd);
  18063. return 0;
  18064. }
  18065. // determine real packet length
  18066. packet_len = packet_db[cmd].len;
  18067. if (packet_len == -1) { // variable-length packet
  18068. if (RFIFOREST(fd) < 4)
  18069. return 0;
  18070. packet_len = RFIFOW(fd,2);
  18071. if (packet_len < 4 || packet_len > 32768) {
  18072. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  18073. #ifdef DUMP_INVALID_PACKET
  18074. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  18075. #endif
  18076. set_eof(fd);
  18077. return 0;
  18078. }
  18079. }
  18080. if ((int)RFIFOREST(fd) < packet_len){
  18081. 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 );
  18082. #ifdef DUMP_INVALID_PACKET
  18083. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  18084. #endif
  18085. set_eof( fd );
  18086. return 0; // not enough data received to form the packet
  18087. }
  18088. #ifdef PACKET_OBFUSCATION
  18089. RFIFOW(fd, 0) = cmd;
  18090. if (sd)
  18091. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  18092. #endif
  18093. if( packet_db[cmd].func == clif_parse_debug )
  18094. packet_db[cmd].func(fd, sd);
  18095. else if( packet_db[cmd].func != NULL ) {
  18096. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  18097. ; //Only valid packet when there is no session
  18098. else
  18099. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  18100. ; //Only valid packet when player is not on a map
  18101. else
  18102. packet_db[cmd].func(fd, sd);
  18103. }
  18104. #ifdef DUMP_UNKNOWN_PACKET
  18105. else DumpUnknown(fd,sd,cmd,packet_len);
  18106. #endif
  18107. RFIFOSKIP(fd, packet_len);
  18108. }; // main loop end
  18109. return 0;
  18110. }
  18111. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  18112. va_list argp;
  18113. int i;
  18114. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  18115. return;
  18116. packet_db[cmd].len = length;
  18117. packet_db[cmd].func = func;
  18118. va_start(argp, func);
  18119. for( i = 0; i < MAX_PACKET_POS; i++ ){
  18120. int offset = va_arg(argp, int);
  18121. if( offset == 0 ){
  18122. break;
  18123. }
  18124. packet_db[cmd].pos[i] = offset;
  18125. }
  18126. if( i == MAX_PACKET_POS ){
  18127. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  18128. }
  18129. va_end(argp);
  18130. }
  18131. /*==========================================
  18132. * Reads packets and setups its array reference
  18133. *------------------------------------------*/
  18134. void packetdb_readdb(){
  18135. memset(packet_db,0,sizeof(packet_db));
  18136. memset(packet_db_ack,0,sizeof(packet_db_ack));
  18137. #include "clif_packetdb.hpp"
  18138. #include "clif_shuffle.hpp"
  18139. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  18140. #ifdef PACKET_OBFUSCATION
  18141. 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]);
  18142. #else
  18143. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  18144. #endif
  18145. }
  18146. /*==========================================
  18147. *
  18148. *------------------------------------------*/
  18149. void do_init_clif(void) {
  18150. const char* colors[COLOR_MAX] = {
  18151. "0x00FF00",
  18152. "0xFF0000",
  18153. "0xFFFFFF",
  18154. "0xFFFF00",
  18155. "0x00FFFF",
  18156. "0xB5FFB5",
  18157. };
  18158. int i;
  18159. /**
  18160. * Setup Color Table (saves unnecessary load of strtoul on every call)
  18161. **/
  18162. for(i = 0; i < COLOR_MAX; i++) {
  18163. color_table[i] = strtoul(colors[i],NULL,0);
  18164. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  18165. }
  18166. packetdb_readdb();
  18167. set_defaultparse(clif_parse);
  18168. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  18169. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  18170. exit(EXIT_FAILURE);
  18171. }
  18172. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  18173. add_timer_func_list(clif_delayquit, "clif_delayquit");
  18174. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  18175. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  18176. if( battle_config.ping_timer_interval > 0 ){
  18177. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  18178. }
  18179. #endif
  18180. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  18181. }
  18182. void do_final_clif(void) {
  18183. ers_destroy(delay_clearunit_ers);
  18184. }