clif.cpp 595 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "clif.hpp"
  4. #include <cstdarg>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <ctime>
  9. #include "../common/cbasetypes.hpp"
  10. #include "../common/conf.hpp"
  11. #include "../common/ers.hpp"
  12. #include "../common/grfio.hpp"
  13. #include "../common/malloc.hpp"
  14. #include "../common/nullpo.hpp"
  15. #include "../common/random.hpp"
  16. #include "../common/showmsg.hpp"
  17. #include "../common/socket.hpp"
  18. #include "../common/strlib.hpp"
  19. #include "../common/timer.hpp"
  20. #include "../common/utils.hpp"
  21. #include "achievement.hpp"
  22. #include "atcommand.hpp"
  23. #include "battle.hpp"
  24. #include "battleground.hpp"
  25. #include "cashshop.hpp"
  26. #include "channel.hpp"
  27. #include "chat.hpp"
  28. #include "chrif.hpp"
  29. #include "clan.hpp"
  30. #include "clif.hpp"
  31. #include "elemental.hpp"
  32. #include "guild.hpp"
  33. #include "homunculus.hpp"
  34. #include "instance.hpp"
  35. #include "intif.hpp"
  36. #include "itemdb.hpp"
  37. #include "log.hpp"
  38. #include "mail.hpp"
  39. #include "map.hpp"
  40. #include "mercenary.hpp"
  41. #include "mob.hpp"
  42. #include "npc.hpp"
  43. #include "party.hpp"
  44. #include "pc.hpp"
  45. #include "pc_groups.hpp"
  46. #include "pet.hpp"
  47. #include "quest.hpp"
  48. #include "script.hpp"
  49. #include "skill.hpp"
  50. #include "status.hpp"
  51. #include "storage.hpp"
  52. #include "trade.hpp"
  53. #include "unit.hpp"
  54. #include "vending.hpp"
  55. static inline uint32 client_tick( t_tick tick ){
  56. return (uint32)tick;
  57. }
  58. /* for clif_clearunit_delayed */
  59. static struct eri *delay_clearunit_ers;
  60. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  61. int packet_db_ack[MAX_ACK_FUNC + 1];
  62. unsigned long color_table[COLOR_MAX];
  63. #include "clif_obfuscation.hpp"
  64. static bool clif_session_isValid(struct map_session_data *sd);
  65. #if PACKETVER >= 20150513
  66. enum mail_type {
  67. MAIL_TYPE_TEXT = 0x0,
  68. MAIL_TYPE_ZENY = 0x2,
  69. MAIL_TYPE_ITEM = 0x4,
  70. MAIL_TYPE_NPC = 0x8
  71. };
  72. #endif
  73. /** Converts item type to display it on client if necessary.
  74. * @param nameid: Item ID
  75. * @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
  76. */
  77. static inline int itemtype(unsigned short nameid) {
  78. 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
  79. int type = id->type;
  80. if( type == IT_SHADOWGEAR ) {
  81. if( id->equip&EQP_SHADOW_WEAPON )
  82. return IT_WEAPON;
  83. else
  84. return IT_ARMOR;
  85. }
  86. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  87. }
  88. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  89. p += pos;
  90. p[0] = (uint8)(x>>2);
  91. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  92. p[2] = (uint8)((y<<4) | (dir&0xf));
  93. }
  94. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  95. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  96. p += pos;
  97. p[0] = (uint8)(x0>>2);
  98. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  99. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  100. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  101. p[4] = (uint8)y1;
  102. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  103. }
  104. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  105. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  106. }
  107. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  108. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  109. }
  110. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  111. p += pos;
  112. if( x ) {
  113. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  114. }
  115. if( y ) {
  116. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  117. }
  118. if( dir ) {
  119. dir[0] = ( p[2] & 0x0f );
  120. }
  121. }
  122. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  123. p += pos;
  124. if( x0 ) {
  125. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  126. }
  127. if( y0 ) {
  128. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  129. }
  130. if( x1 ) {
  131. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  132. }
  133. if( y1 ) {
  134. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  135. }
  136. if( sx0 ) {
  137. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  138. }
  139. if( sy0 ) {
  140. sy0[0] = ( p[5] & 0x0f ) >> 0;
  141. }
  142. }
  143. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  144. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  145. }
  146. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  147. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  148. }
  149. //To idenfity disguised characters.
  150. static inline bool disguised(struct block_list* bl) {
  151. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  152. }
  153. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  154. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  155. if( len > max )
  156. len = max;
  157. mes[len-1] = '\0';
  158. return len;
  159. }
  160. static char map_ip_str[128];
  161. static uint32 map_ip;
  162. static uint32 bind_ip = INADDR_ANY;
  163. static uint16 map_port = 5121;
  164. static bool clif_ally_only = false;
  165. int map_fd;
  166. static int clif_parse (int fd);
  167. /*==========================================
  168. * Ip setting of map-server
  169. *------------------------------------------*/
  170. int clif_setip(const char* ip) {
  171. char ip_str[16];
  172. map_ip = host2ip(ip);
  173. if (!map_ip) {
  174. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  175. return 0;
  176. }
  177. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  178. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  179. return 1;
  180. }
  181. void clif_setbindip(const char* ip)
  182. {
  183. bind_ip = host2ip(ip);
  184. if (bind_ip) {
  185. char ip_str[16];
  186. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  187. } else {
  188. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  189. }
  190. }
  191. /*==========================================
  192. * Sets map port to 'port'
  193. * is run from map.cpp upon loading map server configuration
  194. *------------------------------------------*/
  195. void clif_setport(uint16 port)
  196. {
  197. map_port = port;
  198. }
  199. /*==========================================
  200. * Returns map server IP
  201. *------------------------------------------*/
  202. uint32 clif_getip(void)
  203. {
  204. return map_ip;
  205. }
  206. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  207. uint32 clif_refresh_ip(void)
  208. {
  209. uint32 new_ip;
  210. new_ip = host2ip(map_ip_str);
  211. if (new_ip && new_ip != map_ip) {
  212. map_ip = new_ip;
  213. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  214. return map_ip;
  215. }
  216. return 0;
  217. }
  218. /*==========================================
  219. * Returns map port which is set by clif_setport()
  220. *------------------------------------------*/
  221. uint16 clif_getport(void)
  222. {
  223. return map_port;
  224. }
  225. #if PACKETVER >= 20071106
  226. static inline unsigned char clif_bl_type(struct block_list *bl) {
  227. switch (bl->type) {
  228. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  229. case BL_ITEM: return 0x2; //ITEM_TYPE
  230. case BL_SKILL: return 0x3; //SKILL_TYPE
  231. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  232. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  233. case BL_NPC: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  234. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  235. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  236. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  237. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  238. default: return 0x1; //NPC_TYPE
  239. }
  240. }
  241. #endif
  242. static bool clif_session_isValid(struct map_session_data *sd) {
  243. return ( sd != NULL && session_isActive(sd->fd) );
  244. }
  245. /*==========================================
  246. * sub process of clif_send
  247. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  248. * In order to send area-wise packets, such as:
  249. * - AREA : everyone nearby your area
  250. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  251. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  252. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  253. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  254. *------------------------------------------*/
  255. static int clif_send_sub(struct block_list *bl, va_list ap)
  256. {
  257. struct block_list *src_bl;
  258. struct map_session_data *sd;
  259. unsigned char *buf;
  260. int len, type, fd;
  261. nullpo_ret(bl);
  262. nullpo_ret(sd = (struct map_session_data *)bl);
  263. fd = sd->fd;
  264. if (!fd) //Don't send to disconnected clients.
  265. return 0;
  266. buf = va_arg(ap,unsigned char*);
  267. len = va_arg(ap,int);
  268. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  269. type = va_arg(ap,int);
  270. switch(type) {
  271. case AREA_WOS:
  272. if (bl == src_bl)
  273. return 0;
  274. break;
  275. case AREA_WOC:
  276. if (sd->chatID || bl == src_bl)
  277. return 0;
  278. break;
  279. case AREA_WOSC:
  280. {
  281. if(src_bl->type == BL_PC) {
  282. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  283. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  284. return 0;
  285. }
  286. else if(src_bl->type == BL_NPC) {
  287. struct npc_data *nd = (struct npc_data *)src_bl;
  288. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  289. return 0;
  290. }
  291. }
  292. break;
  293. }
  294. if (session[fd] == NULL)
  295. return 0;
  296. /* unless visible, hold it here */
  297. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  298. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  299. return 0;
  300. WFIFOHEAD(fd, len);
  301. if (WFIFOP(fd,0) == buf) {
  302. ShowError("WARNING: Invalid use of clif_send function\n");
  303. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  304. ShowError(" Please correct your code.\n");
  305. // don't send to not move the pointer of the packet for next sessions in the loop
  306. //WFIFOSET(fd,0);//## TODO is this ok?
  307. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  308. return 0;
  309. }
  310. memcpy(WFIFOP(fd,0), buf, len);
  311. WFIFOSET(fd,len);
  312. return 0;
  313. }
  314. /*==========================================
  315. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  316. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  317. *------------------------------------------*/
  318. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  319. {
  320. int i;
  321. struct map_session_data *sd, *tsd;
  322. struct party_data *p = NULL;
  323. struct guild *g = NULL;
  324. struct battleground_data *bg = NULL;
  325. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  326. struct s_mapiterator* iter;
  327. if( type != ALL_CLIENT )
  328. nullpo_ret(bl);
  329. sd = BL_CAST(BL_PC, bl);
  330. switch(type) {
  331. case ALL_CLIENT: //All player clients.
  332. iter = mapit_getallusers();
  333. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ){
  334. WFIFOHEAD(tsd->fd, len);
  335. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  336. WFIFOSET(tsd->fd, len);
  337. }
  338. mapit_free(iter);
  339. break;
  340. case ALL_SAMEMAP: //All players on the same map
  341. iter = mapit_getallusers();
  342. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  343. {
  344. if( bl->m == tsd->bl.m ){
  345. WFIFOHEAD(tsd->fd, len);
  346. memcpy(WFIFOP(tsd->fd,0), buf, len);
  347. WFIFOSET(tsd->fd,len);
  348. }
  349. }
  350. mapit_free(iter);
  351. break;
  352. case AREA:
  353. case AREA_WOSC:
  354. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  355. clif_send (buf, len, bl, SELF);
  356. case AREA_WOC:
  357. case AREA_WOS:
  358. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  359. BL_PC, buf, len, bl, type);
  360. break;
  361. case AREA_CHAT_WOC:
  362. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  363. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  364. break;
  365. case CHAT:
  366. case CHAT_WOS:
  367. {
  368. struct chat_data *cd;
  369. if (sd) {
  370. cd = (struct chat_data*)map_id2bl(sd->chatID);
  371. } else if (bl->type == BL_CHAT) {
  372. cd = (struct chat_data*)bl;
  373. } else break;
  374. if (cd == NULL)
  375. break;
  376. for(i = 0; i < cd->users; i++) {
  377. if (type == CHAT_WOS && cd->usersd[i] == sd)
  378. continue;
  379. if ((fd=cd->usersd[i]->fd) >0 && session[fd]){ // Added check to see if session exists [PoW]
  380. WFIFOHEAD(fd,len);
  381. memcpy(WFIFOP(fd,0), buf, len);
  382. WFIFOSET(fd,len);
  383. }
  384. }
  385. }
  386. break;
  387. case PARTY_AREA:
  388. case PARTY_AREA_WOS:
  389. x0 = bl->x - AREA_SIZE;
  390. y0 = bl->y - AREA_SIZE;
  391. x1 = bl->x + AREA_SIZE;
  392. y1 = bl->y + AREA_SIZE;
  393. case PARTY:
  394. case PARTY_WOS:
  395. case PARTY_SAMEMAP:
  396. case PARTY_SAMEMAP_WOS:
  397. if (sd && sd->status.party_id)
  398. p = party_search(sd->status.party_id);
  399. if (p) {
  400. for(i=0;i<MAX_PARTY;i++){
  401. if( (sd = p->data[i].sd) == NULL )
  402. continue;
  403. if( !(fd=sd->fd) )
  404. continue;
  405. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  406. continue;
  407. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  408. continue;
  409. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  410. continue;
  411. WFIFOHEAD(fd, len);
  412. memcpy(WFIFOP(fd, 0), buf, len);
  413. WFIFOSET(fd, len);
  414. }
  415. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  416. break;
  417. iter = mapit_getallusers();
  418. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  419. {
  420. if( tsd->partyspy == p->party.party_id ){
  421. WFIFOHEAD(tsd->fd, len);
  422. memcpy(WFIFOP(tsd->fd,0), buf, len);
  423. WFIFOSET(tsd->fd,len);
  424. }
  425. }
  426. mapit_free(iter);
  427. }
  428. break;
  429. case DUEL:
  430. case DUEL_WOS:
  431. if (!sd || !sd->duel_group) break; //Invalid usage.
  432. iter = mapit_getallusers();
  433. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  434. {
  435. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  436. continue;
  437. if( sd->duel_group == tsd->duel_group ){
  438. WFIFOHEAD(tsd->fd, len);
  439. memcpy(WFIFOP(tsd->fd,0), buf, len);
  440. WFIFOSET(tsd->fd,len);
  441. }
  442. }
  443. mapit_free(iter);
  444. break;
  445. case SELF:
  446. if (sd && (fd=sd->fd)) {
  447. WFIFOHEAD(fd,len);
  448. memcpy(WFIFOP(fd,0), buf, len);
  449. WFIFOSET(fd,len);
  450. }
  451. break;
  452. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  453. case GUILD_AREA:
  454. case GUILD_AREA_WOS:
  455. x0 = bl->x - AREA_SIZE;
  456. y0 = bl->y - AREA_SIZE;
  457. x1 = bl->x + AREA_SIZE;
  458. y1 = bl->y + AREA_SIZE;
  459. case GUILD_SAMEMAP:
  460. case GUILD_SAMEMAP_WOS:
  461. case GUILD:
  462. case GUILD_WOS:
  463. case GUILD_NOBG:
  464. if (sd && sd->status.guild_id)
  465. g = sd->guild;
  466. if (g) {
  467. for(i = 0; i < g->max_member; i++) {
  468. if( (sd = g->member[i].sd) != NULL )
  469. {
  470. if( !(fd=sd->fd) )
  471. continue;
  472. if( type == GUILD_NOBG && sd->bg_id )
  473. continue;
  474. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  475. continue;
  476. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  477. continue;
  478. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  479. continue;
  480. WFIFOHEAD(fd,len);
  481. memcpy(WFIFOP(fd,0), buf, len);
  482. WFIFOSET(fd,len);
  483. }
  484. }
  485. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  486. break;
  487. iter = mapit_getallusers();
  488. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  489. {
  490. if( tsd->guildspy == g->guild_id ){
  491. WFIFOHEAD(tsd->fd, len);
  492. memcpy(WFIFOP(tsd->fd,0), buf, len);
  493. WFIFOSET(tsd->fd,len);
  494. }
  495. }
  496. mapit_free(iter);
  497. }
  498. break;
  499. case BG_AREA:
  500. case BG_AREA_WOS:
  501. x0 = bl->x - AREA_SIZE;
  502. y0 = bl->y - AREA_SIZE;
  503. x1 = bl->x + AREA_SIZE;
  504. y1 = bl->y + AREA_SIZE;
  505. case BG_SAMEMAP:
  506. case BG_SAMEMAP_WOS:
  507. case BG:
  508. case BG_WOS:
  509. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  510. {
  511. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  512. {
  513. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  514. continue;
  515. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  516. continue;
  517. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  518. continue;
  519. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  520. continue;
  521. WFIFOHEAD(fd,len);
  522. memcpy(WFIFOP(fd,0), buf, len);
  523. WFIFOSET(fd,len);
  524. }
  525. }
  526. break;
  527. case CLAN:
  528. if( sd && sd->clan ){
  529. struct clan* clan = sd->clan;
  530. for( i = 0; i < clan->max_member; i++ ){
  531. if( ( sd = clan->members[i] ) == NULL || !(fd = sd->fd) ){
  532. continue;
  533. }
  534. WFIFOHEAD(fd,len);
  535. memcpy(WFIFOP(fd,0), buf, len);
  536. WFIFOSET(fd,len);
  537. }
  538. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  539. break;
  540. iter = mapit_getallusers();
  541. while ((tsd = (TBL_PC*)mapit_next(iter)) != NULL){
  542. if (tsd->clanspy == clan->id){
  543. WFIFOHEAD(tsd->fd, len);
  544. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  545. WFIFOSET(tsd->fd, len);
  546. }
  547. }
  548. mapit_free(iter);
  549. }
  550. break;
  551. default:
  552. ShowError("clif_send: Unrecognized type %d\n",type);
  553. return -1;
  554. }
  555. return 0;
  556. }
  557. /// Notifies the client, that it's connection attempt was accepted.
  558. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  559. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  560. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  561. void clif_authok(struct map_session_data *sd)
  562. {
  563. #if PACKETVER < 20080102
  564. const int cmd = 0x73;
  565. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  566. const int cmd = 0x2eb;
  567. #else
  568. const int cmd = 0xa18;
  569. #endif
  570. int fd = sd->fd;
  571. WFIFOHEAD(fd,packet_len(cmd));
  572. WFIFOW(fd, 0) = cmd;
  573. WFIFOL(fd, 2) = client_tick(gettick());
  574. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  575. WFIFOB(fd, 9) = 5; // ignored
  576. WFIFOB(fd,10) = 5; // ignored
  577. #if PACKETVER >= 20080102
  578. WFIFOW(fd,11) = sd->status.font;
  579. #endif
  580. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  581. WFIFOB(fd,13) = sd->status.sex;
  582. #endif
  583. WFIFOSET(fd,packet_len(cmd));
  584. }
  585. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  586. /// 0074 <error code>.B
  587. /// error code:
  588. /// 0 = client type mismatch
  589. /// 1 = ID mismatch
  590. /// 2 = mobile - out of available time
  591. /// 3 = mobile - already logged in
  592. /// 4 = mobile - waiting state
  593. void clif_authrefuse(int fd, uint8 error_code)
  594. {
  595. WFIFOHEAD(fd,packet_len(0x74));
  596. WFIFOW(fd,0) = 0x74;
  597. WFIFOB(fd,2) = error_code;
  598. WFIFOSET(fd,packet_len(0x74));
  599. }
  600. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  601. /// 0081 <error code>.B
  602. /// error code:
  603. /// 0 = BAN_UNFAIR
  604. /// 1 = server closed -> MsgStringTable[4]
  605. /// 2 = ID already logged in -> MsgStringTable[5]
  606. /// 3 = timeout/too much lag -> MsgStringTable[241]
  607. /// 4 = server full -> MsgStringTable[264]
  608. /// 5 = underaged -> MsgStringTable[305]
  609. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  610. /// 9 = too many connections from this ip -> MsgStringTable[529]
  611. /// 10 = out of available time paid for -> MsgStringTable[530]
  612. /// 11 = BAN_PAY_SUSPEND
  613. /// 12 = BAN_PAY_CHANGE
  614. /// 13 = BAN_PAY_WRONGIP
  615. /// 14 = BAN_PAY_PNGAMEROOM
  616. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  617. /// 16 = BAN_JAPAN_REFUSE1
  618. /// 17 = BAN_JAPAN_REFUSE2
  619. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  620. /// 100 = BAN_PC_IP_UNFAIR
  621. /// 101 = BAN_PC_IP_COUNT_ALL
  622. /// 102 = BAN_PC_IP_COUNT
  623. /// 103 = BAN_GRAVITY_MEM_AGREE
  624. /// 104 = BAN_GAME_MEM_AGREE
  625. /// 105 = BAN_HAN_VALID
  626. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  627. /// 107 = BAN_OVER_CHARACTER_LIST
  628. /// 108 = BAN_IP_BLOCK
  629. /// 109 = BAN_INVALID_PWD_CNT
  630. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  631. /// ? = disconnected -> MsgStringTable[3]
  632. void clif_authfail_fd(int fd, int type)
  633. {
  634. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  635. return;
  636. WFIFOHEAD(fd, packet_len(0x81));
  637. WFIFOW(fd,0) = 0x81;
  638. WFIFOB(fd,2) = type;
  639. WFIFOSET(fd,packet_len(0x81));
  640. set_eof(fd);
  641. }
  642. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  643. /// 00b3 <type>.B
  644. /// type:
  645. /// 1 = disconnect, char-select
  646. /// ? = nothing
  647. void clif_charselectok(int id, uint8 ok)
  648. {
  649. struct map_session_data* sd;
  650. int fd;
  651. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  652. return;
  653. fd = sd->fd;
  654. WFIFOHEAD(fd,packet_len(0xb3));
  655. WFIFOW(fd,0) = 0xb3;
  656. WFIFOB(fd,2) = ok;
  657. WFIFOSET(fd,packet_len(0xb3));
  658. }
  659. /// Makes an item appear on the ground.
  660. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  661. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  662. /// 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)
  663. void clif_dropflooritem(struct flooritem_data* fitem, bool canShowEffect)
  664. {
  665. #if PACKETVER >= 20180418
  666. uint8 buf[22];
  667. uint32 header = 0xadd;
  668. #elif PACKETVER >= 20130000
  669. uint8 buf[19];
  670. uint32 header=0x84b;
  671. #else
  672. uint8 buf[17];
  673. uint32 header=0x09e;
  674. #endif
  675. int view, offset=0;
  676. nullpo_retv(fitem);
  677. if (fitem->item.nameid == 0)
  678. return;
  679. WBUFW(buf, offset+0) = header;
  680. WBUFL(buf, offset+2) = fitem->bl.id;
  681. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  682. #if PACKETVER >= 20130000
  683. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  684. offset +=2;
  685. #endif
  686. WBUFB(buf, offset+8) = fitem->item.identify;
  687. WBUFW(buf, offset+9) = fitem->bl.x;
  688. WBUFW(buf, offset+11) = fitem->bl.y;
  689. WBUFB(buf, offset+13) = fitem->subx;
  690. WBUFB(buf, offset+14) = fitem->suby;
  691. WBUFW(buf, offset+15) = fitem->item.amount;
  692. #if PACKETVER >= 20180418
  693. if( canShowEffect ){
  694. uint8 dropEffect = itemdb_dropeffect(fitem->item.nameid);
  695. if( dropEffect > 0 ){
  696. WBUFB(buf, offset+17) = 1;
  697. WBUFW(buf, offset+18) = dropEffect - 1;
  698. }else{
  699. WBUFB(buf, offset+17) = 0;
  700. WBUFW(buf, offset+18) = 0;
  701. }
  702. }else{
  703. WBUFB(buf, offset+17) = 0;
  704. WBUFW(buf, offset+18) = 0;
  705. }
  706. #endif
  707. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  708. }
  709. /// Makes an item disappear from the ground.
  710. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  711. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  712. {
  713. unsigned char buf[16];
  714. nullpo_retv(fitem);
  715. WBUFW(buf,0) = 0xa1;
  716. WBUFL(buf,2) = fitem->bl.id;
  717. if (fd == 0) {
  718. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  719. } else {
  720. WFIFOHEAD(fd,packet_len(0xa1));
  721. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  722. WFIFOSET(fd,packet_len(0xa1));
  723. }
  724. }
  725. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  726. /// 0080 <id>.L <type>.B
  727. /// type:
  728. /// 0 = out of sight
  729. /// 1 = died
  730. /// 2 = logged out
  731. /// 3 = teleport
  732. /// 4 = trickdead
  733. void clif_clearunit_single(int id, clr_type type, int fd)
  734. {
  735. WFIFOHEAD(fd, packet_len(0x80));
  736. WFIFOW(fd,0) = 0x80;
  737. WFIFOL(fd,2) = id;
  738. WFIFOB(fd,6) = type;
  739. WFIFOSET(fd, packet_len(0x80));
  740. }
  741. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  742. /// 0080 <id>.L <type>.B
  743. /// type:
  744. /// 0 = out of sight
  745. /// 1 = died
  746. /// 2 = logged out
  747. /// 3 = teleport
  748. /// 4 = trickdead
  749. void clif_clearunit_area(struct block_list* bl, clr_type type)
  750. {
  751. unsigned char buf[8];
  752. nullpo_retv(bl);
  753. WBUFW(buf,0) = 0x80;
  754. WBUFL(buf,2) = bl->id;
  755. WBUFB(buf,6) = type;
  756. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  757. if(disguised(bl)) {
  758. WBUFL(buf,2) = -bl->id;
  759. clif_send(buf, packet_len(0x80), bl, SELF);
  760. }
  761. }
  762. /// Used to make monsters with player-sprites disappear after dying
  763. /// like normal monsters, because the client does not remove those
  764. /// automatically.
  765. static TIMER_FUNC(clif_clearunit_delayed_sub){
  766. struct block_list *bl = (struct block_list *)data;
  767. clif_clearunit_area(bl, (clr_type) id);
  768. ers_free(delay_clearunit_ers,bl);
  769. return 0;
  770. }
  771. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  772. {
  773. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  774. memcpy (tbl, bl, sizeof (struct block_list));
  775. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  776. }
  777. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  778. {
  779. if(sd->sc.option&OPTION_COSTUME)
  780. {
  781. *rhand = *lhand = 0;
  782. return;
  783. }
  784. #if PACKETVER < 4
  785. *rhand = sd->status.weapon;
  786. *lhand = sd->status.shield;
  787. #else
  788. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  789. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  790. {
  791. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  792. if (id->view_id > 0)
  793. *rhand = id->view_id;
  794. else
  795. *rhand = id->nameid;
  796. } else
  797. *rhand = 0;
  798. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  799. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  800. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  801. {
  802. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  803. if (id->view_id > 0)
  804. *lhand = id->view_id;
  805. else
  806. *lhand = id->nameid;
  807. } else
  808. *lhand = 0;
  809. #endif
  810. }
  811. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  812. static int clif_setlevel_sub(int lv) {
  813. if( lv < battle_config.max_lv ) {
  814. ;
  815. } else if( lv < battle_config.aura_lv ) {
  816. lv = battle_config.max_lv - 1;
  817. } else {
  818. lv = battle_config.max_lv;
  819. }
  820. return lv;
  821. }
  822. static int clif_setlevel(struct block_list* bl) {
  823. int lv = status_get_lv(bl);
  824. if( battle_config.client_limit_unit_lv&bl->type )
  825. return clif_setlevel_sub(lv);
  826. switch( bl->type ) {
  827. case BL_NPC:
  828. case BL_PET:
  829. // npcs and pets do not have level
  830. return 0;
  831. }
  832. return lv;
  833. }
  834. /*==========================================
  835. * Prepares 'unit standing/spawning' packet
  836. *------------------------------------------*/
  837. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  838. {
  839. struct map_session_data* sd;
  840. struct status_change* sc = status_get_sc(bl);
  841. struct view_data* vd = status_get_viewdata(bl);
  842. unsigned char *buf = WBUFP(buffer, 0);
  843. #if PACKETVER < 20091103
  844. bool type = !pcdb_checkid(vd->class_);
  845. #endif
  846. unsigned short offset = 0;
  847. #if PACKETVER >= 20091103
  848. const char *name;
  849. #endif
  850. sd = BL_CAST(BL_PC, bl);
  851. #if PACKETVER < 20091103
  852. if(type)
  853. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  854. else
  855. #endif
  856. #if PACKETVER < 4
  857. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  858. #elif PACKETVER < 7
  859. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  860. #elif PACKETVER < 20080102
  861. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  862. #elif PACKETVER < 20091103
  863. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  864. #elif PACKETVER < 20101124
  865. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  866. #elif PACKETVER < 20120221
  867. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  868. #elif PACKETVER < 20131223
  869. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  870. #elif PACKETVER < 20150513
  871. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  872. #else
  873. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  874. #endif
  875. #if PACKETVER >= 20091103
  876. name = status_get_name(bl);
  877. #if PACKETVER < 20110111
  878. WBUFW(buf,2) = (uint16)((spawn ? 62 : 63)+strlen(name));
  879. #elif PACKETVER < 20120221
  880. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  881. #elif PACKETVER < 20130807
  882. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  883. #else
  884. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  885. #endif
  886. WBUFB(buf,4) = clif_bl_type(bl);
  887. offset+=3;
  888. buf = WBUFP(buffer,offset);
  889. #elif PACKETVER >= 20071106
  890. if (type) { //Non-player packets
  891. WBUFB(buf,2) = clif_bl_type(bl);
  892. offset++;
  893. buf = WBUFP(buffer,offset);
  894. }
  895. #endif
  896. WBUFL(buf, 2) = bl->id;
  897. #if PACKETVER >= 20131223
  898. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  899. offset+=4;
  900. buf = WBUFP(buffer,offset);
  901. #endif
  902. WBUFW(buf, 6) = status_get_speed(bl);
  903. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  904. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  905. #if PACKETVER < 20091103
  906. if (type&&spawn) { //uses an older and different packet structure
  907. WBUFW(buf,12) = (sc)? sc->option : 0;
  908. WBUFW(buf,14) = vd->hair_style;
  909. WBUFW(buf,16) = vd->weapon;
  910. WBUFW(buf,18) = vd->head_bottom;
  911. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  912. WBUFW(buf,22) = vd->shield;
  913. } else {
  914. #endif
  915. #if PACKETVER >= 20091103
  916. WBUFL(buf,12) = (sc)? sc->option : 0;
  917. offset+=2;
  918. buf = WBUFP(buffer,offset);
  919. #elif PACKETVER >= 7
  920. if (!type) {
  921. WBUFL(buf,12) = (sc)? sc->option : 0;
  922. offset+=2;
  923. buf = WBUFP(buffer,offset);
  924. } else
  925. WBUFW(buf,12) = (sc)? sc->option : 0;
  926. #else
  927. WBUFW(buf,12) = (sc)? sc->option : 0;
  928. #endif
  929. WBUFW(buf,14) = vd->class_;
  930. WBUFW(buf,16) = vd->hair_style;
  931. WBUFW(buf,18) = vd->weapon;
  932. #if PACKETVER < 4
  933. WBUFW(buf,20) = vd->head_bottom;
  934. WBUFW(buf,22) = vd->shield;
  935. #else
  936. WBUFW(buf,20) = vd->shield;
  937. WBUFW(buf,22) = vd->head_bottom;
  938. #endif
  939. #if PACKETVER < 20091103
  940. }
  941. #endif
  942. WBUFW(buf,24) = vd->head_top;
  943. WBUFW(buf,26) = vd->head_mid;
  944. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG )
  945. { //The hell, why flags work like this?
  946. WBUFW(buf,22) = status_get_emblem_id(bl);
  947. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  948. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  949. }
  950. WBUFW(buf,28) = vd->hair_color;
  951. WBUFW(buf,30) = vd->cloth_color;
  952. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  953. #if PACKETVER < 20091103
  954. if (type&&spawn) { //End of packet 0x7c
  955. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  956. WBUFB(buf,35) = vd->sex;
  957. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  958. WBUFB(buf,39) = 0;
  959. WBUFB(buf,40) = 0;
  960. return packet_len(0x7c);
  961. }
  962. #endif
  963. #if PACKETVER >= 20110111
  964. WBUFW(buf,34) = vd->robe;
  965. offset+= 2;
  966. buf = WBUFP(buffer,offset);
  967. #endif
  968. WBUFL(buf,34) = status_get_guild_id(bl);
  969. WBUFW(buf,38) = status_get_emblem_id(bl);
  970. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  971. #if PACKETVER >= 20091103
  972. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  973. offset+=2;
  974. buf = WBUFP(buffer,offset);
  975. #elif PACKETVER >= 7
  976. if (!type) {
  977. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  978. offset+=2;
  979. buf = WBUFP(buffer,offset);
  980. } else
  981. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  982. #else
  983. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  984. #endif
  985. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  986. WBUFB(buf,45) = vd->sex;
  987. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  988. WBUFB(buf,49) = (sd)? 5 : 0;
  989. WBUFB(buf,50) = (sd)? 5 : 0;
  990. if (!spawn) {
  991. WBUFB(buf,51) = vd->dead_sit;
  992. offset++;
  993. buf = WBUFP(buffer,offset);
  994. }
  995. WBUFW(buf,51) = clif_setlevel(bl);
  996. #if PACKETVER < 20091103
  997. if (type) //End for non-player packet
  998. return packet_len(WBUFW(buffer,0));
  999. #endif
  1000. #if PACKETVER >= 20080102
  1001. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  1002. #endif
  1003. #if PACKETVER >= 20120221
  1004. 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)) ) {
  1005. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  1006. WBUFL(buf,59) = status_get_hp(bl); // HP
  1007. } else {
  1008. WBUFL(buf,55) = -1; // maxHP
  1009. WBUFL(buf,59) = -1; // HP
  1010. }
  1011. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1012. #endif
  1013. #if PACKETVER >= 20150513
  1014. WBUFW(buf,64) = vd->body_style; // body
  1015. offset+= 2;
  1016. buf = WBUFP(buffer,offset);
  1017. #endif
  1018. #if PACKETVER >= 20091103
  1019. #if PACKETVER >= 20120221
  1020. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  1021. #else
  1022. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  1023. #endif
  1024. return WBUFW(buffer,2);
  1025. #else
  1026. return packet_len(WBUFW(buffer,0));
  1027. #endif
  1028. }
  1029. /*==========================================
  1030. * Prepares 'unit walking' packet
  1031. *------------------------------------------*/
  1032. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1033. {
  1034. struct map_session_data* sd;
  1035. struct status_change* sc = status_get_sc(bl);
  1036. struct view_data* vd = status_get_viewdata(bl);
  1037. unsigned char* buf = WBUFP(buffer,0);
  1038. #if PACKETVER >= 7
  1039. unsigned short offset = 0;
  1040. #endif
  1041. #if PACKETVER >= 20091103
  1042. const char *name;
  1043. #endif
  1044. sd = BL_CAST(BL_PC, bl);
  1045. #if PACKETVER < 4
  1046. WBUFW(buf, 0) = 0x7b;
  1047. #elif PACKETVER < 7
  1048. WBUFW(buf, 0) = 0x1da;
  1049. #elif PACKETVER < 20080102
  1050. WBUFW(buf, 0) = 0x22c;
  1051. #elif PACKETVER < 20091103
  1052. WBUFW(buf, 0) = 0x2ec;
  1053. #elif PACKETVER < 20101124
  1054. WBUFW(buf, 0) = 0x7f7;
  1055. #elif PACKETVER < 20120221
  1056. WBUFW(buf, 0) = 0x856;
  1057. #elif PACKETVER < 20131223
  1058. WBUFW(buf, 0) = 0x914;
  1059. #elif PACKETVER < 20150513
  1060. WBUFW(buf, 0) = 0x9db;
  1061. #else
  1062. WBUFW(buf, 0) = 0x9fd;
  1063. #endif
  1064. #if PACKETVER >= 20091103
  1065. name = status_get_name(bl);
  1066. #if PACKETVER < 20110111
  1067. WBUFW(buf, 2) = (uint16)(69+strlen(name));
  1068. #elif PACKETVER < 20120221
  1069. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1070. #elif PACKETVER < 20130807
  1071. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1072. #else
  1073. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  1074. #endif
  1075. offset+=2;
  1076. buf = WBUFP(buffer,offset);
  1077. #endif
  1078. #if PACKETVER >= 20071106
  1079. WBUFB(buf, 2) = clif_bl_type(bl);
  1080. offset++;
  1081. buf = WBUFP(buffer,offset);
  1082. #endif
  1083. WBUFL(buf, 2) = bl->id;
  1084. #if PACKETVER >= 20131223
  1085. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1086. offset+=4;
  1087. buf = WBUFP(buffer,offset);
  1088. #endif
  1089. WBUFW(buf, 6) = status_get_speed(bl);
  1090. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1091. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1092. #if PACKETVER < 7
  1093. WBUFW(buf,12) = (sc)? sc->option : 0;
  1094. #else
  1095. WBUFL(buf,12) = (sc)? sc->option : 0;
  1096. offset+=2; //Shift the rest of elements by 2 bytes.
  1097. buf = WBUFP(buffer,offset);
  1098. #endif
  1099. WBUFW(buf,14) = vd->class_;
  1100. WBUFW(buf,16) = vd->hair_style;
  1101. WBUFW(buf,18) = vd->weapon;
  1102. #if PACKETVER < 4
  1103. WBUFW(buf,20) = vd->head_bottom;
  1104. WBUFL(buf,22) = client_tick(gettick());
  1105. WBUFW(buf,26) = vd->shield;
  1106. #else
  1107. WBUFW(buf,20) = vd->shield;
  1108. WBUFW(buf,22) = vd->head_bottom;
  1109. WBUFL(buf,24) = client_tick(gettick());
  1110. #endif
  1111. WBUFW(buf,28) = vd->head_top;
  1112. WBUFW(buf,30) = vd->head_mid;
  1113. WBUFW(buf,32) = vd->hair_color;
  1114. WBUFW(buf,34) = vd->cloth_color;
  1115. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1116. #if PACKETVER >= 20110111
  1117. WBUFW(buf,38) = vd->robe;
  1118. offset+= 2;
  1119. buf = WBUFP(buffer,offset);
  1120. #endif
  1121. WBUFL(buf,38) = status_get_guild_id(bl);
  1122. WBUFW(buf,42) = status_get_emblem_id(bl);
  1123. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1124. #if PACKETVER < 7
  1125. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1126. #else
  1127. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1128. offset+=2; //Shift the rest of elements by 2 bytes.
  1129. buf = WBUFP(buffer,offset);
  1130. #endif
  1131. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1132. WBUFB(buf,49) = vd->sex;
  1133. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1134. WBUFB(buf,56) = (sd)? 5 : 0;
  1135. WBUFB(buf,57) = (sd)? 5 : 0;
  1136. WBUFW(buf,58) = clif_setlevel(bl);
  1137. #if PACKETVER >= 20080102
  1138. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1139. #endif
  1140. #if PACKETVER >= 20120221
  1141. 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)) ) {
  1142. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1143. WBUFL(buf,66) = status_get_hp(bl); // HP
  1144. } else {
  1145. WBUFL(buf,62) = -1; // maxHP
  1146. WBUFL(buf,66) = -1; // HP
  1147. }
  1148. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1149. #endif
  1150. #if PACKETVER >= 20150513
  1151. WBUFW(buf,71) = vd->body_style; // body
  1152. offset+= 2;
  1153. buf = WBUFP(buffer,offset);
  1154. #endif
  1155. #if PACKETVER >= 20091103
  1156. #if PACKETVER >= 20120221
  1157. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1158. #else
  1159. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1160. #endif
  1161. return WBUFW(buffer,2);
  1162. #else
  1163. return packet_len(WBUFW(buffer,0));
  1164. #endif
  1165. }
  1166. //Modifies the buffer for disguise characters and sends it to self.
  1167. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1168. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1169. {
  1170. #if PACKETVER >= 20091103
  1171. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1172. WBUFL(buf,5)=-bl->id;
  1173. #elif PACKETVER >= 20071106
  1174. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1175. WBUFL(buf,3)=-bl->id;
  1176. #else
  1177. WBUFL(buf,2)=-bl->id;
  1178. #endif
  1179. clif_send(buf, len, bl, SELF);
  1180. }
  1181. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1182. /// 01b0 <id>.L <type>.B <value>.L
  1183. /// type:
  1184. /// unused
  1185. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1186. {
  1187. nullpo_retv(bl);
  1188. if(!pcdb_checkid(class_))
  1189. {// player classes yield missing sprites
  1190. unsigned char buf[16];
  1191. WBUFW(buf,0)=0x1b0;
  1192. WBUFL(buf,2)=bl->id;
  1193. WBUFB(buf,6)=type;
  1194. WBUFL(buf,7)=class_;
  1195. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1196. }
  1197. }
  1198. /// Notifies the client of an object's spirits.
  1199. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1200. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1201. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1202. {
  1203. WFIFOHEAD(fd, packet_len(0x1e1));
  1204. WFIFOW(fd,0)=0x1e1;
  1205. WFIFOL(fd,2)=sd->bl.id;
  1206. WFIFOW(fd,6)=sd->spiritball;
  1207. WFIFOSET(fd, packet_len(0x1e1));
  1208. }
  1209. /*==========================================
  1210. * Kagerou/Oboro amulet spirit
  1211. *------------------------------------------*/
  1212. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1213. {
  1214. WFIFOHEAD(fd, packet_len(0x08cf));
  1215. WFIFOW(fd,0)=0x08cf;
  1216. WFIFOL(fd,2)=sd->bl.id;
  1217. WFIFOW(fd,6)=sd->spiritcharm_type;
  1218. WFIFOW(fd,8)=sd->spiritcharm;
  1219. WFIFOSET(fd, packet_len(0x08cf));
  1220. }
  1221. /*==========================================
  1222. * Run when player changes map / refreshes
  1223. * Tells its client to display all weather settings being used by this map
  1224. *------------------------------------------*/
  1225. static void clif_weather_check(struct map_session_data *sd)
  1226. {
  1227. int16 m = sd->bl.m;
  1228. int fd = sd->fd;
  1229. if (map_getmapflag(m, MF_SNOW)
  1230. || map_getmapflag(m, MF_CLOUDS)
  1231. || map_getmapflag(m, MF_FOG)
  1232. || map_getmapflag(m, MF_FIREWORKS)
  1233. || map_getmapflag(m, MF_SAKURA)
  1234. || map_getmapflag(m, MF_LEAVES)
  1235. || map_getmapflag(m, MF_CLOUDS2))
  1236. {
  1237. if (map_getmapflag(m, MF_SNOW))
  1238. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1239. if (map_getmapflag(m, MF_CLOUDS))
  1240. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1241. if (map_getmapflag(m, MF_CLOUDS2))
  1242. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1243. if (map_getmapflag(m, MF_FOG))
  1244. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1245. if (map_getmapflag(m, MF_FIREWORKS)) {
  1246. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1247. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1248. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1249. }
  1250. if (map_getmapflag(m, MF_SAKURA))
  1251. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1252. if (map_getmapflag(m, MF_LEAVES))
  1253. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1254. }
  1255. }
  1256. /**
  1257. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1258. **/
  1259. void clif_weather(int16 m)
  1260. {
  1261. struct s_mapiterator* iter;
  1262. struct map_session_data *sd=NULL;
  1263. iter = mapit_getallusers();
  1264. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1265. {
  1266. if( sd->bl.m == m )
  1267. clif_weather_check(sd);
  1268. }
  1269. mapit_free(iter);
  1270. }
  1271. /**
  1272. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1273. **/
  1274. int clif_spawn(struct block_list *bl)
  1275. {
  1276. unsigned char buf[128];
  1277. struct view_data *vd;
  1278. int len;
  1279. vd = status_get_viewdata(bl);
  1280. if( !vd || vd->class_ == JT_INVISIBLE )
  1281. return 0;
  1282. /**
  1283. * Hide NPC from maya purple card.
  1284. **/
  1285. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1286. return 0;
  1287. len = clif_set_unit_idle(bl, buf,true);
  1288. clif_send(buf, len, bl, AREA_WOS);
  1289. if (disguised(bl))
  1290. clif_setdisguise(bl, buf, len);
  1291. if (vd->cloth_color)
  1292. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1293. if (vd->body_style)
  1294. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1295. switch (bl->type)
  1296. {
  1297. case BL_PC:
  1298. {
  1299. TBL_PC *sd = ((TBL_PC*)bl);
  1300. if (sd->spiritball > 0)
  1301. clif_spiritball(&sd->bl);
  1302. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1303. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1304. else if(sd->state.size==SZ_MEDIUM)
  1305. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1306. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1307. clif_sendbgemblem_area(sd);
  1308. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1309. clif_spiritcharm(sd);
  1310. if (sd->status.robe)
  1311. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1312. clif_efst_status_change_sub(bl, bl, AREA);
  1313. clif_hat_effects(sd,bl,AREA);
  1314. }
  1315. break;
  1316. case BL_MOB:
  1317. {
  1318. TBL_MOB *md = ((TBL_MOB*)bl);
  1319. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1320. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1321. else if(md->special_state.size==SZ_MEDIUM)
  1322. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1323. }
  1324. break;
  1325. case BL_NPC:
  1326. {
  1327. TBL_NPC *nd = ((TBL_NPC*)bl);
  1328. if( nd->size == SZ_BIG )
  1329. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1330. else if( nd->size == SZ_MEDIUM )
  1331. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1332. clif_efst_status_change_sub(bl, bl, AREA);
  1333. clif_progressbar_npc_area(nd);
  1334. }
  1335. break;
  1336. case BL_PET:
  1337. if (vd->head_bottom)
  1338. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1339. break;
  1340. }
  1341. return 0;
  1342. }
  1343. /// Sends information about owned homunculus to the client . [orn]
  1344. /// 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)
  1345. /// 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)
  1346. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1347. {
  1348. struct status_data *status;
  1349. unsigned char buf[128];
  1350. int offset;
  1351. #if PACKETVER < 20141016
  1352. const int cmd = 0x22e;
  1353. #else
  1354. const int cmd = 0x9f7;
  1355. #endif
  1356. int htype;
  1357. nullpo_retv(hd);
  1358. if (!clif_session_isValid(sd))
  1359. return;
  1360. status = &hd->battle_status;
  1361. htype = hom_class2type(hd->homunculus.class_);
  1362. memset(buf,0,packet_len(cmd));
  1363. WBUFW(buf,0) = cmd;
  1364. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1365. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1366. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1367. WBUFW(buf,27) = hd->homunculus.level;
  1368. WBUFW(buf,29) = hd->homunculus.hunger;
  1369. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1370. WBUFW(buf,33) = 0; // equip id
  1371. WBUFW(buf,35) = cap_value(status->rhw.atk2 + status->batk, 0, INT16_MAX);
  1372. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1373. WBUFW(buf,39)=status->hit;
  1374. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1375. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1376. else
  1377. WBUFW(buf,41) = status->cri/10;
  1378. #ifdef RENEWAL
  1379. WBUFW(buf,43) = status->def + status->def2;
  1380. WBUFW(buf,45) = status->mdef + status->mdef2;
  1381. #else
  1382. WBUFW(buf,43) = status->def + status->vit;
  1383. WBUFW(buf,45) = status->mdef;
  1384. #endif
  1385. WBUFW(buf,47) = status->flee;
  1386. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1387. #if PACKETVER >= 20141016
  1388. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1389. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1390. if (status->max_hp > (INT32_MAX/100)) {
  1391. WBUFL(buf,51) = status->hp/(status->max_hp/100);
  1392. WBUFL(buf,55) = 100;
  1393. } else {
  1394. WBUFL(buf,51) = status->hp;
  1395. WBUFL(buf,55) = status->max_hp;
  1396. }
  1397. offset = 4;
  1398. #else
  1399. if (status->max_hp > INT16_MAX) {
  1400. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1401. WBUFW(buf,53) = 100;
  1402. } else {
  1403. WBUFW(buf,51) = status->hp;
  1404. WBUFW(buf,53) = status->max_hp;
  1405. }
  1406. offset = 0;
  1407. #endif
  1408. if (status->max_sp > INT16_MAX) {
  1409. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1410. WBUFW(buf,57+offset) = 100;
  1411. } else {
  1412. WBUFW(buf,55+offset) = status->sp;
  1413. WBUFW(buf,57+offset) = status->max_sp;
  1414. }
  1415. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1416. WBUFL(buf,63+offset) = hd->exp_next;
  1417. switch( htype ) {
  1418. case HT_REG:
  1419. case HT_EVO:
  1420. if( hd->homunculus.level >= battle_config.hom_max_level )
  1421. WBUFL(buf,63+offset) = 0;
  1422. break;
  1423. case HT_S:
  1424. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1425. WBUFL(buf,63+offset) = 0;
  1426. break;
  1427. }
  1428. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1429. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1430. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1431. }
  1432. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1433. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1434. /// type:
  1435. /// unused
  1436. /// state:
  1437. /// 0 = pre-init
  1438. /// 1 = intimacy
  1439. /// 2 = hunger
  1440. /// 3 = accessory?
  1441. /// ? = ignored
  1442. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1443. { //[orn]
  1444. int fd = sd->fd;
  1445. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1446. hom_calc_skilltree(sd->hd, 0);
  1447. WFIFOHEAD(fd, packet_len(0x230));
  1448. WFIFOW(fd,0)=0x230;
  1449. WFIFOB(fd,2)=0;
  1450. WFIFOB(fd,3)=state;
  1451. WFIFOL(fd,4)=sd->hd->bl.id;
  1452. WFIFOL(fd,8)=param;
  1453. WFIFOSET(fd,packet_len(0x230));
  1454. }
  1455. int clif_homskillinfoblock(struct map_session_data *sd)
  1456. { //[orn]
  1457. struct homun_data *hd;
  1458. int fd = sd->fd;
  1459. int i, len=4;
  1460. nullpo_ret(sd);
  1461. hd = sd->hd;
  1462. if ( !hd )
  1463. return 0 ;
  1464. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1465. WFIFOW(fd,0)=0x235;
  1466. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1467. int id = hd->homunculus.hskill[i].id;
  1468. if( id != 0 ){
  1469. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1470. short idx = hom_skill_get_index(id);
  1471. if (idx == -1)
  1472. continue;
  1473. WFIFOW(fd,len ) = id;
  1474. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1475. WFIFOW(fd,len+4) = 0;
  1476. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1477. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1478. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1479. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1480. 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;
  1481. len+=37;
  1482. }
  1483. }
  1484. WFIFOW(fd,2)=len;
  1485. WFIFOSET(fd,len);
  1486. return 0;
  1487. }
  1488. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1489. { //[orn]
  1490. struct homun_data *hd;
  1491. int fd;
  1492. short idx = -1;
  1493. nullpo_retv(sd);
  1494. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1495. return;
  1496. fd = sd->fd;
  1497. hd = sd->hd;
  1498. WFIFOHEAD(fd, packet_len(0x239));
  1499. WFIFOW(fd,0) = 0x239;
  1500. WFIFOW(fd,2) = skill_id;
  1501. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1502. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1503. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1504. 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;
  1505. WFIFOSET(fd,packet_len(0x239));
  1506. }
  1507. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1508. {
  1509. int fd=sd->fd;
  1510. WFIFOHEAD(fd,packet_len(0x22f));
  1511. WFIFOW(fd,0)=0x22f;
  1512. WFIFOB(fd,2)=fail;
  1513. WFIFOW(fd,3)=foodid;
  1514. WFIFOSET(fd,packet_len(0x22f));
  1515. return 0;
  1516. }
  1517. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1518. /// 0087 <walk start time>.L <walk data>.6B
  1519. void clif_walkok(struct map_session_data *sd)
  1520. {
  1521. int fd=sd->fd;
  1522. WFIFOHEAD(fd, packet_len(0x87));
  1523. WFIFOW(fd,0)=0x87;
  1524. WFIFOL(fd,2)=client_tick(gettick());
  1525. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1526. WFIFOSET(fd,packet_len(0x87));
  1527. }
  1528. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1529. {
  1530. uint8 buf[128];
  1531. int len;
  1532. struct status_change *sc = NULL;
  1533. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1534. clif_ally_only = true;
  1535. len = clif_set_unit_walking(bl,ud,buf);
  1536. clif_send(buf,len,bl,AREA_WOS);
  1537. if (disguised(bl))
  1538. clif_setdisguise(bl, buf, len);
  1539. if(vd->cloth_color)
  1540. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1541. if(vd->body_style)
  1542. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1543. switch(bl->type) {
  1544. case BL_PC:
  1545. {
  1546. TBL_PC *sd = ((TBL_PC*)bl);
  1547. // clif_movepc(sd);
  1548. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1549. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1550. else if(sd->state.size==SZ_MEDIUM)
  1551. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1552. if (sd->status.robe)
  1553. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1554. }
  1555. break;
  1556. case BL_MOB:
  1557. {
  1558. TBL_MOB *md = ((TBL_MOB*)bl);
  1559. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1560. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1561. else if(md->special_state.size==SZ_MEDIUM)
  1562. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1563. }
  1564. break;
  1565. case BL_PET:
  1566. if(vd->head_bottom) // needed to display pet equip properly
  1567. clif_pet_equip_area((TBL_PET*)bl);
  1568. break;
  1569. }
  1570. clif_ally_only = false;
  1571. }
  1572. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1573. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1574. /// Note: unit must not be self
  1575. void clif_move(struct unit_data *ud)
  1576. {
  1577. unsigned char buf[16];
  1578. struct view_data* vd;
  1579. struct block_list* bl = ud->bl;
  1580. struct status_change *sc = NULL;
  1581. vd = status_get_viewdata(bl);
  1582. if (!vd )
  1583. return;
  1584. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1585. else if( vd->class_ == JT_INVISIBLE ){
  1586. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1587. if(disguised(bl)) {
  1588. WBUFW(buf,0)=0x86;
  1589. WBUFL(buf,2)=-bl->id;
  1590. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1591. WBUFL(buf,12)=client_tick(gettick());
  1592. clif_send(buf, packet_len(0x86), bl, SELF);
  1593. }
  1594. return;
  1595. }
  1596. /**
  1597. * Hide NPC from maya purple card.
  1598. **/
  1599. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1600. return;
  1601. if (ud->state.speed_changed) {
  1602. // Since we don't know how to update the speed of other objects,
  1603. // use the old walk packet to update the data.
  1604. ud->state.speed_changed = 0;
  1605. clif_move2(bl, vd, ud);
  1606. return;
  1607. }
  1608. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1609. clif_ally_only = true;
  1610. WBUFW(buf,0)=0x86;
  1611. WBUFL(buf,2)=bl->id;
  1612. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1613. WBUFL(buf,12)=client_tick(gettick());
  1614. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1615. if (disguised(bl)) {
  1616. WBUFL(buf,2)=-bl->id;
  1617. clif_send(buf, packet_len(0x86), bl, SELF);
  1618. }
  1619. clif_ally_only = false;
  1620. }
  1621. /*==========================================
  1622. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1623. *------------------------------------------*/
  1624. static TIMER_FUNC(clif_delayquit){
  1625. struct map_session_data *sd = NULL;
  1626. //Remove player from map server
  1627. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1628. map_quit(sd);
  1629. return 0;
  1630. }
  1631. /*==========================================
  1632. *
  1633. *------------------------------------------*/
  1634. void clif_quitsave(int fd,struct map_session_data *sd) {
  1635. if (!battle_config.prevent_logout ||
  1636. sd->canlog_tick == 0 ||
  1637. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1638. map_quit(sd);
  1639. else if (sd->fd) {
  1640. //Disassociate session from player (session is deleted after this function was called)
  1641. //And set a timer to make him quit later.
  1642. session[sd->fd]->session_data = NULL;
  1643. sd->fd = 0;
  1644. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1645. }
  1646. }
  1647. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1648. /// 0091 <map name>.16B <x>.W <y>.W
  1649. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1650. {
  1651. int fd;
  1652. nullpo_retv(sd);
  1653. fd = sd->fd;
  1654. WFIFOHEAD(fd,packet_len(0x91));
  1655. WFIFOW(fd,0) = 0x91;
  1656. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1657. WFIFOW(fd,18) = x;
  1658. WFIFOW(fd,20) = y;
  1659. WFIFOSET(fd,packet_len(0x91));
  1660. }
  1661. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1662. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1663. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1664. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1665. {
  1666. int fd;
  1667. #if PACKETVER >= 20170315
  1668. int cmd = 0xac7;
  1669. #else
  1670. int cmd = 0x92;
  1671. #endif
  1672. nullpo_retv(sd);
  1673. fd = sd->fd;
  1674. WFIFOHEAD(fd,packet_len(cmd));
  1675. WFIFOW(fd,0) = cmd;
  1676. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1677. WFIFOW(fd,18) = x;
  1678. WFIFOW(fd,20) = y;
  1679. WFIFOL(fd,22) = htonl(ip);
  1680. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1681. #if PACKETVER >= 20170315
  1682. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1683. #endif
  1684. WFIFOSET(fd,packet_len(cmd));
  1685. }
  1686. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1687. /// This function combines both calls and allows to simplify the calling code
  1688. void clif_blown(struct block_list *bl)
  1689. {
  1690. clif_slide(bl, bl->x, bl->y);
  1691. clif_fixpos(bl);
  1692. }
  1693. /// Visually moves(slides) a character to x,y. If the target cell
  1694. /// isn't walkable, the char doesn't move at all. If the char is
  1695. /// sitting it will stand up (ZC_STOPMOVE).
  1696. /// 0088 <id>.L <x>.W <y>.W
  1697. void clif_fixpos(struct block_list *bl)
  1698. {
  1699. unsigned char buf[10];
  1700. nullpo_retv(bl);
  1701. WBUFW(buf,0) = 0x88;
  1702. WBUFL(buf,2) = bl->id;
  1703. WBUFW(buf,6) = bl->x;
  1704. WBUFW(buf,8) = bl->y;
  1705. clif_send(buf, packet_len(0x88), bl, AREA);
  1706. if( disguised(bl) ) {
  1707. WBUFL(buf,2) = -bl->id;
  1708. clif_send(buf, packet_len(0x88), bl, SELF);
  1709. }
  1710. }
  1711. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1712. /// 00c4 <shop id>.L
  1713. void clif_npcbuysell(struct map_session_data* sd, int id)
  1714. {
  1715. int fd;
  1716. nullpo_retv(sd);
  1717. fd=sd->fd;
  1718. WFIFOHEAD(fd, packet_len(0xc4));
  1719. WFIFOW(fd,0)=0xc4;
  1720. WFIFOL(fd,2)=id;
  1721. WFIFOSET(fd,packet_len(0xc4));
  1722. }
  1723. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1724. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1725. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1726. {
  1727. int fd,i,c;
  1728. bool discount;
  1729. nullpo_retv(sd);
  1730. nullpo_retv(nd);
  1731. fd = sd->fd;
  1732. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1733. WFIFOW(fd,0) = 0xc6;
  1734. c = 0;
  1735. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1736. for( i = 0; i < nd->u.shop.count; i++ )
  1737. {
  1738. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1739. int val = nd->u.shop.shop_item[i].value;
  1740. if( id == NULL )
  1741. continue;
  1742. WFIFOL(fd, 4+c*11) = val;
  1743. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1744. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1745. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1746. c++;
  1747. }
  1748. WFIFOW(fd,2) = 4 + c*11;
  1749. WFIFOSET(fd,WFIFOW(fd,2));
  1750. }
  1751. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1752. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1753. void clif_selllist(struct map_session_data *sd)
  1754. {
  1755. int fd,i,c=0,val;
  1756. struct npc_data *nd;
  1757. nullpo_retv(sd);
  1758. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1759. return;
  1760. fd=sd->fd;
  1761. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1762. WFIFOW(fd,0)=0xc7;
  1763. for( i = 0; i < MAX_INVENTORY; i++ )
  1764. {
  1765. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1766. {
  1767. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1768. continue;
  1769. val=sd->inventory_data[i]->value_sell;
  1770. if( val < 0 )
  1771. continue;
  1772. WFIFOW(fd,4+c*10)=i+2;
  1773. WFIFOL(fd,6+c*10)=val;
  1774. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1775. c++;
  1776. }
  1777. }
  1778. WFIFOW(fd,2)=c*10+4;
  1779. WFIFOSET(fd,WFIFOW(fd,2));
  1780. }
  1781. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1782. /// 09d4
  1783. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1784. // TODO: State tracking?
  1785. sd->npc_shopid = 0;
  1786. }
  1787. /**
  1788. * Presents list of items, that can be sold to a Market shop.
  1789. * @author: Ind and Yommy
  1790. **/
  1791. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1792. #if PACKETVER >= 20131223
  1793. struct npc_item_list *shop = nd->u.shop.shop_item;
  1794. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1795. struct item_data *id = NULL;
  1796. struct s_packet_db *info;
  1797. int fd;
  1798. nullpo_retv(sd);
  1799. if (sd->state.trading)
  1800. return;
  1801. info = &packet_db[cmd];
  1802. if (!info || info->len == 0)
  1803. return;
  1804. fd = sd->fd;
  1805. WFIFOHEAD(fd, 4 + shop_size * 13);
  1806. WFIFOW(fd,0) = cmd;
  1807. for (i = 0, c = 0; i < shop_size; i++) {
  1808. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1809. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1810. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1811. WFIFOL(fd, 7+c*13) = shop[i].value;
  1812. WFIFOL(fd,11+c*13) = shop[i].qty;
  1813. WFIFOW(fd,15+c*13) = id->weight;
  1814. c++;
  1815. }
  1816. }
  1817. WFIFOW(fd,2) = 4 + c*13;
  1818. WFIFOSET(fd,WFIFOW(fd,2));
  1819. sd->state.trading = 1;
  1820. #endif
  1821. }
  1822. /// Closes the Market shop window.
  1823. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1824. nullpo_retv(sd);
  1825. sd->npc_shopid = 0;
  1826. sd->state.trading = 0;
  1827. }
  1828. /// Purchase item from Market shop.
  1829. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1830. #if PACKETVER >= 20131223
  1831. unsigned short cmd = 0x9d7, len = 0;
  1832. struct npc_data* nd;
  1833. uint8 result = (res == 0 ? 1 : 0);
  1834. int fd = 0;
  1835. struct s_packet_db *info;
  1836. nullpo_retv(sd);
  1837. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1838. info = &packet_db[cmd];
  1839. if (!info || info->len == 0)
  1840. return;
  1841. fd = sd->fd;
  1842. len = 5 + 8*n;
  1843. WFIFOHEAD(fd, len);
  1844. WFIFOW(fd, 0) = cmd;
  1845. WFIFOW(fd, 2) = len;
  1846. if (result) {
  1847. uint8 i, j;
  1848. struct npc_item_list *shop = nd->u.shop.shop_item;
  1849. unsigned short count = nd->u.shop.count;
  1850. for (i = 0; i < n; i++) {
  1851. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1852. WFIFOW(fd, 7+i*8) = list[i].qty;
  1853. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1854. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1855. }
  1856. }
  1857. WFIFOB(fd, 4) = n;
  1858. WFIFOSET(fd, len);
  1859. #endif
  1860. }
  1861. /// Purchase item from Market shop.
  1862. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1863. #if PACKETVER >= 20131223
  1864. struct s_packet_db* info;
  1865. struct s_npc_buy_list *item_list;
  1866. uint16 len = 0, i = 0;
  1867. uint8 res = 0, n = 0;
  1868. nullpo_retv(sd);
  1869. if (!sd->npc_shopid)
  1870. return;
  1871. info = &packet_db[RFIFOW(fd,0)];
  1872. if (!info || info->len == 0)
  1873. return;
  1874. len = RFIFOW(fd,info->pos[0]);
  1875. n = (len-4) / 6;
  1876. CREATE(item_list, struct s_npc_buy_list, n);
  1877. for (i = 0; i < n; i++) {
  1878. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1879. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1880. }
  1881. res = npc_buylist(sd, n, item_list);
  1882. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1883. aFree(item_list);
  1884. #endif
  1885. }
  1886. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1887. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1888. /// Client behavior (dialog window):
  1889. /// - disable mouse targeting
  1890. /// - open the dialog window
  1891. /// - set npcid of dialog window (0 by default)
  1892. /// - if set to clear on next mes, clear contents
  1893. /// - append this text
  1894. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1895. {
  1896. int fd = sd->fd;
  1897. int slen = strlen(mes) + 9;
  1898. WFIFOHEAD(fd, slen);
  1899. WFIFOW(fd,0)=0xb4;
  1900. WFIFOW(fd,2)=slen;
  1901. WFIFOL(fd,4)=npcid;
  1902. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1903. WFIFOSET(fd,WFIFOW(fd,2));
  1904. }
  1905. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1906. /// 00b5 <npc id>.L
  1907. /// Client behavior (dialog window):
  1908. /// - disable mouse targeting
  1909. /// - open the dialog window
  1910. /// - add 'next' button
  1911. /// When 'next' is pressed:
  1912. /// - 00B9 <npcid of dialog window>.L
  1913. /// - set to clear on next mes
  1914. /// - remove 'next' button
  1915. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1916. {
  1917. int fd;
  1918. nullpo_retv(sd);
  1919. fd=sd->fd;
  1920. WFIFOHEAD(fd, packet_len(0xb5));
  1921. WFIFOW(fd,0)=0xb5;
  1922. WFIFOL(fd,2)=npcid;
  1923. WFIFOSET(fd,packet_len(0xb5));
  1924. }
  1925. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1926. /// 00b6 <npc id>.L
  1927. /// Client behavior:
  1928. /// - if dialog window is open:
  1929. /// - remove 'next' button
  1930. /// - add 'close' button
  1931. /// - else:
  1932. /// - enable mouse targeting
  1933. /// - close the dialog window
  1934. /// - close the menu window
  1935. /// When 'close' is pressed:
  1936. /// - enable mouse targeting
  1937. /// - close the dialog window
  1938. /// - close the menu window
  1939. /// - 0146 <npcid of dialog window>.L
  1940. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1941. {
  1942. int fd;
  1943. nullpo_retv(sd);
  1944. fd=sd->fd;
  1945. WFIFOHEAD(fd, packet_len(0xb6));
  1946. WFIFOW(fd,0)=0xb6;
  1947. WFIFOL(fd,2)=npcid;
  1948. WFIFOSET(fd,packet_len(0xb6));
  1949. }
  1950. /**
  1951. * Close script when player is idle
  1952. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1953. * @author [Ind/Hercules]
  1954. * @param sd : player pointer
  1955. * @param npcid : npc gid to close
  1956. */
  1957. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1958. {
  1959. struct s_packet_db* info;
  1960. int16 len;
  1961. int cmd = 0;
  1962. int fd;
  1963. nullpo_retv(sd);
  1964. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  1965. if(!cmd) cmd = 0x8d6; //default
  1966. info = &packet_db[cmd];
  1967. len = info->len;
  1968. fd = sd->fd;
  1969. WFIFOHEAD(fd, len);
  1970. WFIFOW(fd,0)=0x8d6;
  1971. WFIFOL(fd,info->pos[0])=npcid;
  1972. WFIFOSET(fd,len);
  1973. }
  1974. /*==========================================
  1975. *
  1976. *------------------------------------------*/
  1977. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1978. unsigned char *buf;
  1979. int fd = sd->fd;
  1980. sd->state.using_fake_npc = 1;
  1981. WFIFOHEAD(fd, packet_len(0x78));
  1982. buf = WFIFOP(fd,0);
  1983. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1984. WBUFW(buf,0)=0x78;
  1985. #if PACKETVER >= 20071106
  1986. WBUFB(buf,2) = 0; // object type
  1987. buf = WFIFOP(fd,1);
  1988. #endif
  1989. WBUFL(buf,2)=npcid;
  1990. WBUFW(buf,14)=111;
  1991. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1992. WBUFB(buf,49)=5;
  1993. WBUFB(buf,50)=5;
  1994. WFIFOSET(fd, packet_len(0x78));
  1995. }
  1996. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1997. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1998. /// Client behavior:
  1999. /// - disable mouse targeting
  2000. /// - close the menu window
  2001. /// - open the menu window
  2002. /// - add options to the menu (separated in the text by ":")
  2003. /// - set npcid of menu window
  2004. /// - if dialog window is open:
  2005. /// - remove 'next' button
  2006. /// When 'ok' is pressed:
  2007. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2008. /// - close the menu window
  2009. /// When 'cancel' is pressed:
  2010. /// - 00B8 <npcid of menu window>.L <-1>.B
  2011. /// - enable mouse targeting
  2012. /// - close a bunch of windows...
  2013. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2014. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2015. /// TODO investigate behavior of other windows [FlavioJS]
  2016. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  2017. {
  2018. int fd = sd->fd;
  2019. int slen = strlen(mes) + 9;
  2020. struct block_list *bl = NULL;
  2021. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2022. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2023. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2024. clif_sendfakenpc(sd, npcid);
  2025. WFIFOHEAD(fd, slen);
  2026. WFIFOW(fd,0)=0xb7;
  2027. WFIFOW(fd,2)=slen;
  2028. WFIFOL(fd,4)=npcid;
  2029. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2030. WFIFOSET(fd,WFIFOW(fd,2));
  2031. }
  2032. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2033. /// 0142 <npc id>.L
  2034. /// Client behavior (inputnum window):
  2035. /// - if npcid exists in the client:
  2036. /// - open the inputnum window
  2037. /// - set npcid of inputnum window
  2038. /// When 'ok' is pressed:
  2039. /// - if inputnum window has text:
  2040. /// - if npcid exists in the client:
  2041. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2042. /// - close inputnum window
  2043. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2044. {
  2045. int fd;
  2046. struct block_list *bl = NULL;
  2047. nullpo_retv(sd);
  2048. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2049. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2050. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2051. clif_sendfakenpc(sd, npcid);
  2052. fd=sd->fd;
  2053. WFIFOHEAD(fd, packet_len(0x142));
  2054. WFIFOW(fd,0)=0x142;
  2055. WFIFOL(fd,2)=npcid;
  2056. WFIFOSET(fd,packet_len(0x142));
  2057. }
  2058. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2059. /// 01d4 <npc id>.L
  2060. /// Client behavior (inputstr window):
  2061. /// - if npcid is 0 or npcid exists in the client:
  2062. /// - open the inputstr window
  2063. /// - set npcid of inputstr window
  2064. /// When 'ok' is pressed:
  2065. /// - if inputstr window has text and isn't an insult(manner.txt):
  2066. /// - if npcid is 0 or npcid exists in the client:
  2067. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2068. /// - close inputstr window
  2069. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2070. {
  2071. int fd;
  2072. struct block_list *bl = NULL;
  2073. nullpo_retv(sd);
  2074. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2075. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2076. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2077. clif_sendfakenpc(sd, npcid);
  2078. fd=sd->fd;
  2079. WFIFOHEAD(fd, packet_len(0x1d4));
  2080. WFIFOW(fd,0)=0x1d4;
  2081. WFIFOL(fd,2)=npcid;
  2082. WFIFOSET(fd,packet_len(0x1d4));
  2083. }
  2084. /// Marks a position on client's minimap (ZC_COMPASS).
  2085. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2086. /// npc id:
  2087. /// is ignored in the client
  2088. /// type:
  2089. /// 0 = display mark for 15 seconds
  2090. /// 1 = display mark until dead or teleported
  2091. /// 2 = remove mark
  2092. /// color:
  2093. /// 0x00RRGGBB
  2094. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2095. {
  2096. int fd;
  2097. nullpo_retv(sd);
  2098. fd=sd->fd;
  2099. WFIFOHEAD(fd, packet_len(0x144));
  2100. WFIFOW(fd,0)=0x144;
  2101. WFIFOL(fd,2)=npc_id;
  2102. WFIFOL(fd,6)=type;
  2103. WFIFOL(fd,10)=x;
  2104. WFIFOL(fd,14)=y;
  2105. WFIFOB(fd,18)=id;
  2106. WFIFOL(fd,19)=color;
  2107. WFIFOSET(fd,packet_len(0x144));
  2108. }
  2109. /// Displays an illustration image.
  2110. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2111. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2112. /// type:
  2113. /// 0 = bottom left corner
  2114. /// 1 = bottom middle
  2115. /// 2 = bottom right corner
  2116. /// 3 = middle of screen, inside a movable window
  2117. /// 4 = middle of screen, movable with a close button, chrome-less
  2118. /// 255 = clear all displayed cutins
  2119. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2120. {
  2121. int fd;
  2122. nullpo_retv(sd);
  2123. fd=sd->fd;
  2124. WFIFOHEAD(fd, packet_len(0x1b3));
  2125. WFIFOW(fd,0)=0x1b3;
  2126. strncpy(WFIFOCP(fd,2),image,64);
  2127. WFIFOB(fd,66)=type;
  2128. WFIFOSET(fd,packet_len(0x1b3));
  2129. }
  2130. /*==========================================
  2131. * Fills in card data from the given item and into the buffer. [Skotlex]
  2132. *------------------------------------------*/
  2133. static void clif_addcards(unsigned char* buf, struct item* item)
  2134. {
  2135. int i=0,j;
  2136. if( item == NULL ) { //Blank data
  2137. WBUFW(buf,0) = 0;
  2138. WBUFW(buf,2) = 0;
  2139. WBUFW(buf,4) = 0;
  2140. WBUFW(buf,6) = 0;
  2141. return;
  2142. }
  2143. if( item->card[0] == CARD0_PET ) { //pet eggs
  2144. WBUFW(buf,0) = 0;
  2145. WBUFW(buf,2) = 0;
  2146. WBUFW(buf,4) = 0;
  2147. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2148. return;
  2149. }
  2150. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2151. WBUFW(buf,0) = item->card[0];
  2152. WBUFW(buf,2) = item->card[1];
  2153. WBUFW(buf,4) = item->card[2];
  2154. WBUFW(buf,6) = item->card[3];
  2155. return;
  2156. }
  2157. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2158. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2159. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2160. //Normal items.
  2161. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2162. WBUFW(buf,0) = j;
  2163. else
  2164. WBUFW(buf,0) = item->card[i];
  2165. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2166. WBUFW(buf,2) = j;
  2167. else
  2168. WBUFW(buf,2) = item->card[i];
  2169. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2170. WBUFW(buf,4) = j;
  2171. else
  2172. WBUFW(buf,4) = item->card[i];
  2173. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2174. WBUFW(buf,6) = j;
  2175. else
  2176. WBUFW(buf,6) = item->card[i];
  2177. }
  2178. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2179. /// A maximum of 5 random options can be supported.
  2180. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2181. #if PACKETVER >= 20150225
  2182. int i;
  2183. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2184. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2185. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2186. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2187. }
  2188. #if MAX_ITEM_RDM_OPT < 5
  2189. for ( ; i < 5; i++) {
  2190. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2191. WBUFW(buf, i*5 + 2) = 0; // Value
  2192. WBUFB(buf, i*5 + 4) = 0; // Param1
  2193. }
  2194. #endif
  2195. #endif
  2196. }
  2197. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2198. /// 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)
  2199. /// 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)
  2200. /// 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)
  2201. /// 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)
  2202. /// 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)
  2203. /// 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)
  2204. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2205. {
  2206. int fd, header, offs=0;
  2207. #if PACKETVER < 20061218
  2208. header = 0xa0;
  2209. #elif PACKETVER < 20071002
  2210. header = 0x29a;
  2211. #elif PACKETVER < 20120925
  2212. header = 0x2d4;
  2213. #elif PACKETVER < 20150225
  2214. header = 0x990;
  2215. #elif PACKETVER < 20160921
  2216. header = 0xa0c;
  2217. #else
  2218. header = 0xa37;
  2219. #endif
  2220. nullpo_retv(sd);
  2221. fd = sd->fd;
  2222. if( !session_isActive(fd) ) //Sasuke-
  2223. return;
  2224. WFIFOHEAD(fd,packet_len(header));
  2225. if( fail )
  2226. {
  2227. WFIFOW(fd,offs+0) = header;
  2228. WFIFOW(fd,offs+2) = n+2;
  2229. WFIFOW(fd,offs+4) = amount;
  2230. WFIFOW(fd,offs+6) = 0;
  2231. WFIFOB(fd,offs+8) = 0;
  2232. WFIFOB(fd,offs+9) = 0;
  2233. WFIFOB(fd,offs+10) = 0;
  2234. WFIFOW(fd,offs+11) = 0;
  2235. WFIFOW(fd,offs+13) = 0;
  2236. WFIFOW(fd,offs+15) = 0;
  2237. WFIFOW(fd,offs+17) = 0;
  2238. #if PACKETVER < 20120925
  2239. WFIFOW(fd,offs+19) = 0;
  2240. #else
  2241. WFIFOL(fd,offs+19) = 0;
  2242. offs += 2;
  2243. #endif
  2244. WFIFOB(fd,offs+21) = 0;
  2245. WFIFOB(fd,offs+22) = fail;
  2246. #if PACKETVER >= 20061218
  2247. WFIFOL(fd,offs+23) = 0;
  2248. #endif
  2249. #if PACKETVER >= 20071002
  2250. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2251. #if PACKETVER >= 20150225
  2252. clif_add_random_options(WFIFOP(fd,offs+31), &sd->inventory.u.items_inventory[n]);
  2253. #if PACKETVER >= 20160921
  2254. WFIFOB(fd,offs+54) = 0; // Favorite
  2255. WFIFOW(fd,offs+55) = 0; // View ID
  2256. #endif
  2257. #endif
  2258. #endif
  2259. }
  2260. else
  2261. {
  2262. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2263. return;
  2264. WFIFOW(fd,offs+0) = header;
  2265. WFIFOW(fd,offs+2) = n+2;
  2266. WFIFOW(fd,offs+4) = amount;
  2267. if (sd->inventory_data[n]->view_id > 0)
  2268. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2269. else
  2270. WFIFOW(fd,offs+6)=sd->inventory.u.items_inventory[n].nameid;
  2271. WFIFOB(fd,offs+8)=sd->inventory.u.items_inventory[n].identify;
  2272. WFIFOB(fd,offs+9)=sd->inventory.u.items_inventory[n].attribute;
  2273. WFIFOB(fd,offs+10)=sd->inventory.u.items_inventory[n].refine;
  2274. clif_addcards(WFIFOP(fd,offs+11), &sd->inventory.u.items_inventory[n]);
  2275. #if PACKETVER < 20120925
  2276. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2277. #else
  2278. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2279. offs += 2;
  2280. #endif
  2281. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2282. WFIFOB(fd,offs+22) = fail;
  2283. #if PACKETVER >= 20061218
  2284. WFIFOL(fd,offs+23)=sd->inventory.u.items_inventory[n].expire_time;
  2285. #endif
  2286. #if PACKETVER >= 20071002
  2287. /* Yellow color only for non-stackable item */
  2288. WFIFOW(fd,offs+27)=(sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable(sd->inventory.u.items_inventory[n].nameid)) ? BOUND_DISPYELLOW : sd->inventory_data[n]->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2289. #endif
  2290. #if PACKETVER >= 20150225
  2291. clif_add_random_options(WFIFOP(fd,31), &sd->inventory.u.items_inventory[n]);
  2292. #if PACKETVER >= 20160921
  2293. WFIFOB(fd,offs+54) = sd->inventory.u.items_inventory[n].favorite;
  2294. WFIFOW(fd,offs+55) = sd->inventory_data[n]->look;
  2295. #endif
  2296. #endif
  2297. }
  2298. WFIFOSET(fd,packet_len(header));
  2299. }
  2300. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2301. /// 00af <index>.W <amount>.W
  2302. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2303. {
  2304. int fd;
  2305. nullpo_retv(sd);
  2306. fd=sd->fd;
  2307. WFIFOHEAD(fd, packet_len(0xaf));
  2308. WFIFOW(fd,0)=0xaf;
  2309. WFIFOW(fd,2)=n+2;
  2310. WFIFOW(fd,4)=amount;
  2311. WFIFOSET(fd,packet_len(0xaf));
  2312. }
  2313. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2314. /// 07fa <delete type>.W <index>.W <amount>.W
  2315. /// delete type:
  2316. /// 0 = Normal
  2317. /// 1 = Item used for a skill
  2318. /// 2 = Refine failed
  2319. /// 3 = Material changed
  2320. /// 4 = Moved to storage
  2321. /// 5 = Moved to cart
  2322. /// 6 = Item sold
  2323. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2324. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2325. {
  2326. #if PACKETVER < 20091117
  2327. clif_dropitem(sd,n,amount);
  2328. #else
  2329. int fd;
  2330. nullpo_retv(sd);
  2331. fd=sd->fd;
  2332. WFIFOHEAD(fd, packet_len(0x7fa));
  2333. WFIFOW(fd,0)=0x7fa;
  2334. WFIFOW(fd,2)=reason;
  2335. WFIFOW(fd,4)=n+2;
  2336. WFIFOW(fd,6)=amount;
  2337. WFIFOSET(fd,packet_len(0x7fa));
  2338. #endif
  2339. }
  2340. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2341. char normal = (equip < 0);
  2342. int offset = 0;
  2343. WBUFW(buf,n) = idx; //index
  2344. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2345. WBUFB(buf,n+4) = itemtype(id->nameid);
  2346. if (!normal){ //equip 31B
  2347. WBUFL(buf,n+5) = equip; //location
  2348. WBUFL(buf,n+9) = it->equip; //wear state
  2349. WBUFB(buf,n+13) = it->refine; //refine lvl
  2350. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2351. WBUFL(buf,n+22) = it->expire_time;
  2352. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2353. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2354. #if PACKETVER >= 20150225
  2355. //V6_ITEM_Option
  2356. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2357. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2358. offset += 26;
  2359. #endif
  2360. //V5_ITEM_flag
  2361. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2362. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2363. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2364. }
  2365. else { //normal 24B
  2366. WBUFW(buf,n+5) = it->amount;
  2367. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2368. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2369. WBUFL(buf,n+19) = it->expire_time;
  2370. //V5_ITEM_flag
  2371. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2372. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2373. }
  2374. }
  2375. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2376. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2377. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2378. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2379. #if PACKETVER >= 20120925
  2380. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2381. #else
  2382. WBUFW(buf,n) = idx; //index
  2383. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2384. WBUFB(buf,n+4) = itemtype(id->nameid);
  2385. WBUFB(buf,n+5) = it->identify;
  2386. if (equip >= 0) { //Equippable item 28.B
  2387. WBUFW(buf,n+6) = equip;
  2388. WBUFW(buf,n+8) = it->equip;
  2389. WBUFB(buf,n+10) = it->attribute;
  2390. WBUFB(buf,n+11) = it->refine;
  2391. clif_addcards(WBUFP(buf, n+12), it); //8B
  2392. #if PACKETVER >= 20071002
  2393. WBUFL(buf,n+20) = it->expire_time;
  2394. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2395. #endif
  2396. #if PACKETVER >= 20100629
  2397. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2398. #endif
  2399. } else { //Stackable item. 22.B
  2400. WBUFW(buf,n+6) = it->amount;
  2401. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2402. clif_addcards(WBUFP(buf, n+10), it); //8B
  2403. #if PACKETVER >= 20071002
  2404. WBUFL(buf,n+18) = it->expire_time;
  2405. #endif
  2406. }
  2407. #endif
  2408. }
  2409. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2410. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2411. void clif_inventorylist(struct map_session_data *sd) {
  2412. int i,n,ne,arrow=-1;
  2413. unsigned char *buf;
  2414. unsigned char *bufe;
  2415. #if PACKETVER < 5
  2416. const int s = 10; //Entry size
  2417. #elif PACKETVER < 20080102
  2418. const int s = 18;
  2419. #elif PACKETVER < 20120925
  2420. const int s = 22;
  2421. #else
  2422. const int s = 24;
  2423. #endif
  2424. #if PACKETVER < 20071002
  2425. const int se = 20;
  2426. #elif PACKETVER < 20100629
  2427. const int se = 26;
  2428. #elif PACKETVER < 20120925
  2429. const int se = 28;
  2430. #elif PACKETVER < 20150225
  2431. const int se = 31;
  2432. #else
  2433. const int se = 57;
  2434. #endif
  2435. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2436. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2437. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2438. {
  2439. if( sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2440. continue;
  2441. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2442. { //Non-stackable (Equippable)
  2443. clif_item_sub(bufe, ne*se+4, i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2444. ne++;
  2445. }
  2446. else { //Stackable.
  2447. clif_item_sub(buf, n*s+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], -2);
  2448. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->inventory.u.items_inventory[i].equip )
  2449. arrow=i;
  2450. n++;
  2451. }
  2452. }
  2453. if( n )
  2454. {
  2455. #if PACKETVER < 5
  2456. WBUFW(buf,0)=0xa3;
  2457. #elif PACKETVER < 20080102
  2458. WBUFW(buf,0)=0x1ee;
  2459. #elif PACKETVER < 20120925
  2460. WBUFW(buf,0)=0x2e8;
  2461. #else
  2462. WBUFW(buf,0)=0x991;
  2463. #endif
  2464. WBUFW(buf,2)=4+n*s;
  2465. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2466. }
  2467. if( arrow >= 0 )
  2468. clif_arrowequip(sd,arrow);
  2469. if( ne ) {
  2470. #if PACKETVER < 20071002
  2471. WBUFW(bufe,0)=0xa4;
  2472. #elif PACKETVER < 20120925
  2473. WBUFW(bufe,0)=0x2d0;
  2474. #elif PACKETVER < 20150225
  2475. WBUFW(bufe,0)=0x992;
  2476. #else
  2477. WBUFW(bufe,0)=0xa0d;
  2478. #endif
  2479. WBUFW(bufe,2)=4+ne*se;
  2480. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2481. }
  2482. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2483. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2484. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2485. continue;
  2486. if ( sd->inventory.u.items_inventory[i].favorite )
  2487. clif_favorite_item(sd, i);
  2488. }
  2489. #endif
  2490. if( buf ) aFree(buf);
  2491. if( bufe ) aFree(bufe);
  2492. }
  2493. //Required when items break/get-repaired. Only sends equippable item list.
  2494. void clif_equiplist(struct map_session_data *sd)
  2495. {
  2496. int i,n,fd = sd->fd;
  2497. unsigned char *buf;
  2498. #if PACKETVER < 20071002
  2499. const int cmd = 20;
  2500. #elif PACKETVER < 20100629
  2501. const int cmd = 26;
  2502. #elif PACKETVER < 20120925
  2503. const int cmd = 28;
  2504. #elif PACKETVER < 20150225
  2505. const int cmd = 31;
  2506. #else
  2507. const int cmd = 57;
  2508. #endif
  2509. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2510. buf = WFIFOP(fd,0);
  2511. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2512. if (sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2513. continue;
  2514. if(itemdb_isstackable2(sd->inventory_data[i]))
  2515. continue;
  2516. //Equippable
  2517. clif_item_sub(buf, n*cmd+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2518. n++;
  2519. }
  2520. if (n) {
  2521. #if PACKETVER < 20071002
  2522. WBUFW(buf,0)=0xa4;
  2523. #elif PACKETVER < 20120925
  2524. WBUFW(buf,0)=0x2d0;
  2525. #elif PACKETVER < 20150225
  2526. WBUFW(buf,0)=0x992;
  2527. #else
  2528. WBUFW(buf,0)=0xa0d;
  2529. #endif
  2530. WBUFW(buf,2)=4+n*cmd;
  2531. WFIFOSET(fd,WFIFOW(fd,2));
  2532. }
  2533. }
  2534. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename)
  2535. {
  2536. static const int client_buf = 0x5000; // Max buffer to send
  2537. struct item_data *id;
  2538. int i,n,ne,nn;
  2539. unsigned char *buf;
  2540. unsigned char *bufe;
  2541. #if PACKETVER < 5
  2542. const int s = 10; //Entry size.normal item
  2543. const int sidx=4; //start itemlist idx
  2544. const int cmd = 0xa5;
  2545. #elif PACKETVER < 20080102
  2546. const int s = 18;
  2547. const int sidx=4;
  2548. const int cmd = 0x1f0;
  2549. #elif PACKETVER < 20120925
  2550. const int s = 22;
  2551. const int sidx=4;
  2552. const int cmd = 0x2ea;
  2553. #else
  2554. const int s = 24;
  2555. const int sidx = 4+24;
  2556. const int cmd = 0x995;
  2557. #endif
  2558. #if PACKETVER < 20071002
  2559. const int se = 20; //entry size equip
  2560. const int sidxe = 4; //start itemlist idx
  2561. const int cmde = 0xa6;
  2562. #elif PACKETVER < 20100629
  2563. const int se = 26;
  2564. const int sidxe = 4;
  2565. const int cmde = 0x2d1;
  2566. #elif PACKETVER < 20120925
  2567. const int se = 28;
  2568. const int sidxe = 4;
  2569. const int cmde = 0x2d1;
  2570. #elif PACKETVER < 20150225
  2571. const int se = 31;
  2572. const int sidxe = 4+24;
  2573. const int cmde = 0x996;
  2574. #else
  2575. const int se = 57;
  2576. const int sidxe = 4+24;
  2577. const int cmde = 0xa10;
  2578. #endif
  2579. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2580. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2581. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2582. {
  2583. if( items[i].nameid <= 0 )
  2584. continue;
  2585. id = itemdb_search(items[i].nameid);
  2586. if( !itemdb_isstackable2(id) ) { //Equippable
  2587. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2588. ne++;
  2589. }
  2590. else { //Stackable
  2591. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2592. n++;
  2593. }
  2594. }
  2595. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2596. {
  2597. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2598. WFIFOHEAD(sd->fd,sidx+nn*s);
  2599. WFIFOW(sd->fd,0)=cmd;
  2600. WFIFOW(sd->fd,2)=sidx+nn*s;
  2601. #if PACKETVER >= 20120925
  2602. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2603. #endif
  2604. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2605. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2606. }
  2607. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2608. {
  2609. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2610. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2611. WFIFOW(sd->fd,0)=cmde;
  2612. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2613. #if PACKETVER >= 20120925
  2614. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2615. #endif
  2616. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2617. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2618. }
  2619. // Empty storage
  2620. if (n == 0 && ne == 0) {
  2621. WFIFOHEAD(sd->fd, 4+NAME_LENGTH);
  2622. WFIFOW(sd->fd,0) = cmd;
  2623. WFIFOW(sd->fd,2) = 4+NAME_LENGTH;
  2624. #if PACKETVER >= 20120925
  2625. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2626. #endif
  2627. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2628. }
  2629. if( buf ) aFree(buf);
  2630. if( bufe ) aFree(bufe);
  2631. }
  2632. void clif_cartlist(struct map_session_data *sd)
  2633. {
  2634. struct item_data *id;
  2635. int i,n,ne;
  2636. unsigned char *buf;
  2637. unsigned char *bufe;
  2638. #if PACKETVER < 5
  2639. const int s = 10; //Entry size.
  2640. #elif PACKETVER < 20080102
  2641. const int s = 18;
  2642. #elif PACKETVER < 20120925
  2643. const int s = 22;
  2644. #else
  2645. const int s = 24;
  2646. #endif
  2647. #if PACKETVER < 20071002
  2648. const int cmd = 20;
  2649. #elif PACKETVER < 20100629
  2650. const int cmd = 26;
  2651. #elif PACKETVER < 20120925
  2652. const int cmd = 28;
  2653. #elif PACKETVER < 20150225
  2654. const int cmd = 31;
  2655. #else
  2656. const int cmd = 57;
  2657. #endif
  2658. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2659. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2660. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2661. {
  2662. if( sd->cart.u.items_cart[i].nameid <= 0 )
  2663. continue;
  2664. id = itemdb_search(sd->cart.u.items_cart[i].nameid);
  2665. if( !itemdb_isstackable2(id) ) { //Equippable
  2666. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->cart.u.items_cart[i], id, id->equip);
  2667. ne++;
  2668. }
  2669. else { //Stackable
  2670. clif_item_sub(buf, n*s+4,i+2, &sd->cart.u.items_cart[i], id,-1);
  2671. n++;
  2672. }
  2673. }
  2674. if( n )
  2675. {
  2676. #if PACKETVER < 5
  2677. WBUFW(buf,0)=0x123;
  2678. #elif PACKETVER < 20080102
  2679. WBUFW(buf,0)=0x1ef;
  2680. #elif PACKETVER < 20120925
  2681. WBUFW(buf,0)=0x2e9;
  2682. #else
  2683. WBUFW(buf,0)=0x993;
  2684. #endif
  2685. WBUFW(buf,2)=4+n*s;
  2686. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2687. }
  2688. if( ne )
  2689. {
  2690. #if PACKETVER < 20071002
  2691. WBUFW(bufe,0)=0x122;
  2692. #elif PACKETVER < 20120925
  2693. WBUFW(bufe,0)=0x2d2;
  2694. #elif PACKETVER < 20150225
  2695. WBUFW(bufe,0)=0x994;
  2696. #else
  2697. WBUFW(bufe,0)=0xa0f;
  2698. #endif
  2699. WBUFW(bufe,2)=4+ne*cmd;
  2700. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2701. }
  2702. if( buf ) aFree(buf);
  2703. if( bufe ) aFree(bufe);
  2704. }
  2705. /// Removes cart (ZC_CARTOFF).
  2706. /// 012b
  2707. /// Client behaviour:
  2708. /// Closes the cart storage and removes all it's items from memory.
  2709. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2710. void clif_clearcart(int fd)
  2711. {
  2712. WFIFOHEAD(fd, packet_len(0x12b));
  2713. WFIFOW(fd,0) = 0x12b;
  2714. WFIFOSET(fd, packet_len(0x12b));
  2715. }
  2716. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2717. /// 01eb <account id>.L <x>.W <y>.W
  2718. void clif_guild_xy(struct map_session_data *sd)
  2719. {
  2720. unsigned char buf[10];
  2721. nullpo_retv(sd);
  2722. WBUFW(buf,0)=0x1eb;
  2723. WBUFL(buf,2)=sd->status.account_id;
  2724. WBUFW(buf,6)=sd->bl.x;
  2725. WBUFW(buf,8)=sd->bl.y;
  2726. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2727. }
  2728. /*==========================================
  2729. * Sends x/y dot to a single fd. [Skotlex]
  2730. *------------------------------------------*/
  2731. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2732. {
  2733. if( sd->bg_id )
  2734. return;
  2735. WFIFOHEAD(fd,packet_len(0x1eb));
  2736. WFIFOW(fd,0)=0x1eb;
  2737. WFIFOL(fd,2)=sd->status.account_id;
  2738. WFIFOW(fd,6)=sd->bl.x;
  2739. WFIFOW(fd,8)=sd->bl.y;
  2740. WFIFOSET(fd,packet_len(0x1eb));
  2741. }
  2742. // Guild XY locators [Valaris]
  2743. void clif_guild_xy_remove(struct map_session_data *sd)
  2744. {
  2745. unsigned char buf[10];
  2746. nullpo_retv(sd);
  2747. WBUFW(buf,0)=0x1eb;
  2748. WBUFL(buf,2)=sd->status.account_id;
  2749. WBUFW(buf,6)=-1;
  2750. WBUFW(buf,8)=-1;
  2751. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2752. }
  2753. /*==========================================
  2754. *
  2755. *------------------------------------------*/
  2756. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2757. {
  2758. struct map_session_data *sd, *tsd;
  2759. #if PACKETVER < 20100126
  2760. const int cmd = 0x106;
  2761. #else
  2762. const int cmd = 0x80e;
  2763. #endif
  2764. sd = va_arg(ap, struct map_session_data *);
  2765. tsd = (TBL_PC *)bl;
  2766. nullpo_ret(sd);
  2767. nullpo_ret(tsd);
  2768. if( !tsd->fd || tsd == sd )
  2769. return 0;
  2770. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2771. return 0;
  2772. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2773. WFIFOW(tsd->fd,0) = cmd;
  2774. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2775. #if PACKETVER < 20100126
  2776. if( sd->battle_status.max_hp > INT16_MAX )
  2777. { //To correctly display the %hp bar. [Skotlex]
  2778. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2779. WFIFOW(tsd->fd,8) = 100;
  2780. } else {
  2781. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2782. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2783. }
  2784. #else
  2785. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2786. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2787. #endif
  2788. WFIFOSET(tsd->fd,packet_len(cmd));
  2789. return 0;
  2790. }
  2791. /*==========================================
  2792. * Server tells all players that are allowed to view HP bars
  2793. * and are nearby 'sd' that 'sd' hp bar was updated.
  2794. *------------------------------------------*/
  2795. static int clif_hpmeter(struct map_session_data *sd)
  2796. {
  2797. nullpo_ret(sd);
  2798. 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);
  2799. return 0;
  2800. }
  2801. /// Notifies client of a character parameter change.
  2802. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2803. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2804. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2805. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2806. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2807. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2808. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2809. /// TODO: Extract individual packets.
  2810. /// FIXME: Packet lengths from packet_len(cmd)
  2811. void clif_updatestatus(struct map_session_data *sd,int type)
  2812. {
  2813. int fd,len=8;
  2814. nullpo_retv(sd);
  2815. fd=sd->fd;
  2816. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2817. return;
  2818. WFIFOHEAD(fd, 14);
  2819. WFIFOW(fd,0)=0xb0;
  2820. WFIFOW(fd,2)=type;
  2821. switch(type){
  2822. // 00b0
  2823. case SP_WEIGHT:
  2824. pc_updateweightstatus(sd);
  2825. WFIFOHEAD(fd,14);
  2826. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2827. WFIFOW(fd,2)=type;
  2828. WFIFOL(fd,4)=sd->weight;
  2829. break;
  2830. case SP_MAXWEIGHT:
  2831. WFIFOL(fd,4)=sd->max_weight;
  2832. break;
  2833. case SP_SPEED:
  2834. WFIFOL(fd,4)=sd->battle_status.speed;
  2835. break;
  2836. case SP_BASELEVEL:
  2837. WFIFOL(fd,4)=sd->status.base_level;
  2838. break;
  2839. case SP_JOBLEVEL:
  2840. WFIFOL(fd,4)=sd->status.job_level;
  2841. break;
  2842. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2843. WFIFOL(fd,4)=sd->status.karma;
  2844. break;
  2845. case SP_MANNER:
  2846. WFIFOL(fd,4)=sd->status.manner;
  2847. break;
  2848. case SP_STATUSPOINT:
  2849. WFIFOL(fd,4)=sd->status.status_point;
  2850. break;
  2851. case SP_SKILLPOINT:
  2852. WFIFOL(fd,4)=sd->status.skill_point;
  2853. break;
  2854. case SP_HIT:
  2855. WFIFOL(fd,4)=sd->battle_status.hit;
  2856. break;
  2857. case SP_FLEE1:
  2858. WFIFOL(fd,4)=sd->battle_status.flee;
  2859. break;
  2860. case SP_FLEE2:
  2861. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2862. break;
  2863. case SP_MAXHP:
  2864. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2865. break;
  2866. case SP_MAXSP:
  2867. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2868. break;
  2869. case SP_HP:
  2870. // On officials the HP never go below 1, even if you die [Lemongrass]
  2871. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2872. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2873. break;
  2874. case SP_SP:
  2875. WFIFOL(fd,4)=sd->battle_status.sp;
  2876. break;
  2877. case SP_ASPD:
  2878. WFIFOL(fd,4)=sd->battle_status.amotion;
  2879. break;
  2880. case SP_ATK1:
  2881. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2882. break;
  2883. case SP_DEF1:
  2884. WFIFOL(fd,4)=pc_leftside_def(sd);
  2885. break;
  2886. case SP_MDEF1:
  2887. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2888. break;
  2889. case SP_ATK2:
  2890. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2891. break;
  2892. case SP_DEF2:
  2893. WFIFOL(fd,4)=pc_rightside_def(sd);
  2894. break;
  2895. case SP_MDEF2: {
  2896. //negative check (in case you have something like Berserk active)
  2897. int mdef2 = pc_rightside_mdef(sd);
  2898. WFIFOL(fd,4)=
  2899. #ifndef RENEWAL
  2900. ( mdef2 < 0 ) ? 0 :
  2901. #endif
  2902. mdef2;
  2903. }
  2904. break;
  2905. case SP_CRITICAL:
  2906. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2907. break;
  2908. case SP_MATK1:
  2909. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2910. break;
  2911. case SP_MATK2:
  2912. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2913. break;
  2914. case SP_ZENY:
  2915. WFIFOW(fd,0)=0xb1;
  2916. WFIFOL(fd,4)=sd->status.zeny;
  2917. break;
  2918. #if PACKETVER >= 20170830
  2919. case SP_BASEEXP:
  2920. WFIFOW(fd,0)=0xacb;
  2921. WFIFOQ(fd,4)=sd->status.base_exp;
  2922. len = packet_len(0xacb);
  2923. break;
  2924. case SP_JOBEXP:
  2925. WFIFOW(fd,0)=0xacb;
  2926. WFIFOQ(fd,4)=sd->status.job_exp;
  2927. len = packet_len(0xacb);
  2928. break;
  2929. case SP_NEXTBASEEXP:
  2930. WFIFOW(fd,0)=0xacb;
  2931. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2932. len = packet_len(0xacb);
  2933. break;
  2934. case SP_NEXTJOBEXP:
  2935. WFIFOW(fd,0)=0xacb;
  2936. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2937. len = packet_len(0xacb);
  2938. break;
  2939. #else
  2940. case SP_BASEEXP:
  2941. WFIFOW(fd,0)=0xb1;
  2942. WFIFOL(fd,4)=sd->status.base_exp;
  2943. break;
  2944. case SP_JOBEXP:
  2945. WFIFOW(fd,0)=0xb1;
  2946. WFIFOL(fd,4)=sd->status.job_exp;
  2947. break;
  2948. case SP_NEXTBASEEXP:
  2949. WFIFOW(fd,0)=0xb1;
  2950. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2951. break;
  2952. case SP_NEXTJOBEXP:
  2953. WFIFOW(fd,0)=0xb1;
  2954. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2955. break;
  2956. #endif
  2957. /**
  2958. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2959. **/
  2960. case SP_USTR:
  2961. case SP_UAGI:
  2962. case SP_UVIT:
  2963. case SP_UINT:
  2964. case SP_UDEX:
  2965. case SP_ULUK:
  2966. WFIFOW(fd,0)=0xbe;
  2967. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2968. len=5;
  2969. break;
  2970. /**
  2971. * Tells the client how far it is allowed to attack (weapon range)
  2972. **/
  2973. case SP_ATTACKRANGE:
  2974. WFIFOW(fd,0)=0x13a;
  2975. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2976. len=4;
  2977. break;
  2978. case SP_STR:
  2979. WFIFOW(fd,0)=0x141;
  2980. WFIFOL(fd,2)=type;
  2981. WFIFOL(fd,6)=sd->status.str;
  2982. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2983. len=14;
  2984. break;
  2985. case SP_AGI:
  2986. WFIFOW(fd,0)=0x141;
  2987. WFIFOL(fd,2)=type;
  2988. WFIFOL(fd,6)=sd->status.agi;
  2989. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2990. len=14;
  2991. break;
  2992. case SP_VIT:
  2993. WFIFOW(fd,0)=0x141;
  2994. WFIFOL(fd,2)=type;
  2995. WFIFOL(fd,6)=sd->status.vit;
  2996. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2997. len=14;
  2998. break;
  2999. case SP_INT:
  3000. WFIFOW(fd,0)=0x141;
  3001. WFIFOL(fd,2)=type;
  3002. WFIFOL(fd,6)=sd->status.int_;
  3003. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3004. len=14;
  3005. break;
  3006. case SP_DEX:
  3007. WFIFOW(fd,0)=0x141;
  3008. WFIFOL(fd,2)=type;
  3009. WFIFOL(fd,6)=sd->status.dex;
  3010. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3011. len=14;
  3012. break;
  3013. case SP_LUK:
  3014. WFIFOW(fd,0)=0x141;
  3015. WFIFOL(fd,2)=type;
  3016. WFIFOL(fd,6)=sd->status.luk;
  3017. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3018. len=14;
  3019. break;
  3020. case SP_CARTINFO:
  3021. WFIFOW(fd,0)=0x121;
  3022. WFIFOW(fd,2)=sd->cart_num;
  3023. WFIFOW(fd,4)=MAX_CART;
  3024. WFIFOL(fd,6)=sd->cart_weight;
  3025. WFIFOL(fd,10)=sd->cart_weight_max;
  3026. len=14;
  3027. break;
  3028. default:
  3029. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3030. return;
  3031. }
  3032. WFIFOSET(fd,len);
  3033. // Additional update packets that should be sent right after
  3034. switch( type ){
  3035. case SP_BASELEVEL:
  3036. if( sd->status.party_id ){
  3037. struct party_data* p;
  3038. int i;
  3039. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3040. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3041. if( i < MAX_PARTY ){
  3042. p->party.member[i].lv = sd->status.base_level;
  3043. clif_party_job_and_level(sd);
  3044. }
  3045. }
  3046. }
  3047. break;
  3048. case SP_HP:
  3049. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3050. clif_hpmeter(sd);
  3051. }
  3052. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3053. clif_party_hp(sd);
  3054. }
  3055. if( sd->bg_id ){
  3056. clif_bg_hp(sd);
  3057. }
  3058. break;
  3059. }
  3060. }
  3061. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3062. /// 01ab <account id>.L <var id>.W <value>.L
  3063. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3064. {
  3065. unsigned char buf[12];
  3066. nullpo_retv(sd);
  3067. WBUFW(buf,0)=0x1ab;
  3068. WBUFL(buf,2)=sd->bl.id;
  3069. WBUFW(buf,6)=type;
  3070. switch(type)
  3071. {
  3072. case SP_MANNER:
  3073. WBUFL(buf,8)=val;
  3074. break;
  3075. default:
  3076. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3077. return;
  3078. }
  3079. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3080. }
  3081. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3082. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3083. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3084. unsigned char buf[32];
  3085. #if PACKETVER < 4
  3086. const int cmd = 0xc3;
  3087. #else
  3088. const int cmd = 0x1d7;
  3089. #endif
  3090. WBUFW(buf,0) = cmd;
  3091. WBUFL(buf,2) = id;
  3092. WBUFB(buf,6) = type;
  3093. WBUFW(buf,7) = val;
  3094. #if PACKETVER >= 4
  3095. WBUFW(buf,9) = val2;
  3096. #endif
  3097. clif_send(buf,packet_len(cmd), 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->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(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3224. nullpo_retv(vd);
  3225. type = LOOK_WEAPON;
  3226. val = vd->weapon;
  3227. val2 = vd->shield;
  3228. }
  3229. if( disguised(bl) ) {
  3230. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3231. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3232. } else
  3233. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3234. #endif
  3235. }
  3236. //Sends a change-base-look packet required for traps as they are triggered.
  3237. void clif_changetraplook(struct block_list *bl,int val) {
  3238. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3239. }
  3240. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3241. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3242. clif_sprite_change(bl, id, type, val, 0, target);
  3243. }
  3244. /// Character status (ZC_STATUS).
  3245. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3246. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3247. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3248. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3249. void clif_initialstatus(struct map_session_data *sd) {
  3250. int fd, mdef2;
  3251. unsigned char *buf;
  3252. nullpo_retv(sd);
  3253. fd=sd->fd;
  3254. WFIFOHEAD(fd, packet_len(0xbd));
  3255. buf = WFIFOP(fd,0);
  3256. WBUFW(buf,0) = 0xbd;
  3257. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3258. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3259. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3260. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3261. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3262. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3263. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3264. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3265. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3266. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3267. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3268. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3269. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3270. WBUFW(buf,16) = pc_leftside_atk(sd);
  3271. WBUFW(buf,18) = pc_rightside_atk(sd);
  3272. WBUFW(buf,20) = pc_rightside_matk(sd);
  3273. WBUFW(buf,22) = pc_leftside_matk(sd);
  3274. WBUFW(buf,24) = pc_leftside_def(sd);
  3275. WBUFW(buf,26) = pc_rightside_def(sd);
  3276. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3277. mdef2 = pc_rightside_mdef(sd);
  3278. WBUFW(buf,30) =
  3279. #ifndef RENEWAL
  3280. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3281. #endif
  3282. mdef2;
  3283. WBUFW(buf,32) = sd->battle_status.hit;
  3284. WBUFW(buf,34) = sd->battle_status.flee;
  3285. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3286. WBUFW(buf,38) = sd->battle_status.cri/10;
  3287. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3288. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3289. WFIFOSET(fd, packet_len(0xbd));
  3290. clif_updatestatus(sd, SP_STR);
  3291. clif_updatestatus(sd, SP_AGI);
  3292. clif_updatestatus(sd, SP_VIT);
  3293. clif_updatestatus(sd, SP_INT);
  3294. clif_updatestatus(sd, SP_DEX);
  3295. clif_updatestatus(sd, SP_LUK);
  3296. clif_updatestatus(sd, SP_ATTACKRANGE);
  3297. clif_updatestatus(sd, SP_ASPD);
  3298. }
  3299. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3300. /// 013c <index>.W
  3301. void clif_arrowequip(struct map_session_data *sd,int val) {
  3302. int fd;
  3303. nullpo_retv(sd);
  3304. #if PACKETVER >= 20121128
  3305. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3306. #endif
  3307. fd=sd->fd;
  3308. WFIFOHEAD(fd, packet_len(0x013c));
  3309. WFIFOW(fd,0) = 0x013c;
  3310. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3311. WFIFOSET(fd, packet_len(0x013c));
  3312. }
  3313. /// Ammunition action message (ZC_ACTION_FAILURE).
  3314. /// 013b <type>.W
  3315. /// type:
  3316. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3317. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3318. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3319. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3320. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3321. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3322. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3323. int fd;
  3324. nullpo_retv(sd);
  3325. fd=sd->fd;
  3326. WFIFOHEAD(fd, packet_len(0x013b));
  3327. WFIFOW(fd,0) = 0x013b;
  3328. WFIFOW(fd,2) = type;
  3329. WFIFOSET(fd, packet_len(0x013b));
  3330. }
  3331. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3332. /// 01ad <packet len>.W { <name id>.W }*
  3333. void clif_arrow_create_list(struct map_session_data *sd)
  3334. {
  3335. int i, c;
  3336. int fd;
  3337. nullpo_retv(sd);
  3338. fd = sd->fd;
  3339. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3340. WFIFOW(fd,0) = 0x1ad;
  3341. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3342. short j, nameid = skill_arrow_db[i].nameid;
  3343. if (nameid > 0 && itemdb_exists(nameid) &&
  3344. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3345. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3346. {
  3347. if ((j = itemdb_viewid(nameid)) > 0)
  3348. WFIFOW(fd,c*2+4) = j;
  3349. else
  3350. WFIFOW(fd,c*2+4) = nameid;
  3351. c++;
  3352. }
  3353. }
  3354. WFIFOW(fd,2) = c*2+4;
  3355. WFIFOSET(fd, WFIFOW(fd,2));
  3356. if (c > 0) {
  3357. sd->menuskill_id = AC_MAKINGARROW;
  3358. sd->menuskill_val = c;
  3359. }
  3360. }
  3361. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3362. /// 00bc <status id>.W <result>.B <value>.B
  3363. /// status id:
  3364. /// SP_STR ~ SP_LUK
  3365. /// result:
  3366. /// 0 = failure
  3367. /// 1 = success
  3368. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3369. int fd;
  3370. nullpo_retv(sd);
  3371. fd=sd->fd;
  3372. WFIFOHEAD(fd, packet_len(0xbc));
  3373. WFIFOW(fd,0) = 0xbc;
  3374. WFIFOW(fd,2) = type;
  3375. WFIFOB(fd,4) = ok;
  3376. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3377. WFIFOSET(fd, packet_len(0xbc));
  3378. }
  3379. /// Notifies the client about the result of a request to equip an item.
  3380. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3381. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3382. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3383. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3384. /// @ok: //inversed forv2 v5
  3385. /// 0 = failure
  3386. /// 1 = success
  3387. /// 2 = failure due to low level
  3388. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3389. {
  3390. int fd = 0, cmd = 0, look = 0;
  3391. struct s_packet_db *info = NULL;
  3392. nullpo_retv(sd);
  3393. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3394. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3395. return;
  3396. fd = sd->fd;
  3397. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3398. look = sd->inventory_data[n]->look;
  3399. WFIFOHEAD(fd, info->len);
  3400. WFIFOW(fd, 0) = cmd;
  3401. WFIFOW(fd, info->pos[0]) = n+2;
  3402. switch (cmd) {
  3403. case 0xaa:
  3404. WFIFOW(fd, info->pos[1]) = pos;
  3405. #if PACKETVER < 20100629
  3406. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3407. #else
  3408. WFIFOL(fd, info->pos[2]) = look;
  3409. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3410. #endif
  3411. break;
  3412. case 0x8d0:
  3413. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3414. flag = 1;
  3415. case 0x999:
  3416. if (cmd == 0x999)
  3417. WFIFOL(fd, info->pos[1]) = pos;
  3418. else
  3419. WFIFOW(fd, info->pos[1]) = pos;
  3420. WFIFOL(fd, info->pos[2]) = look;
  3421. WFIFOW(fd, info->pos[3]) = flag;
  3422. break;
  3423. }
  3424. WFIFOSET(fd, info->len);
  3425. }
  3426. /// Notifies the client about the result of a request to take off an item.
  3427. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3428. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3429. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3430. /// @ok : //inversed for v2 v5
  3431. /// 0 = failure
  3432. /// 1 = success
  3433. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3434. {
  3435. int fd, header, offs = 0;
  3436. #if PACKETVER >= 20130000
  3437. header = 0x99a;
  3438. ok = ok ? 0 : 1;
  3439. #elif PACKETVER >= 20110824
  3440. header = 0x8d1;
  3441. ok = ok ? 0 : 1;
  3442. #else
  3443. header = 0xac;
  3444. #endif
  3445. nullpo_retv(sd);
  3446. fd=sd->fd;
  3447. WFIFOHEAD(fd, packet_len(header));
  3448. WFIFOW(fd,offs+0) = header;
  3449. WFIFOW(fd,offs+2) = n+2;
  3450. #if PACKETVER >= 20130000
  3451. WFIFOL(fd,offs+4) = pos;
  3452. offs += 2;
  3453. #else
  3454. WFIFOW(fd,offs+4) = pos;
  3455. #endif
  3456. WFIFOB(fd,offs+6) = ok;
  3457. WFIFOSET(fd, packet_len(header));
  3458. }
  3459. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3460. /// 019b <id>.L <effect id>.L
  3461. /// effect id:
  3462. /// 0 = base level up
  3463. /// 1 = job level up
  3464. /// 2 = refine failure
  3465. /// 3 = refine success
  3466. /// 4 = game over
  3467. /// 5 = pharmacy success
  3468. /// 6 = pharmacy failure
  3469. /// 7 = base level up (super novice)
  3470. /// 8 = job level up (super novice)
  3471. /// 9 = base level up (taekwon)
  3472. void clif_misceffect(struct block_list* bl,int type)
  3473. {
  3474. unsigned char buf[32];
  3475. nullpo_retv(bl);
  3476. WBUFW(buf,0) = 0x19b;
  3477. WBUFL(buf,2) = bl->id;
  3478. WBUFL(buf,6) = type;
  3479. clif_send(buf,packet_len(0x19b),bl,AREA);
  3480. }
  3481. /// Notifies clients in the area of a state change.
  3482. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3483. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3484. void clif_changeoption(struct block_list* bl)
  3485. {
  3486. unsigned char buf[32];
  3487. struct status_change *sc;
  3488. struct map_session_data* sd;
  3489. nullpo_retv(bl);
  3490. sc = status_get_sc(bl);
  3491. if (!sc) return; //How can an option change if there's no sc?
  3492. sd = BL_CAST(BL_PC, bl);
  3493. #if PACKETVER >= 7
  3494. WBUFW(buf,0) = 0x229;
  3495. WBUFL(buf,2) = bl->id;
  3496. WBUFW(buf,6) = sc->opt1;
  3497. WBUFW(buf,8) = sc->opt2;
  3498. WBUFL(buf,10) = sc->option;
  3499. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3500. if(disguised(bl)) {
  3501. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3502. WBUFL(buf,2) = -bl->id;
  3503. clif_send(buf,packet_len(0x229),bl,SELF);
  3504. WBUFL(buf,2) = bl->id;
  3505. WBUFL(buf,10) = OPTION_INVISIBLE;
  3506. clif_send(buf,packet_len(0x229),bl,SELF);
  3507. } else
  3508. clif_send(buf,packet_len(0x229),bl,AREA);
  3509. #else
  3510. WBUFW(buf,0) = 0x119;
  3511. WBUFL(buf,2) = bl->id;
  3512. WBUFW(buf,6) = sc->opt1;
  3513. WBUFW(buf,8) = sc->opt2;
  3514. WBUFW(buf,10) = sc->option;
  3515. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3516. if(disguised(bl)) {
  3517. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3518. WBUFL(buf,2) = -bl->id;
  3519. clif_send(buf,packet_len(0x119),bl,SELF);
  3520. WBUFL(buf,2) = bl->id;
  3521. WBUFW(buf,10) = OPTION_INVISIBLE;
  3522. clif_send(buf,packet_len(0x119),bl,SELF);
  3523. } else
  3524. clif_send(buf,packet_len(0x119),bl,AREA);
  3525. #endif
  3526. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3527. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3528. if (sc->data[SC_PROVOKE]) {
  3529. const struct TimerData *td = get_timer(sc->data[SC_PROVOKE]->timer);
  3530. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, (!td ? INFINITE_TICK : DIFF_TICK(td->tick, gettick())), 0, 0, 0);
  3531. }
  3532. }
  3533. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3534. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3535. void clif_changeoption2(struct block_list* bl)
  3536. {
  3537. unsigned char buf[20];
  3538. struct status_change *sc;
  3539. sc = status_get_sc(bl);
  3540. if (!sc) return; //How can an option change if there's no sc?
  3541. WBUFW(buf,0) = 0x28a;
  3542. WBUFL(buf,2) = bl->id;
  3543. WBUFL(buf,6) = sc->option;
  3544. WBUFL(buf,10) = clif_setlevel(bl);
  3545. WBUFL(buf,14) = sc->opt3;
  3546. if(disguised(bl)) {
  3547. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3548. WBUFL(buf,2) = -bl->id;
  3549. clif_send(buf,packet_len(0x28a),bl,SELF);
  3550. WBUFL(buf,2) = bl->id;
  3551. WBUFL(buf,6) = OPTION_INVISIBLE;
  3552. clif_send(buf,packet_len(0x28a),bl,SELF);
  3553. } else
  3554. clif_send(buf,packet_len(0x28a),bl,AREA);
  3555. }
  3556. /// Notifies the client about the result of an item use request.
  3557. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3558. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3559. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3560. {
  3561. nullpo_retv(sd);
  3562. if(!ok) {
  3563. int fd=sd->fd;
  3564. WFIFOHEAD(fd,packet_len(0xa8));
  3565. WFIFOW(fd,0)=0xa8;
  3566. WFIFOW(fd,2)=index+2;
  3567. WFIFOW(fd,4)=amount;
  3568. WFIFOB(fd,6)=ok;
  3569. WFIFOSET(fd,packet_len(0xa8));
  3570. }
  3571. else {
  3572. #if PACKETVER < 3
  3573. int fd=sd->fd;
  3574. WFIFOHEAD(fd,packet_len(0xa8));
  3575. WFIFOW(fd,0)=0xa8;
  3576. WFIFOW(fd,2)=index+2;
  3577. WFIFOW(fd,4)=amount;
  3578. WFIFOB(fd,6)=ok;
  3579. WFIFOSET(fd,packet_len(0xa8));
  3580. #else
  3581. unsigned char buf[32];
  3582. WBUFW(buf,0)=0x1c8;
  3583. WBUFW(buf,2)=index+2;
  3584. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3585. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3586. else
  3587. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3588. WBUFL(buf,6)=sd->bl.id;
  3589. WBUFW(buf,10)=amount;
  3590. WBUFB(buf,12)=ok;
  3591. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3592. #endif
  3593. }
  3594. }
  3595. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3596. /// 00d6 <flag>.B
  3597. /// flag:
  3598. /// 0 = Room has been successfully created (opens chat room)
  3599. /// 1 = Room limit exceeded
  3600. /// 2 = Same room already exists
  3601. void clif_createchat(struct map_session_data* sd, int flag)
  3602. {
  3603. int fd;
  3604. nullpo_retv(sd);
  3605. fd = sd->fd;
  3606. WFIFOHEAD(fd,packet_len(0xd6));
  3607. WFIFOW(fd,0) = 0xd6;
  3608. WFIFOB(fd,2) = flag;
  3609. WFIFOSET(fd,packet_len(0xd6));
  3610. }
  3611. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3612. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3613. /// type:
  3614. /// 0 = private (password protected)
  3615. /// 1 = public
  3616. /// 2 = arena (npc waiting room)
  3617. /// 3 = PK zone (non-clickable)
  3618. void clif_dispchat(struct chat_data* cd, int fd)
  3619. {
  3620. unsigned char buf[128];
  3621. uint8 type;
  3622. if( cd == NULL || cd->owner == NULL )
  3623. return;
  3624. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3625. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3626. : 1;
  3627. WBUFW(buf, 0) = 0xd7;
  3628. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3629. WBUFL(buf, 4) = cd->owner->id;
  3630. WBUFL(buf, 8) = cd->bl.id;
  3631. WBUFW(buf,12) = cd->limit;
  3632. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3633. WBUFB(buf,16) = type;
  3634. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3635. if( fd ) {
  3636. WFIFOHEAD(fd,WBUFW(buf,2));
  3637. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3638. WFIFOSET(fd,WBUFW(buf,2));
  3639. } else {
  3640. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3641. }
  3642. }
  3643. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3644. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3645. /// type:
  3646. /// 0 = private (password protected)
  3647. /// 1 = public
  3648. /// 2 = arena (npc waiting room)
  3649. /// 3 = PK zone (non-clickable)
  3650. void clif_changechatstatus(struct chat_data* cd)
  3651. {
  3652. unsigned char buf[128];
  3653. uint8 type;
  3654. if( cd == NULL || cd->usersd[0] == NULL )
  3655. return;
  3656. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3657. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3658. : 1;
  3659. WBUFW(buf, 0) = 0xdf;
  3660. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3661. WBUFL(buf, 4) = cd->owner->id;
  3662. WBUFL(buf, 8) = cd->bl.id;
  3663. WBUFW(buf,12) = cd->limit;
  3664. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3665. WBUFB(buf,16) = type;
  3666. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3667. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3668. }
  3669. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3670. /// 00d8 <chat id>.L
  3671. void clif_clearchat(struct chat_data *cd,int fd)
  3672. {
  3673. unsigned char buf[32];
  3674. nullpo_retv(cd);
  3675. WBUFW(buf,0) = 0xd8;
  3676. WBUFL(buf,2) = cd->bl.id;
  3677. if( fd ) {
  3678. WFIFOHEAD(fd,packet_len(0xd8));
  3679. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3680. WFIFOSET(fd,packet_len(0xd8));
  3681. } else {
  3682. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3683. }
  3684. }
  3685. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3686. /// 00da <result>.B
  3687. /// result:
  3688. /// 0 = room full
  3689. /// 1 = wrong password
  3690. /// 2 = kicked
  3691. /// 3 = success (no message)
  3692. /// 4 = no enough zeny
  3693. /// 5 = too low level
  3694. /// 6 = too high level
  3695. /// 7 = unsuitable job class
  3696. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3697. {
  3698. int fd;
  3699. nullpo_retv(sd);
  3700. fd = sd->fd;
  3701. WFIFOHEAD(fd,packet_len(0xda));
  3702. WFIFOW(fd,0) = 0xda;
  3703. WFIFOB(fd,2) = flag;
  3704. WFIFOSET(fd,packet_len(0xda));
  3705. }
  3706. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3707. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3708. /// role:
  3709. /// 0 = owner (menu)
  3710. /// 1 = normal
  3711. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3712. {
  3713. int fd;
  3714. int i,t;
  3715. nullpo_retv(sd);
  3716. nullpo_retv(cd);
  3717. fd = sd->fd;
  3718. if (!session_isActive(fd))
  3719. return;
  3720. t = (int)(cd->owner->type == BL_NPC);
  3721. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3722. WFIFOW(fd, 0) = 0xdb;
  3723. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3724. WFIFOL(fd, 4) = cd->bl.id;
  3725. if(cd->owner->type == BL_NPC){
  3726. WFIFOL(fd, 30) = 1;
  3727. WFIFOL(fd, 8) = 0;
  3728. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3729. for (i = 0; i < cd->users; i++) {
  3730. WFIFOL(fd, 8+(i+1)*28) = 1;
  3731. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3732. }
  3733. }else{
  3734. for (i = 0; i < cd->users; i++) {
  3735. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3736. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3737. }
  3738. }
  3739. WFIFOSET(fd, WFIFOW(fd, 2));
  3740. }
  3741. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3742. /// 00dc <users>.W <name>.24B
  3743. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3744. {
  3745. unsigned char buf[29];
  3746. nullpo_retv(sd);
  3747. nullpo_retv(cd);
  3748. WBUFW(buf, 0) = 0xdc;
  3749. WBUFW(buf, 2) = cd->users;
  3750. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3751. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3752. }
  3753. /// Announce the new owner (ZC_ROLE_CHANGE).
  3754. /// 00e1 <role>.L <nick>.24B
  3755. /// role:
  3756. /// 0 = owner (menu)
  3757. /// 1 = normal
  3758. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3759. {
  3760. unsigned char buf[64];
  3761. nullpo_retv(sd);
  3762. nullpo_retv(cd);
  3763. WBUFW(buf, 0) = 0xe1;
  3764. WBUFL(buf, 2) = 1;
  3765. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3766. WBUFW(buf,30) = 0xe1;
  3767. WBUFL(buf,32) = 0;
  3768. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3769. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3770. }
  3771. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3772. /// 00dd <users>.W <nick>.24B <flag>.B
  3773. /// flag:
  3774. /// 0 = left
  3775. /// 1 = kicked
  3776. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3777. {
  3778. unsigned char buf[32];
  3779. nullpo_retv(sd);
  3780. nullpo_retv(cd);
  3781. WBUFW(buf, 0) = 0xdd;
  3782. WBUFW(buf, 2) = cd->users-1;
  3783. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3784. WBUFB(buf,28) = flag;
  3785. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3786. }
  3787. /// Opens a trade request window from char 'name'.
  3788. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3789. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3790. void clif_traderequest(struct map_session_data* sd, const char* name)
  3791. {
  3792. int fd = sd->fd;
  3793. #if PACKETVER < 6
  3794. WFIFOHEAD(fd,packet_len(0xe5));
  3795. WFIFOW(fd,0) = 0xe5;
  3796. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3797. WFIFOSET(fd,packet_len(0xe5));
  3798. #else
  3799. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3800. if( !tsd ) return;
  3801. WFIFOHEAD(fd,packet_len(0x1f4));
  3802. WFIFOW(fd,0) = 0x1f4;
  3803. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3804. WFIFOL(fd,26) = tsd->status.char_id;
  3805. WFIFOW(fd,30) = tsd->status.base_level;
  3806. WFIFOSET(fd,packet_len(0x1f4));
  3807. #endif
  3808. }
  3809. /// Reply to a trade-request.
  3810. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3811. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3812. /// result:
  3813. /// 0 = Char is too far
  3814. /// 1 = Character does not exist
  3815. /// 2 = Trade failed
  3816. /// 3 = Accept
  3817. /// 4 = Cancel
  3818. /// 5 = Busy
  3819. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3820. {
  3821. int fd = sd->fd;
  3822. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3823. if( PACKETVER < 6 || !tsd ) {
  3824. WFIFOHEAD(fd,packet_len(0xe7));
  3825. WFIFOW(fd,0) = 0xe7;
  3826. WFIFOB(fd,2) = type;
  3827. WFIFOSET(fd,packet_len(0xe7));
  3828. } else {
  3829. WFIFOHEAD(fd,packet_len(0x1f5));
  3830. WFIFOW(fd,0) = 0x1f5;
  3831. WFIFOB(fd,2) = type;
  3832. WFIFOL(fd,3) = tsd->status.char_id;
  3833. WFIFOW(fd,7) = tsd->status.base_level;
  3834. WFIFOSET(fd,packet_len(0x1f5));
  3835. }
  3836. }
  3837. /// Notifies the client about an item from other player in current trade.
  3838. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3839. /// 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)
  3840. /// 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)
  3841. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3842. {
  3843. int fd;
  3844. unsigned char *buf;
  3845. #if PACKETVER < 20100223
  3846. const int cmd = 0xe9;
  3847. #elif PACKETVER < 20150225
  3848. const int cmd = 0x80f;
  3849. #else
  3850. const int cmd = 0xa09;
  3851. #endif
  3852. nullpo_retv(sd);
  3853. nullpo_retv(tsd);
  3854. fd = tsd->fd;
  3855. buf = WFIFOP(fd,0);
  3856. WFIFOHEAD(fd,packet_len(cmd));
  3857. WBUFW(buf,0) = cmd;
  3858. if( index == 0 )
  3859. {
  3860. #if PACKETVER < 20100223
  3861. WBUFL(buf,2) = amount; //amount
  3862. WBUFW(buf,6) = 0; // type id
  3863. #else
  3864. WBUFW(buf,2) = 0; // type id
  3865. WBUFB(buf,4) = 0; // item type
  3866. WBUFL(buf,5) = amount; // amount
  3867. buf = WBUFP(buf,1); //Advance 1B
  3868. #endif
  3869. WBUFB(buf,8) = 0; //identify flag
  3870. WBUFB(buf,9) = 0; // attribute
  3871. WBUFB(buf,10)= 0; //refine
  3872. WBUFW(buf,11)= 0; //card (4w)
  3873. WBUFW(buf,13)= 0; //card (4w)
  3874. WBUFW(buf,15)= 0; //card (4w)
  3875. WBUFW(buf,17)= 0; //card (4w)
  3876. #if PACKETVER >= 20150225
  3877. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3878. #endif
  3879. }
  3880. else
  3881. {
  3882. index -= 2; //index fix
  3883. #if PACKETVER < 20100223
  3884. WBUFL(buf,2) = amount; //amount
  3885. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3886. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3887. else
  3888. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3889. #else
  3890. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3891. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3892. else
  3893. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3894. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3895. WBUFL(buf,5) = amount; // amount
  3896. buf = WBUFP(buf,1); //Advance 1B
  3897. #endif
  3898. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3899. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3900. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3901. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3902. #if PACKETVER >= 20150225
  3903. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3904. #endif
  3905. }
  3906. WFIFOSET(fd,packet_len(cmd));
  3907. }
  3908. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3909. /// 00ea <index>.W <result>.B
  3910. /// result:
  3911. /// 0 = success
  3912. /// 1 = overweight
  3913. /// 2 = trade canceled
  3914. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3915. {
  3916. int fd;
  3917. nullpo_retv(sd);
  3918. fd = sd->fd;
  3919. WFIFOHEAD(fd,packet_len(0xea));
  3920. WFIFOW(fd,0) = 0xea;
  3921. WFIFOW(fd,2) = index;
  3922. WFIFOB(fd,4) = fail;
  3923. WFIFOSET(fd,packet_len(0xea));
  3924. }
  3925. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3926. /// 00ec <who>.B
  3927. /// who:
  3928. /// 0 = self
  3929. /// 1 = other player
  3930. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3931. {
  3932. int fd;
  3933. nullpo_retv(sd);
  3934. fd = sd->fd;
  3935. WFIFOHEAD(fd,packet_len(0xec));
  3936. WFIFOW(fd,0) = 0xec;
  3937. WFIFOB(fd,2) = fail;
  3938. WFIFOSET(fd,packet_len(0xec));
  3939. }
  3940. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3941. /// 00ee
  3942. void clif_tradecancelled(struct map_session_data* sd)
  3943. {
  3944. int fd;
  3945. nullpo_retv(sd);
  3946. fd = sd->fd;
  3947. WFIFOHEAD(fd,packet_len(0xee));
  3948. WFIFOW(fd,0) = 0xee;
  3949. WFIFOSET(fd,packet_len(0xee));
  3950. }
  3951. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3952. /// 00f0 <result>.B
  3953. /// result:
  3954. /// 0 = success
  3955. /// 1 = failure
  3956. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3957. {
  3958. int fd;
  3959. nullpo_retv(sd);
  3960. fd = sd->fd;
  3961. WFIFOHEAD(fd,packet_len(0xf0));
  3962. WFIFOW(fd,0) = 0xf0;
  3963. WFIFOB(fd,2) = fail;
  3964. WFIFOSET(fd,packet_len(0xf0));
  3965. }
  3966. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3967. /// 00f1
  3968. /// NOTE: Unknown purpose. Items are not removed until the window is
  3969. /// refreshed (ex. by putting another item in there).
  3970. void clif_tradeundo(struct map_session_data* sd)
  3971. {
  3972. int fd = sd->fd;
  3973. WFIFOHEAD(fd,packet_len(0xf1));
  3974. WFIFOW(fd,0) = 0xf1;
  3975. WFIFOSET(fd,packet_len(0xf1));
  3976. }
  3977. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3978. /// 00f2 <current count>.W <max count>.W
  3979. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3980. {
  3981. int fd;
  3982. nullpo_retv(sd);
  3983. fd=sd->fd;
  3984. WFIFOHEAD(fd,packet_len(0xf2));
  3985. WFIFOW(fd,0) = 0xf2;
  3986. WFIFOW(fd,2) = amount;
  3987. WFIFOW(fd,4) = max_amount;
  3988. WFIFOSET(fd,packet_len(0xf2));
  3989. }
  3990. /// Notifies the client of an item being added to the storage.
  3991. /// 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)
  3992. /// 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)
  3993. /// 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)
  3994. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3995. {
  3996. #if PACKETVER < 5
  3997. const int cmd = 0xf4;
  3998. #elif PACKETVER < 20150225
  3999. const int cmd = 0x1c4;
  4000. #else
  4001. const int cmd = 0xa0a;
  4002. #endif
  4003. int view,fd;
  4004. int offset = 0;
  4005. nullpo_retv(sd);
  4006. nullpo_retv(i);
  4007. fd=sd->fd;
  4008. view = itemdb_viewid(i->nameid);
  4009. WFIFOHEAD(fd,packet_len(cmd));
  4010. WFIFOW(fd, 0) = cmd; // Storage item added
  4011. WFIFOW(fd, 2) = index+1; // index
  4012. WFIFOL(fd, 4) = amount; // amount
  4013. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  4014. #if PACKETVER >= 5
  4015. WFIFOB(fd,10) = itemtype(i->nameid); //type
  4016. offset += 1;
  4017. #endif
  4018. WFIFOB(fd,10+offset) = i->identify; //identify flag
  4019. WFIFOB(fd,11+offset) = i->attribute; // attribute
  4020. WFIFOB(fd,12+offset) = i->refine; //refine
  4021. clif_addcards(WFIFOP(fd,13+offset), i);
  4022. #if PACKETVER >= 20150225
  4023. clif_add_random_options(WFIFOP(fd,21+offset), i);
  4024. #endif
  4025. WFIFOSET(fd,packet_len(cmd));
  4026. }
  4027. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4028. /// 00f6 <index>.W <amount>.L
  4029. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4030. {
  4031. int fd;
  4032. nullpo_retv(sd);
  4033. fd=sd->fd;
  4034. WFIFOHEAD(fd,packet_len(0xf6));
  4035. WFIFOW(fd,0)=0xf6; // Storage item removed
  4036. WFIFOW(fd,2)=index+1;
  4037. WFIFOL(fd,4)=amount;
  4038. WFIFOSET(fd,packet_len(0xf6));
  4039. }
  4040. /// Closes storage (ZC_CLOSE_STORE).
  4041. /// 00f8
  4042. void clif_storageclose(struct map_session_data* sd)
  4043. {
  4044. int fd;
  4045. nullpo_retv(sd);
  4046. fd=sd->fd;
  4047. WFIFOHEAD(fd,packet_len(0xf8));
  4048. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4049. WFIFOSET(fd,packet_len(0xf8));
  4050. }
  4051. /*==========================================
  4052. * Server tells 'sd' player client the abouts of 'dstsd' player
  4053. *------------------------------------------*/
  4054. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4055. {
  4056. struct block_list *d_bl;
  4057. int i;
  4058. if( dstsd->chatID ) {
  4059. struct chat_data *cd = NULL;
  4060. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4061. clif_dispchat(cd,sd->fd);
  4062. } else if( dstsd->state.vending )
  4063. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4064. else if( dstsd->state.buyingstore )
  4065. clif_buyingstore_entry_single(sd, dstsd);
  4066. if(dstsd->spiritball > 0)
  4067. clif_spiritball_single(sd->fd, dstsd);
  4068. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4069. clif_spiritcharm_single(sd->fd, dstsd);
  4070. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4071. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4072. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4073. )
  4074. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4075. // display link (sd - dstsd) to sd
  4076. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4077. if( i < MAX_DEVOTION )
  4078. clif_devotion(&sd->bl, sd);
  4079. // display links (dstsd - devotees) to sd
  4080. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4081. if( i < MAX_DEVOTION )
  4082. clif_devotion(&dstsd->bl, sd);
  4083. // display link (dstsd - crusader) to sd
  4084. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4085. clif_devotion(d_bl, sd);
  4086. }
  4087. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4088. {
  4089. uint8 buf[128];
  4090. struct unit_data *ud;
  4091. struct view_data *vd;
  4092. int len;
  4093. vd = status_get_viewdata(bl);
  4094. if (!vd || vd->class_ == JT_INVISIBLE)
  4095. return;
  4096. /**
  4097. * Hide NPC from maya purple card.
  4098. **/
  4099. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4100. return;
  4101. ud = unit_bl2ud(bl);
  4102. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4103. clif_send(buf,len,&sd->bl,SELF);
  4104. if (vd->cloth_color)
  4105. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4106. if (vd->body_style)
  4107. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4108. switch (bl->type)
  4109. {
  4110. case BL_PC:
  4111. {
  4112. TBL_PC* tsd = (TBL_PC*)bl;
  4113. clif_getareachar_pc(sd, tsd);
  4114. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4115. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4116. else if(tsd->state.size==SZ_MEDIUM)
  4117. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4118. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4119. clif_sendbgemblem_single(sd->fd,tsd);
  4120. if ( tsd->status.robe )
  4121. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4122. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4123. clif_hat_effects(sd,bl,SELF);
  4124. }
  4125. break;
  4126. case BL_MER: // Devotion Effects
  4127. if( ((TBL_MER*)bl)->devotion_flag )
  4128. clif_devotion(bl, sd);
  4129. break;
  4130. case BL_NPC:
  4131. {
  4132. TBL_NPC* nd = (TBL_NPC*)bl;
  4133. if( nd->chat_id )
  4134. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4135. if( nd->size == SZ_BIG )
  4136. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4137. else if( nd->size == SZ_MEDIUM )
  4138. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4139. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4140. clif_progressbar_npc(nd, sd);
  4141. }
  4142. break;
  4143. case BL_MOB:
  4144. {
  4145. TBL_MOB* md = (TBL_MOB*)bl;
  4146. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4147. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4148. else if(md->special_state.size==SZ_MEDIUM)
  4149. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4150. #if PACKETVER >= 20120404
  4151. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4152. int i;
  4153. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4154. if( md->dmglog[i].id == sd->status.char_id )
  4155. clif_monster_hp_bar(md, sd->fd);
  4156. }
  4157. #endif
  4158. }
  4159. break;
  4160. case BL_PET:
  4161. if (vd->head_bottom)
  4162. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4163. break;
  4164. }
  4165. }
  4166. //Modifies the type of damage according to status changes [Skotlex]
  4167. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4168. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4169. {
  4170. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4171. }
  4172. /*==========================================
  4173. * Estimates walk delay based on the damage criteria. [Skotlex]
  4174. *------------------------------------------*/
  4175. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4176. {
  4177. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4178. return 0;
  4179. if (bl->type == BL_PC) {
  4180. if (battle_config.pc_walk_delay_rate != 100)
  4181. delay = delay*battle_config.pc_walk_delay_rate/100;
  4182. } else
  4183. if (battle_config.walk_delay_rate != 100)
  4184. delay = delay*battle_config.walk_delay_rate/100;
  4185. if (div_ > 1) //Multi-hit skills mean higher delays.
  4186. delay += battle_config.multihit_delay*(div_-1);
  4187. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4188. }
  4189. /*========================================== [Playtester]
  4190. * Returns hallucination damage the client displays
  4191. *------------------------------------------*/
  4192. static int clif_hallucination_damage()
  4193. {
  4194. int digit = rnd() % 5 + 1;
  4195. switch (digit)
  4196. {
  4197. case 1:
  4198. return (rnd() % 10);
  4199. case 2:
  4200. return (rnd() % 100);
  4201. case 3:
  4202. return (rnd() % 1000);
  4203. case 4:
  4204. return (rnd() % 10000);
  4205. }
  4206. return (rnd() % 32767);
  4207. }
  4208. /// Sends a 'damage' packet (src performs action on dst)
  4209. /// 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)
  4210. /// 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)
  4211. /// 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)
  4212. /// type:
  4213. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4214. /// 1 = pick up item
  4215. /// 2 = sit down
  4216. /// 3 = stand up
  4217. /// 4 = damage (endure)
  4218. /// 5 = (splash?)
  4219. /// 6 = (skill?)
  4220. /// 7 = (repeat damage?)
  4221. /// 8 = multi-hit damage
  4222. /// 9 = multi-hit damage (endure)
  4223. /// 10 = critical hit
  4224. /// 11 = lucky dodge
  4225. /// 12 = (touch skill?)
  4226. 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)
  4227. {
  4228. unsigned char buf[34];
  4229. struct status_change *sc;
  4230. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4231. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4232. #if PACKETVER < 20071113
  4233. const int cmd = 0x8a;
  4234. int offset = 0;
  4235. #elif PACKETVER < 20131223
  4236. const int cmd = 0x2e1;
  4237. int offset = 2;
  4238. #else
  4239. const int cmd = 0x8c8;
  4240. int offset = 3;
  4241. #endif
  4242. nullpo_ret(src);
  4243. nullpo_ret(dst);
  4244. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4245. sc = status_get_sc(dst);
  4246. if(sc && sc->count) {
  4247. if(sc->data[SC_HALLUCINATION]) {
  4248. if(damage) damage = clif_hallucination_damage();
  4249. if(damage2) damage2 = clif_hallucination_damage();
  4250. }
  4251. }
  4252. WBUFW(buf,0) = cmd;
  4253. WBUFL(buf,2) = src->id;
  4254. WBUFL(buf,6) = dst->id;
  4255. WBUFL(buf,10) = client_tick(tick);
  4256. WBUFL(buf,14) = sdelay;
  4257. WBUFL(buf,18) = ddelay;
  4258. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4259. #if PACKETVER < 20071113
  4260. WBUFW(buf,22) = damage ? div : 0;
  4261. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4262. #else
  4263. WBUFL(buf, 22) = damage ? div : 0;
  4264. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4265. #endif
  4266. } else {
  4267. #if PACKETVER < 20071113
  4268. WBUFW(buf,22) = min(damage, INT16_MAX);
  4269. WBUFW(buf,27+offset) = damage2;
  4270. #else
  4271. WBUFL(buf,22) = damage;
  4272. WBUFL(buf,27+offset) = damage2;
  4273. #endif
  4274. }
  4275. #if PACKETVER >= 20131223
  4276. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4277. #endif
  4278. WBUFW(buf,24+offset) = div;
  4279. WBUFB(buf,26+offset) = type;
  4280. if(disguised(dst)) {
  4281. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4282. WBUFL(buf,6) = -dst->id;
  4283. clif_send(buf, packet_len(cmd), dst, SELF);
  4284. } else
  4285. clif_send(buf, packet_len(cmd), dst, AREA);
  4286. if(disguised(src)) {
  4287. WBUFL(buf,2) = -src->id;
  4288. if (disguised(dst))
  4289. WBUFL(buf,6) = dst->id;
  4290. #if PACKETVER < 20071113
  4291. if(damage > 0) WBUFW(buf,22) = -1;
  4292. if(damage2 > 0) WBUFW(buf,27) = -1;
  4293. #else
  4294. if(damage > 0) WBUFL(buf,22) = -1;
  4295. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4296. #endif
  4297. clif_send(buf,packet_len(cmd),src,SELF);
  4298. }
  4299. if(src == dst) {
  4300. unit_setdir(src, unit_getdir(src));
  4301. }
  4302. //Return adjusted can't walk delay for further processing.
  4303. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4304. }
  4305. /*==========================================
  4306. * src picks up dst
  4307. *------------------------------------------*/
  4308. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4309. {
  4310. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4311. unsigned char buf[32];
  4312. nullpo_retv(src);
  4313. nullpo_retv(dst);
  4314. WBUFW(buf, 0) = 0x8a;
  4315. WBUFL(buf, 2) = src->id;
  4316. WBUFL(buf, 6) = dst->id;
  4317. WBUFB(buf,26) = 1;
  4318. clif_send(buf, packet_len(0x8a), src, AREA);
  4319. }
  4320. /*==========================================
  4321. * inform clients in area that `bl` is sitting
  4322. *------------------------------------------*/
  4323. void clif_sitting(struct block_list* bl)
  4324. {
  4325. unsigned char buf[32];
  4326. nullpo_retv(bl);
  4327. WBUFW(buf, 0) = 0x8a;
  4328. WBUFL(buf, 2) = bl->id;
  4329. WBUFB(buf,26) = 2;
  4330. clif_send(buf, packet_len(0x8a), bl, AREA);
  4331. if(disguised(bl)) {
  4332. WBUFL(buf, 2) = - bl->id;
  4333. clif_send(buf, packet_len(0x8a), bl, SELF);
  4334. }
  4335. }
  4336. /*==========================================
  4337. * inform clients in area that `bl` is standing
  4338. *------------------------------------------*/
  4339. void clif_standing(struct block_list* bl)
  4340. {
  4341. unsigned char buf[32];
  4342. nullpo_retv(bl);
  4343. WBUFW(buf, 0) = 0x8a;
  4344. WBUFL(buf, 2) = bl->id;
  4345. WBUFB(buf,26) = 3;
  4346. clif_send(buf, packet_len(0x8a), bl, AREA);
  4347. if(disguised(bl)) {
  4348. WBUFL(buf, 2) = - bl->id;
  4349. clif_send(buf, packet_len(0x8a), bl, SELF);
  4350. }
  4351. }
  4352. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4353. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4354. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4355. {
  4356. unsigned char buf[32];
  4357. WBUFW(buf,0) = 0x192;
  4358. WBUFW(buf,2) = x;
  4359. WBUFW(buf,4) = y;
  4360. WBUFW(buf,6) = type;
  4361. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4362. if( fd )
  4363. {
  4364. WFIFOHEAD(fd,packet_len(0x192));
  4365. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4366. WFIFOSET(fd,packet_len(0x192));
  4367. }
  4368. else
  4369. {
  4370. struct block_list dummy_bl;
  4371. dummy_bl.type = BL_NUL;
  4372. dummy_bl.x = x;
  4373. dummy_bl.y = y;
  4374. dummy_bl.m = m;
  4375. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4376. }
  4377. }
  4378. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4379. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4380. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4381. {
  4382. int view,fd;
  4383. fd=sd->fd;
  4384. WFIFOHEAD(fd,packet_len(0x9d));
  4385. WFIFOW(fd,0)=0x9d;
  4386. WFIFOL(fd,2)=fitem->bl.id;
  4387. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4388. WFIFOW(fd,6)=view;
  4389. else
  4390. WFIFOW(fd,6)=fitem->item.nameid;
  4391. WFIFOB(fd,8)=fitem->item.identify;
  4392. WFIFOW(fd,9)=fitem->bl.x;
  4393. WFIFOW(fd,11)=fitem->bl.y;
  4394. WFIFOW(fd,13)=fitem->item.amount;
  4395. WFIFOB(fd,15)=fitem->subx;
  4396. WFIFOB(fd,16)=fitem->suby;
  4397. WFIFOSET(fd,packet_len(0x9d));
  4398. }
  4399. /// Notifes client about Graffiti
  4400. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4401. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4402. unsigned char buf[128];
  4403. nullpo_retv(bl);
  4404. nullpo_retv(unit);
  4405. WBUFW(buf, 0) = 0x1c9;
  4406. WBUFL(buf, 2) = unit->bl.id;
  4407. WBUFL(buf, 6) = unit->group->src_id;
  4408. WBUFW(buf,10) = unit->bl.x;
  4409. WBUFW(buf,12) = unit->bl.y;
  4410. WBUFB(buf,14) = unit->group->unit_id;
  4411. WBUFB(buf,15) = 1;
  4412. WBUFB(buf,16) = 1;
  4413. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4414. clif_send(buf,packet_len(0x1c9),bl,target);
  4415. }
  4416. /// Notifies the client of a skill unit.
  4417. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4418. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4419. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4420. /// 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)
  4421. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4422. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4423. unsigned char buf[128];
  4424. nullpo_retv(bl);
  4425. nullpo_retv(unit);
  4426. if (bl->type == BL_PC)
  4427. fd = ((TBL_PC*)bl)->fd;
  4428. if (unit->group->state.guildaura)
  4429. return;
  4430. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4431. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4432. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4433. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4434. else
  4435. unit_id = unit->group->unit_id;
  4436. if (!visible)
  4437. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4438. #if PACKETVER >= 3
  4439. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4440. clif_graffiti(bl, unit, target);
  4441. return;
  4442. }
  4443. #endif
  4444. #if PACKETVER <= 20120702
  4445. header = 0x011f;
  4446. //#if PACKETVER < 20110718
  4447. // header = 0x011f;
  4448. //#elif PACKETVER < 20121212
  4449. // header = 0x08c7;
  4450. #elif PACKETVER < 20130731
  4451. header = 0x099f;
  4452. #else
  4453. header = 0x09ca;
  4454. #endif
  4455. len = packet_len(header);
  4456. WBUFW(buf,pos) = header;
  4457. if (header != 0x011f) {
  4458. WBUFW(buf, pos+2) = len;
  4459. pos += 2;
  4460. }
  4461. WBUFL(buf,pos+2) = unit->bl.id;
  4462. WBUFL(buf,pos+6) = unit->group->src_id;
  4463. WBUFW(buf,pos+10) = unit->bl.x;
  4464. WBUFW(buf,pos+12) = unit->bl.y;
  4465. switch (header) {
  4466. case 0x011f:
  4467. WBUFB(buf,pos+14) = unit_id;
  4468. WBUFB(buf,pos+15) = visible;
  4469. break;
  4470. case 0x08c7:
  4471. WBUFB(buf,pos+14) = unit_id;
  4472. WBUFW(buf,pos+15) = unit->range;
  4473. WBUFB(buf,pos+17) = visible;
  4474. break;
  4475. case 0x099f:
  4476. WBUFL(buf,pos+14) = unit_id;
  4477. WBUFW(buf,pos+18) = unit->range;
  4478. WBUFB(buf,pos+20) = visible;
  4479. break;
  4480. case 0x09ca:
  4481. WBUFL(buf,pos+14) = unit_id;
  4482. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4483. WBUFB(buf,pos+19) = visible;
  4484. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4485. break;
  4486. }
  4487. clif_send(buf, len, bl, target);
  4488. if (unit->group->skill_id == WZ_ICEWALL)
  4489. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4490. }
  4491. /*==========================================
  4492. * Server tells client to remove unit of id 'unit->bl.id'
  4493. *------------------------------------------*/
  4494. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4495. {
  4496. nullpo_retv(unit);
  4497. WFIFOHEAD(fd,packet_len(0x120));
  4498. WFIFOW(fd, 0)=0x120;
  4499. WFIFOL(fd, 2)=unit->bl.id;
  4500. WFIFOSET(fd,packet_len(0x120));
  4501. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4502. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4503. }
  4504. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4505. /// 0120 <id>.L
  4506. void clif_skill_delunit(struct skill_unit *unit)
  4507. {
  4508. unsigned char buf[16];
  4509. nullpo_retv(unit);
  4510. WBUFW(buf, 0)=0x120;
  4511. WBUFL(buf, 2)=unit->bl.id;
  4512. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4513. }
  4514. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4515. /// 01ac <id>.L
  4516. /// Only affects units with class [139,153] client-side.
  4517. void clif_skillunit_update(struct block_list* bl)
  4518. {
  4519. unsigned char buf[6];
  4520. nullpo_retv(bl);
  4521. WBUFW(buf,0) = 0x1ac;
  4522. WBUFL(buf,2) = bl->id;
  4523. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4524. }
  4525. /*==========================================
  4526. *
  4527. *------------------------------------------*/
  4528. static int clif_getareachar(struct block_list* bl,va_list ap)
  4529. {
  4530. struct map_session_data *sd;
  4531. nullpo_ret(bl);
  4532. sd=va_arg(ap,struct map_session_data*);
  4533. if (sd == NULL || !sd->fd)
  4534. return 0;
  4535. switch(bl->type){
  4536. case BL_ITEM:
  4537. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4538. break;
  4539. case BL_SKILL:
  4540. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4541. break;
  4542. default:
  4543. if(&sd->bl == bl)
  4544. break;
  4545. clif_getareachar_unit(sd,bl);
  4546. break;
  4547. }
  4548. return 0;
  4549. }
  4550. /*==========================================
  4551. * tbl has gone out of view-size of bl
  4552. *------------------------------------------*/
  4553. int clif_outsight(struct block_list *bl,va_list ap)
  4554. {
  4555. struct block_list *tbl;
  4556. struct view_data *vd;
  4557. TBL_PC *sd, *tsd;
  4558. tbl=va_arg(ap,struct block_list*);
  4559. if(bl == tbl) return 0;
  4560. sd = BL_CAST(BL_PC, bl);
  4561. tsd = BL_CAST(BL_PC, tbl);
  4562. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4563. nullpo_ret(bl);
  4564. switch(bl->type){
  4565. case BL_PC:
  4566. if(sd->vd.class_ != JT_INVISIBLE)
  4567. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4568. if(sd->chatID){
  4569. struct chat_data *cd;
  4570. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4571. if(cd->usersd[0]==sd)
  4572. clif_dispchat(cd,tsd->fd);
  4573. }
  4574. if(sd->state.vending)
  4575. clif_closevendingboard(bl,tsd->fd);
  4576. if(sd->state.buyingstore)
  4577. clif_buyingstore_disappear_entry_single(tsd, sd);
  4578. break;
  4579. case BL_ITEM:
  4580. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4581. break;
  4582. case BL_SKILL:
  4583. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4584. break;
  4585. case BL_NPC:
  4586. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4587. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4588. break;
  4589. default:
  4590. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4591. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4592. break;
  4593. }
  4594. }
  4595. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4596. nullpo_ret(tbl);
  4597. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4598. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4599. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4600. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4601. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4602. }
  4603. return 0;
  4604. }
  4605. /*==========================================
  4606. * tbl has come into view of bl
  4607. *------------------------------------------*/
  4608. int clif_insight(struct block_list *bl,va_list ap)
  4609. {
  4610. struct block_list *tbl;
  4611. TBL_PC *sd, *tsd;
  4612. tbl=va_arg(ap,struct block_list*);
  4613. if (bl == tbl) return 0;
  4614. sd = BL_CAST(BL_PC, bl);
  4615. tsd = BL_CAST(BL_PC, tbl);
  4616. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4617. switch(bl->type){
  4618. case BL_ITEM:
  4619. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4620. break;
  4621. case BL_SKILL:
  4622. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4623. break;
  4624. default:
  4625. clif_getareachar_unit(tsd,bl);
  4626. break;
  4627. }
  4628. }
  4629. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4630. clif_getareachar_unit(sd,tbl);
  4631. }
  4632. return 0;
  4633. }
  4634. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4635. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4636. void clif_skillinfoblock(struct map_session_data *sd)
  4637. {
  4638. int fd;
  4639. int i,len,id;
  4640. nullpo_retv(sd);
  4641. fd = sd->fd;
  4642. if (!fd)
  4643. return;
  4644. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4645. WFIFOW(fd,0) = 0x10f;
  4646. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4647. {
  4648. if( (id = sd->status.skill[i].id) != 0 )
  4649. {
  4650. // workaround for bugreport:5348
  4651. if (len + 37 > 8192)
  4652. break;
  4653. WFIFOW(fd,len) = id;
  4654. WFIFOL(fd,len+2) = skill_get_inf(id);
  4655. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4656. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4657. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4658. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4659. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4660. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4661. else
  4662. WFIFOB(fd,len+36) = 0;
  4663. len += 37;
  4664. }
  4665. }
  4666. WFIFOW(fd,2)=len;
  4667. WFIFOSET(fd,len);
  4668. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4669. for ( ; i < MAX_SKILL; i++)
  4670. {
  4671. if( (id = sd->status.skill[i].id) != 0 )
  4672. {
  4673. clif_addskill(sd, id);
  4674. clif_skillinfo(sd, id, 0);
  4675. }
  4676. }
  4677. }
  4678. /**
  4679. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4680. **/
  4681. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4682. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4683. void clif_addskill(struct map_session_data *sd, int skill_id)
  4684. {
  4685. int fd;
  4686. uint16 idx = 0;
  4687. nullpo_retv(sd);
  4688. fd = sd->fd;
  4689. if (!fd || !(idx = skill_get_index(skill_id)))
  4690. return;
  4691. if( sd->status.skill[idx].id <= 0 )
  4692. return;
  4693. WFIFOHEAD(fd, packet_len(0x111));
  4694. WFIFOW(fd,0) = 0x111;
  4695. WFIFOW(fd,2) = skill_id;
  4696. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4697. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4698. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4699. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4700. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4701. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4702. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4703. else
  4704. WFIFOB(fd,38) = 0;
  4705. WFIFOSET(fd,packet_len(0x111));
  4706. }
  4707. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4708. /// 0441 <skill id>.W
  4709. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4710. {
  4711. #if PACKETVER >= 20081217
  4712. int fd;
  4713. uint16 idx = 0;
  4714. nullpo_retv(sd);
  4715. fd = sd->fd;
  4716. if (!fd || !(idx = skill_get_index(skill_id)))
  4717. return;
  4718. WFIFOHEAD(fd,packet_len(0x441));
  4719. WFIFOW(fd,0) = 0x441;
  4720. WFIFOW(fd,2) = skill_id;
  4721. WFIFOSET(fd,packet_len(0x441));
  4722. #endif
  4723. clif_skillinfoblock(sd);
  4724. }
  4725. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4726. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4727. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4728. int fd;
  4729. nullpo_retv(sd);
  4730. fd = sd->fd;
  4731. WFIFOHEAD(fd, packet_len(0x10e));
  4732. WFIFOW(fd, 0) = 0x10e;
  4733. WFIFOW(fd, 2) = skill_id;
  4734. WFIFOW(fd, 4) = lv;
  4735. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4736. WFIFOW(fd, 8) = range;
  4737. WFIFOB(fd, 10) = upgradable;
  4738. WFIFOSET(fd, packet_len(0x10e));
  4739. }
  4740. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4741. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4742. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4743. {
  4744. const int fd = sd->fd;
  4745. uint16 idx = skill_get_index(skill_id);
  4746. if (!idx)
  4747. return;
  4748. WFIFOHEAD(fd,packet_len(0x7e1));
  4749. WFIFOW(fd,0) = 0x7e1;
  4750. WFIFOW(fd,2) = skill_id;
  4751. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4752. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4753. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4754. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4755. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4756. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4757. else
  4758. WFIFOB(fd,14) = 0;
  4759. WFIFOSET(fd,packet_len(0x7e1));
  4760. }
  4761. /// Notifies clients in area, that an object is about to use a skill.
  4762. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4763. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4764. /// property:
  4765. /// 0 = Yellow cast aura
  4766. /// 1 = Water elemental cast aura
  4767. /// 2 = Earth elemental cast aura
  4768. /// 3 = Fire elemental cast aura
  4769. /// 4 = Wind elemental cast aura
  4770. /// 5 = Poison elemental cast aura
  4771. /// 6 = Holy elemental cast aura
  4772. /// ? = like 0
  4773. /// is disposable:
  4774. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4775. /// 1 = no text
  4776. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, int property, int casttime)
  4777. {
  4778. #if PACKETVER < 20091124
  4779. const int cmd = 0x13e;
  4780. #else
  4781. const int cmd = 0x7fb;
  4782. #endif
  4783. unsigned char buf[32];
  4784. WBUFW(buf,0) = cmd;
  4785. WBUFL(buf,2) = src_id;
  4786. WBUFL(buf,6) = dst_id;
  4787. WBUFW(buf,10) = dst_x;
  4788. WBUFW(buf,12) = dst_y;
  4789. WBUFW(buf,14) = skill_id;
  4790. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4791. WBUFL(buf,20) = casttime;
  4792. #if PACKETVER >= 20091124
  4793. WBUFB(buf,24) = 0; // isDisposable
  4794. #endif
  4795. if (disguised(bl)) {
  4796. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4797. WBUFL(buf,2) = -src_id;
  4798. clif_send(buf,packet_len(cmd), bl, SELF);
  4799. } else
  4800. clif_send(buf,packet_len(cmd), bl, AREA);
  4801. }
  4802. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4803. /// 01b9 <id>.L
  4804. void clif_skillcastcancel(struct block_list* bl)
  4805. {
  4806. unsigned char buf[16];
  4807. nullpo_retv(bl);
  4808. WBUFW(buf,0) = 0x1b9;
  4809. WBUFL(buf,2) = bl->id;
  4810. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4811. }
  4812. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4813. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4814. /// num (only used when skill id = NV_BASIC and cause = 0):
  4815. /// 0 = "skill failed" MsgStringTable[159]
  4816. /// 1 = "no emotions" MsgStringTable[160]
  4817. /// 2 = "no sit" MsgStringTable[161]
  4818. /// 3 = "no chat" MsgStringTable[162]
  4819. /// 4 = "no party" MsgStringTable[163]
  4820. /// 5 = "no shout" MsgStringTable[164]
  4821. /// 6 = "no PKing" MsgStringTable[165]
  4822. /// 7 = "no alligning" MsgStringTable[383]
  4823. /// ? = ignored
  4824. /// cause:
  4825. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4826. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4827. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4828. /// "skill failed" MsgStringTable[204] (otherwise)
  4829. /// ... = @see enum useskill_fail_cause
  4830. /// ? = ignored
  4831. ///
  4832. /// if(result!=0) doesn't display any of the previous messages
  4833. /// Note: when this packet is received an unknown flag is always set to 0,
  4834. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4835. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4836. {
  4837. int fd;
  4838. if (!sd) { //Since this is the most common nullpo....
  4839. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4840. return;
  4841. }
  4842. fd=sd->fd;
  4843. if (!fd) return;
  4844. if(battle_config.display_skill_fail&1)
  4845. return; //Disable all skill failed messages
  4846. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4847. return; //Disable delay failed messages
  4848. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4849. return;
  4850. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4851. return;
  4852. WFIFOHEAD(fd,packet_len(0x110));
  4853. WFIFOW(fd,0) = 0x110;
  4854. WFIFOW(fd,2) = skill_id;
  4855. WFIFOL(fd,4) = btype;
  4856. WFIFOB(fd,8) = 0;// success
  4857. WFIFOB(fd,9) = cause;
  4858. WFIFOSET(fd,packet_len(0x110));
  4859. }
  4860. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4861. /// 043d <skill ID>.W <tick>.L
  4862. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4863. {
  4864. #if PACKETVER>=20081112
  4865. int fd;
  4866. nullpo_retv(sd);
  4867. fd=sd->fd;
  4868. WFIFOHEAD(fd,packet_len(0x43d));
  4869. WFIFOW(fd,0) = 0x43d;
  4870. WFIFOW(fd,2) = skill_id;
  4871. WFIFOL(fd,4) = client_tick(tick);
  4872. WFIFOSET(fd,packet_len(0x43d));
  4873. #endif
  4874. }
  4875. /// Skill attack effect and damage.
  4876. /// 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)
  4877. /// 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)
  4878. 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)
  4879. {
  4880. unsigned char buf[64];
  4881. struct status_change *sc;
  4882. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4883. nullpo_ret(src);
  4884. nullpo_ret(dst);
  4885. type = clif_calc_delay(type,div,damage,ddelay);
  4886. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4887. if(sc->data[SC_HALLUCINATION] && damage)
  4888. damage = clif_hallucination_damage();
  4889. }
  4890. #if PACKETVER < 3
  4891. WBUFW(buf,0)=0x114;
  4892. WBUFW(buf,2)=skill_id;
  4893. WBUFL(buf,4)=src->id;
  4894. WBUFL(buf,8)=dst->id;
  4895. WBUFL(buf,12)=client_tick(tick);
  4896. WBUFL(buf,16)=sdelay;
  4897. WBUFL(buf,20)=ddelay;
  4898. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4899. WBUFW(buf,24)=damage?div:0;
  4900. } else {
  4901. WBUFW(buf,24)=damage;
  4902. }
  4903. WBUFW(buf,26)=skill_lv;
  4904. WBUFW(buf,28)=div;
  4905. WBUFB(buf,30)=type;
  4906. if (disguised(dst)) {
  4907. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4908. WBUFL(buf,8)=-dst->id;
  4909. clif_send(buf,packet_len(0x114),dst,SELF);
  4910. } else
  4911. clif_send(buf,packet_len(0x114),dst,AREA);
  4912. if(disguised(src)) {
  4913. WBUFL(buf,4)=-src->id;
  4914. if (disguised(dst))
  4915. WBUFL(buf,8)=dst->id;
  4916. if(damage > 0)
  4917. WBUFW(buf,24)=-1;
  4918. clif_send(buf,packet_len(0x114),src,SELF);
  4919. }
  4920. #else
  4921. WBUFW(buf,0)=0x1de;
  4922. WBUFW(buf,2)=skill_id;
  4923. WBUFL(buf,4)=src->id;
  4924. WBUFL(buf,8)=dst->id;
  4925. WBUFL(buf,12)=client_tick(tick);
  4926. WBUFL(buf,16)=sdelay;
  4927. WBUFL(buf,20)=ddelay;
  4928. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4929. WBUFL(buf,24)=damage?div:0;
  4930. } else {
  4931. WBUFL(buf,24)=damage;
  4932. }
  4933. WBUFW(buf,28)=skill_lv;
  4934. WBUFW(buf,30)=div;
  4935. // For some reason, late 2013 and newer clients have
  4936. // a issue that causes players and monsters to endure
  4937. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4938. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4939. #if PACKETVER < 20131223
  4940. WBUFB(buf,32)=type;
  4941. #else
  4942. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4943. #endif
  4944. if (disguised(dst)) {
  4945. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4946. WBUFL(buf,8)=-dst->id;
  4947. clif_send(buf,packet_len(0x1de),dst,SELF);
  4948. } else
  4949. clif_send(buf,packet_len(0x1de),dst,AREA);
  4950. if(disguised(src)) {
  4951. WBUFL(buf,4)=-src->id;
  4952. if (disguised(dst))
  4953. WBUFL(buf,8)=dst->id;
  4954. if(damage > 0)
  4955. WBUFL(buf,24)=-1;
  4956. clif_send(buf,packet_len(0x1de),src,SELF);
  4957. }
  4958. #endif
  4959. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4960. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4961. }
  4962. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4963. /// 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
  4964. /*
  4965. 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)
  4966. {
  4967. unsigned char buf[64];
  4968. struct status_change *sc;
  4969. nullpo_ret(src);
  4970. nullpo_ret(dst);
  4971. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4972. type = clif_calc_delay(type,div,damage,ddelay);
  4973. sc = status_get_sc(dst);
  4974. if(sc && sc->count) {
  4975. if(sc->data[SC_HALLUCINATION] && damage)
  4976. damage = clif_hallucination_damage();
  4977. }
  4978. WBUFW(buf,0)=0x115;
  4979. WBUFW(buf,2)=skill_id;
  4980. WBUFL(buf,4)=src->id;
  4981. WBUFL(buf,8)=dst->id;
  4982. WBUFL(buf,12)=client_tick(tick);
  4983. WBUFL(buf,16)=sdelay;
  4984. WBUFL(buf,20)=ddelay;
  4985. WBUFW(buf,24)=dst->x;
  4986. WBUFW(buf,26)=dst->y;
  4987. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4988. WBUFW(buf,28)=damage?div:0;
  4989. } else {
  4990. WBUFW(buf,28)=damage;
  4991. }
  4992. WBUFW(buf,30)=skill_lv;
  4993. WBUFW(buf,32)=div;
  4994. WBUFB(buf,34)=type;
  4995. clif_send(buf,packet_len(0x115),src,AREA);
  4996. if(disguised(src)) {
  4997. WBUFL(buf,4)=-src->id;
  4998. if(damage > 0)
  4999. WBUFW(buf,28)=-1;
  5000. clif_send(buf,packet_len(0x115),src,SELF);
  5001. }
  5002. if (disguised(dst)) {
  5003. WBUFL(buf,8)=-dst->id;
  5004. if (disguised(src))
  5005. WBUFL(buf,4)=src->id;
  5006. else if(damage > 0)
  5007. WBUFW(buf,28)=-1;
  5008. clif_send(buf,packet_len(0x115),dst,SELF);
  5009. }
  5010. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5011. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5012. }
  5013. */
  5014. /// Non-damaging skill effect
  5015. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5016. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5017. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5018. {
  5019. unsigned char buf[17];
  5020. #if PACKETVER < 20130731
  5021. const int cmd = 0x11a;
  5022. #else
  5023. const int cmd = 0x9cb;
  5024. #endif
  5025. int offset = 0;
  5026. bool success = ( tick != 0 );
  5027. nullpo_ret(dst);
  5028. WBUFW(buf,0) = cmd;
  5029. WBUFW(buf,2) = skill_id;
  5030. #if PACKETVER < 20130731
  5031. WBUFW(buf,4) = min(heal, INT16_MAX);
  5032. #else
  5033. WBUFL(buf,4) = min(heal, INT32_MAX);
  5034. offset += 2;
  5035. #endif
  5036. WBUFL(buf,6+offset) = dst->id;
  5037. WBUFL(buf,10+offset) = src ? src->id : 0;
  5038. WBUFB(buf,14+offset) = success;
  5039. if (disguised(dst)) {
  5040. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5041. WBUFL(buf,6+offset) = -dst->id;
  5042. clif_send(buf, packet_len(cmd), dst, SELF);
  5043. } else
  5044. clif_send(buf, packet_len(cmd), dst, AREA);
  5045. if(src && disguised(src)) {
  5046. WBUFL(buf,10+offset) = -src->id;
  5047. if (disguised(dst))
  5048. WBUFL(buf,6+offset) = dst->id;
  5049. clif_send(buf, packet_len(cmd), src, SELF);
  5050. }
  5051. return success;
  5052. }
  5053. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5054. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5055. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5056. {
  5057. unsigned char buf[32];
  5058. nullpo_retv(src);
  5059. WBUFW(buf,0)=0x117;
  5060. WBUFW(buf,2)=skill_id;
  5061. WBUFL(buf,4)=src->id;
  5062. WBUFW(buf,8)=val;
  5063. WBUFW(buf,10)=x;
  5064. WBUFW(buf,12)=y;
  5065. WBUFL(buf,14)=client_tick(tick);
  5066. if(disguised(src)) {
  5067. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5068. WBUFL(buf,4)=-src->id;
  5069. clif_send(buf,packet_len(0x117),src,SELF);
  5070. } else
  5071. clif_send(buf,packet_len(0x117),src,AREA);
  5072. }
  5073. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5074. /// 011c <skill id>.W { <map name>.16B }*4
  5075. 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)
  5076. {
  5077. int fd;
  5078. nullpo_retv(sd);
  5079. fd = sd->fd;
  5080. WFIFOHEAD(fd,packet_len(0x11c));
  5081. WFIFOW(fd,0) = 0x11c;
  5082. WFIFOW(fd,2) = skill_id;
  5083. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5084. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5085. else // normal map name
  5086. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5087. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5088. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5089. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5090. WFIFOSET(fd,packet_len(0x11c));
  5091. sd->menuskill_id = skill_id;
  5092. if (skill_id == AL_WARP) {
  5093. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5094. sd->state.workinprogress = WIP_DISABLE_ALL;
  5095. } else
  5096. sd->menuskill_val = skill_lv;
  5097. }
  5098. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5099. /// 011e <type>.B
  5100. /// type:
  5101. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5102. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5103. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5104. ///
  5105. /// @param sd Who receives the message
  5106. /// @param type What message
  5107. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5108. {
  5109. int fd;
  5110. nullpo_retv(sd);
  5111. fd=sd->fd;
  5112. WFIFOHEAD(fd,packet_len(0x11e));
  5113. WFIFOW(fd,0)=0x11e;
  5114. WFIFOB(fd,2)=type;
  5115. WFIFOSET(fd,packet_len(0x11e));
  5116. }
  5117. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5118. /// 0189 <type>.W
  5119. /// type:
  5120. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5121. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5122. ///
  5123. /// @param sd Who receives the message
  5124. /// @param type What message
  5125. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5126. {
  5127. int fd;
  5128. nullpo_retv(sd);
  5129. fd=sd->fd;
  5130. WFIFOHEAD(fd,packet_len(0x189));
  5131. WFIFOW(fd,0)=0x189;
  5132. WFIFOW(fd,2)=type;
  5133. WFIFOSET(fd,packet_len(0x189));
  5134. }
  5135. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5136. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5137. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5138. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5139. {
  5140. struct status_data *status;
  5141. unsigned char buf[64];
  5142. int i, fix;
  5143. nullpo_retv(sd);
  5144. nullpo_retv(dst);
  5145. if( dst->type != BL_MOB )
  5146. return;
  5147. status = status_get_status_data(dst);
  5148. WBUFW(buf, 0)=0x18c;
  5149. WBUFW(buf, 2)=status_get_class(dst);
  5150. WBUFW(buf, 4)=status_get_lv(dst);
  5151. WBUFW(buf, 6)=status->size;
  5152. WBUFL(buf, 8)=status->hp;
  5153. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5154. +(battle_config.estimation_type&2?status->def2:0);
  5155. WBUFW(buf,14)=status->race;
  5156. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5157. +(battle_config.estimation_type&2?status->mdef2:0);
  5158. WBUFW(buf,18)= status->def_ele;
  5159. for(i=0;i<9;i++)
  5160. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5161. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5162. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5163. }
  5164. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5165. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5166. /// material id:
  5167. /// unused by the client
  5168. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5169. {
  5170. int i,c,view,fd;
  5171. nullpo_retv(sd);
  5172. if (sd->menuskill_id == skill_id)
  5173. return; //Avoid resending the menu twice or more times...
  5174. if (skill_id == GC_CREATENEWPOISON)
  5175. skill_id = GC_RESEARCHNEWPOISON;
  5176. fd = sd->fd;
  5177. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5178. WFIFOW(fd, 0) = 0x18d;
  5179. for (i = 0, c = 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. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5185. WFIFOW(fd,c*8+ 4) = view;
  5186. else
  5187. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5188. WFIFOW(fd,c*8+ 6) = 0;
  5189. WFIFOW(fd,c*8+ 8) = 0;
  5190. WFIFOW(fd,c*8+10) = 0;
  5191. c++;
  5192. }
  5193. }
  5194. WFIFOW(fd, 2) = c*8+8;
  5195. WFIFOSET(fd,WFIFOW(fd,2));
  5196. if (c > 0) {
  5197. sd->menuskill_id = skill_id;
  5198. sd->menuskill_val = trigger;
  5199. return;
  5200. }
  5201. }
  5202. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5203. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5204. /// mk type:
  5205. /// 1 = cooking
  5206. /// 2 = arrow
  5207. /// 3 = elemental
  5208. /// 4 = GN_MIX_COOKING
  5209. /// 5 = GN_MAKEBOMB
  5210. /// 6 = GN_S_PHARMACY
  5211. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5212. {
  5213. int fd;
  5214. int i, c;
  5215. int view;
  5216. nullpo_retv(sd);
  5217. fd = sd->fd;
  5218. if(sd->menuskill_id == skill_id)
  5219. return; //Avoid resending the menu twice or more times...
  5220. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5221. WFIFOW(fd,0) = 0x25a;
  5222. WFIFOW(fd,4) = list_type; // list type
  5223. c = 0;
  5224. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5225. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5226. continue;
  5227. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5228. WFIFOW(fd, 6 + 2 * c) = view;
  5229. else
  5230. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5231. c++;
  5232. }
  5233. if( c > 0 || skill_id == AM_PHARMACY) {
  5234. sd->menuskill_id = skill_id;
  5235. sd->menuskill_val = trigger;
  5236. sd->menuskill_val2 = qty; // amount.
  5237. WFIFOW(fd,2) = 6 + 2 * c;
  5238. WFIFOSET(fd,WFIFOW(fd,2));
  5239. } else {
  5240. clif_menuskill_clear(sd);
  5241. #if PACKETVER >= 20090922
  5242. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5243. #else
  5244. WFIFOW(fd,2) = 6 + 2 * c;
  5245. WFIFOSET(fd,WFIFOW(fd,2));
  5246. #endif
  5247. }
  5248. }
  5249. /// Notifies clients of a status change.
  5250. /// 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)]
  5251. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5252. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5253. /// @param bl Sends packet to clients around this object
  5254. /// @param id ID of object that has this effect
  5255. /// @param type Status icon see enum efst_types
  5256. /// @param flag 1:Active, 0:Deactive
  5257. /// @param tick Duration in ms
  5258. /// @param val1
  5259. /// @param val2
  5260. /// @param val3
  5261. 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)
  5262. {
  5263. unsigned char buf[32];
  5264. if (type == EFST_BLANK) //It shows nothing on the client...
  5265. return;
  5266. if (type == EFST_POSTDELAY && tick == 0)
  5267. return;
  5268. nullpo_retv(bl);
  5269. #if PACKETVER < 20151104
  5270. if (type == EFST_WEAPONPROPERTY)
  5271. type = EFST_ATTACK_PROPERTY_NOTHING + val1; // Assign status icon for older clients
  5272. #endif
  5273. #if PACKETVER >= 20120618
  5274. if (flag && battle_config.display_status_timers)
  5275. WBUFW(buf,0) = 0x983;
  5276. else
  5277. #elif PACKETVER >= 20090121
  5278. if (flag && battle_config.display_status_timers)
  5279. WBUFW(buf,0) = 0x43f;
  5280. else
  5281. #endif
  5282. WBUFW(buf,0) = 0x196;
  5283. WBUFW(buf,2) = type;
  5284. WBUFL(buf,4) = id;
  5285. WBUFB(buf,8) = flag;
  5286. #if PACKETVER >= 20120618
  5287. if (flag && battle_config.display_status_timers) {
  5288. if (tick <= 0)
  5289. tick = 9999; // this is indeed what official servers do
  5290. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5291. WBUFL(buf,13) = client_tick(tick);
  5292. WBUFL(buf,17) = val1;
  5293. WBUFL(buf,21) = val2;
  5294. WBUFL(buf,25) = val3;
  5295. }
  5296. #elif PACKETVER >= 20090121
  5297. if (flag && battle_config.display_status_timers) {
  5298. if (tick <= 0)
  5299. tick = 9999; // this is indeed what official servers do
  5300. WBUFL(buf,9) = client_tick(tick);
  5301. WBUFL(buf,13) = val1;
  5302. WBUFL(buf,17) = val2;
  5303. WBUFL(buf,21) = val3;
  5304. }
  5305. #endif
  5306. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5307. }
  5308. /* Sends status effect to clients around the bl
  5309. * @param bl Object that has the effect
  5310. * @param type Status icon see enum efst_types
  5311. * @param flag 1:Active, 0:Deactive
  5312. * @param tick Duration in ms
  5313. * @param val1
  5314. * @param val2
  5315. * @param val3
  5316. */
  5317. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5318. struct map_session_data *sd = NULL;
  5319. if (type == EFST_BLANK) //It shows nothing on the client...
  5320. return;
  5321. if (type == EFST_POSTDELAY && tick == 0)
  5322. return;
  5323. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5324. return;
  5325. nullpo_retv(bl);
  5326. sd = BL_CAST(BL_PC, bl);
  5327. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5328. return;
  5329. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5330. }
  5331. /**
  5332. * Send any active EFST to those around.
  5333. * @param tbl: Unit to send the packet to
  5334. * @param bl: Objects walking into view
  5335. * @param target: Client send type
  5336. */
  5337. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5338. unsigned char i;
  5339. struct sc_display_entry **sc_display;
  5340. unsigned char sc_display_count;
  5341. bool spheres_sent;
  5342. nullpo_retv(bl);
  5343. switch( bl->type ){
  5344. case BL_PC: {
  5345. struct map_session_data* sd = (struct map_session_data*)bl;
  5346. sc_display = sd->sc_display;
  5347. sc_display_count = sd->sc_display_count;
  5348. spheres_sent = !sd->state.connect_new;
  5349. }
  5350. break;
  5351. case BL_NPC: {
  5352. struct npc_data* nd = (struct npc_data*)bl;
  5353. sc_display = nd->sc_display;
  5354. sc_display_count = nd->sc_display_count;
  5355. spheres_sent = true;
  5356. }
  5357. break;
  5358. default:
  5359. return;
  5360. }
  5361. for (i = 0; i < sc_display_count; i++) {
  5362. enum sc_type type = sc_display[i]->type;
  5363. struct status_change *sc = status_get_sc(bl);
  5364. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5365. t_tick tick = 0;
  5366. if (td)
  5367. tick = DIFF_TICK(td->tick, gettick());
  5368. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5369. #if PACKETVER > 20120418
  5370. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5371. #else
  5372. 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);
  5373. #endif
  5374. }else{
  5375. #if PACKETVER > 20120418
  5376. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5377. #else
  5378. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5379. #endif
  5380. }
  5381. }
  5382. }
  5383. /// Notifies the client when a player enters the screen with an active EFST.
  5384. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5385. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5386. 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) {
  5387. #if PACKETVER >= 20111108
  5388. unsigned char buf[32];
  5389. #if PACKETVER >= 20120618
  5390. const int cmd = 0x984;
  5391. #elif PACKETVER >= 20111108
  5392. const int cmd = 0x8ff;
  5393. #endif
  5394. int offset = 0;
  5395. if (type == EFST_BLANK)
  5396. return;
  5397. nullpo_retv(bl);
  5398. if (tick <= 0)
  5399. tick = 9999;
  5400. WBUFW(buf,offset + 0) = cmd;
  5401. WBUFL(buf,offset + 2) = tid;
  5402. WBUFW(buf,offset + 6) = type;
  5403. #if PACKETVER >= 20111108
  5404. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5405. #if PACKETVER >= 20120618
  5406. WBUFL(buf,offset + 12) = client_tick(tick);
  5407. offset += 4;
  5408. #endif
  5409. WBUFL(buf,offset + 12) = val1;
  5410. WBUFL(buf,offset + 16) = val2;
  5411. WBUFL(buf,offset + 20) = val3;
  5412. #endif
  5413. clif_send(buf,packet_len(cmd),bl,target);
  5414. #endif
  5415. }
  5416. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5417. /// 008e <packet len>.W <message>.?B
  5418. void clif_displaymessage(const int fd, const char* mes)
  5419. {
  5420. nullpo_retv(mes);
  5421. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5422. if (fd == 0)
  5423. ;
  5424. else {
  5425. char *message, *line;
  5426. message = aStrdup(mes);
  5427. line = strtok(message, "\n");
  5428. while(line != NULL) {
  5429. #if PACKETVER == 20141022
  5430. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5431. /** so we redirect to ZC_NPC_CHAT **/
  5432. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5433. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5434. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5435. if (len > 0) {
  5436. WFIFOHEAD(fd, 13 + len);
  5437. WFIFOW(fd, 0) = 0x2C1;
  5438. WFIFOW(fd, 2) = 13 + len;
  5439. WFIFOL(fd, 4) = 0;
  5440. WFIFOL(fd, 8) = color;
  5441. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5442. WFIFOSET(fd, WFIFOW(fd, 2));
  5443. }
  5444. #else
  5445. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5446. int len = strnlen(line, CHAT_SIZE_MAX);
  5447. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5448. WFIFOHEAD(fd, 5 + len);
  5449. WFIFOW(fd,0) = 0x8e;
  5450. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5451. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5452. WFIFOSET(fd, 5 + len);
  5453. }
  5454. #endif
  5455. line = strtok(NULL, "\n");
  5456. }
  5457. aFree(message);
  5458. }
  5459. }
  5460. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5461. /// 009a <packet len>.W <message>.?B
  5462. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5463. {
  5464. nullpo_retv(mes);
  5465. if (len < 2)
  5466. return;
  5467. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5468. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5469. WBUFW(buf.get(),0) = 0x9a;
  5470. WBUFW(buf.get(),2) = 4 + lp + len;
  5471. if (type&BC_BLUE)
  5472. 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.
  5473. else if (type&BC_WOE)
  5474. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5475. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5476. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5477. }
  5478. /*==========================================
  5479. * Displays a message on a 'bl' to all it's nearby clients
  5480. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5481. *------------------------------------------*/
  5482. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5483. size_t len;
  5484. nullpo_retv(bl);
  5485. if(!message)
  5486. return;
  5487. len = strlen(message)+1;
  5488. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5489. if( len > CHAT_SIZE_MAX ) {
  5490. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  5491. len = CHAT_SIZE_MAX;
  5492. }
  5493. std::unique_ptr<char> buf(new char[8+len]);
  5494. WBUFW(buf.get(),0)=0x8d;
  5495. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5496. WBUFL(buf.get(),4)=bl->id;
  5497. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5498. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5499. }
  5500. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5501. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5502. 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)
  5503. {
  5504. nullpo_retv(mes);
  5505. if (len < 2)
  5506. return;
  5507. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5508. WBUFW(buf.get(),0) = 0x1c3;
  5509. WBUFW(buf.get(),2) = len + 16;
  5510. WBUFL(buf.get(),4) = fontColor;
  5511. WBUFW(buf.get(),8) = fontType;
  5512. WBUFW(buf.get(),10) = fontSize;
  5513. WBUFW(buf.get(),12) = fontAlign;
  5514. WBUFW(buf.get(),14) = fontY;
  5515. memcpy(WBUFP(buf.get(),16), mes, len);
  5516. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5517. }
  5518. /*
  5519. * Display *msg to all *users in channel
  5520. */
  5521. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5522. DBIterator *iter;
  5523. struct map_session_data *user;
  5524. unsigned short msg_len = 0, len = 0;
  5525. unsigned char buf[CHAT_SIZE_MAX];
  5526. if (!channel || !msg)
  5527. return;
  5528. msg_len = (unsigned short)(strlen(msg) + 1);
  5529. if( msg_len > sizeof(buf)-12 ) {
  5530. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5531. msg_len = sizeof(buf)-12;
  5532. }
  5533. WBUFW(buf,0) = 0x2C1;
  5534. WBUFW(buf,2) = (len = msg_len + 12);
  5535. WBUFL(buf,4) = 0;
  5536. WBUFL(buf,8) = color;
  5537. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5538. iter = db_iterator(channel->users);
  5539. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5540. clif_send(buf, len, &user->bl, SELF);
  5541. }
  5542. dbi_destroy(iter);
  5543. }
  5544. /// Displays heal effect.
  5545. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5546. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5547. /// var id:
  5548. /// 5 = HP (SP_HP)
  5549. /// 7 = SP (SP_SP)
  5550. /// ? = ignored
  5551. void clif_heal(int fd,int type,int val) {
  5552. #if PACKETVER < 20141022
  5553. const int cmd = 0x13d;
  5554. #else
  5555. const int cmd = 0xa27;
  5556. #endif
  5557. WFIFOHEAD(fd, packet_len(cmd));
  5558. WFIFOW(fd,0) = cmd;
  5559. WFIFOW(fd,2) = type;
  5560. #if PACKETVER < 20141022
  5561. WFIFOW(fd,4) = min(val, INT16_MAX);
  5562. #else
  5563. WFIFOL(fd,4) = min(val, INT32_MAX);
  5564. #endif
  5565. WFIFOSET(fd, packet_len(cmd));
  5566. }
  5567. /// Displays resurrection effect (ZC_RESURRECTION).
  5568. /// 0148 <id>.L <type>.W
  5569. /// type:
  5570. /// ignored
  5571. void clif_resurrection(struct block_list *bl,int type)
  5572. {
  5573. unsigned char buf[16];
  5574. nullpo_retv(bl);
  5575. WBUFW(buf,0)=0x148;
  5576. WBUFL(buf,2)=bl->id;
  5577. WBUFW(buf,6)=0;
  5578. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5579. if (disguised(bl))
  5580. clif_spawn(bl);
  5581. }
  5582. /// Sets the map property
  5583. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5584. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5585. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5586. {
  5587. #if PACKETVER >= 20121010
  5588. short cmd = 0x99b;
  5589. unsigned char buf[8];
  5590. #else
  5591. short cmd = 0x199;
  5592. unsigned char buf[4];
  5593. #endif
  5594. WBUFW(buf,0)=cmd;
  5595. WBUFW(buf,2)=property;
  5596. #if PACKETVER >= 20121010
  5597. struct map_data *mapdata = map_getmapdata(bl->m);
  5598. WBUFL(buf,4) = ((mapdata->flag[MF_PVP]?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5599. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5600. ((mapdata->flag[MF_BATTLEGROUND] || mapdata_flag_gvg2(mapdata)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5601. ((mapdata->flag[MF_NOMINEEFFECT] || !mapdata_flag_gvg2(mapdata)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5602. ((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
  5603. ((mapdata->flag[MF_PVP]?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5604. ((mapdata->flag[MF_PARTYLOCK]?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5605. ((mapdata->flag[MF_BATTLEGROUND]?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5606. ((mapdata->flag[MF_NOCOSTUME]?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5607. ((mapdata->flag[MF_NOUSECART]?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5608. ((mapdata->flag[MF_NOSUNMOONSTARMIRACLE]?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5609. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5610. #endif
  5611. clif_send(buf,packet_len(cmd),bl,t);
  5612. }
  5613. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5614. /// 01d6 <type>.W
  5615. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5616. {
  5617. int fd;
  5618. nullpo_retv(sd);
  5619. fd=sd->fd;
  5620. WFIFOHEAD(fd,packet_len(0x1D6));
  5621. WFIFOW(fd,0)=0x1D6;
  5622. WFIFOW(fd,2)=type;
  5623. WFIFOSET(fd,packet_len(0x1D6));
  5624. }
  5625. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5626. /// 019a <id>.L <ranking>.L <total>.L
  5627. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5628. {
  5629. if(type == 2) {
  5630. int fd = sd->fd;
  5631. WFIFOHEAD(fd,packet_len(0x19a));
  5632. WFIFOW(fd,0) = 0x19a;
  5633. WFIFOL(fd,2) = sd->bl.id;
  5634. WFIFOL(fd,6) = pvprank;
  5635. WFIFOL(fd,10) = pvpnum;
  5636. WFIFOSET(fd,packet_len(0x19a));
  5637. } else {
  5638. unsigned char buf[32];
  5639. WBUFW(buf,0) = 0x19a;
  5640. WBUFL(buf,2) = sd->bl.id;
  5641. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5642. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5643. else
  5644. WBUFL(buf,6) = pvprank;
  5645. WBUFL(buf,10) = pvpnum;
  5646. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5647. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5648. else if(!type)
  5649. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5650. else
  5651. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5652. }
  5653. }
  5654. /*==========================================
  5655. *
  5656. *------------------------------------------*/
  5657. void clif_map_property_mapall(int map_idx, enum map_property property)
  5658. {
  5659. struct block_list bl;
  5660. bl.id = 0;
  5661. bl.type = BL_NUL;
  5662. bl.m = map_idx;
  5663. clif_map_property( &bl, property, ALL_SAMEMAP );
  5664. }
  5665. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5666. /// 0188 <result>.W <index>.W <refine>.W
  5667. /// result:
  5668. /// 0 = success
  5669. /// 1 = failure
  5670. /// 2 = downgrade
  5671. void clif_refine(int fd, int fail, int index, int val)
  5672. {
  5673. WFIFOHEAD(fd,packet_len(0x188));
  5674. WFIFOW(fd,0)=0x188;
  5675. WFIFOW(fd,2)=fail;
  5676. WFIFOW(fd,4)=index+2;
  5677. WFIFOW(fd,6)=val;
  5678. WFIFOSET(fd,packet_len(0x188));
  5679. }
  5680. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5681. /// 0223 <result>.L <nameid>.W
  5682. /// result:
  5683. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5684. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5685. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5686. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5687. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5688. {
  5689. WFIFOHEAD(fd,packet_len(0x223));
  5690. WFIFOW(fd,0)=0x223;
  5691. WFIFOL(fd,2)=result;
  5692. WFIFOW(fd,6)=item_id;
  5693. WFIFOSET(fd,packet_len(0x223));
  5694. }
  5695. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5696. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5697. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5698. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5699. int fd;
  5700. nullpo_retv(sd);
  5701. fd = sd->fd;
  5702. #if PACKETVER < 20091104
  5703. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5704. WFIFOW(fd,0) = 0x97;
  5705. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5706. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5707. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5708. WFIFOSET(fd,WFIFOW(fd,2));
  5709. #else
  5710. struct map_session_data *ssd = map_nick2sd(nick,false);
  5711. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5712. WFIFOW(fd,0) = 0x97;
  5713. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5714. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5715. // If it is not a message from the server or a player from another map-server
  5716. if( ssd ){
  5717. gmlvl = pc_get_group_level(ssd);
  5718. }
  5719. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5720. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5721. WFIFOSET(fd,WFIFOW(fd,2));
  5722. #endif
  5723. }
  5724. /// Inform the player about the result of his whisper action
  5725. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5726. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5727. /// result:
  5728. /// 0 = success to send wisper
  5729. /// 1 = target character is not loged in
  5730. /// 2 = ignored by target
  5731. /// 3 = everyone ignored by target
  5732. void clif_wis_end(int fd, int result)
  5733. {
  5734. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5735. #if PACKETVER < 20131223
  5736. const int cmd = 0x98;
  5737. #else
  5738. const int cmd = 0x9df;
  5739. #endif
  5740. if (!sd)
  5741. return;
  5742. WFIFOHEAD(fd,packet_len(cmd));
  5743. WFIFOW(fd,0) = cmd;
  5744. WFIFOB(fd,2) = (char)result;
  5745. #if PACKETVER >= 20131223
  5746. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5747. #endif
  5748. WFIFOSET(fd,packet_len(cmd));
  5749. }
  5750. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5751. /// 0194 <char id>.L <name>.24B
  5752. /// 0af7 <flag>.W <char id>.L <name>.24B
  5753. void clif_solved_charname(int fd, int charid, const char* name)
  5754. {
  5755. #if PACKETVER >= 20180221
  5756. WFIFOHEAD(fd,packet_len(0xaf7));
  5757. WFIFOW(fd,0) = 0xaf7;
  5758. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5759. WFIFOL(fd,4) = charid;
  5760. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5761. WFIFOSET(fd,packet_len(0x0af7));
  5762. #else
  5763. WFIFOHEAD(fd,packet_len(0x194));
  5764. WFIFOW(fd,0)=0x194;
  5765. WFIFOL(fd,2)=charid;
  5766. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5767. WFIFOSET(fd,packet_len(0x194));
  5768. #endif
  5769. }
  5770. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5771. /// 017b <packet len>.W { <name id>.W }*
  5772. void clif_use_card(struct map_session_data *sd,int idx)
  5773. {
  5774. int i,c,ep;
  5775. int fd=sd->fd;
  5776. nullpo_retv(sd);
  5777. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5778. return;
  5779. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5780. return; //Avoid parsing invalid item indexes (no card/no item)
  5781. ep=sd->inventory_data[idx]->equip;
  5782. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5783. WFIFOW(fd,0)=0x17b;
  5784. for(i=c=0;i<MAX_INVENTORY;i++){
  5785. int j;
  5786. if(sd->inventory_data[i] == NULL)
  5787. continue;
  5788. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5789. continue;
  5790. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5791. continue;
  5792. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5793. continue;
  5794. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5795. continue;
  5796. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5797. continue;
  5798. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5799. if( j == sd->inventory_data[i]->slot ) // No room
  5800. continue;
  5801. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5802. continue;
  5803. WFIFOW(fd,4+c*2)=i+2;
  5804. c++;
  5805. }
  5806. if( !c ) return; // no item is available for card insertion
  5807. WFIFOW(fd,2)=4+c*2;
  5808. WFIFOSET(fd,WFIFOW(fd,2));
  5809. }
  5810. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5811. /// 017d <equip index>.W <card index>.W <result>.B
  5812. /// result:
  5813. /// 0 = success
  5814. /// 1 = failure
  5815. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5816. {
  5817. int fd;
  5818. nullpo_retv(sd);
  5819. fd=sd->fd;
  5820. WFIFOHEAD(fd,packet_len(0x17d));
  5821. WFIFOW(fd,0)=0x17d;
  5822. WFIFOW(fd,2)=idx_equip+2;
  5823. WFIFOW(fd,4)=idx_card+2;
  5824. WFIFOB(fd,6)=flag;
  5825. WFIFOSET(fd,packet_len(0x17d));
  5826. }
  5827. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5828. /// 0177 <packet len>.W { <name id>.W }*
  5829. void clif_item_identify_list(struct map_session_data *sd)
  5830. {
  5831. int i,c;
  5832. int fd;
  5833. nullpo_retv(sd);
  5834. fd=sd->fd;
  5835. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5836. WFIFOW(fd,0)=0x177;
  5837. for(i=c=0;i<MAX_INVENTORY;i++){
  5838. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5839. WFIFOW(fd,c*2+4)=i+2;
  5840. c++;
  5841. }
  5842. }
  5843. if(c > 0) {
  5844. WFIFOW(fd,2)=c*2+4;
  5845. WFIFOSET(fd,WFIFOW(fd,2));
  5846. sd->menuskill_id = MC_IDENTIFY;
  5847. sd->menuskill_val = c;
  5848. sd->state.workinprogress = WIP_DISABLE_ALL;
  5849. }
  5850. }
  5851. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5852. /// 0179 <index>.W <result>.B
  5853. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5854. {
  5855. int fd;
  5856. nullpo_retv(sd);
  5857. fd=sd->fd;
  5858. WFIFOHEAD(fd,packet_len(0x179));
  5859. WFIFOW(fd, 0)=0x179;
  5860. WFIFOW(fd, 2)=idx+2;
  5861. WFIFOB(fd, 4)=flag;
  5862. WFIFOSET(fd,packet_len(0x179));
  5863. }
  5864. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5865. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5866. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5867. {
  5868. int i,c;
  5869. int fd;
  5870. nullpo_retv(sd);
  5871. nullpo_retv(dstsd);
  5872. fd=sd->fd;
  5873. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5874. WFIFOW(fd,0)=0x1fc;
  5875. for(i=c=0;i<MAX_INVENTORY;i++){
  5876. unsigned short nameid;
  5877. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5878. WFIFOW(fd,c*13+4) = i;
  5879. WFIFOW(fd,c*13+6) = nameid;
  5880. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5881. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5882. c++;
  5883. }
  5884. }
  5885. if(c > 0) {
  5886. WFIFOW(fd,2)=c*13+4;
  5887. WFIFOSET(fd,WFIFOW(fd,2));
  5888. sd->menuskill_id = BS_REPAIRWEAPON;
  5889. sd->menuskill_val = dstsd->bl.id;
  5890. sd->menuskill_val2 = lv;
  5891. }else
  5892. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5893. }
  5894. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5895. /// 01fe <index>.W <result>.B
  5896. /// index:
  5897. /// ignored (inventory index)
  5898. /// result:
  5899. /// 0 = Item repair success.
  5900. /// 1 = Item repair failure.
  5901. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5902. {
  5903. int fd;
  5904. nullpo_retv(sd);
  5905. fd = sd->fd;
  5906. WFIFOHEAD(fd,packet_len(0x1fe));
  5907. WFIFOW(fd, 0)=0x1fe;
  5908. WFIFOW(fd, 2)=idx+2;
  5909. WFIFOB(fd, 4)=flag;
  5910. WFIFOSET(fd,packet_len(0x1fe));
  5911. }
  5912. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5913. /// 02bb <equip location>.W <account id>.L
  5914. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5915. {
  5916. int fd = sd->fd;
  5917. WFIFOHEAD(fd,packet_len(0x2bb));
  5918. WFIFOW(fd,0) = 0x2bb;
  5919. WFIFOW(fd,2) = position;
  5920. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5921. WFIFOSET(fd,packet_len(0x2bb));
  5922. }
  5923. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5924. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5925. void clif_item_refine_list(struct map_session_data *sd)
  5926. {
  5927. int i,c;
  5928. int fd;
  5929. uint16 skill_lv;
  5930. int refine_item[5];
  5931. nullpo_retv(sd);
  5932. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5933. fd=sd->fd;
  5934. refine_item[0] = -1;
  5935. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5936. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5937. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5938. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5939. WFIFOW(fd,0) = 0x221;
  5940. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5941. unsigned char wlv;
  5942. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5943. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5944. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5945. WFIFOW(fd,c*13+ 4)=i+2;
  5946. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5947. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5948. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5949. c++;
  5950. }
  5951. }
  5952. WFIFOW(fd,2)=c*13+4;
  5953. WFIFOSET(fd,WFIFOW(fd,2));
  5954. if (c > 0) {
  5955. sd->menuskill_id = WS_WEAPONREFINE;
  5956. sd->menuskill_val = skill_lv;
  5957. }
  5958. }
  5959. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5960. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5961. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5962. {
  5963. int fd;
  5964. nullpo_retv(sd);
  5965. fd=sd->fd;
  5966. WFIFOHEAD(fd,packet_len(0x147));
  5967. WFIFOW(fd, 0)=0x147;
  5968. WFIFOW(fd, 2)=skill_id;
  5969. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5970. WFIFOW(fd, 6)=0;
  5971. WFIFOW(fd, 8)=skill_lv;
  5972. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5973. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5974. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5975. WFIFOB(fd,38)=0;
  5976. WFIFOSET(fd,packet_len(0x147));
  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,int fail)
  5983. {
  5984. #if PACKETVER < 5
  5985. const int cmd = 0x124;
  5986. #elif PACKETVER < 20150225
  5987. const int cmd = 0x1c5;
  5988. #else
  5989. const int cmd = 0xa0b;
  5990. #endif
  5991. int view,fd;
  5992. unsigned char *buf;
  5993. int offset = 0;
  5994. nullpo_retv(sd);
  5995. fd=sd->fd;
  5996. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  5997. return;
  5998. WFIFOHEAD(fd,packet_len(cmd));
  5999. buf=WFIFOP(fd,0);
  6000. WBUFW(buf,0)=cmd;
  6001. WBUFW(buf,2)=n+2;
  6002. WBUFL(buf,4)=amount;
  6003. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  6004. WBUFW(buf,8)=view;
  6005. else
  6006. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  6007. #if PACKETVER >= 5
  6008. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  6009. offset += 1;
  6010. #endif
  6011. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  6012. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  6013. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  6014. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  6015. #if PACKETVER >= 20150225
  6016. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  6017. #endif
  6018. WFIFOSET(fd,packet_len(cmd));
  6019. }
  6020. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6021. /* Acknowledge an item have been added to cart
  6022. * 012c <result>B
  6023. * result :
  6024. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6025. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6026. */
  6027. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6028. {
  6029. int fd;
  6030. unsigned char *buf;
  6031. nullpo_retv(sd);
  6032. fd = sd->fd;
  6033. buf = WFIFOP(fd,0);
  6034. WBUFW(buf,0) = 0x12c;
  6035. WBUFB(buf,2) = flag;
  6036. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6037. }
  6038. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6039. void clif_bank_open(struct map_session_data *sd){
  6040. int fd;
  6041. nullpo_retv(sd);
  6042. fd = sd->fd;
  6043. WFIFOHEAD(fd,4);
  6044. WFIFOW(fd,0) = 0x09b7;
  6045. WFIFOW(fd,2) = 0;
  6046. WFIFOSET(fd,4);
  6047. }
  6048. /*
  6049. * Request to Open the banking system
  6050. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6051. */
  6052. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6053. //TODO check if preventing trade or stuff like that
  6054. //also mark something in case char ain't available for saving, should we check now ?
  6055. nullpo_retv(sd);
  6056. if( !battle_config.feature_banking ) {
  6057. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6058. return;
  6059. }
  6060. else {
  6061. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6062. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6063. if(sd->status.account_id == aid){
  6064. sd->state.banking = 1;
  6065. //request save ?
  6066. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6067. //on succes open bank ?
  6068. clif_bank_open(sd);
  6069. }
  6070. }
  6071. }
  6072. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6073. void clif_bank_close(struct map_session_data *sd){
  6074. int fd;
  6075. nullpo_retv(sd);
  6076. fd = sd->fd;
  6077. WFIFOHEAD(fd,4);
  6078. WFIFOW(fd,0) = 0x09B9;
  6079. WFIFOW(fd,2) = 0;
  6080. WFIFOSET(fd,4);
  6081. }
  6082. /*
  6083. * Request to close the banking system
  6084. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6085. */
  6086. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6087. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6088. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6089. nullpo_retv(sd);
  6090. if( !battle_config.feature_banking ) {
  6091. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6092. //still allow to go trough to not stuck player if we have disable it while they was in
  6093. }
  6094. if(sd->status.account_id == aid){
  6095. sd->state.banking = 0;
  6096. clif_bank_close(sd);
  6097. }
  6098. }
  6099. /*
  6100. * Display how much we got in bank (I suppose)
  6101. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6102. */
  6103. void clif_Bank_Check(struct map_session_data* sd) {
  6104. unsigned char buf[13];
  6105. struct s_packet_db* info;
  6106. int16 len;
  6107. int cmd = 0;
  6108. nullpo_retv(sd);
  6109. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6110. if(!cmd) cmd = 0x09A6; //default
  6111. info = &packet_db[cmd];
  6112. len = info->len;
  6113. if(!len) return; //version as packet disable
  6114. // sd->state.banking = 1; //mark opening and closing
  6115. WBUFW(buf,0) = cmd;
  6116. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6117. WBUFW(buf,info->pos[1]) = 0; //reason
  6118. clif_send(buf,len,&sd->bl,SELF);
  6119. }
  6120. /*
  6121. * Requesting the data in bank
  6122. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6123. */
  6124. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6125. nullpo_retv(sd);
  6126. if( !battle_config.feature_banking ) {
  6127. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6128. return;
  6129. }
  6130. else {
  6131. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6132. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6133. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6134. clif_Bank_Check(sd);
  6135. }
  6136. }
  6137. /*
  6138. * Acknowledge of deposit some money in bank
  6139. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6140. */
  6141. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6142. unsigned char buf[17];
  6143. struct s_packet_db* info;
  6144. int16 len;
  6145. int cmd =0;
  6146. nullpo_retv(sd);
  6147. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6148. if(!cmd) cmd = 0x09A8;
  6149. info = &packet_db[cmd];
  6150. len = info->len;
  6151. if(!len) return; //version as packet disable
  6152. WBUFW(buf,0) = cmd;
  6153. WBUFW(buf,info->pos[0]) = (short)reason;
  6154. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6155. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6156. clif_send(buf,len,&sd->bl,SELF);
  6157. }
  6158. /*
  6159. * Request saving some money in bank
  6160. * @author : original [Yommy/Hercules]
  6161. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6162. */
  6163. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6164. nullpo_retv(sd);
  6165. if( !battle_config.feature_banking ) {
  6166. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6167. return;
  6168. }
  6169. else {
  6170. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6171. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6172. int money = RFIFOL(fd,info->pos[1]);
  6173. if(sd->status.account_id == aid){
  6174. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6175. clif_bank_deposit(sd,reason);
  6176. }
  6177. }
  6178. }
  6179. /*
  6180. * Acknowledge of withdrawing some money from bank
  6181. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6182. */
  6183. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6184. unsigned char buf[17];
  6185. struct s_packet_db* info;
  6186. int16 len;
  6187. int cmd;
  6188. nullpo_retv(sd);
  6189. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6190. if(!cmd) cmd = 0x09AA;
  6191. info = &packet_db[cmd];
  6192. len = info->len;
  6193. if(!len) return; //version as packet disable
  6194. WBUFW(buf,0) = cmd;
  6195. WBUFW(buf,info->pos[0]) = (short)reason;
  6196. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6197. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6198. clif_send(buf,len,&sd->bl,SELF);
  6199. }
  6200. /*
  6201. * Request Withdrawing some money from bank
  6202. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6203. */
  6204. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6205. nullpo_retv(sd);
  6206. if( !battle_config.feature_banking ) {
  6207. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6208. return;
  6209. }
  6210. else {
  6211. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6212. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6213. int money = RFIFOL(fd,info->pos[1]);
  6214. if(sd->status.account_id == aid){
  6215. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6216. clif_bank_withdraw(sd,reason);
  6217. }
  6218. }
  6219. }
  6220. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6221. /// 0125 <index>.W <amount>.L
  6222. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6223. {
  6224. int fd;
  6225. nullpo_retv(sd);
  6226. fd=sd->fd;
  6227. WFIFOHEAD(fd,packet_len(0x125));
  6228. WFIFOW(fd,0)=0x125;
  6229. WFIFOW(fd,2)=n+2;
  6230. WFIFOL(fd,4)=amount;
  6231. WFIFOSET(fd,packet_len(0x125));
  6232. }
  6233. /// Opens the shop creation menu (ZC_OPENSTORE).
  6234. /// 012d <num>.W
  6235. /// num:
  6236. /// number of allowed item slots
  6237. void clif_openvendingreq(struct map_session_data* sd, int num)
  6238. {
  6239. int fd;
  6240. nullpo_retv(sd);
  6241. fd = sd->fd;
  6242. WFIFOHEAD(fd,packet_len(0x12d));
  6243. WFIFOW(fd,0) = 0x12d;
  6244. WFIFOW(fd,2) = num;
  6245. WFIFOSET(fd,packet_len(0x12d));
  6246. }
  6247. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6248. /// 0131 <owner id>.L <message>.80B
  6249. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6250. {
  6251. unsigned char buf[128];
  6252. nullpo_retv(bl);
  6253. WBUFW(buf,0) = 0x131;
  6254. WBUFL(buf,2) = bl->id;
  6255. safestrncpy(WBUFCP(buf,6), message, 80);
  6256. if( fd ) {
  6257. WFIFOHEAD(fd,packet_len(0x131));
  6258. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6259. WFIFOSET(fd,packet_len(0x131));
  6260. } else {
  6261. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6262. }
  6263. }
  6264. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6265. /// 0132 <owner id>.L
  6266. void clif_closevendingboard(struct block_list* bl, int fd)
  6267. {
  6268. unsigned char buf[16];
  6269. nullpo_retv(bl);
  6270. WBUFW(buf,0) = 0x132;
  6271. WBUFL(buf,2) = bl->id;
  6272. if( fd ) {
  6273. WFIFOHEAD(fd,packet_len(0x132));
  6274. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6275. WFIFOSET(fd,packet_len(0x132));
  6276. } else {
  6277. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6278. }
  6279. }
  6280. /// Sends a list of items in a shop.
  6281. /// 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)
  6282. /// 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)
  6283. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6284. {
  6285. int i,fd;
  6286. int count;
  6287. struct map_session_data* vsd;
  6288. #if PACKETVER < 20100105
  6289. const int cmd = 0x133;
  6290. const int offset = 8;
  6291. #else
  6292. const int cmd = 0x800;
  6293. const int offset = 12;
  6294. #endif
  6295. #if PACKETVER < 20150225
  6296. const int item_length = 22;
  6297. #elif PACKETVER < 20160921
  6298. const int item_length = 47;
  6299. #else
  6300. const int item_length = 53;
  6301. #endif
  6302. nullpo_retv(sd);
  6303. nullpo_retv(vending);
  6304. nullpo_retv(vsd=map_id2sd(id));
  6305. fd = sd->fd;
  6306. count = vsd->vend_num;
  6307. WFIFOHEAD(fd, offset+count*item_length);
  6308. WFIFOW(fd,0) = cmd;
  6309. WFIFOW(fd,2) = offset+count*item_length;
  6310. WFIFOL(fd,4) = id;
  6311. #if PACKETVER >= 20100105
  6312. WFIFOL(fd,8) = vsd->vender_id;
  6313. #endif
  6314. for( i = 0; i < count; i++ )
  6315. {
  6316. int index = vending[i].index;
  6317. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6318. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6319. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6320. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6321. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6322. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6323. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6324. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6325. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6326. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6327. #if PACKETVER >= 20150225
  6328. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6329. #if PACKETVER >= 20160921
  6330. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6331. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6332. #endif
  6333. #endif
  6334. }
  6335. WFIFOSET(fd,WFIFOW(fd,2));
  6336. }
  6337. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6338. /// 0135 <index>.W <amount>.W <result>.B
  6339. /// result:
  6340. /// 0 = success
  6341. /// 1 = not enough zeny
  6342. /// 2 = overweight
  6343. /// 4 = out of stock
  6344. /// 5 = "cannot use an npc shop while in a trade"
  6345. /// 6 = Because the store information was incorrect the item was not purchased.
  6346. /// 7 = No sales information.
  6347. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6348. {
  6349. int fd;
  6350. nullpo_retv(sd);
  6351. fd = sd->fd;
  6352. WFIFOHEAD(fd,packet_len(0x135));
  6353. WFIFOW(fd,0) = 0x135;
  6354. WFIFOW(fd,2) = index+2;
  6355. WFIFOW(fd,4) = amount;
  6356. WFIFOB(fd,6) = fail;
  6357. WFIFOSET(fd,packet_len(0x135));
  6358. }
  6359. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6360. /// 0a28 <Result>.B
  6361. /// result:
  6362. /// 0 = Successed
  6363. /// 1 = Failed
  6364. void clif_openvending_ack(struct map_session_data* sd, int result)
  6365. {
  6366. int fd;
  6367. nullpo_retv(sd);
  6368. fd = sd->fd;
  6369. WFIFOHEAD(fd, 3);
  6370. WFIFOW(fd,0) = 0xa28;
  6371. WFIFOB(fd,2) = result;
  6372. WFIFOSET(fd, 3);
  6373. }
  6374. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6375. /// 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 }*
  6376. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6377. {
  6378. int i,fd;
  6379. int count;
  6380. #if PACKETVER < 20150225
  6381. const int item_length = 22;
  6382. #else
  6383. const int item_length = 47;
  6384. #endif
  6385. nullpo_retv(sd);
  6386. fd = sd->fd;
  6387. count = sd->vend_num;
  6388. WFIFOHEAD(fd, 8+count*item_length);
  6389. WFIFOW(fd,0) = 0x136;
  6390. WFIFOW(fd,2) = 8+count*item_length;
  6391. WFIFOL(fd,4) = id;
  6392. for( i = 0; i < count; i++ ) {
  6393. int index = vending[i].index;
  6394. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6395. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6396. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6397. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6398. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6399. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6400. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6401. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6402. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6403. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6404. #if PACKETVER >= 20150225
  6405. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6406. #endif
  6407. }
  6408. WFIFOSET(fd,WFIFOW(fd,2));
  6409. #if PACKETVER >= 20141022
  6410. /// 0 = Successed
  6411. /// 1 = Failed
  6412. clif_openvending_ack(sd, 0);
  6413. #endif
  6414. }
  6415. /// Inform merchant that someone has bought an item.
  6416. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6417. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6418. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6419. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6420. const int cmd = 0x137;
  6421. #else
  6422. const int cmd = 0x9e5;
  6423. #endif
  6424. int fd = sd->fd;
  6425. nullpo_retv(sd);
  6426. WFIFOHEAD(fd,packet_len(cmd));
  6427. WFIFOW(fd,0) = cmd;
  6428. WFIFOW(fd,2) = index+2;
  6429. WFIFOW(fd,4) = amount;
  6430. #if PACKETVER >= 20141016
  6431. WFIFOL(fd,6) = char_id; // GID
  6432. WFIFOL(fd,10) = (int)time(NULL); // Date
  6433. WFIFOL(fd,14) = zeny; // zeny
  6434. #endif
  6435. WFIFOSET(fd,packet_len(cmd));
  6436. }
  6437. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6438. /// 00fa <result>.B
  6439. /// result:
  6440. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6441. /// 1 = MsgStringTable[78]="party name already exists"
  6442. /// 2 = MsgStringTable[79]="already in a party"
  6443. /// 3 = cannot organize parties on this map
  6444. /// ? = nothing
  6445. void clif_party_created(struct map_session_data *sd,int result)
  6446. {
  6447. int fd;
  6448. nullpo_retv(sd);
  6449. fd=sd->fd;
  6450. WFIFOHEAD(fd,packet_len(0xfa));
  6451. WFIFOW(fd,0)=0xfa;
  6452. WFIFOB(fd,2)=result;
  6453. WFIFOSET(fd,packet_len(0xfa));
  6454. }
  6455. /// Adds new member to a party.
  6456. /// 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)
  6457. /// 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)
  6458. /// 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)
  6459. /// role:
  6460. /// 0 = leader
  6461. /// 1 = normal
  6462. /// state:
  6463. /// 0 = connected
  6464. /// 1 = disconnected
  6465. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6466. {
  6467. int i;
  6468. #if PACKETVER < 20170502
  6469. unsigned char buf[81];
  6470. int cmd = 0x1e9;
  6471. int offset = 0;
  6472. #else
  6473. unsigned char buf[85];
  6474. int cmd = 0xa43;
  6475. int offset = 4;
  6476. #endif
  6477. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6478. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6479. } else {
  6480. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6481. }
  6482. if (i >= MAX_PARTY) return; //Should never happen...
  6483. sd = p->data[i].sd;
  6484. WBUFW(buf, 0) = cmd;
  6485. WBUFL(buf, 2) = sd->status.account_id;
  6486. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6487. #if PACKETVER >= 20170502
  6488. WBUFW(buf,10) = sd->status.class_;
  6489. WBUFW(buf,12) = sd->status.base_level;
  6490. #endif
  6491. WBUFW(buf,offset+10) = sd->bl.x;
  6492. WBUFW(buf,offset+12) = sd->bl.y;
  6493. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6494. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6495. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6496. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6497. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6498. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6499. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6500. }
  6501. /// Sends party information (ZC_GROUP_LIST).
  6502. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6503. /// role:
  6504. /// 0 = leader
  6505. /// 1 = normal
  6506. /// state:
  6507. /// 0 = connected
  6508. /// 1 = disconnected
  6509. /// 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
  6510. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6511. {
  6512. struct map_session_data* party_sd = NULL;
  6513. int i, c;
  6514. #if PACKETVER < 20170502
  6515. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6516. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6517. int cmd = 0xfb;
  6518. #else
  6519. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6520. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6521. int cmd = 0xa44;
  6522. #endif
  6523. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6524. nullpo_retv(p);
  6525. WBUFW(buf,0) = cmd;
  6526. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6527. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6528. {
  6529. struct party_member* m = &p->party.member[i];
  6530. if(!m->account_id) continue;
  6531. if(party_sd == NULL) party_sd = p->data[i].sd;
  6532. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6533. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6534. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6535. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6536. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6537. #if PACKETVER >= 20170502
  6538. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6539. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6540. #endif
  6541. c++;
  6542. }
  6543. #if PACKETVER < 20170502
  6544. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6545. #else
  6546. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6547. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6548. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6549. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6550. #endif
  6551. if(sd) { // send only to self
  6552. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6553. } else if (party_sd) { // send to whole party
  6554. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6555. }
  6556. }
  6557. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6558. /// 02c9 <flag>.B
  6559. /// flag:
  6560. /// 0 = allow party invites
  6561. /// 1 = auto-deny party invites
  6562. void clif_partyinvitationstate(struct map_session_data* sd)
  6563. {
  6564. int fd;
  6565. nullpo_retv(sd);
  6566. fd = sd->fd;
  6567. WFIFOHEAD(fd, packet_len(0x2c9));
  6568. WFIFOW(fd, 0) = 0x2c9;
  6569. WFIFOB(fd, 2) = 0; // not implemented
  6570. WFIFOSET(fd, packet_len(0x2c9));
  6571. }
  6572. /// Party invitation request.
  6573. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6574. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6575. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6576. {
  6577. #if PACKETVER < 20070821
  6578. const int cmd = 0xfe;
  6579. #else
  6580. const int cmd = 0x2c6;
  6581. #endif
  6582. int fd;
  6583. struct party_data *p;
  6584. nullpo_retv(sd);
  6585. nullpo_retv(tsd);
  6586. fd=tsd->fd;
  6587. if( (p=party_search(sd->status.party_id))==NULL )
  6588. return;
  6589. WFIFOHEAD(fd,packet_len(cmd));
  6590. WFIFOW(fd,0)=cmd;
  6591. WFIFOL(fd,2)=sd->status.party_id;
  6592. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6593. WFIFOSET(fd,packet_len(cmd));
  6594. }
  6595. /// Party invite result.
  6596. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6597. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6598. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6599. {
  6600. int fd;
  6601. nullpo_retv(sd);
  6602. fd=sd->fd;
  6603. #if PACKETVER < 20070904
  6604. if( reply == PARTY_REPLY_OFFLINE ) {
  6605. clif_displaymessage(fd, msg_txt(sd,3));
  6606. return;
  6607. }
  6608. #endif
  6609. #if PACKETVER < 20070821
  6610. WFIFOHEAD(fd,packet_len(0xfd));
  6611. WFIFOW(fd,0) = 0xfd;
  6612. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6613. WFIFOB(fd,26) = reply;
  6614. WFIFOSET(fd,packet_len(0xfd));
  6615. #else
  6616. WFIFOHEAD(fd,packet_len(0x2c5));
  6617. WFIFOW(fd,0) = 0x2c5;
  6618. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6619. WFIFOL(fd,26) = reply;
  6620. WFIFOSET(fd,packet_len(0x2c5));
  6621. #endif
  6622. }
  6623. /// Updates party settings.
  6624. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6625. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6626. /// exp option:
  6627. /// 0 = exp sharing disabled
  6628. /// 1 = exp sharing enabled
  6629. /// 2 = cannot change exp sharing
  6630. ///
  6631. /// flag:
  6632. /// 0 = send to party
  6633. /// 1 = send to sd
  6634. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6635. {
  6636. unsigned char buf[16];
  6637. #if PACKETVER < 20090603
  6638. const int cmd = 0x101;
  6639. #else
  6640. const int cmd = 0x7d8;
  6641. #endif
  6642. nullpo_retv(p);
  6643. if(!sd && flag==0){
  6644. int i;
  6645. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6646. if (i < MAX_PARTY)
  6647. sd = p->data[i].sd;
  6648. }
  6649. if(!sd) return;
  6650. WBUFW(buf,0)=cmd;
  6651. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6652. #if PACKETVER >= 20090603
  6653. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6654. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6655. #endif
  6656. if(flag==0)
  6657. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6658. else
  6659. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6660. }
  6661. /**
  6662. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6663. * @param sd Send the notification for this player
  6664. * @param account_id Account ID of kicked member
  6665. * @param name Name of kicked member
  6666. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6667. * @param target Send target
  6668. **/
  6669. 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) {
  6670. unsigned char buf[2+4+NAME_LENGTH+1];
  6671. if (!sd)
  6672. return;
  6673. WBUFW(buf,0) = 0x0105;
  6674. WBUFL(buf,2) = account_id;
  6675. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6676. WBUFB(buf,6+NAME_LENGTH) = result;
  6677. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6678. }
  6679. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6680. /// 0109 <packet len>.W <account id>.L <message>.?B
  6681. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6682. {
  6683. struct map_session_data *sd;
  6684. int i;
  6685. nullpo_retv(p);
  6686. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6687. if(i < MAX_PARTY){
  6688. unsigned char buf[1024];
  6689. if( len > sizeof(buf)-8 )
  6690. {
  6691. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6692. len = sizeof(buf)-8;
  6693. }
  6694. sd = p->data[i].sd;
  6695. WBUFW(buf,0)=0x109;
  6696. WBUFW(buf,2)=len+8;
  6697. WBUFL(buf,4)=account_id;
  6698. safestrncpy(WBUFCP(buf,8), mes, len);
  6699. clif_send(buf,len+8,&sd->bl,PARTY);
  6700. }
  6701. }
  6702. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6703. /// 0107 <account id>.L <x>.W <y>.W
  6704. void clif_party_xy(struct map_session_data *sd)
  6705. {
  6706. unsigned char buf[16];
  6707. nullpo_retv(sd);
  6708. WBUFW(buf,0)=0x107;
  6709. WBUFL(buf,2)=sd->status.account_id;
  6710. WBUFW(buf,6)=sd->bl.x;
  6711. WBUFW(buf,8)=sd->bl.y;
  6712. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6713. }
  6714. /*==========================================
  6715. * Sends x/y dot to a single fd. [Skotlex]
  6716. *------------------------------------------*/
  6717. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6718. {
  6719. WFIFOHEAD(fd,packet_len(0x107));
  6720. WFIFOW(fd,0)=0x107;
  6721. WFIFOL(fd,2)=sd->status.account_id;
  6722. WFIFOW(fd,6)=sd->bl.x;
  6723. WFIFOW(fd,8)=sd->bl.y;
  6724. WFIFOSET(fd,packet_len(0x107));
  6725. }
  6726. /// Updates HP bar of a party member.
  6727. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6728. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6729. void clif_party_hp(struct map_session_data *sd)
  6730. {
  6731. unsigned char buf[16];
  6732. #if PACKETVER < 20100126
  6733. const int cmd = 0x106;
  6734. #else
  6735. const int cmd = 0x80e;
  6736. #endif
  6737. nullpo_retv(sd);
  6738. WBUFW(buf,0)=cmd;
  6739. WBUFL(buf,2)=sd->status.account_id;
  6740. #if PACKETVER < 20100126
  6741. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6742. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6743. WBUFW(buf,8) = 100;
  6744. } else {
  6745. WBUFW(buf,6) = sd->battle_status.hp;
  6746. WBUFW(buf,8) = sd->battle_status.max_hp;
  6747. }
  6748. #else
  6749. WBUFL(buf,6) = sd->battle_status.hp;
  6750. WBUFL(buf,10) = sd->battle_status.max_hp;
  6751. #endif
  6752. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6753. }
  6754. /// Notifies the party members of a character's death or revival.
  6755. /// 0AB2 <GID>.L <dead>.B
  6756. void clif_party_dead( struct map_session_data *sd ){
  6757. #if PACKETVER >= 20170502
  6758. unsigned char buf[7];
  6759. nullpo_retv(sd);
  6760. WBUFW(buf, 0) = 0xab2;
  6761. WBUFL(buf, 2) = sd->status.account_id;
  6762. WBUFB(buf, 6) = pc_isdead(sd);
  6763. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6764. #endif
  6765. }
  6766. /// Updates the job and level of a party member
  6767. /// 0abd <account id>.L <job>.W <level>.W
  6768. void clif_party_job_and_level(struct map_session_data *sd){
  6769. #if PACKETVER >= 20170502
  6770. unsigned char buf[10];
  6771. nullpo_retv(sd);
  6772. WBUFW(buf, 0) = 0xabd;
  6773. WBUFL(buf, 2) = sd->status.account_id;
  6774. WBUFW(buf, 6) = sd->status.class_;
  6775. WBUFW(buf, 8) = sd->status.base_level;
  6776. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6777. #endif
  6778. }
  6779. /*==========================================
  6780. * Sends HP bar to a single fd. [Skotlex]
  6781. *------------------------------------------*/
  6782. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6783. {
  6784. #if PACKETVER < 20100126
  6785. const int cmd = 0x106;
  6786. #else
  6787. const int cmd = 0x80e;
  6788. #endif
  6789. WFIFOHEAD(fd,packet_len(cmd));
  6790. WFIFOW(fd,0) = cmd;
  6791. WFIFOL(fd,2) = id;
  6792. #if PACKETVER < 20100126
  6793. if( maxhp > INT16_MAX )
  6794. {// To correctly display the %hp bar. [Skotlex]
  6795. WFIFOW(fd,6) = hp/(maxhp/100);
  6796. WFIFOW(fd,8) = 100;
  6797. } else {
  6798. WFIFOW(fd,6) = hp;
  6799. WFIFOW(fd,8) = maxhp;
  6800. }
  6801. #else
  6802. WFIFOL(fd,6) = hp;
  6803. WFIFOL(fd,10) = maxhp;
  6804. #endif
  6805. WFIFOSET(fd, packet_len(cmd));
  6806. }
  6807. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6808. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6809. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6810. {
  6811. int fd;
  6812. nullpo_retv(sd);
  6813. nullpo_retv(bl);
  6814. fd=sd->fd;
  6815. WFIFOHEAD(fd,packet_len(0x139));
  6816. WFIFOW(fd, 0)=0x139;
  6817. WFIFOL(fd, 2)=bl->id;
  6818. WFIFOW(fd, 6)=bl->x;
  6819. WFIFOW(fd, 8)=bl->y;
  6820. WFIFOW(fd,10)=sd->bl.x;
  6821. WFIFOW(fd,12)=sd->bl.y;
  6822. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6823. WFIFOSET(fd,packet_len(0x139));
  6824. }
  6825. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6826. /// 018f <result>.W <name id>.W
  6827. /// result:
  6828. /// 0 = success
  6829. /// 1 = failure
  6830. /// 2 = success (alchemist)
  6831. /// 3 = failure (alchemist)
  6832. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6833. {
  6834. int view,fd;
  6835. nullpo_retv(sd);
  6836. fd = sd->fd;
  6837. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6838. WFIFOHEAD(fd,packet_len(0x18f));
  6839. WFIFOW(fd, 0)=0x18f;
  6840. WFIFOW(fd, 2)=flag;
  6841. if((view = itemdb_viewid(nameid)) > 0)
  6842. WFIFOW(fd, 4)=view;
  6843. else
  6844. WFIFOW(fd, 4)=nameid;
  6845. WFIFOSET(fd,packet_len(0x18f));
  6846. }
  6847. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6848. /// 019e
  6849. void clif_catch_process(struct map_session_data *sd)
  6850. {
  6851. int fd;
  6852. nullpo_retv(sd);
  6853. fd=sd->fd;
  6854. WFIFOHEAD(fd,packet_len(0x19e));
  6855. WFIFOW(fd,0)=0x19e;
  6856. WFIFOSET(fd,packet_len(0x19e));
  6857. }
  6858. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6859. /// 01a0 <result>.B
  6860. /// 0 = failure
  6861. /// 1 = success
  6862. void clif_pet_roulette(struct map_session_data *sd,int data)
  6863. {
  6864. int fd;
  6865. nullpo_retv(sd);
  6866. fd=sd->fd;
  6867. WFIFOHEAD(fd,packet_len(0x1a0));
  6868. WFIFOW(fd,0)=0x1a0;
  6869. WFIFOB(fd,2)=data;
  6870. WFIFOSET(fd,packet_len(0x1a0));
  6871. }
  6872. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6873. /// 01a6 <packet len>.W { <index>.W }*
  6874. void clif_sendegg(struct map_session_data *sd)
  6875. {
  6876. int i,n=0,fd;
  6877. nullpo_retv(sd);
  6878. fd=sd->fd;
  6879. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6880. clif_displaymessage(fd, msg_txt(sd,666));
  6881. return;
  6882. }
  6883. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6884. WFIFOW(fd,0)=0x1a6;
  6885. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6886. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6887. sd->inventory_data[i]->type != IT_PETEGG ||
  6888. sd->inventory.u.items_inventory[i].amount <= 0)
  6889. continue;
  6890. WFIFOW(fd,n*2+4)=i+2;
  6891. n++;
  6892. }
  6893. WFIFOW(fd,2)=4+n*2;
  6894. WFIFOSET(fd,WFIFOW(fd,2));
  6895. sd->menuskill_id = SA_TAMINGMONSTER;
  6896. sd->menuskill_val = -1;
  6897. }
  6898. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6899. /// 01a4 <type>.B <id>.L <data>.L
  6900. /// type:
  6901. /// 0 = pre-init (data = 0)
  6902. /// 1 = intimacy (data = 0~4)
  6903. /// 2 = hunger (data = 0~4)
  6904. /// 3 = accessory
  6905. /// 4 = performance (data = 1~3: normal, 4: special)
  6906. /// 5 = hairstyle
  6907. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6908. ///
  6909. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6910. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6911. {
  6912. uint8 buf[16];
  6913. nullpo_retv(pd);
  6914. WBUFW(buf,0) = 0x1a4;
  6915. WBUFB(buf,2) = type;
  6916. WBUFL(buf,3) = pd->bl.id;
  6917. WBUFL(buf,7) = param;
  6918. if (sd)
  6919. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6920. else
  6921. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6922. }
  6923. /// Pet's base data (ZC_PROPERTY_PET).
  6924. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6925. void clif_send_petstatus(struct map_session_data *sd)
  6926. {
  6927. int fd;
  6928. struct s_pet *pet;
  6929. nullpo_retv(sd);
  6930. nullpo_retv(sd->pd);
  6931. fd=sd->fd;
  6932. pet = &sd->pd->pet;
  6933. WFIFOHEAD(fd,packet_len(0x1a2));
  6934. WFIFOW(fd,0)=0x1a2;
  6935. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6936. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6937. WFIFOW(fd,27)=pet->level;
  6938. WFIFOW(fd,29)=pet->hungry;
  6939. WFIFOW(fd,31)=pet->intimate;
  6940. WFIFOW(fd,33)=pet->equip;
  6941. #if PACKETVER >= 20081126
  6942. WFIFOW(fd,35)=pet->class_;
  6943. #endif
  6944. WFIFOSET(fd,packet_len(0x1a2));
  6945. }
  6946. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6947. /// 01aa <id>.L <data>.L
  6948. /// data:
  6949. /// @see CZ_PET_ACT.
  6950. void clif_pet_emotion(struct pet_data *pd,int param)
  6951. {
  6952. unsigned char buf[16];
  6953. nullpo_retv(pd);
  6954. memset(buf,0,packet_len(0x1aa));
  6955. WBUFW(buf,0)=0x1aa;
  6956. WBUFL(buf,2)=pd->bl.id;
  6957. WBUFL(buf,6)=param;
  6958. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6959. }
  6960. /// Result of request to feed a pet (ZC_FEED_PET).
  6961. /// 01a3 <result>.B <name id>.W
  6962. /// result:
  6963. /// 0 = failure
  6964. /// 1 = success
  6965. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6966. {
  6967. int fd;
  6968. nullpo_retv(sd);
  6969. fd=sd->fd;
  6970. WFIFOHEAD(fd,packet_len(0x1a3));
  6971. WFIFOW(fd,0)=0x1a3;
  6972. WFIFOB(fd,2)=fail;
  6973. WFIFOW(fd,3)=foodid;
  6974. WFIFOSET(fd,packet_len(0x1a3));
  6975. }
  6976. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6977. /// 01cd { <skill id>.L }*7
  6978. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6979. {
  6980. int fd;
  6981. nullpo_retv(sd);
  6982. fd=sd->fd;
  6983. WFIFOHEAD(fd,packet_len(0x1cd));
  6984. WFIFOW(fd, 0)=0x1cd;
  6985. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6986. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6987. else
  6988. WFIFOL(fd,2)= 0x00000000;
  6989. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6990. WFIFOL(fd,6)= MG_COLDBOLT;
  6991. else
  6992. WFIFOL(fd,6)= 0x00000000;
  6993. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6994. WFIFOL(fd,10)= MG_FIREBOLT;
  6995. else
  6996. WFIFOL(fd,10)= 0x00000000;
  6997. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6998. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6999. else
  7000. WFIFOL(fd,14)= 0x00000000;
  7001. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7002. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7003. else
  7004. WFIFOL(fd,18)= 0x00000000;
  7005. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7006. WFIFOL(fd,22)= MG_FIREBALL;
  7007. else
  7008. WFIFOL(fd,22)= 0x00000000;
  7009. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7010. WFIFOL(fd,26)= MG_FROSTDIVER;
  7011. else
  7012. WFIFOL(fd,26)= 0x00000000;
  7013. WFIFOSET(fd,packet_len(0x1cd));
  7014. sd->menuskill_id = SA_AUTOSPELL;
  7015. sd->menuskill_val = skill_lv;
  7016. }
  7017. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7018. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7019. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  7020. {
  7021. unsigned char buf[56];
  7022. nullpo_retv(src);
  7023. memset(buf,0,packet_len(0x1cf));
  7024. WBUFW(buf,0) = 0x1cf;
  7025. WBUFL(buf,2) = src->id;
  7026. if( src->type == BL_MER )
  7027. {
  7028. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7029. if( md && md->master && md->devotion_flag )
  7030. WBUFL(buf,6) = md->master->bl.id;
  7031. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7032. }
  7033. else
  7034. {
  7035. int i;
  7036. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7037. if( sd == NULL )
  7038. return;
  7039. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7040. WBUFL(buf,6+4*i) = sd->devotion[i];
  7041. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7042. }
  7043. if( tsd )
  7044. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7045. else
  7046. clif_send(buf, packet_len(0x1cf), src, AREA);
  7047. }
  7048. /*==========================================
  7049. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  7050. * Notifies clients in an area of an object's spirits.
  7051. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7052. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7053. *------------------------------------------*/
  7054. void clif_spiritball(struct block_list *bl) {
  7055. unsigned char buf[16];
  7056. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7057. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7058. nullpo_retv(bl);
  7059. WBUFW(buf, 0) = 0x1d0;
  7060. WBUFL(buf, 2) = bl->id;
  7061. WBUFW(buf, 6) = 0; //init to 0
  7062. switch(bl->type){
  7063. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7064. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7065. }
  7066. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7067. }
  7068. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7069. /// 01d2 <account id>.L <delay>.L
  7070. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7071. {
  7072. unsigned char buf[32];
  7073. nullpo_retv(bl);
  7074. WBUFW(buf,0)=0x1d2;
  7075. WBUFL(buf,2)=bl->id;
  7076. WBUFL(buf,6)=client_tick(wait);
  7077. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7078. }
  7079. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7080. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7081. /// flag:
  7082. /// 0 = inactive
  7083. /// 1 = active
  7084. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7085. {
  7086. unsigned char buf[32];
  7087. nullpo_retv(src);
  7088. WBUFW(buf,0)=0x1d1;
  7089. WBUFL(buf,2)=src->id;
  7090. WBUFL(buf,6)=dst_id;
  7091. WBUFL(buf,10)=active;
  7092. clif_send(buf,packet_len(0x1d1),src,AREA);
  7093. }
  7094. /// MVP effect (ZC_MVP).
  7095. /// 010c <account id>.L
  7096. void clif_mvp_effect(struct map_session_data *sd)
  7097. {
  7098. unsigned char buf[16];
  7099. nullpo_retv(sd);
  7100. WBUFW(buf,0)=0x10c;
  7101. WBUFL(buf,2)=sd->bl.id;
  7102. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7103. }
  7104. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7105. /// 010a <name id>.W
  7106. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7107. {
  7108. int view,fd;
  7109. nullpo_retv(sd);
  7110. fd=sd->fd;
  7111. WFIFOHEAD(fd,packet_len(0x10a));
  7112. WFIFOW(fd,0)=0x10a;
  7113. if((view = itemdb_viewid(nameid)) > 0)
  7114. WFIFOW(fd,2)=view;
  7115. else
  7116. WFIFOW(fd,2)=nameid;
  7117. WFIFOSET(fd,packet_len(0x10a));
  7118. }
  7119. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7120. /// 010b <exp>.L
  7121. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7122. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7123. if (battle_config.mvp_exp_reward_message) {
  7124. char e_msg[CHAT_SIZE_MAX];
  7125. sprintf(e_msg, msg_txt(sd, 717), exp);
  7126. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7127. }
  7128. #else
  7129. int fd;
  7130. nullpo_retv(sd);
  7131. fd = sd->fd;
  7132. WFIFOHEAD(fd, packet_len(0x10b));
  7133. WFIFOW(fd,0) = 0x10b;
  7134. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7135. WFIFOSET(fd, packet_len(0x10b));
  7136. #endif
  7137. }
  7138. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7139. /// 010d
  7140. ///
  7141. /// "You are the MVP, but cannot obtain the reward because
  7142. /// you are overweight."
  7143. void clif_mvp_noitem(struct map_session_data* sd)
  7144. {
  7145. int fd = sd->fd;
  7146. WFIFOHEAD(fd,packet_len(0x10d));
  7147. WFIFOW(fd,0) = 0x10d;
  7148. WFIFOSET(fd,packet_len(0x10d));
  7149. }
  7150. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7151. /// 0167 <result>.B
  7152. /// result:
  7153. /// 0 = "Guild has been created."
  7154. /// 1 = "You are already in a Guild."
  7155. /// 2 = "That Guild Name already exists."
  7156. /// 3 = "You need the neccessary item to create a Guild."
  7157. void clif_guild_created(struct map_session_data *sd,int flag)
  7158. {
  7159. int fd;
  7160. nullpo_retv(sd);
  7161. fd=sd->fd;
  7162. WFIFOHEAD(fd,packet_len(0x167));
  7163. WFIFOW(fd,0)=0x167;
  7164. WFIFOB(fd,2)=flag;
  7165. WFIFOSET(fd,packet_len(0x167));
  7166. }
  7167. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7168. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7169. /// mode:
  7170. /// &0x01 = allow invite
  7171. /// &0x10 = allow expel
  7172. void clif_guild_belonginfo(struct map_session_data *sd)
  7173. {
  7174. int ps,fd;
  7175. struct guild* g;
  7176. nullpo_retv(sd);
  7177. nullpo_retv(g = sd->guild);
  7178. fd=sd->fd;
  7179. ps=guild_getposition(sd);
  7180. WFIFOHEAD(fd,packet_len(0x16c));
  7181. WFIFOW(fd,0)=0x16c;
  7182. WFIFOL(fd,2)=g->guild_id;
  7183. WFIFOL(fd,6)=g->emblem_id;
  7184. WFIFOL(fd,10)=g->position[ps].mode;
  7185. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7186. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7187. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7188. WFIFOSET(fd,packet_len(0x16c));
  7189. }
  7190. /// Guild member login notice.
  7191. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7192. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7193. /// status:
  7194. /// 0 = offline
  7195. /// 1 = online
  7196. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7197. {
  7198. unsigned char buf[64];
  7199. struct map_session_data* sd;
  7200. nullpo_retv(g);
  7201. WBUFW(buf, 0)=0x1f2;
  7202. WBUFL(buf, 2)=g->member[idx].account_id;
  7203. WBUFL(buf, 6)=g->member[idx].char_id;
  7204. WBUFL(buf,10)=flag;
  7205. if( ( sd = g->member[idx].sd ) != NULL )
  7206. {
  7207. WBUFW(buf,14) = sd->status.sex;
  7208. WBUFW(buf,16) = sd->status.hair;
  7209. WBUFW(buf,18) = sd->status.hair_color;
  7210. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7211. }
  7212. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7213. {
  7214. WBUFW(buf,14) = 0;
  7215. WBUFW(buf,16) = 0;
  7216. WBUFW(buf,18) = 0;
  7217. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7218. }
  7219. }
  7220. // Function `clif_guild_memberlogin_notice` sends info about
  7221. // logins and logouts of a guild member to the rest members.
  7222. // But at the 1st time (after a player login or map changing)
  7223. // the client won't show the message.
  7224. // So I suggest use this function for sending "first-time-info"
  7225. // to some player on entering the game or changing location.
  7226. // At next time the client would always show the message.
  7227. // The function sends all the statuses in the single packet
  7228. // to economize traffic. [LuzZza]
  7229. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7230. {
  7231. struct guild *g;
  7232. unsigned char buf[14*128];
  7233. int i, count=0, p_len;
  7234. nullpo_retv(sd);
  7235. p_len = packet_len(0x16d);
  7236. if(!(g = sd->guild))
  7237. return;
  7238. for(i=0; i<g->max_member; i++) {
  7239. if(g->member[i].account_id > 0 &&
  7240. g->member[i].account_id != sd->status.account_id) {
  7241. WBUFW(buf,count*p_len) = 0x16d;
  7242. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7243. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7244. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7245. count++;
  7246. }
  7247. }
  7248. clif_send(buf, p_len*count, &sd->bl, SELF);
  7249. }
  7250. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7251. /// 014e <menu flag>.L
  7252. /// menu flag:
  7253. /// 0x00 = Basic Info (always on)
  7254. /// &0x01 = Member manager
  7255. /// &0x02 = Positions
  7256. /// &0x04 = Skills
  7257. /// &0x10 = Expulsion list
  7258. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7259. /// &0x80 = Notice
  7260. void clif_guild_masterormember(struct map_session_data *sd)
  7261. {
  7262. int fd;
  7263. nullpo_retv(sd);
  7264. fd=sd->fd;
  7265. WFIFOHEAD(fd,packet_len(0x14e));
  7266. WFIFOW(fd,0) = 0x14e;
  7267. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7268. WFIFOSET(fd,packet_len(0x14e));
  7269. }
  7270. /// Guild basic information (Territories [Valaris])
  7271. /// 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)
  7272. /// 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)
  7273. /// 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)
  7274. void clif_guild_basicinfo(struct map_session_data *sd) {
  7275. int fd;
  7276. struct guild *g;
  7277. #if PACKETVER < 20160622
  7278. int cmd = 0x1b6;
  7279. int offset = NAME_LENGTH;
  7280. #else
  7281. int cmd = 0xa84;
  7282. int offset = 0;
  7283. #endif
  7284. nullpo_retv(sd);
  7285. fd = sd->fd;
  7286. if( (g = sd->guild) == NULL )
  7287. return;
  7288. WFIFOHEAD(fd,packet_len(cmd));
  7289. WFIFOW(fd, 0)=cmd;
  7290. WFIFOL(fd, 2)=g->guild_id;
  7291. WFIFOL(fd, 6)=g->guild_lv;
  7292. WFIFOL(fd,10)=g->connect_member;
  7293. WFIFOL(fd,14)=g->max_member;
  7294. WFIFOL(fd,18)=g->average_lv;
  7295. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7296. WFIFOL(fd,26)=g->next_exp;
  7297. WFIFOL(fd,30)=0; // Tax Points
  7298. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7299. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7300. WFIFOL(fd,42)=g->emblem_id;
  7301. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7302. #if PACKETVER < 20160622
  7303. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7304. #endif
  7305. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7306. WFIFOL(fd,70+offset+16) = 0; // zeny
  7307. #if PACKETVER >= 20160622
  7308. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7309. #endif
  7310. WFIFOSET(fd,packet_len(cmd));
  7311. }
  7312. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7313. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7314. void clif_guild_allianceinfo(struct map_session_data *sd)
  7315. {
  7316. int fd,i,c;
  7317. struct guild *g;
  7318. nullpo_retv(sd);
  7319. if( (g = sd->guild) == NULL )
  7320. return;
  7321. fd = sd->fd;
  7322. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7323. WFIFOW(fd, 0)=0x14c;
  7324. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7325. struct guild_alliance *a=&g->alliance[i];
  7326. if(a->guild_id>0){
  7327. WFIFOL(fd,c*32+4)=a->opposition;
  7328. WFIFOL(fd,c*32+8)=a->guild_id;
  7329. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7330. c++;
  7331. }
  7332. }
  7333. WFIFOW(fd, 2)=c*32+4;
  7334. WFIFOSET(fd,WFIFOW(fd,2));
  7335. }
  7336. /// Guild member manager information
  7337. /// 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)
  7338. /// state:
  7339. /// 0 = offline
  7340. /// 1 = online
  7341. /// memo:
  7342. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7343. /// 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)
  7344. void clif_guild_memberlist(struct map_session_data *sd)
  7345. {
  7346. int fd;
  7347. int i,c;
  7348. struct guild *g;
  7349. #if PACKETVER < 20161026
  7350. int cmd = 0x154;
  7351. int size = 104;
  7352. #else
  7353. int cmd = 0xaa5;
  7354. int size = 34;
  7355. #endif
  7356. nullpo_retv(sd);
  7357. if( (fd = sd->fd) == 0 )
  7358. return;
  7359. if( (g = sd->guild) == NULL )
  7360. return;
  7361. WFIFOHEAD(fd, g->max_member * size + 4);
  7362. WFIFOW(fd, 0)=cmd;
  7363. for(i=0,c=0;i<g->max_member;i++){
  7364. struct guild_member *m=&g->member[i];
  7365. if(m->account_id==0)
  7366. continue;
  7367. WFIFOL(fd,c*size+ 4)=m->account_id;
  7368. WFIFOL(fd,c*size+ 8)=m->char_id;
  7369. WFIFOW(fd,c*size+12)=m->hair;
  7370. WFIFOW(fd,c*size+14)=m->hair_color;
  7371. WFIFOW(fd,c*size+16)=m->gender;
  7372. WFIFOW(fd,c*size+18)=m->class_;
  7373. WFIFOW(fd,c*size+20)=m->lv;
  7374. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7375. WFIFOL(fd,c*size+26)=m->online;
  7376. WFIFOL(fd,c*size+30)=m->position;
  7377. #if PACKETVER < 20161026
  7378. 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.
  7379. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7380. #else
  7381. WFIFOL(fd,c*size+34)=m->last_login;
  7382. #endif
  7383. c++;
  7384. }
  7385. WFIFOW(fd, 2)=c*size+4;
  7386. WFIFOSET(fd,WFIFOW(fd,2));
  7387. }
  7388. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7389. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7390. void clif_guild_positionnamelist(struct map_session_data *sd)
  7391. {
  7392. int i,fd;
  7393. struct guild *g;
  7394. nullpo_retv(sd);
  7395. if( (g = sd->guild) == NULL )
  7396. return;
  7397. fd = sd->fd;
  7398. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7399. WFIFOW(fd, 0)=0x166;
  7400. for(i=0;i<MAX_GUILDPOSITION;i++){
  7401. WFIFOL(fd,i*28+4)=i;
  7402. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7403. }
  7404. WFIFOW(fd,2)=i*28+4;
  7405. WFIFOSET(fd,WFIFOW(fd,2));
  7406. }
  7407. /// Guild position information (ZC_POSITION_INFO).
  7408. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7409. /// mode:
  7410. /// &0x01 = allow invite
  7411. /// &0x10 = allow expel
  7412. /// ranking:
  7413. /// TODO
  7414. void clif_guild_positioninfolist(struct map_session_data *sd)
  7415. {
  7416. int i,fd;
  7417. struct guild *g;
  7418. nullpo_retv(sd);
  7419. if( (g = sd->guild) == NULL )
  7420. return;
  7421. fd = sd->fd;
  7422. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7423. WFIFOW(fd, 0)=0x160;
  7424. for(i=0;i<MAX_GUILDPOSITION;i++){
  7425. struct guild_position *p=&g->position[i];
  7426. WFIFOL(fd,i*16+ 4)=i;
  7427. WFIFOL(fd,i*16+ 8)=p->mode;
  7428. WFIFOL(fd,i*16+12)=i;
  7429. WFIFOL(fd,i*16+16)=p->exp_mode;
  7430. }
  7431. WFIFOW(fd, 2)=i*16+4;
  7432. WFIFOSET(fd,WFIFOW(fd,2));
  7433. }
  7434. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7435. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7436. /// mode:
  7437. /// &0x01 = allow invite
  7438. /// &0x10 = allow expel
  7439. /// ranking:
  7440. /// TODO
  7441. void clif_guild_positionchanged(struct guild *g,int idx)
  7442. {
  7443. // FIXME: This packet is intended to update the clients after a
  7444. // commit of position info changes, not sending one packet per
  7445. // position.
  7446. struct map_session_data *sd;
  7447. unsigned char buf[128];
  7448. nullpo_retv(g);
  7449. WBUFW(buf, 0)=0x174;
  7450. WBUFW(buf, 2)=44; // packet len
  7451. // GUILD_REG_POSITION_INFO{
  7452. WBUFL(buf, 4)=idx;
  7453. WBUFL(buf, 8)=g->position[idx].mode;
  7454. WBUFL(buf,12)=idx;
  7455. WBUFL(buf,16)=g->position[idx].exp_mode;
  7456. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7457. // }*
  7458. if( (sd=guild_getavailablesd(g))!=NULL )
  7459. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7460. }
  7461. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7462. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7463. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7464. {
  7465. // FIXME: This packet is intended to update the clients after a
  7466. // commit of member position assignment changes, not sending one
  7467. // packet per position.
  7468. struct map_session_data *sd;
  7469. unsigned char buf[64];
  7470. nullpo_retv(g);
  7471. WBUFW(buf, 0)=0x156;
  7472. WBUFW(buf, 2)=16; // packet len
  7473. // MEMBER_POSITION_INFO{
  7474. WBUFL(buf, 4)=g->member[idx].account_id;
  7475. WBUFL(buf, 8)=g->member[idx].char_id;
  7476. WBUFL(buf,12)=g->member[idx].position;
  7477. // }*
  7478. if( (sd=guild_getavailablesd(g))!=NULL )
  7479. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7480. }
  7481. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7482. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7483. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7484. {
  7485. int fd;
  7486. nullpo_retv(sd);
  7487. nullpo_retv(g);
  7488. fd = sd->fd;
  7489. if( g->emblem_len <= 0 )
  7490. return;
  7491. WFIFOHEAD(fd,g->emblem_len+12);
  7492. WFIFOW(fd,0)=0x152;
  7493. WFIFOW(fd,2)=g->emblem_len+12;
  7494. WFIFOL(fd,4)=g->guild_id;
  7495. WFIFOL(fd,8)=g->emblem_id;
  7496. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7497. WFIFOSET(fd,WFIFOW(fd,2));
  7498. }
  7499. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7500. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7501. void clif_guild_emblem_area(struct block_list* bl)
  7502. {
  7503. uint8 buf[12];
  7504. nullpo_retv(bl);
  7505. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7506. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7507. WBUFW(buf,0) = 0x1b4;
  7508. WBUFL(buf,2) = bl->id;
  7509. WBUFL(buf,6) = status_get_guild_id(bl);
  7510. WBUFW(buf,10) = status_get_emblem_id(bl);
  7511. clif_send(buf, 12, bl, AREA_WOS);
  7512. }
  7513. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7514. /// 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 }*
  7515. void clif_guild_skillinfo(struct map_session_data* sd)
  7516. {
  7517. int fd;
  7518. struct guild* g;
  7519. int i,c;
  7520. nullpo_retv(sd);
  7521. if( (g = sd->guild) == NULL )
  7522. return;
  7523. fd = sd->fd;
  7524. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7525. WFIFOW(fd,0) = 0x0162;
  7526. WFIFOW(fd,4) = g->skill_point;
  7527. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7528. {
  7529. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7530. {
  7531. int id = g->skill[i].id;
  7532. int p = 6 + c*37;
  7533. WFIFOW(fd,p+0) = id;
  7534. WFIFOL(fd,p+2) = skill_get_inf(id);
  7535. WFIFOW(fd,p+6) = g->skill[i].lv;
  7536. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7537. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7538. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7539. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7540. c++;
  7541. }
  7542. }
  7543. WFIFOW(fd,2) = 6 + c*37;
  7544. WFIFOSET(fd,WFIFOW(fd,2));
  7545. }
  7546. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7547. /// 016f <subject>.60B <notice>.120B
  7548. void clif_guild_notice(struct map_session_data* sd)
  7549. {
  7550. int fd;
  7551. struct guild* g;
  7552. nullpo_retv(sd);
  7553. nullpo_retv(g = sd->guild);
  7554. fd = sd->fd;
  7555. if ( !session_isActive(fd) )
  7556. return;
  7557. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7558. return;
  7559. WFIFOHEAD(fd,packet_len(0x16f));
  7560. WFIFOW(fd,0) = 0x16f;
  7561. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7562. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7563. WFIFOSET(fd,packet_len(0x16f));
  7564. }
  7565. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7566. /// 016a <guild id>.L <guild name>.24B
  7567. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7568. {
  7569. int fd;
  7570. nullpo_retv(sd);
  7571. nullpo_retv(g);
  7572. fd=sd->fd;
  7573. WFIFOHEAD(fd,packet_len(0x16a));
  7574. WFIFOW(fd,0)=0x16a;
  7575. WFIFOL(fd,2)=g->guild_id;
  7576. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7577. WFIFOSET(fd,packet_len(0x16a));
  7578. }
  7579. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7580. /// 0169 <answer>.B
  7581. /// answer:
  7582. /// 0 = Already in guild.
  7583. /// 1 = Offer rejected.
  7584. /// 2 = Offer accepted.
  7585. /// 3 = Guild full.
  7586. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7587. {
  7588. int fd;
  7589. nullpo_retv(sd);
  7590. fd=sd->fd;
  7591. WFIFOHEAD(fd,packet_len(0x169));
  7592. WFIFOW(fd,0)=0x169;
  7593. WFIFOB(fd,2)=flag;
  7594. WFIFOSET(fd,packet_len(0x169));
  7595. }
  7596. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7597. /// 015a <char name>.24B <reason>.40B
  7598. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7599. {
  7600. unsigned char buf[128];
  7601. nullpo_retv(sd);
  7602. WBUFW(buf, 0)=0x15a;
  7603. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7604. memcpy(WBUFP(buf,26),mes,40);
  7605. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7606. }
  7607. /// Notifies clients of a guild of an expelled member.
  7608. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7609. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7610. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7611. {
  7612. unsigned char buf[128];
  7613. #if PACKETVER < 20100803
  7614. const unsigned short cmd = 0x15c;
  7615. #else
  7616. const unsigned short cmd = 0x839;
  7617. #endif
  7618. nullpo_retv(sd);
  7619. WBUFW(buf,0) = cmd;
  7620. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7621. safestrncpy(WBUFCP(buf,26), mes, 40);
  7622. #if PACKETVER < 20100803
  7623. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7624. #endif
  7625. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7626. }
  7627. /// Guild expulsion list (ZC_BAN_LIST).
  7628. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7629. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7630. void clif_guild_expulsionlist(struct map_session_data* sd)
  7631. {
  7632. #if PACKETVER < 20100803
  7633. const int offset = NAME_LENGTH*2+40;
  7634. #else
  7635. const int offset = NAME_LENGTH+40;
  7636. #endif
  7637. int fd, i, c = 0;
  7638. struct guild* g;
  7639. nullpo_retv(sd);
  7640. if( (g = sd->guild) == NULL )
  7641. return;
  7642. fd = sd->fd;
  7643. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7644. WFIFOW(fd,0) = 0x163;
  7645. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7646. {
  7647. struct guild_expulsion* e = &g->expulsion[i];
  7648. if( e->account_id > 0 )
  7649. {
  7650. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7651. #if PACKETVER < 20100803
  7652. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7653. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7654. #else
  7655. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7656. #endif
  7657. c++;
  7658. }
  7659. }
  7660. WFIFOW(fd,2) = 4 + c*offset;
  7661. WFIFOSET(fd,WFIFOW(fd,2));
  7662. }
  7663. /// Guild chat message (ZC_GUILD_CHAT).
  7664. /// 017f <packet len>.W <message>.?B
  7665. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7666. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7667. struct map_session_data *sd;
  7668. uint8 buf[256];
  7669. if( len == 0 )
  7670. {
  7671. return;
  7672. }
  7673. else if( len > sizeof(buf)-5 )
  7674. {
  7675. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7676. len = sizeof(buf)-5;
  7677. }
  7678. WBUFW(buf, 0) = 0x17f;
  7679. WBUFW(buf, 2) = len + 5;
  7680. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7681. if ((sd = guild_getavailablesd(g)) != NULL)
  7682. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7683. }
  7684. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7685. /// 0171 <inviter account id>.L <guild name>.24B
  7686. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7687. {
  7688. int fd;
  7689. nullpo_retv(sd);
  7690. fd=sd->fd;
  7691. WFIFOHEAD(fd,packet_len(0x171));
  7692. WFIFOW(fd,0)=0x171;
  7693. WFIFOL(fd,2)=account_id;
  7694. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7695. WFIFOSET(fd,packet_len(0x171));
  7696. }
  7697. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7698. /// 0173 <answer>.B
  7699. /// answer:
  7700. /// 0 = Already allied.
  7701. /// 1 = You rejected the offer.
  7702. /// 2 = You accepted the offer.
  7703. /// 3 = They have too any alliances.
  7704. /// 4 = You have too many alliances.
  7705. /// 5 = Alliances are disabled.
  7706. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7707. {
  7708. int fd;
  7709. nullpo_retv(sd);
  7710. fd=sd->fd;
  7711. WFIFOHEAD(fd,packet_len(0x173));
  7712. WFIFOW(fd,0)=0x173;
  7713. WFIFOL(fd,2)=flag;
  7714. WFIFOSET(fd,packet_len(0x173));
  7715. }
  7716. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7717. /// 0184 <other guild id>.L <relation>.L
  7718. /// relation:
  7719. /// 0 = Ally
  7720. /// 1 = Enemy
  7721. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7722. {
  7723. int fd;
  7724. nullpo_retv(sd);
  7725. fd = sd->fd;
  7726. if (fd <= 0)
  7727. return;
  7728. WFIFOHEAD(fd,packet_len(0x184));
  7729. WFIFOW(fd,0)=0x184;
  7730. WFIFOL(fd,2)=guild_id;
  7731. WFIFOL(fd,6)=flag;
  7732. WFIFOSET(fd,packet_len(0x184));
  7733. }
  7734. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7735. /// 0181 <result>.B
  7736. /// result:
  7737. /// 0 = Antagonist has been set.
  7738. /// 1 = Guild has too many Antagonists.
  7739. /// 2 = Already set as an Antagonist.
  7740. /// 3 = Antagonists are disabled.
  7741. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7742. {
  7743. int fd;
  7744. nullpo_retv(sd);
  7745. fd=sd->fd;
  7746. WFIFOHEAD(fd,packet_len(0x181));
  7747. WFIFOW(fd,0)=0x181;
  7748. WFIFOB(fd,2)=flag;
  7749. WFIFOSET(fd,packet_len(0x181));
  7750. }
  7751. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7752. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7753. /*
  7754. void clif_guild_allianceadded(struct guild *g,int idx)
  7755. {
  7756. unsigned char buf[64];
  7757. WBUFW(buf,0)=0x185;
  7758. WBUFL(buf,2)=g->alliance[idx].opposition;
  7759. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7760. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7761. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7762. }
  7763. */
  7764. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7765. /// 015e <reason>.L
  7766. /// 0 = success
  7767. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7768. /// 2 = there are still members in the guild
  7769. void clif_guild_broken(struct map_session_data *sd,int flag)
  7770. {
  7771. int fd;
  7772. nullpo_retv(sd);
  7773. fd=sd->fd;
  7774. WFIFOHEAD(fd,packet_len(0x15e));
  7775. WFIFOW(fd,0)=0x15e;
  7776. WFIFOL(fd,2)=flag;
  7777. WFIFOSET(fd,packet_len(0x15e));
  7778. }
  7779. /// Displays emotion on an object (ZC_EMOTION).
  7780. /// 00c0 <id>.L <type>.B
  7781. /// type:
  7782. /// enum emotion_type
  7783. void clif_emotion(struct block_list *bl,int type)
  7784. {
  7785. unsigned char buf[8];
  7786. nullpo_retv(bl);
  7787. WBUFW(buf,0)=0xc0;
  7788. WBUFL(buf,2)=bl->id;
  7789. WBUFB(buf,6)=type;
  7790. clif_send(buf,packet_len(0xc0),bl,AREA);
  7791. }
  7792. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7793. /// 0191 <id>.L <contents>.80B
  7794. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7795. {
  7796. unsigned char buf[MESSAGE_SIZE+6];
  7797. nullpo_retv(bl);
  7798. WBUFW(buf,0) = 0x191;
  7799. WBUFL(buf,2) = bl->id;
  7800. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7801. clif_send(buf,packet_len(0x191),bl,AREA);
  7802. }
  7803. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7804. /// 01ea <id>.L
  7805. void clif_wedding_effect(struct block_list *bl)
  7806. {
  7807. unsigned char buf[6];
  7808. nullpo_retv(bl);
  7809. WBUFW(buf,0) = 0x1ea;
  7810. WBUFL(buf,2) = bl->id;
  7811. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7812. }
  7813. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7814. /// 01e6 <partner name>.24B
  7815. void clif_callpartner(struct map_session_data *sd)
  7816. {
  7817. unsigned char buf[26];
  7818. nullpo_retv(sd);
  7819. WBUFW(buf,0) = 0x1e6;
  7820. if( sd->status.partner_id ) {
  7821. const char *p = map_charid2nick(sd->status.partner_id);
  7822. struct map_session_data *p_sd = pc_get_partner(sd);
  7823. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7824. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7825. else
  7826. WBUFB(buf,2) = 0;
  7827. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7828. WBUFB(buf,2) = 0;
  7829. }
  7830. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7831. }
  7832. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7833. /// 01e4
  7834. /// This packet while still implemented by the client is no longer being officially used.
  7835. /*
  7836. void clif_marriage_process(struct map_session_data *sd)
  7837. {
  7838. int fd;
  7839. nullpo_retv(sd);
  7840. fd=sd->fd;
  7841. WFIFOHEAD(fd,packet_len(0x1e4));
  7842. WFIFOW(fd,0)=0x1e4;
  7843. WFIFOSET(fd,packet_len(0x1e4));
  7844. }
  7845. */
  7846. /// Notice of divorce (ZC_DIVORCE).
  7847. /// 0205 <partner name>.24B
  7848. void clif_divorced(struct map_session_data* sd, const char* name)
  7849. {
  7850. int fd;
  7851. nullpo_retv(sd);
  7852. fd=sd->fd;
  7853. WFIFOHEAD(fd,packet_len(0x205));
  7854. WFIFOW(fd,0)=0x205;
  7855. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7856. WFIFOSET(fd, packet_len(0x205));
  7857. }
  7858. /// Marriage proposal (ZC_REQ_COUPLE).
  7859. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7860. /// This packet while still implemented by the client is no longer being officially used.
  7861. /*
  7862. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7863. {
  7864. nullpo_retv(sd);
  7865. WFIFOHEAD(fd,packet_len(0x1e2));
  7866. WFIFOW(fd,0) = 0x1e2;
  7867. WFIFOL(fd,2) = ssd->status.account_id;
  7868. WFIFOL(fd,6) = ssd->status.char_id;
  7869. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7870. WFIFOSET(fd, packet_len(0x1e2));
  7871. }
  7872. */
  7873. /*==========================================
  7874. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7875. *------------------------------------------*/
  7876. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7877. {
  7878. unsigned char buf[256];
  7879. if( len == 0 ) {
  7880. return;
  7881. } else if( len > sizeof(buf)-5 ) {
  7882. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7883. len = sizeof(buf)-5;
  7884. }
  7885. WBUFW(buf, 0) = 0x17f;
  7886. WBUFW(buf, 2) = len + 5;
  7887. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7888. clif_send(buf, WBUFW(buf,2), src, target);
  7889. }
  7890. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7891. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7892. /// 00cd <result>.B
  7893. /// result:
  7894. /// 0 = failure
  7895. /// 1 = success
  7896. void clif_GM_kickack(struct map_session_data *sd, int id)
  7897. {
  7898. int fd;
  7899. nullpo_retv(sd);
  7900. fd = sd->fd;
  7901. WFIFOHEAD(fd,packet_len(0xcd));
  7902. WFIFOW(fd,0) = 0xcd;
  7903. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7904. WFIFOSET(fd, packet_len(0xcd));
  7905. }
  7906. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7907. {
  7908. int fd;
  7909. nullpo_retv(tsd);
  7910. fd = tsd->fd;
  7911. if (sd == NULL)
  7912. tsd->state.keepshop = true;
  7913. if (fd > 0)
  7914. clif_authfail_fd(fd, 15);
  7915. else
  7916. map_quit(tsd);
  7917. if (sd)
  7918. clif_GM_kickack(sd, tsd->status.account_id);
  7919. }
  7920. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7921. /// 014a <result>.L
  7922. /// result:
  7923. /// 0 = "A manner point has been successfully aligned."
  7924. /// 1 = MP_FAILURE_EXHAUST
  7925. /// 2 = MP_FAILURE_ALREADY_GIVING
  7926. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7927. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7928. /// 5 = "You got a good point from %s."
  7929. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7930. {
  7931. int fd;
  7932. nullpo_retv(sd);
  7933. fd = sd->fd;
  7934. WFIFOHEAD(fd,packet_len(0x14a));
  7935. WFIFOW(fd,0) = 0x14a;
  7936. WFIFOL(fd,2) = type;
  7937. WFIFOSET(fd, packet_len(0x14a));
  7938. }
  7939. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7940. /// 014b <type>.B <GM name>.24B
  7941. /// type:
  7942. /// 0 = positive (unmute)
  7943. /// 1 = negative (mute)
  7944. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7945. {
  7946. int fd;
  7947. nullpo_retv(sd);
  7948. nullpo_retv(tsd);
  7949. fd = tsd->fd;
  7950. WFIFOHEAD(fd,packet_len(0x14b));
  7951. WFIFOW(fd,0) = 0x14b;
  7952. WFIFOB(fd,2) = type;
  7953. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7954. WFIFOSET(fd, packet_len(0x14b));
  7955. }
  7956. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7957. /// 00d1 <type>.B <result>.B
  7958. /// type:
  7959. /// 0 = /ex (deny)
  7960. /// 1 = /in (allow)
  7961. /// result:
  7962. /// 0 = success
  7963. /// 1 = failure
  7964. /// 2 = too many blocks
  7965. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7966. {
  7967. int fd;
  7968. nullpo_retv(sd);
  7969. fd=sd->fd;
  7970. WFIFOHEAD(fd,packet_len(0xd1));
  7971. WFIFOW(fd,0)=0xd1;
  7972. WFIFOB(fd,2)=type;
  7973. WFIFOB(fd,3)=flag;
  7974. WFIFOSET(fd,packet_len(0xd1));
  7975. }
  7976. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7977. /// 00d2 <type>.B <result>.B
  7978. /// type:
  7979. /// 0 = /exall (deny)
  7980. /// 1 = /inall (allow)
  7981. /// result:
  7982. /// 0 = success
  7983. /// 1 = failure
  7984. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7985. {
  7986. int fd;
  7987. nullpo_retv(sd);
  7988. fd=sd->fd;
  7989. WFIFOHEAD(fd,packet_len(0xd2));
  7990. WFIFOW(fd,0)=0xd2;
  7991. WFIFOB(fd,2)=type;
  7992. WFIFOB(fd,3)=flag;
  7993. WFIFOSET(fd,packet_len(0xd2));
  7994. }
  7995. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7996. /// 07fe <bgm>.24B
  7997. void clif_playBGM(struct map_session_data* sd, const char* name)
  7998. {
  7999. int fd;
  8000. nullpo_retv(sd);
  8001. fd = sd->fd;
  8002. WFIFOHEAD(fd,packet_len(0x7fe));
  8003. WFIFOW(fd,0) = 0x7fe;
  8004. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8005. WFIFOSET(fd,packet_len(0x7fe));
  8006. }
  8007. /// Plays/stops a wave sound (ZC_SOUND).
  8008. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8009. /// file name:
  8010. /// relative to data\wav
  8011. /// act:
  8012. /// 0 = play (once)
  8013. /// 1 = play (repeat, does not work)
  8014. /// 2 = stops all sound instances of file name (does not work)
  8015. /// term:
  8016. /// unknown purpose, only relevant to act = 1
  8017. /// npc id:
  8018. /// The accustic direction of the sound is determined by the
  8019. /// relative position of the NPC to the player (3D sound).
  8020. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  8021. {
  8022. int fd;
  8023. nullpo_retv(sd);
  8024. nullpo_retv(bl);
  8025. fd = sd->fd;
  8026. WFIFOHEAD(fd,packet_len(0x1d3));
  8027. WFIFOW(fd,0) = 0x1d3;
  8028. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8029. WFIFOB(fd,26) = type;
  8030. WFIFOL(fd,27) = 0;
  8031. WFIFOL(fd,31) = bl->id;
  8032. WFIFOSET(fd,packet_len(0x1d3));
  8033. }
  8034. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8035. {
  8036. unsigned char buf[40];
  8037. nullpo_retv(bl);
  8038. WBUFW(buf,0) = 0x1d3;
  8039. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8040. WBUFB(buf,26) = type;
  8041. WBUFL(buf,27) = 0;
  8042. WBUFL(buf,31) = bl->id;
  8043. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8044. }
  8045. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8046. /// 01f3 <id>.L <effect id>.L
  8047. /// effect id:
  8048. /// @see doc/effect_list.txt
  8049. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8050. {
  8051. unsigned char buf[24];
  8052. nullpo_retv(bl);
  8053. memset(buf, 0, packet_len(0x1f3));
  8054. WBUFW(buf,0) = 0x1f3;
  8055. WBUFL(buf,2) = bl->id;
  8056. WBUFL(buf,6) = type;
  8057. clif_send(buf, packet_len(0x1f3), bl, target);
  8058. if (disguised(bl)) {
  8059. WBUFL(buf,2) = -bl->id;
  8060. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8061. }
  8062. }
  8063. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8064. {
  8065. WFIFOHEAD(fd,10);
  8066. WFIFOW(fd,0) = 0x1f3;
  8067. WFIFOL(fd,2) = bl->id;
  8068. WFIFOL(fd,6) = type;
  8069. WFIFOSET(fd,10);
  8070. }
  8071. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8072. /// 0284 <id>.L <effect id>.L <num data>.L
  8073. /// effect id:
  8074. /// @see doc/effect_list.txt
  8075. /// num data:
  8076. /// effect-dependent value
  8077. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8078. {
  8079. uint8 buf[14];
  8080. WBUFW(buf,0) = 0x284;
  8081. WBUFL(buf,2) = bl->id;
  8082. WBUFL(buf,6) = effect_id;
  8083. WBUFL(buf,10) = num;
  8084. clif_send(buf, packet_len(0x284), bl, target);
  8085. if( disguised(bl) )
  8086. {
  8087. WBUFL(buf,2) = -bl->id;
  8088. clif_send(buf, packet_len(0x284), bl, SELF);
  8089. }
  8090. }
  8091. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8092. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8093. 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) {
  8094. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8095. uint8 buf[CHAT_SIZE_MAX];
  8096. nullpo_retv(bl);
  8097. if (msg_len > sizeof(buf) - 12) {
  8098. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8099. msg_len = sizeof(buf) - 12;
  8100. }
  8101. if (rgb2bgr)
  8102. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8103. WBUFW(buf,0) = 0x2C1;
  8104. WBUFW(buf,2) = msg_len + 12;
  8105. WBUFL(buf,4) = bl->id;
  8106. WBUFL(buf,8) = color;
  8107. memcpy(WBUFCP(buf,12), msg, msg_len);
  8108. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8109. }
  8110. /**
  8111. * Notifies the client that the storage window is still open
  8112. *
  8113. * Should only be used in cases where the client closed the
  8114. * storage window without server's consent
  8115. */
  8116. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8117. // Notify the client that the storage is open
  8118. if( sd->state.storage_flag == 1 ) {
  8119. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8120. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8121. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8122. }
  8123. // Notify the client that the gstorage is open otherwise it will
  8124. // remain locked forever and nobody will be able to access it
  8125. if( sd->state.storage_flag == 2 ) {
  8126. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8127. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8128. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8129. else {
  8130. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8131. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8132. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8133. }
  8134. }
  8135. }
  8136. // refresh the client's screen, getting rid of any effects
  8137. void clif_refresh(struct map_session_data *sd)
  8138. {
  8139. nullpo_retv(sd);
  8140. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8141. clif_inventorylist(sd);
  8142. clif_equipswitch_list(sd);
  8143. if(pc_iscarton(sd)) {
  8144. clif_cartlist(sd);
  8145. clif_updatestatus(sd,SP_CARTINFO);
  8146. }
  8147. clif_updatestatus(sd,SP_WEIGHT);
  8148. clif_updatestatus(sd,SP_MAXWEIGHT);
  8149. clif_updatestatus(sd,SP_STR);
  8150. clif_updatestatus(sd,SP_AGI);
  8151. clif_updatestatus(sd,SP_VIT);
  8152. clif_updatestatus(sd,SP_INT);
  8153. clif_updatestatus(sd,SP_DEX);
  8154. clif_updatestatus(sd,SP_LUK);
  8155. if (sd->spiritball)
  8156. clif_spiritball_single(sd->fd, sd);
  8157. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8158. clif_spiritcharm_single(sd->fd, sd);
  8159. if (sd->vd.cloth_color)
  8160. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8161. if (sd->vd.body_style)
  8162. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8163. if(hom_is_active(sd->hd))
  8164. clif_send_homdata(sd,SP_ACK,0);
  8165. if( sd->md ) {
  8166. clif_mercenary_info(sd);
  8167. clif_mercenary_skillblock(sd);
  8168. }
  8169. if( sd->ed )
  8170. clif_elemental_info(sd);
  8171. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8172. clif_weather_check(sd);
  8173. if( sd->chatID )
  8174. chat_leavechat(sd,0);
  8175. if( sd->state.vending )
  8176. clif_openvending(sd, sd->bl.id, sd->vending);
  8177. if( pc_issit(sd) )
  8178. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8179. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8180. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8181. else
  8182. clif_changed_dir(&sd->bl, SELF);
  8183. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8184. //Issue #2143
  8185. //Cancel Trading State
  8186. if (sd->state.trading)
  8187. trade_tradecancel(sd);
  8188. //Cancel Buying/Selling State
  8189. if (sd->state.buyingstore)
  8190. buyingstore_close(sd);
  8191. mail_clear(sd);
  8192. if( disguised(&sd->bl) ) {/* refresh-da */
  8193. short disguise = sd->disguise;
  8194. pc_disguise(sd, 0);
  8195. pc_disguise(sd, disguise);
  8196. }
  8197. clif_refresh_storagewindow(sd);
  8198. }
  8199. /// Updates the object's (bl) name on client.
  8200. /// Used to update when a char leaves a party/guild. [Skotlex]
  8201. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8202. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8203. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8204. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8205. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8206. unsigned char buf[106];
  8207. int cmd = 0x95;
  8208. nullpo_retv(src);
  8209. nullpo_retv(bl);
  8210. WBUFW(buf,0) = cmd;
  8211. WBUFL(buf,2) = bl->id;
  8212. switch( bl->type )
  8213. {
  8214. case BL_PC:
  8215. {
  8216. struct map_session_data *sd = (struct map_session_data *)bl;
  8217. struct party_data *p = NULL;
  8218. #if PACKETVER >= 20150513
  8219. WBUFW(buf, 0) = cmd = 0xa30;
  8220. #else
  8221. WBUFW(buf, 0) = cmd = 0x195;
  8222. #endif
  8223. //Requesting your own "shadow" name. [Skotlex]
  8224. if( src == bl && target == SELF && sd->disguise ){
  8225. WBUFL(buf,2) = -bl->id;
  8226. }
  8227. if( sd->fakename[0] ) {
  8228. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8229. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8230. #if PACKETVER >= 20150513
  8231. WBUFL(buf,102) = 0; // Title ID
  8232. #endif
  8233. break;
  8234. }
  8235. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8236. if( sd->status.party_id ){
  8237. p = party_search(sd->status.party_id);
  8238. }
  8239. // do not display party unless the player is also in a guild
  8240. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8241. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8242. }else{
  8243. WBUFB(buf,30) = 0;
  8244. }
  8245. if( sd->guild ){
  8246. int position;
  8247. // Will get the position of the guild the player is in
  8248. position = guild_getposition(sd);
  8249. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8250. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8251. }else if( sd->clan ){
  8252. WBUFB(buf,54) = 0;
  8253. safestrncpy(WBUFCP(buf,78), sd->clan->name,NAME_LENGTH);
  8254. }else{ //Assume no guild and no clan
  8255. WBUFB(buf,54) = 0;
  8256. WBUFB(buf,78) = 0;
  8257. }
  8258. #if PACKETVER >= 20150513
  8259. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8260. #endif
  8261. }
  8262. break;
  8263. //[blackhole89]
  8264. case BL_HOM:
  8265. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8266. break;
  8267. case BL_MER:
  8268. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8269. break;
  8270. case BL_PET:
  8271. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8272. break;
  8273. case BL_NPC:
  8274. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8275. break;
  8276. case BL_MOB:
  8277. {
  8278. struct mob_data *md = (struct mob_data *)bl;
  8279. nullpo_retv(md);
  8280. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8281. if( md->guardian_data && md->guardian_data->guild_id )
  8282. {
  8283. #if PACKETVER >= 20150513
  8284. WBUFW(buf, 0) = cmd = 0xa30;
  8285. #else
  8286. WBUFW(buf, 0) = cmd = 0x195;
  8287. #endif
  8288. WBUFB(buf,30) = 0;
  8289. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8290. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8291. }
  8292. else if( battle_config.show_mob_info )
  8293. {
  8294. char mobhp[50], *str_p = mobhp;
  8295. #if PACKETVER >= 20150513
  8296. WBUFW(buf, 0) = cmd = 0xa30;
  8297. #else
  8298. WBUFW(buf, 0) = cmd = 0x195;
  8299. #endif
  8300. if( battle_config.show_mob_info&4 )
  8301. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8302. if( battle_config.show_mob_info&1 )
  8303. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8304. if( battle_config.show_mob_info&2 )
  8305. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8306. //Even thought mobhp ain't a name, we send it as one so the client
  8307. //can parse it. [Skotlex]
  8308. if( str_p != mobhp )
  8309. {
  8310. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8311. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8312. WBUFB(buf,54) = 0;
  8313. WBUFB(buf,78) = 0;
  8314. }
  8315. }
  8316. #if PACKETVER >= 20150513
  8317. WBUFL(buf, 102) = 0; // Title ID
  8318. #endif
  8319. }
  8320. break;
  8321. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8322. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8323. // break;
  8324. return;
  8325. case BL_ELEM:
  8326. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8327. break;
  8328. default:
  8329. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8330. return;
  8331. }
  8332. clif_send(buf, packet_len(cmd), src, target);
  8333. }
  8334. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8335. /// 01ff <id>.L <x>.W <y>.W
  8336. ///
  8337. /// Visually moves(instant) a character to x,y. The char moves even
  8338. /// when the target cell isn't walkable. If the char is sitting it
  8339. /// stays that way.
  8340. void clif_slide(struct block_list *bl, int x, int y)
  8341. {
  8342. unsigned char buf[10];
  8343. nullpo_retv(bl);
  8344. WBUFW(buf, 0) = 0x01ff;
  8345. WBUFL(buf, 2) = bl->id;
  8346. WBUFW(buf, 6) = x;
  8347. WBUFW(buf, 8) = y;
  8348. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8349. if( disguised(bl) )
  8350. {
  8351. WBUFL(buf,2) = -bl->id;
  8352. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8353. }
  8354. }
  8355. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8356. /// 008d <packet len>.W <id>.L <message>.?B
  8357. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8358. {
  8359. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8360. int len_mes = strlen(mes)+1; //Account for \0
  8361. if (len_mes > sizeof(buf)-8) {
  8362. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8363. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8364. }
  8365. // send message to others
  8366. if (flag == AREA) {
  8367. WBUFW(buf,0) = 0x8d;
  8368. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8369. WBUFL(buf,4) = bl->id;
  8370. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8371. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8372. }
  8373. // send back message to the speaker
  8374. if( bl->type == BL_PC ) {
  8375. WBUFW(buf,0) = 0x8e;
  8376. WBUFW(buf, 2) = len_mes + 4;
  8377. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8378. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8379. }
  8380. }
  8381. /*==========================
  8382. * Minimap fix [Kevin]
  8383. * Remove dot from minimap
  8384. *--------------------------*/
  8385. void clif_party_xy_remove(struct map_session_data *sd)
  8386. {
  8387. unsigned char buf[16];
  8388. nullpo_retv(sd);
  8389. WBUFW(buf,0)=0x107;
  8390. WBUFL(buf,2)=sd->status.account_id;
  8391. WBUFW(buf,6)=-1;
  8392. WBUFW(buf,8)=-1;
  8393. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8394. }
  8395. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8396. /// 0215 <msg id>.L
  8397. /// msg id:
  8398. /// 0x15 = End all negative status (PA_GOSPEL)
  8399. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8400. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8401. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8402. /// 0x19 = All stats +20 (PA_GOSPEL)
  8403. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8404. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8405. /// 0x1e = DEF +25% (PA_GOSPEL)
  8406. /// 0x1f = ATK +100% (PA_GOSPEL)
  8407. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8408. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8409. /// ? = nothing
  8410. void clif_gospel_info(struct map_session_data *sd, int type)
  8411. {
  8412. int fd=sd->fd;
  8413. WFIFOHEAD(fd,packet_len(0x215));
  8414. WFIFOW(fd,0)=0x215;
  8415. WFIFOL(fd,2)=type;
  8416. WFIFOSET(fd, packet_len(0x215));
  8417. }
  8418. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8419. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8420. /// result:
  8421. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8422. /// star:
  8423. /// 0 = Place of the Sun
  8424. /// 1 = Place of the Moon
  8425. /// 2 = Place of the Stars
  8426. /// 1 = Star Gladiator %s's %s: <mapname>
  8427. /// star:
  8428. /// 0 = Place of the Sun
  8429. /// 1 = Place of the Moon
  8430. /// 2 = Place of the Stars
  8431. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8432. /// star:
  8433. /// 0 = Target of the Sun
  8434. /// 1 = Target of the Moon
  8435. /// 2 = Target of the Stars
  8436. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8437. /// star:
  8438. /// 0 = Monster of the Sun
  8439. /// 1 = Monster of the Moon
  8440. /// 2 = Monster of the Stars
  8441. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8442. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8443. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8444. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8445. /// 40 = Target HP : <monster_id used as HP>
  8446. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8447. {
  8448. int fd = sd->fd;
  8449. WFIFOHEAD(fd,packet_len(0x20e));
  8450. WFIFOW(fd,0) = 0x20e;
  8451. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8452. WFIFOL(fd,26) = monster_id;
  8453. WFIFOB(fd,30) = star;
  8454. WFIFOB(fd,31) = result;
  8455. WFIFOSET(fd,packet_len(0x20e));
  8456. }
  8457. /*==========================================
  8458. * Info about Star Glaldiator save map [Komurka]
  8459. * type: 1: Information, 0: Map registered
  8460. *------------------------------------------*/
  8461. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8462. {
  8463. char mapname[MAP_NAME_LENGTH_EXT];
  8464. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8465. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8466. }
  8467. /*==========================================
  8468. * Info about Star Glaldiator hate mob [Komurka]
  8469. * type: 1: Register mob, 0: Information.
  8470. *------------------------------------------*/
  8471. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8472. {
  8473. if( pcdb_checkid(class_) ) {
  8474. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8475. } else if( mobdb_checkid(class_) ) {
  8476. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8477. } else {
  8478. 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);
  8479. }
  8480. }
  8481. /*==========================================
  8482. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8483. *------------------------------------------*/
  8484. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8485. {
  8486. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8487. }
  8488. /*==========================================
  8489. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8490. *------------------------------------------*/
  8491. void clif_feel_hate_reset(struct map_session_data *sd)
  8492. {
  8493. clif_starskill(sd, "", 0, 0, 30);
  8494. }
  8495. /// Send out reply to configuration change
  8496. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8497. /// type: see enum e_config_type
  8498. /// value:
  8499. /// false = disabled
  8500. /// true = enabled
  8501. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8502. int fd;
  8503. nullpo_retv(sd);
  8504. fd = sd->fd;
  8505. WFIFOHEAD(fd, packet_len(0x2d9));
  8506. WFIFOW(fd, 0) = 0x2d9;
  8507. WFIFOL(fd, 2) = type;
  8508. WFIFOL(fd, 6) = enabled;
  8509. WFIFOSET(fd, packet_len(0x2d9));
  8510. }
  8511. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8512. /// 02da <open equip window>.B
  8513. /// open equip window:
  8514. /// 0 = disabled
  8515. /// 1 = enabled
  8516. void clif_equipcheckbox(struct map_session_data* sd)
  8517. {
  8518. int fd;
  8519. nullpo_retv(sd);
  8520. fd = sd->fd;
  8521. WFIFOHEAD(fd, packet_len(0x2da));
  8522. WFIFOW(fd, 0) = 0x2da;
  8523. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8524. WFIFOSET(fd, packet_len(0x2da));
  8525. }
  8526. /// Sends info about a player's equipped items.
  8527. /// 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)
  8528. /// 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)
  8529. /// 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)
  8530. /// 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)
  8531. /// 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)
  8532. /// 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)
  8533. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8534. {
  8535. uint8* buf;
  8536. int i, n, fd, offset = 0;
  8537. #if PACKETVER < 20100629
  8538. const int s = 26;
  8539. #elif PACKETVER < 20120925
  8540. const int s = 28;
  8541. #elif PACKETVER < 20150225
  8542. const int s = 31;
  8543. #else
  8544. const int s = 57;
  8545. #endif
  8546. nullpo_retv(sd);
  8547. nullpo_retv(tsd);
  8548. fd = sd->fd;
  8549. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8550. buf = WFIFOP(fd,0);
  8551. #if PACKETVER < 20101124
  8552. WBUFW(buf, 0) = 0x2d7;
  8553. #elif PACKETVER < 20120925
  8554. WBUFW(buf, 0) = 0x859;
  8555. #elif PACKETVER < 20150225
  8556. WBUFW(buf, 0) = 0x997;
  8557. #else
  8558. WBUFW(buf, 0) = 0xa2d;
  8559. #endif
  8560. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8561. WBUFW(buf,28) = tsd->status.class_;
  8562. WBUFW(buf,30) = tsd->vd.hair_style;
  8563. WBUFW(buf,32) = tsd->vd.head_bottom;
  8564. WBUFW(buf,34) = tsd->vd.head_mid;
  8565. WBUFW(buf,36) = tsd->vd.head_top;
  8566. #if PACKETVER >= 20110111
  8567. WBUFW(buf,38) = tsd->vd.robe;
  8568. offset+= 2;
  8569. buf = WBUFP(buf,2);
  8570. #endif
  8571. WBUFW(buf,38) = tsd->vd.hair_color;
  8572. WBUFW(buf,40) = tsd->vd.cloth_color;
  8573. WBUFB(buf,42) = tsd->vd.sex;
  8574. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8575. {
  8576. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8577. continue;
  8578. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8579. continue;
  8580. // Add item info : refine, identify flag, element, etc.
  8581. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->inventory.u.items_inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8582. n++;
  8583. }
  8584. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8585. WFIFOSET(fd, WFIFOW(fd, 2));
  8586. }
  8587. /// Display msgstringtable.txt string (ZC_MSG).
  8588. /// 0291 <message>.W
  8589. void clif_msg(struct map_session_data* sd, unsigned short id)
  8590. {
  8591. int fd;
  8592. nullpo_retv(sd);
  8593. fd = sd->fd;
  8594. WFIFOHEAD(fd, packet_len(0x291));
  8595. WFIFOW(fd, 0) = 0x291;
  8596. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8597. WFIFOSET(fd, packet_len(0x291));
  8598. }
  8599. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8600. /// 0x7e2 <message>.W <value>.L
  8601. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8602. {
  8603. int fd = sd->fd;
  8604. WFIFOHEAD(fd, packet_len(0x7e2));
  8605. WFIFOW(fd,0) = 0x7e2;
  8606. WFIFOW(fd,2) = id;
  8607. WFIFOL(fd,4) = value;
  8608. WFIFOSET(fd, packet_len(0x7e2));
  8609. }
  8610. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8611. /// 07e6 <skill id>.W <msg id>.L
  8612. ///
  8613. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8614. /// "[SkillName] Message"
  8615. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8616. {
  8617. int fd = sd->fd;
  8618. WFIFOHEAD(fd, packet_len(0x7e6));
  8619. WFIFOW(fd,0) = 0x7e6;
  8620. WFIFOW(fd,2) = skill_id;
  8621. WFIFOL(fd,4) = msg_id;
  8622. WFIFOSET(fd, packet_len(0x7e6));
  8623. }
  8624. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8625. /// 09cd <msg id>.W <color>.L
  8626. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8627. nullpo_retv(sd);
  8628. int fd = sd->fd;
  8629. WFIFOHEAD(fd, packet_len(0x9cd));
  8630. WFIFOW(fd, 0) = 0x9cd;
  8631. WFIFOW(fd, 2) = msg_id;
  8632. WFIFOL(fd, 4) = color;
  8633. WFIFOSET(fd, packet_len(0x9cd));
  8634. }
  8635. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8636. /// Returns true if the packet was parsed successfully.
  8637. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8638. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8639. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8640. const char* seperator = " : ";
  8641. int fd;
  8642. struct s_packet_db* info;
  8643. uint16 packetLength, inputLength;
  8644. const char *input, *name, *message;
  8645. size_t nameLength, messageLength;
  8646. fd = sd->fd;
  8647. info = &packet_db[RFIFOW(fd,0)];
  8648. packetLength = RFIFOW(fd,info->pos[0]);
  8649. input = RFIFOCP(fd,info->pos[1]);
  8650. // basic structure check for the 4-byte header
  8651. if( packetLength < 4 ){
  8652. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8653. return false;
  8654. }else{
  8655. inputLength = packetLength - 4;
  8656. }
  8657. // process <name> part of the packet
  8658. if( whisperFormat ) {
  8659. // name has fixed width
  8660. if( inputLength < NAME_LENGTH + 1 ) {
  8661. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8662. return false;
  8663. }
  8664. name = input;
  8665. // validate name
  8666. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8667. // only restriction is that the name must be zero-terminated
  8668. if( name[nameLength] != '\0' ) {
  8669. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8670. return false;
  8671. }
  8672. message = input + NAME_LENGTH;
  8673. messageLength = inputLength - NAME_LENGTH;
  8674. }else{
  8675. // name and message are separated by ' : '
  8676. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8677. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8678. // check if there's enough data provided
  8679. if( inputLength < nameLength + seperatorLength + 1 ){
  8680. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8681. return false;
  8682. }
  8683. name = input;
  8684. // validate name
  8685. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8686. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8687. {
  8688. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8689. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8690. set_eof(sd->fd); // Just kick them out to correct it.
  8691. return false;
  8692. }
  8693. message = input + nameLength + seperatorLength;
  8694. messageLength = inputLength - nameLength - seperatorLength;
  8695. }
  8696. #if PACKETVER < 20151001
  8697. // the declared length must match real length
  8698. if( messageLength != strnlen(message, messageLength)+1 ) {
  8699. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8700. return false;
  8701. }
  8702. // verify <message> part of the packet
  8703. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8704. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8705. return false;
  8706. }
  8707. #else
  8708. // No zero termination anymore
  8709. messageLength += 1;
  8710. #endif
  8711. // messages mustn't be too long
  8712. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8713. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8714. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8715. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8716. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8717. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8718. return false;
  8719. }
  8720. // If it is not a whisper message, set the name to the fakename of the player
  8721. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8722. strcpy( out_name, sd->fakename );
  8723. }else{
  8724. safestrncpy( out_name, name, nameLength + 1 );
  8725. }
  8726. safestrncpy( out_message, message, messageLength );
  8727. if( whisperFormat ){
  8728. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8729. out_full_message[nameLength] = '\0';
  8730. }else{
  8731. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8732. }
  8733. if( is_atcommand( fd, sd, out_message, 1 ) )
  8734. return false;
  8735. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8736. return false; //no "chatting" while muted.
  8737. if( battle_config.min_chat_delay ) { //[Skotlex]
  8738. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8739. return false;
  8740. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8741. }
  8742. if (battle_config.idletime_option&IDLE_CHAT)
  8743. sd->idletime = last_tick;
  8744. return true;
  8745. }
  8746. /**
  8747. * Displays a message if the player enters a PK Zone (during pk_mode)
  8748. * @param sd: Player data
  8749. */
  8750. inline void clif_pk_mode_message(struct map_session_data * sd)
  8751. {
  8752. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8753. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8754. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8755. char output[CHAT_SIZE_MAX];
  8756. // 1504: You've entered a PK Zone (safe until level %d).
  8757. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8758. battle_config.pk_min_level);
  8759. clif_showscript(&sd->bl, output, SELF);
  8760. } else {
  8761. // 1503: You've entered a PK Zone.
  8762. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8763. }
  8764. }
  8765. return;
  8766. }
  8767. // ---------------------
  8768. // clif_parse_wanttoconnect
  8769. // ---------------------
  8770. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8771. // error codes:
  8772. // 0 - Success
  8773. // 1 - Unknown packet_ver
  8774. // 2 - Invalid account_id
  8775. // 3 - Invalid char_id
  8776. // 4 - Invalid login_id1 (reserved)
  8777. // 5 - Invalid client_tick (reserved)
  8778. // 6 - Invalid sex
  8779. // Only the first 'invalid' error that appears is used.
  8780. static int clif_parse_WantToConnection_sub(int fd)
  8781. {
  8782. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8783. unsigned short cmd;
  8784. //By default, start searching on the default one.
  8785. cmd = RFIFOW(fd, 0);
  8786. packet_len = RFIFOREST(fd);
  8787. // FIXME: If the packet is not received at once, this will FAIL.
  8788. // Figure out, when it happens, that only part of the packet is
  8789. // received, or fix the function to be able to deal with that
  8790. // case.
  8791. if( packet_len != packet_db[cmd].len )
  8792. return 1; /* wrong length */
  8793. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8794. return 2; /* invalid account_id */
  8795. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8796. return 3; /* invalid char_id */
  8797. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8798. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8799. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8800. return 6; /* invalid sex */
  8801. else
  8802. return 0;
  8803. }
  8804. /// Request to connect to map-server.
  8805. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8806. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8807. /// There are various variants of this packet, some of them have padding between fields.
  8808. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8809. {
  8810. struct block_list* bl;
  8811. struct auth_node* node;
  8812. int cmd, account_id, char_id, login_id1, sex, err;
  8813. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8814. if (sd) {
  8815. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8816. return;
  8817. }
  8818. cmd = RFIFOW(fd, 0);
  8819. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8820. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8821. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8822. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8823. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8824. err = clif_parse_WantToConnection_sub(fd);
  8825. if( err ){ // connection rejected
  8826. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8827. err == 1 ? "." :
  8828. err == 2 ? ", possibly for having an invalid account_id." :
  8829. err == 3 ? ", possibly for having an invalid char_id." :
  8830. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8831. err == 4 ? ", possibly for having an invalid login_id1." :
  8832. err == 5 ? ", possibly for having an invalid client_tick." :
  8833. */
  8834. err == 6 ? ", possibly for having an invalid sex." :
  8835. ". ERROR invalid error code"));
  8836. WFIFOHEAD(fd,packet_len(0x6a));
  8837. WFIFOW(fd,0) = 0x6a;
  8838. WFIFOB(fd,2) = err;
  8839. WFIFOSET(fd,packet_len(0x6a));
  8840. #ifdef DUMP_INVALID_PACKET
  8841. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8842. #endif
  8843. RFIFOSKIP(fd, RFIFOREST(fd));
  8844. set_eof(fd);
  8845. return;
  8846. }
  8847. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8848. clif_authfail_fd(fd,1);// server closed
  8849. return;
  8850. }
  8851. //Check for double login.
  8852. bl = map_id2bl(account_id);
  8853. if(bl && bl->type != BL_PC) {
  8854. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8855. WFIFOHEAD(fd,packet_len(0x6a));
  8856. WFIFOW(fd,0) = 0x6a;
  8857. WFIFOB(fd,2) = 3; // Rejected by server
  8858. WFIFOSET(fd,packet_len(0x6a));
  8859. set_eof(fd);
  8860. return;
  8861. }
  8862. if (bl ||
  8863. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8864. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8865. {
  8866. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8867. return;
  8868. }
  8869. CREATE(sd, TBL_PC, 1);
  8870. sd->fd = fd;
  8871. #ifdef PACKET_OBFUSCATION
  8872. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8873. #endif
  8874. session[fd]->session_data = sd;
  8875. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8876. #if PACKETVER < 20070521
  8877. WFIFOHEAD(fd,4);
  8878. WFIFOL(fd,0) = sd->bl.id;
  8879. WFIFOSET(fd,4);
  8880. #else
  8881. WFIFOHEAD(fd,packet_len(0x283));
  8882. WFIFOW(fd,0) = 0x283;
  8883. WFIFOL(fd,2) = sd->bl.id;
  8884. WFIFOSET(fd,packet_len(0x283));
  8885. #endif
  8886. chrif_authreq(sd,false);
  8887. }
  8888. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8889. /// 007d
  8890. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8891. {
  8892. bool guild_notice = false;
  8893. if(sd->bl.prev != NULL)
  8894. return;
  8895. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8896. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8897. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8898. sd->state.connect_new = 0;
  8899. return;
  8900. }
  8901. if (sd->state.rewarp) { //Rewarp player.
  8902. sd->state.rewarp = 0;
  8903. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8904. return;
  8905. }
  8906. sd->state.warping = 0;
  8907. // look
  8908. #if PACKETVER < 4
  8909. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8910. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8911. #else
  8912. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8913. #endif
  8914. pc_set_costume_view(sd);
  8915. if(sd->vd.cloth_color)
  8916. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8917. if(sd->vd.body_style)
  8918. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8919. // item
  8920. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8921. pc_checkitem(sd);
  8922. clif_equipswitch_list(sd);
  8923. // cart
  8924. if(pc_iscarton(sd)) {
  8925. clif_cartlist(sd);
  8926. clif_updatestatus(sd,SP_CARTINFO);
  8927. }
  8928. // weight
  8929. clif_updatestatus(sd,SP_WEIGHT);
  8930. clif_updatestatus(sd,SP_MAXWEIGHT);
  8931. // guild
  8932. // (needs to go before clif_spawn() to show guild emblems correctly)
  8933. if(sd->status.guild_id)
  8934. guild_send_memberinfoshort(sd,1);
  8935. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8936. if(battle_config.pc_invincible_time > 0) {
  8937. if(mapdata_flag_gvg(mapdata))
  8938. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8939. else
  8940. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8941. }
  8942. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8943. map_spawnmobs(sd->bl.m);
  8944. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8945. mapdata->users_pvp++;
  8946. }
  8947. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8948. // reset the callshop flag if the player changes map
  8949. sd->state.callshop = 0;
  8950. if(map_addblock(&sd->bl))
  8951. return;
  8952. clif_spawn(&sd->bl);
  8953. // Party
  8954. // (needs to go after clif_spawn() to show hp bars correctly)
  8955. if(sd->status.party_id) {
  8956. party_send_movemap(sd);
  8957. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8958. }
  8959. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8960. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8961. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8962. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8963. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8964. sd->pvp_rank = 0;
  8965. sd->pvp_lastusers = 0;
  8966. sd->pvp_point = 5;
  8967. sd->pvp_won = 0;
  8968. sd->pvp_lost = 0;
  8969. }
  8970. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8971. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8972. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8973. else if (mapdata->flag[MF_GVG_DUNGEON])
  8974. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8975. else if( mapdata_flag_gvg(mapdata) )
  8976. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8977. else
  8978. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8979. // info about nearby objects
  8980. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8981. 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);
  8982. // pet
  8983. if( sd->pd ) {
  8984. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8985. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8986. pet_return_egg( sd, sd->pd );
  8987. } else {
  8988. if(map_addblock(&sd->pd->bl))
  8989. return;
  8990. clif_spawn(&sd->pd->bl);
  8991. clif_send_petdata(sd,sd->pd,0,0);
  8992. clif_send_petstatus(sd);
  8993. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8994. }
  8995. }
  8996. //homunculus [blackhole89]
  8997. if( hom_is_active(sd->hd) ) {
  8998. if(map_addblock(&sd->hd->bl))
  8999. return;
  9000. clif_spawn(&sd->hd->bl);
  9001. clif_send_homdata(sd,SP_ACK,0);
  9002. clif_hominfo(sd,sd->hd,1);
  9003. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9004. clif_homskillinfoblock(sd);
  9005. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9006. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  9007. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9008. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9009. }
  9010. if( sd->md ) {
  9011. if(map_addblock(&sd->md->bl))
  9012. return;
  9013. clif_spawn(&sd->md->bl);
  9014. clif_mercenary_info(sd);
  9015. clif_mercenary_skillblock(sd);
  9016. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  9017. }
  9018. if( sd->ed ) {
  9019. if (map_addblock(&sd->ed->bl))
  9020. return;
  9021. clif_spawn(&sd->ed->bl);
  9022. clif_elemental_info(sd);
  9023. clif_elemental_updatestatus(sd,SP_HP);
  9024. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9025. clif_elemental_updatestatus(sd,SP_SP);
  9026. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9027. }
  9028. if(sd->state.connect_new) {
  9029. int lv;
  9030. guild_notice = true;
  9031. clif_skillinfoblock(sd);
  9032. clif_hotkeys_send(sd);
  9033. clif_updatestatus(sd,SP_BASEEXP);
  9034. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9035. clif_updatestatus(sd,SP_JOBEXP);
  9036. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9037. clif_updatestatus(sd,SP_SKILLPOINT);
  9038. clif_initialstatus(sd);
  9039. if (sd->sc.option&OPTION_FALCON)
  9040. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9041. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  9042. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9043. else if (sd->sc.option&OPTION_WUGRIDER)
  9044. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9045. else if (sd->sc.data[SC_ALL_RIDING])
  9046. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9047. if(sd->status.manner < 0)
  9048. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9049. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9050. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9051. if(sd->bl.m == sd->feel_map[0].m
  9052. || sd->bl.m == sd->feel_map[1].m
  9053. || sd->bl.m == sd->feel_map[2].m)
  9054. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9055. }
  9056. if(sd->pd && sd->pd->pet.intimate > 900)
  9057. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9058. if(hom_is_active(sd->hd))
  9059. hom_init_timers(sd->hd);
  9060. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9061. sd->state.night = 1;
  9062. clif_status_load(&sd->bl, EFST_SKE, 1);
  9063. }
  9064. // Notify everyone that this char logged in [Skotlex].
  9065. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9066. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9067. //Login Event
  9068. npc_script_event(sd, NPCE_LOGIN);
  9069. }
  9070. } else {
  9071. //For some reason the client "loses" these on warp/map-change.
  9072. clif_updatestatus(sd,SP_STR);
  9073. clif_updatestatus(sd,SP_AGI);
  9074. clif_updatestatus(sd,SP_VIT);
  9075. clif_updatestatus(sd,SP_INT);
  9076. clif_updatestatus(sd,SP_DEX);
  9077. clif_updatestatus(sd,SP_LUK);
  9078. // abort currently running script
  9079. sd->state.using_fake_npc = 0;
  9080. sd->state.menu_or_input = 0;
  9081. sd->npc_menu = 0;
  9082. if(sd->npc_id)
  9083. npc_event_dequeue(sd);
  9084. }
  9085. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9086. #if PACKETVER >= 20070918
  9087. clif_partyinvitationstate(sd);
  9088. clif_equipcheckbox(sd);
  9089. #endif
  9090. #if PACKETVER >= 20141008
  9091. if( battle_config.pet_autofeed_always ){
  9092. // Always send ON or OFF
  9093. if( sd->pd && battle_config.feature_pet_autofeed ){
  9094. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  9095. }else{
  9096. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  9097. }
  9098. }else{
  9099. // Only send when enabled
  9100. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9101. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9102. }
  9103. }
  9104. #endif
  9105. #if PACKETVER >= 20170920
  9106. if( battle_config.homunculus_autofeed_always ){
  9107. // Always send ON or OFF
  9108. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9109. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9110. }else{
  9111. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9112. }
  9113. }else{
  9114. // Only send when enabled
  9115. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9116. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9117. }
  9118. }
  9119. #endif
  9120. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9121. clif_guild_notice(sd); // Displays after VIP
  9122. guild_notice = false; // Do not display it twice
  9123. }
  9124. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9125. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9126. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9127. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9128. }
  9129. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9130. { //Display night.
  9131. if( !sd->state.night )
  9132. {
  9133. sd->state.night = 1;
  9134. clif_status_load(&sd->bl, EFST_SKE, 1);
  9135. }
  9136. }
  9137. else if( sd->state.night )
  9138. { //Clear night display.
  9139. sd->state.night = 0;
  9140. clif_status_load(&sd->bl, EFST_SKE, 0);
  9141. }
  9142. if( mapdata->flag[MF_BATTLEGROUND] )
  9143. {
  9144. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9145. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9146. clif_bg_updatescore_single(sd);
  9147. }
  9148. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9149. {
  9150. char output[128];
  9151. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9152. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9153. }
  9154. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9155. mapdata->hpmeter_visible++;
  9156. sd->state.hpmeter_visible = 1;
  9157. }
  9158. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9159. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9160. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9161. #ifdef VIP_ENABLE
  9162. if (!sd->state.connect_new &&
  9163. !sd->vip.disableshowrate &&
  9164. sd->state.pmap != sd->bl.m &&
  9165. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9166. )
  9167. {
  9168. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9169. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9170. }
  9171. #endif
  9172. // Instances do not need their own channels
  9173. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9174. channel_mjoin(sd); //join new map
  9175. clif_pk_mode_message(sd);
  9176. }
  9177. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9178. clif_guild_notice(sd); // Displays at end
  9179. }
  9180. mail_clear(sd);
  9181. /* Guild Aura Init */
  9182. if( sd->guild && sd->state.gmaster_flag ) {
  9183. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9184. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9185. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9186. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9187. }
  9188. if( sd->state.vending ) { /* show we have a vending */
  9189. clif_openvending(sd,sd->bl.id,sd->vending);
  9190. clif_showvendingboard(&sd->bl,sd->message,0);
  9191. }
  9192. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9193. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9194. npc_script_event(sd, NPCE_LOADMAP);
  9195. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9196. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9197. if (sd->sc.opt2) //Client loses these on warp.
  9198. clif_changeoption(&sd->bl);
  9199. 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)) {
  9200. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9201. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9202. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9203. }
  9204. clif_weather_check(sd);
  9205. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9206. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9207. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9208. else
  9209. sd->areanpc.clear();
  9210. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9211. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9212. pc_setdead(sd);
  9213. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9214. if(pc_isdead(sd))
  9215. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9216. else {
  9217. skill_usave_trigger(sd);
  9218. if (battle_config.spawn_direction)
  9219. clif_changed_dir(&sd->bl, SELF);
  9220. }
  9221. // Trigger skill effects if you appear standing on them
  9222. if(!battle_config.pc_invincible_time)
  9223. skill_unit_move(&sd->bl,gettick(),1);
  9224. pc_show_questinfo_reinit(sd);
  9225. pc_show_questinfo(sd);
  9226. #if PACKETVER >= 20150513
  9227. if( sd->mail.inbox.unread ){
  9228. clif_Mail_new(sd, 0, NULL, NULL);
  9229. }
  9230. #endif
  9231. sd->state.connect_new = 0;
  9232. sd->state.changemap = false;
  9233. }
  9234. /// Server's tick (ZC_NOTIFY_TIME).
  9235. /// 007f <time>.L
  9236. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9237. {
  9238. int fd = sd->fd;
  9239. WFIFOHEAD(fd,packet_len(0x7f));
  9240. WFIFOW(fd,0) = 0x7f;
  9241. WFIFOL(fd,2) = client_tick(time);
  9242. WFIFOSET(fd,packet_len(0x7f));
  9243. }
  9244. /// Request for server's tick.
  9245. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9246. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9247. /// There are various variants of this packet, some of them have padding between fields.
  9248. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9249. {
  9250. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9251. clif_notify_time(sd, gettick());
  9252. }
  9253. /// Sends hotkey bar.
  9254. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9255. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9256. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9257. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9258. void clif_hotkeys_send(struct map_session_data *sd) {
  9259. #ifdef HOTKEY_SAVING
  9260. const int fd = sd->fd;
  9261. int i;
  9262. int offset = 2;
  9263. #if PACKETVER < 20090603
  9264. const int cmd = 0x2b9;
  9265. #elif PACKETVER < 20141022
  9266. const int cmd = 0x7d9;
  9267. #else
  9268. char Rotate = sd->status.hotkey_rowshift;
  9269. const int cmd = 0xa00;
  9270. offset = 3;
  9271. #endif
  9272. if (!fd) return;
  9273. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9274. WFIFOW(fd, 0) = cmd;
  9275. #if PACKETVER >= 20141022
  9276. WFIFOB(fd, 2) = Rotate;
  9277. #endif
  9278. for(i = 0; i < MAX_HOTKEYS; i++) {
  9279. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9280. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9281. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9282. }
  9283. WFIFOSET(fd, packet_len(cmd));
  9284. #endif
  9285. }
  9286. /// Request to update a position on the hotkey row bar
  9287. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9288. int cmd = RFIFOW(fd, 0);
  9289. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9290. }
  9291. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9292. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9293. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9294. #ifdef HOTKEY_SAVING
  9295. unsigned short idx;
  9296. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9297. idx = RFIFOW(fd, info->pos[0]);
  9298. if (idx >= MAX_HOTKEYS) return;
  9299. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9300. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9301. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9302. #endif
  9303. }
  9304. /// Displays cast-like progress bar (ZC_PROGRESS).
  9305. /// 02f0 <color>.L <time>.L
  9306. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9307. {
  9308. int fd = sd->fd;
  9309. WFIFOHEAD(fd,packet_len(0x2f0));
  9310. WFIFOW(fd,0) = 0x2f0;
  9311. WFIFOL(fd,2) = color;
  9312. WFIFOL(fd,6) = second;
  9313. WFIFOSET(fd,packet_len(0x2f0));
  9314. }
  9315. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9316. /// 02f2
  9317. void clif_progressbar_abort(struct map_session_data * sd)
  9318. {
  9319. int fd = sd->fd;
  9320. WFIFOHEAD(fd,packet_len(0x2f2));
  9321. WFIFOW(fd,0) = 0x2f2;
  9322. WFIFOSET(fd,packet_len(0x2f2));
  9323. }
  9324. /// Notification from the client, that the progress bar has reached 100%.
  9325. /// 02f1 (CZ_PROGRESS)
  9326. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9327. // No progressbar active, ignore it
  9328. if( !sd->progressbar.npc_id ){
  9329. return;
  9330. }
  9331. int npc_id = sd->progressbar.npc_id;
  9332. bool closing = false;
  9333. // Check if the progress was canceled
  9334. if( gettick() < sd->progressbar.timeout && sd->st ){
  9335. closing = true;
  9336. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9337. // If a message window was open, offer a close button to the user
  9338. if( sd->st->mes_active ){
  9339. clif_scriptclose( sd, npc_id );
  9340. }
  9341. }
  9342. sd->progressbar.npc_id = 0;
  9343. sd->progressbar.timeout = 0;
  9344. sd->state.workinprogress = WIP_DISABLE_NONE;
  9345. npc_scriptcont(sd, npc_id, closing);
  9346. }
  9347. /// Displays cast-like progress bar on a NPC
  9348. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9349. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9350. #if PACKETVER >= 20130821
  9351. unsigned char buf[14];
  9352. if( nd->progressbar.timeout > 0 ){
  9353. WBUFW(buf,0) = 0x9d1;
  9354. WBUFL(buf,2) = nd->bl.id;
  9355. WBUFL(buf,6) = nd->progressbar.color;
  9356. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9357. if( sd ){
  9358. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9359. }else{
  9360. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9361. }
  9362. }
  9363. #endif
  9364. }
  9365. /// Request to walk to a certain position on the current map.
  9366. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9367. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9368. /// There are various variants of this packet, some of them have padding between fields.
  9369. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9370. {
  9371. short x, y;
  9372. if (pc_isdead(sd)) {
  9373. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9374. return;
  9375. }
  9376. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9377. ; //You CAN walk on this OPT1 value.
  9378. else if (sd->progressbar.npc_id) {
  9379. clif_progressbar_abort(sd);
  9380. return; // First walk attempt cancels the progress bar
  9381. } else if (pc_cant_act(sd))
  9382. return;
  9383. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9384. return;
  9385. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9386. //A move command one cell west is only valid if the target cell is free
  9387. if(battle_config.official_cell_stack_limit > 0
  9388. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9389. return;
  9390. // Cloaking wall check is actually updated when you click to process next movement
  9391. // not when you move each cell. This is official behaviour.
  9392. if (sd->sc.data[SC_CLOAKING])
  9393. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9394. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9395. pc_delinvincibletimer(sd);
  9396. //Set last idle time... [Skotlex]
  9397. if (battle_config.idletime_option&IDLE_WALK)
  9398. sd->idletime = last_tick;
  9399. unit_walktoxy(&sd->bl, x, y, 4);
  9400. }
  9401. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9402. /// 018b <result>.W
  9403. /// result:
  9404. /// 0 = disconnect (quit)
  9405. /// 1 = cannot disconnect (wait 10 seconds)
  9406. /// ? = ignored
  9407. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9408. {
  9409. int fd = sd->fd;
  9410. WFIFOHEAD(fd,packet_len(0x18b));
  9411. WFIFOW(fd,0) = 0x18b;
  9412. WFIFOW(fd,2) = result;
  9413. WFIFOSET(fd,packet_len(0x18b));
  9414. }
  9415. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9416. /// 018a <type>.W
  9417. /// type:
  9418. /// 0 = quit
  9419. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9420. {
  9421. /* Rovert's prevent logout option fixed [Valaris] */
  9422. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9423. 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] &&
  9424. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9425. {
  9426. set_eof(fd);
  9427. pc_damage_log_clear(sd,0);
  9428. clif_disconnect_ack(sd, 0);
  9429. } else {
  9430. clif_disconnect_ack(sd, 1);
  9431. }
  9432. }
  9433. /// Requesting unit's name.
  9434. /// 0094 <id>.L (CZ_REQNAME)
  9435. /// 0368 <id>.L (CZ_REQNAME2)
  9436. /// There are various variants of this packet, some of them have padding between fields.
  9437. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9438. {
  9439. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9440. struct block_list* bl;
  9441. //struct status_change *sc;
  9442. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9443. id = sd->bl.id;
  9444. bl = map_id2bl(id);
  9445. if( bl == NULL )
  9446. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9447. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9448. return; // Block namerequests past view range
  9449. // 'see people in GM hide' cheat detection
  9450. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9451. sc = status_get_sc(bl);
  9452. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9453. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9454. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9455. ) {
  9456. char gm_msg[256];
  9457. 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);
  9458. ShowWarning(gm_msg);
  9459. // information is sent to all online GMs
  9460. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9461. return;
  9462. }
  9463. */
  9464. clif_name(&sd->bl,bl,SELF);
  9465. }
  9466. /// Validates and processes global messages
  9467. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9468. /// There are various variants of this packet.
  9469. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9470. {
  9471. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9472. size_t length;
  9473. // validate packet and retrieve name and message
  9474. if( !clif_process_message(sd, false, name, message, output ) )
  9475. return;
  9476. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9477. channel_send(sd->gcbind,sd,message);
  9478. return;
  9479. }
  9480. // send message to others (using the send buffer for temp. storage)
  9481. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9482. length = strlen(output) + 1;
  9483. // send back message to the speaker
  9484. WFIFOHEAD(fd,4+length);
  9485. WFIFOW(fd,0) = 0x8e;
  9486. WFIFOW(fd,2) = (uint16)(4+length);
  9487. safestrncpy(WFIFOCP(fd,4), output, length );
  9488. WFIFOSET(fd, WFIFOW(fd,2));
  9489. #ifdef PCRE_SUPPORT
  9490. // trigger listening npcs
  9491. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9492. #endif
  9493. // Chat logging type 'O' / Global Chat
  9494. 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);
  9495. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9496. }
  9497. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9498. /// Request to warp to a map on given coordinates.
  9499. /// 0140 <map name>.16B <x>.W <y>.W
  9500. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9501. {
  9502. char command[MAP_NAME_LENGTH_EXT+25];
  9503. char* map_name;
  9504. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9505. map_name = RFIFOCP(fd,info->pos[0]);
  9506. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9507. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9508. RFIFOW(fd,info->pos[1]), //x
  9509. RFIFOW(fd,info->pos[2])); //y
  9510. is_atcommand(fd, sd, command, 1);
  9511. }
  9512. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9513. /// 009c <id>.L <head dir>.W <dir>.B
  9514. /// head dir:
  9515. /// 0 = straight
  9516. /// 1 = turned CW
  9517. /// 2 = turned CCW
  9518. /// dir:
  9519. /// 0 = north
  9520. /// 1 = northwest
  9521. /// 2 = west
  9522. /// 3 = southwest
  9523. /// 4 = south
  9524. /// 5 = southeast
  9525. /// 6 = east
  9526. /// 7 = northeast
  9527. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9528. {
  9529. unsigned char buf[64];
  9530. WBUFW(buf,0) = 0x9c;
  9531. WBUFL(buf,2) = bl->id;
  9532. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9533. WBUFB(buf,8) = unit_getdir(bl);
  9534. clif_send(buf, packet_len(0x9c), bl, target);
  9535. if (disguised(bl)) {
  9536. WBUFL(buf,2) = -bl->id;
  9537. WBUFW(buf,6) = 0;
  9538. clif_send(buf, packet_len(0x9c), bl, SELF);
  9539. }
  9540. }
  9541. /// Request to change own body and head direction.
  9542. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9543. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9544. /// There are various variants of this packet, some of them have padding between fields.
  9545. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9546. {
  9547. unsigned char headdir, dir;
  9548. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9549. headdir = RFIFOB(fd,info->pos[0]);
  9550. dir = RFIFOB(fd,info->pos[1]);
  9551. pc_setdir(sd, dir, headdir);
  9552. clif_changed_dir(&sd->bl, AREA_WOS);
  9553. }
  9554. /// Request to show an emotion (CZ_REQ_EMOTION).
  9555. /// 00bf <type>.B
  9556. /// type:
  9557. /// @see enum emotion_type
  9558. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9559. {
  9560. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9561. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9562. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9563. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9564. return;
  9565. }
  9566. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9567. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9568. sd->emotionlasttime = time(NULL);
  9569. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9570. return;
  9571. }
  9572. sd->emotionlasttime = time(NULL);
  9573. if (battle_config.idletime_option&IDLE_EMOTION)
  9574. sd->idletime = last_tick;
  9575. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9576. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9577. return;
  9578. }
  9579. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9580. emoticon = rnd()%6+ET_DICE1;
  9581. }
  9582. clif_emotion(&sd->bl, emoticon);
  9583. } else
  9584. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9585. }
  9586. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9587. /// 00c2 <count>.L
  9588. void clif_user_count(struct map_session_data* sd, int count)
  9589. {
  9590. int fd = sd->fd;
  9591. WFIFOHEAD(fd,packet_len(0xc2));
  9592. WFIFOW(fd,0) = 0xc2;
  9593. WFIFOL(fd,2) = count;
  9594. WFIFOSET(fd,packet_len(0xc2));
  9595. }
  9596. /// /w /who (CZ_REQ_USER_COUNT).
  9597. /// Request to display amount of currently connected players.
  9598. /// 00c1
  9599. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9600. {
  9601. clif_user_count(sd, map_getusers());
  9602. }
  9603. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9604. {
  9605. if (pc_isdead(sd)) {
  9606. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9607. return;
  9608. }
  9609. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9610. // (not all are included in pc_can_attack)
  9611. if (sd->sc.count &&
  9612. (sd->sc.data[SC_TRICKDEAD] ||
  9613. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9614. sd->sc.data[SC_BLADESTOP] ||
  9615. sd->sc.data[SC__MANHOLE] ||
  9616. sd->sc.data[SC_SUHIDE] ))
  9617. return;
  9618. if(action_type != 0x00 && action_type != 0x07)
  9619. pc_stop_walking(sd, 1);
  9620. pc_stop_attack(sd);
  9621. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9622. target_id = sd->bl.id;
  9623. switch(action_type)
  9624. {
  9625. case 0x00: // once attack
  9626. case 0x07: // continuous attack
  9627. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9628. return;
  9629. if( sd->sc.option&OPTION_COSTUME )
  9630. return;
  9631. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9632. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9633. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9634. return;
  9635. }
  9636. }
  9637. pc_delinvincibletimer(sd);
  9638. if (battle_config.idletime_option&IDLE_ATTACK)
  9639. sd->idletime = last_tick;
  9640. unit_attack(&sd->bl, target_id, action_type != 0);
  9641. break;
  9642. case 0x02: // sitdown
  9643. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9644. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9645. break;
  9646. }
  9647. if(pc_issit(sd)) {
  9648. //Bugged client? Just refresh them.
  9649. clif_sitting(&sd->bl);
  9650. return;
  9651. }
  9652. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9653. break;
  9654. if (sd->sc.count && (
  9655. sd->sc.data[SC_DANCING] ||
  9656. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9657. )) //No sitting during these states either.
  9658. break;
  9659. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9660. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9661. break;
  9662. }
  9663. if (battle_config.idletime_option&IDLE_SIT)
  9664. sd->idletime = last_tick;
  9665. pc_setsit(sd);
  9666. skill_sit(sd, true);
  9667. clif_sitting(&sd->bl);
  9668. break;
  9669. case 0x03: // standup
  9670. if (!pc_issit(sd)) {
  9671. //Bugged client? Just refresh them.
  9672. clif_standing(&sd->bl);
  9673. return;
  9674. }
  9675. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9676. break;
  9677. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9678. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9679. break;
  9680. }
  9681. if (pc_setstand(sd, false)) {
  9682. if (battle_config.idletime_option&IDLE_SIT)
  9683. sd->idletime = last_tick;
  9684. skill_sit(sd, false);
  9685. clif_standing(&sd->bl);
  9686. }
  9687. break;
  9688. }
  9689. }
  9690. /// Request for an action.
  9691. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9692. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9693. /// action:
  9694. /// 0 = attack
  9695. /// 1 = pick up item
  9696. /// 2 = sit down
  9697. /// 3 = stand up
  9698. /// 7 = continous attack
  9699. /// 12 = (touch skill?)
  9700. /// There are various variants of this packet, some of them have padding between fields.
  9701. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9702. {
  9703. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9704. clif_parse_ActionRequest_sub(sd,
  9705. RFIFOB(fd,info->pos[1]),
  9706. RFIFOL(fd,info->pos[0]),
  9707. gettick()
  9708. );
  9709. }
  9710. /// Response to the death/system menu (CZ_RESTART).
  9711. /// 00b2 <type>.B
  9712. /// type:
  9713. /// 0 = restart (respawn)
  9714. /// 1 = char-select (disconnect)
  9715. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9716. {
  9717. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9718. case 0x00:
  9719. pc_respawn(sd,CLR_OUTSIGHT);
  9720. break;
  9721. case 0x01:
  9722. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9723. 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] &&
  9724. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9725. { //Send to char-server for character selection.
  9726. pc_damage_log_clear(sd,0);
  9727. chrif_charselectreq(sd, session[fd]->client_addr);
  9728. } else {
  9729. clif_disconnect_ack(sd, 1);
  9730. }
  9731. break;
  9732. }
  9733. }
  9734. /// Validates and processes whispered messages (CZ_WHISPER).
  9735. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9736. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9737. {
  9738. struct map_session_data* dstsd;
  9739. int i;
  9740. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9741. // validate packet and retrieve name and message
  9742. if( !clif_process_message( sd, true, target, message, output ) )
  9743. return;
  9744. // Chat logging type 'W' / Whisper
  9745. 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);
  9746. //-------------------------------------------------------//
  9747. // Lordalfa - Paperboy - To whisper NPC commands //
  9748. //-------------------------------------------------------//
  9749. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9750. {
  9751. char* str = target+4; //Skip the NPC: string part.
  9752. struct npc_data* npc;
  9753. if ((npc = npc_name2id(str))) {
  9754. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9755. char *split;
  9756. char event[EVENT_NAME_LENGTH];
  9757. str = message;
  9758. // skip codepage indicator, if detected
  9759. if( str[0] == '|' && strlen(str) >= 4 )
  9760. str += 3;
  9761. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9762. split = strchr(str,'#');
  9763. if( split == NULL ) { // use the remaining string
  9764. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9765. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9766. split_data[i][0] = '\0';
  9767. break;
  9768. }
  9769. *split = '\0';
  9770. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9771. str = split+1;
  9772. }
  9773. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9774. char variablename[CHAT_SIZE_MAX];
  9775. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9776. set_var(sd,variablename,(char *) split_data[i]);
  9777. }
  9778. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9779. npc_event(sd,event,0); // Calls the NPC label
  9780. return;
  9781. }
  9782. } else if( target[0] == '#' ) {
  9783. struct Channel *channel = NULL;
  9784. char* chname = target;
  9785. channel = channel_name2channel(chname,sd,3);
  9786. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9787. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9788. channel_send(channel,sd,message);
  9789. }
  9790. else if( channel->pass[0] == '\0') { //no pass needed
  9791. if (channel_join(channel,sd)==0)
  9792. channel_send(channel,sd,message); //join success
  9793. }
  9794. else {
  9795. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9796. }
  9797. return;
  9798. }
  9799. }
  9800. // searching destination character
  9801. dstsd = map_nick2sd(target,false);
  9802. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9803. // player is not on this map-server
  9804. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9805. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9806. // and if we ask for 'Test', we must not contact 'test' player
  9807. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9808. intif_wis_message(sd, target, message, strlen(message) + 1);
  9809. return;
  9810. }
  9811. // if player ignores everyone
  9812. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9813. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9814. clif_wis_end(fd, 1); // 1: target character is not logged in
  9815. else
  9816. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9817. return;
  9818. }
  9819. // if player is autotrading
  9820. if (dstsd->state.autotrade == 1){
  9821. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9822. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9823. return;
  9824. }
  9825. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9826. // if player ignores the source character
  9827. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9828. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9829. clif_wis_end(fd, 2); // 2: ignored by target
  9830. return;
  9831. }
  9832. }
  9833. // notify sender of success
  9834. clif_wis_end(fd, 0); // 0: success to send wisper
  9835. // Normal message
  9836. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9837. }
  9838. /// /b /nb (CZ_BROADCAST).
  9839. /// Request to broadcast a message on whole server.
  9840. /// 0099 <packet len>.W <text>.?B 00
  9841. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9842. char command[CHAT_SIZE_MAX+11];
  9843. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9844. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9845. char* msg = RFIFOCP(fd,info->pos[1]);
  9846. // as the length varies depending on the command used, just block unreasonably long strings
  9847. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9848. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9849. is_atcommand(fd, sd, command, 1);
  9850. }
  9851. /// Request to pick up an item.
  9852. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9853. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9854. /// There are various variants of this packet, some of them have padding between fields.
  9855. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9856. {
  9857. struct flooritem_data *fitem;
  9858. int map_object_id;
  9859. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9860. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9861. do {
  9862. if (pc_isdead(sd)) {
  9863. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9864. break;
  9865. }
  9866. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9867. break;
  9868. if (pc_cant_act(sd))
  9869. break;
  9870. if (!pc_takeitem(sd, fitem))
  9871. break;
  9872. return;
  9873. } while (0);
  9874. // Client REQUIRES a fail packet or you can no longer pick items.
  9875. clif_additem(sd,0,0,6);
  9876. }
  9877. /// Request to drop an item.
  9878. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9879. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9880. /// There are various variants of this packet, some of them have padding between fields.
  9881. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9882. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9883. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9884. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9885. for(;;) {
  9886. if (pc_isdead(sd))
  9887. break;
  9888. if (pc_cant_act2(sd) || sd->npc_id)
  9889. break;
  9890. if (sd->sc.count && (
  9891. sd->sc.data[SC_AUTOCOUNTER] ||
  9892. sd->sc.data[SC_BLADESTOP] ||
  9893. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9894. ))
  9895. break;
  9896. if (!pc_dropitem(sd, item_index, item_amount))
  9897. break;
  9898. if (battle_config.idletime_option&IDLE_DROPITEM)
  9899. sd->idletime = last_tick;
  9900. return;
  9901. }
  9902. //Because the client does not like being ignored.
  9903. clif_dropitem(sd, item_index,0);
  9904. }
  9905. /// Request to use an item.
  9906. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9907. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9908. /// There are various variants of this packet, some of them have padding between fields.
  9909. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9910. {
  9911. int n;
  9912. if (pc_isdead(sd)) {
  9913. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9914. return;
  9915. }
  9916. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9917. clif_msg(sd, WORK_IN_PROGRESS);
  9918. return;
  9919. }
  9920. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9921. if (battle_config.idletime_option&IDLE_USEITEM)
  9922. sd->idletime = last_tick;
  9923. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9924. if(n <0 || n >= MAX_INVENTORY)
  9925. return;
  9926. if (!pc_useitem(sd,n))
  9927. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9928. }
  9929. /// Request to equip an item
  9930. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9931. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9932. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9933. {
  9934. int index;
  9935. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9936. if(pc_isdead(sd)) {
  9937. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9938. return;
  9939. }
  9940. index = RFIFOW(fd,info->pos[0])-2;
  9941. if (index < 0 || index >= MAX_INVENTORY)
  9942. return; //Out of bounds check.
  9943. if(sd->npc_id && !sd->npc_item_flag) {
  9944. return;
  9945. } else if (sd->state.storage_flag || sd->sc.opt1)
  9946. ; //You can equip/unequip stuff while storage is open/under status changes
  9947. else if (pc_cant_act2(sd))
  9948. return;
  9949. if(!sd->inventory.u.items_inventory[index].identify) {
  9950. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9951. return;
  9952. }
  9953. if(!sd->inventory_data[index])
  9954. return;
  9955. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9956. pet_equipitem(sd,index);
  9957. return;
  9958. }
  9959. if (battle_config.idletime_option&IDLE_USEITEM)
  9960. sd->idletime = last_tick;
  9961. //Client doesn't send the position for ammo.
  9962. if(sd->inventory_data[index]->type == IT_AMMO)
  9963. pc_equipitem(sd,index,EQP_AMMO);
  9964. else {
  9965. int req_pos;
  9966. #if PACKETVER >= 20120925
  9967. req_pos = RFIFOL(fd,info->pos[1]);
  9968. #else
  9969. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9970. #endif
  9971. pc_equipitem(sd,index,req_pos);
  9972. }
  9973. }
  9974. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9975. /// 00ab <index>.W
  9976. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9977. {
  9978. int index;
  9979. if(pc_isdead(sd)) {
  9980. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9981. return;
  9982. }
  9983. if (sd->npc_id && !sd->npc_item_flag) {
  9984. return;
  9985. } else if (sd->state.storage_flag || sd->sc.opt1)
  9986. ; //You can equip/unequip stuff while storage is open/under status changes
  9987. else if (pc_cant_act2(sd))
  9988. return;
  9989. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9990. if (battle_config.idletime_option&IDLE_USEITEM)
  9991. sd->idletime = last_tick;
  9992. pc_unequipitem(sd,index,1);
  9993. }
  9994. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9995. /// 0090 <id>.L <type>.B
  9996. /// type:
  9997. /// 1 = click
  9998. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9999. {
  10000. struct block_list *bl;
  10001. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10002. if(pc_isdead(sd)) {
  10003. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10004. return;
  10005. }
  10006. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10007. #ifdef RENEWAL
  10008. clif_msg( sd, WORK_IN_PROGRESS );
  10009. #endif
  10010. return;
  10011. }
  10012. if( sd->state.mail_writing )
  10013. return;
  10014. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10015. //type = RFIFOB(fd,info->pos[1]);
  10016. if (!bl) return;
  10017. switch (bl->type) {
  10018. case BL_MOB:
  10019. case BL_PC:
  10020. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10021. break;
  10022. case BL_NPC:
  10023. #ifdef RENEWAL
  10024. 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
  10025. clif_msg(sd, WORK_IN_PROGRESS);
  10026. break;
  10027. }
  10028. #endif
  10029. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10030. struct npc_data* nd = (struct npc_data*)bl;
  10031. // Progressbar is running
  10032. if( nd->progressbar.timeout > 0 ){
  10033. return;
  10034. }
  10035. npc_click(sd,nd);
  10036. }
  10037. break;
  10038. }
  10039. }
  10040. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10041. /// 00c5 <id>.L <type>.B
  10042. /// type:
  10043. /// 0 = buy
  10044. /// 1 = sell
  10045. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10046. {
  10047. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10048. if (sd->state.trading)
  10049. return;
  10050. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10051. }
  10052. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10053. /// 00ca <result>.B
  10054. /// result:
  10055. /// 0 = "The deal has successfully completed."
  10056. /// 1 = "You do not have enough zeny."
  10057. /// 2 = "You are over your Weight Limit."
  10058. /// 3 = "Out of the maximum capacity, you have too many items."
  10059. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10060. {
  10061. int fd = sd->fd;
  10062. WFIFOHEAD(fd,packet_len(0xca));
  10063. WFIFOW(fd,0) = 0xca;
  10064. WFIFOB(fd,2) = result;
  10065. WFIFOSET(fd,packet_len(0xca));
  10066. }
  10067. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10068. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10069. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  10070. {
  10071. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10072. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  10073. int result;
  10074. if( sd->state.trading || !sd->npc_shopid )
  10075. result = 1;
  10076. else
  10077. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  10078. sd->npc_shopid = 0; //Clear shop data.
  10079. clif_npc_buy_result(sd, result);
  10080. }
  10081. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10082. /// 00cb <result>.B
  10083. /// result:
  10084. /// 0 = "The deal has successfully completed."
  10085. /// 1 = "The deal has failed."
  10086. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10087. {
  10088. int fd = sd->fd;
  10089. WFIFOHEAD(fd,packet_len(0xcb));
  10090. WFIFOW(fd,0) = 0xcb;
  10091. WFIFOB(fd,2) = result;
  10092. WFIFOSET(fd,packet_len(0xcb));
  10093. }
  10094. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10095. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10096. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10097. {
  10098. int fail=0,n;
  10099. unsigned short *item_list;
  10100. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10101. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10102. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10103. if (sd->state.trading || !sd->npc_shopid)
  10104. fail = 1;
  10105. else
  10106. fail = npc_selllist(sd,n,item_list);
  10107. sd->npc_shopid = 0; //Clear shop data.
  10108. clif_npc_sell_result(sd, fail);
  10109. }
  10110. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10111. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10112. /// type:
  10113. /// 0 = private
  10114. /// 1 = public
  10115. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10116. {
  10117. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10118. int len = RFIFOW(fd,info->pos[0])-15;
  10119. int limit = RFIFOW(fd,info->pos[1]);
  10120. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10121. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10122. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10123. char s_password[CHATROOM_PASS_SIZE];
  10124. char s_title[CHATROOM_TITLE_SIZE];
  10125. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10126. return;
  10127. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10128. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10129. return;
  10130. }
  10131. if( npc_isnear(&sd->bl) ) {
  10132. // uncomment to send msg_txt.
  10133. //char output[150];
  10134. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10135. //clif_displaymessage(sd->fd, output);
  10136. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10137. return;
  10138. }
  10139. if( len <= 0 )
  10140. return; // invalid input
  10141. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10142. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10143. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10144. }
  10145. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10146. /// 00d9 <chat ID>.L <passwd>.8B
  10147. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10148. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10149. int chatid = RFIFOL(fd,info->pos[0]);
  10150. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10151. chat_joinchat(sd,chatid,password);
  10152. }
  10153. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10154. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10155. /// type:
  10156. /// 0 = private
  10157. /// 1 = public
  10158. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10159. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10160. int len = RFIFOW(fd,info->pos[0])-15;
  10161. int limit = RFIFOW(fd,info->pos[1]);
  10162. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10163. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10164. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10165. char s_password[CHATROOM_PASS_SIZE];
  10166. char s_title[CHATROOM_TITLE_SIZE];
  10167. if( len <= 0 )
  10168. return; // invalid input
  10169. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10170. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10171. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10172. }
  10173. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10174. /// 00e0 <role>.L <nick>.24B
  10175. /// role:
  10176. /// 0 = owner
  10177. /// 1 = normal
  10178. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10179. {
  10180. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10181. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10182. }
  10183. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10184. /// 00e2 <name>.24B
  10185. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10186. {
  10187. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10188. }
  10189. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10190. /// 00e3
  10191. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10192. {
  10193. chat_leavechat(sd,0);
  10194. }
  10195. //Handles notifying asker and rejecter of what has just ocurred.
  10196. //Type is used to determine the correct msg_txt to use:
  10197. //0:
  10198. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10199. {
  10200. const char* msg;
  10201. char output[256];
  10202. // Your request has been rejected by autoreject option.
  10203. msg = msg_txt(sd,392);
  10204. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10205. //Notice that a request was rejected.
  10206. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10207. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10208. }
  10209. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10210. /// 00e4 <account id>.L
  10211. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10212. {
  10213. struct map_session_data *t_sd;
  10214. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10215. if(!sd->chatID && pc_cant_act(sd))
  10216. return; //You can trade while in a chatroom.
  10217. if(t_sd){
  10218. // @noask [LuzZza]
  10219. if(t_sd->state.noask) {
  10220. clif_noask_sub(sd, t_sd, 0);
  10221. return;
  10222. }
  10223. if (t_sd->state.mail_writing) {
  10224. int old = sd->trade_partner;
  10225. // Fake trading
  10226. sd->trade_partner = t_sd->status.account_id;
  10227. clif_tradestart(sd, 5);
  10228. // Restore old state
  10229. sd->trade_partner = old;
  10230. return;
  10231. }
  10232. }
  10233. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10234. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10235. return;
  10236. }
  10237. trade_traderequest(sd,t_sd);
  10238. }
  10239. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10240. /// 00e6 <result>.B
  10241. /// result:
  10242. /// 3 = accepted
  10243. /// 4 = rejected
  10244. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10245. {
  10246. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10247. }
  10248. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10249. /// 00e8 <index>.W <amount>.L
  10250. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10251. {
  10252. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10253. short index = RFIFOW(fd,info->pos[0]);
  10254. int amount = RFIFOL(fd,info->pos[1]);
  10255. if( index == 0 )
  10256. trade_tradeaddzeny(sd, amount);
  10257. else
  10258. trade_tradeadditem(sd, index, (short)amount);
  10259. }
  10260. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10261. /// 00eb
  10262. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10263. {
  10264. trade_tradeok(sd);
  10265. }
  10266. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10267. /// 00ed
  10268. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10269. {
  10270. trade_tradecancel(sd);
  10271. }
  10272. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10273. /// 00ef
  10274. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10275. {
  10276. trade_tradecommit(sd);
  10277. }
  10278. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10279. /// 0118
  10280. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10281. {
  10282. pc_stop_attack(sd);
  10283. if (sd) sd->ud.state.attack_continue = 0;
  10284. }
  10285. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10286. /// 0126 <index>.W <amount>.L
  10287. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10288. {
  10289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10290. if (pc_istrading(sd))
  10291. return;
  10292. if (!pc_iscarton(sd))
  10293. return;
  10294. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10295. }
  10296. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10297. /// 0127 <index>.W <amount>.L
  10298. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10299. {
  10300. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10301. if (!pc_iscarton(sd))
  10302. return;
  10303. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10304. }
  10305. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10306. /// 012a
  10307. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10308. {
  10309. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10310. #ifdef NEW_CARTS
  10311. && sd->sc.data[SC_PUSH_CART] )
  10312. pc_setcart(sd,0);
  10313. #else
  10314. )
  10315. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10316. #endif
  10317. else // priority to remove this option before we can clear cart
  10318. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10319. }
  10320. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10321. /// 097f <Length>.W <identity>.L <type>.B
  10322. void clif_SelectCart(struct map_session_data *sd) {
  10323. #if PACKETVER >= 20150826
  10324. int i = 0, carts = 3;
  10325. int fd = sd->fd;
  10326. WFIFOHEAD(fd,8 + carts);
  10327. WFIFOW(fd,0) = 0x97f;
  10328. WFIFOW(fd,2) = 8 + carts;
  10329. WFIFOL(fd,4) = sd->status.account_id;
  10330. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10331. for( i = 0; i < carts; i++ ) {
  10332. WFIFOB(fd,8 + i) = 10 + i;
  10333. }
  10334. WFIFOSET(fd,8 + carts);
  10335. #endif
  10336. }
  10337. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10338. /// 0980 <identity>.L <type>.B
  10339. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10340. #if PACKETVER >= 20150826
  10341. int type;
  10342. // Check identity
  10343. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10344. return;
  10345. type = (int)RFIFOB(fd,6);
  10346. // Check type
  10347. if( type < 10 || type > MAX_CARTS )
  10348. return;
  10349. pc_setcart(sd, type);
  10350. #endif
  10351. }
  10352. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10353. /// 01af <num>.W
  10354. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10355. {// TODO: State tracking?
  10356. int type;
  10357. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10358. return;
  10359. #ifdef RENEWAL
  10360. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10361. clif_msg(sd, WORK_IN_PROGRESS);
  10362. return;
  10363. }
  10364. #endif
  10365. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10366. if(
  10367. #ifdef NEW_CARTS
  10368. (type == 9 && sd->status.base_level > 130) ||
  10369. (type == 8 && sd->status.base_level > 120) ||
  10370. (type == 7 && sd->status.base_level > 110) ||
  10371. (type == 6 && sd->status.base_level > 100) ||
  10372. #endif
  10373. (type == 5 && sd->status.base_level > 90) ||
  10374. (type == 4 && sd->status.base_level > 80) ||
  10375. (type == 3 && sd->status.base_level > 65) ||
  10376. (type == 2 && sd->status.base_level > 40) ||
  10377. (type == 1))
  10378. pc_setcart(sd, type);
  10379. }
  10380. /// Request to increase status (CZ_STATUS_CHANGE).
  10381. /// 00bb <status id>.W <amount>.B
  10382. /// status id:
  10383. /// SP_STR ~ SP_LUK
  10384. /// amount:
  10385. /// Old clients always send 1 for this, even when using /str+ and the like.
  10386. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10387. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10388. {
  10389. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10390. if( increase_amount < 0 ) {
  10391. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10392. fd, increase_amount);
  10393. }
  10394. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10395. }
  10396. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10397. /// 0112 <skill id>.W
  10398. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10399. {
  10400. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10401. }
  10402. 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)
  10403. {
  10404. int lv;
  10405. if( !hd )
  10406. return;
  10407. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10408. clif_emotion(&hd->bl, ET_THINK);
  10409. return;
  10410. }
  10411. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10412. target_id = hd->bl.id;
  10413. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10414. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10415. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10416. clif_emotion(&hd->bl, ET_THINK);
  10417. if (hd->master)
  10418. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10419. return;
  10420. }
  10421. lv = hom_checkskill(hd, skill_id);
  10422. if( skill_lv > lv )
  10423. skill_lv = lv;
  10424. if( skill_lv )
  10425. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10426. }
  10427. 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)
  10428. {
  10429. int lv;
  10430. if( !hd )
  10431. return;
  10432. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10433. clif_emotion(&hd->bl, ET_THINK);
  10434. return;
  10435. }
  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. if( hd->sc.data[SC_BASILICA] )
  10445. return;
  10446. lv = hom_checkskill(hd, skill_id);
  10447. if( skill_lv > lv )
  10448. skill_lv = lv;
  10449. if( skill_lv )
  10450. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10451. }
  10452. 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)
  10453. {
  10454. int lv;
  10455. if( !md )
  10456. return;
  10457. if( skill_isNotOk_mercenary(skill_id, md) )
  10458. return;
  10459. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10460. target_id = md->bl.id;
  10461. if( md->ud.skilltimer != INVALID_TIMER )
  10462. {
  10463. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10464. }
  10465. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10466. return;
  10467. lv = mercenary_checkskill(md, skill_id);
  10468. if( skill_lv > lv )
  10469. skill_lv = lv;
  10470. if( skill_lv )
  10471. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10472. }
  10473. 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)
  10474. {
  10475. int lv;
  10476. if( !md )
  10477. return;
  10478. if( skill_isNotOk_mercenary(skill_id, md) )
  10479. return;
  10480. if( md->ud.skilltimer != INVALID_TIMER )
  10481. return;
  10482. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10483. {
  10484. if (md->master)
  10485. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10486. return;
  10487. }
  10488. if( md->sc.data[SC_BASILICA] )
  10489. return;
  10490. lv = mercenary_checkskill(md, skill_id);
  10491. if( skill_lv > lv )
  10492. skill_lv = lv;
  10493. if( skill_lv )
  10494. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10495. }
  10496. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10497. t_tick tick = gettick();
  10498. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10499. int inf = skill_get_inf(skill_id);
  10500. if (inf&INF_GROUND_SKILL || !inf)
  10501. return; //Using a ground/passive skill on a target? WRONG.
  10502. if (sd->state.block_action & PCBLOCK_SKILL) {
  10503. clif_msg(sd, WORK_IN_PROGRESS);
  10504. return;
  10505. }
  10506. if( SKILL_CHK_HOMUN(skill_id) ) {
  10507. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10508. return;
  10509. }
  10510. if( SKILL_CHK_MERC(skill_id) ) {
  10511. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10512. return;
  10513. }
  10514. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10515. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10516. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10517. sd->idletime = last_tick;
  10518. if( sd->npc_id ){
  10519. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10520. #ifdef RENEWAL
  10521. clif_msg( sd, WORK_IN_PROGRESS );
  10522. #endif
  10523. return;
  10524. }
  10525. }
  10526. if ((pc_cant_act2(sd) || sd->chatID) &&
  10527. skill_id != RK_REFRESH &&
  10528. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10529. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10530. return;
  10531. if( pc_issit(sd) )
  10532. return;
  10533. if( skill_isNotOk(skill_id, sd) )
  10534. return;
  10535. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10536. target_id = sd->bl.id; // never trust the client
  10537. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10538. target_id = sd->bl.id;
  10539. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10540. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10541. return;
  10542. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10543. if( sd->skillitem != skill_id ) {
  10544. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10545. return;
  10546. }
  10547. }
  10548. if( sd->sc.option&OPTION_COSTUME )
  10549. return;
  10550. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10551. return; // On basilica only caster can use Basilica again to stop it.
  10552. if( sd->menuskill_id ) {
  10553. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10554. clif_menuskill_clear(sd); //Cancel pet capture.
  10555. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10556. return; //Can't use skills while a menu is open.
  10557. }
  10558. if( sd->skillitem == skill_id ) {
  10559. if( skill_lv != sd->skillitemlv )
  10560. skill_lv = sd->skillitemlv;
  10561. if( !(inf&INF_SELF_SKILL) )
  10562. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10563. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10564. return;
  10565. }
  10566. sd->skillitem = sd->skillitemlv = 0;
  10567. if( SKILL_CHK_GUILD(skill_id) ) {
  10568. if( sd->state.gmaster_flag )
  10569. skill_lv = guild_checkskill(sd->guild, skill_id);
  10570. else
  10571. skill_lv = 0;
  10572. } else {
  10573. if( skill_id != ALL_EQSWITCH ){
  10574. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10575. }
  10576. }
  10577. pc_delinvincibletimer(sd);
  10578. if( skill_lv )
  10579. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10580. }
  10581. /// Request to use a targeted skill.
  10582. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10583. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10584. /// There are various variants of this packet, some of them have padding between fields.
  10585. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10586. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10587. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10588. }
  10589. /*==========================================
  10590. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10591. *------------------------------------------*/
  10592. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10593. {
  10594. t_tick tick = gettick();
  10595. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10596. return; //Using a target skill on the ground? WRONG.
  10597. if (sd->state.block_action & PCBLOCK_SKILL) {
  10598. clif_msg(sd, WORK_IN_PROGRESS);
  10599. return;
  10600. }
  10601. if( SKILL_CHK_HOMUN(skill_id) ) {
  10602. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10603. return;
  10604. }
  10605. if( SKILL_CHK_MERC(skill_id) ) {
  10606. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10607. return;
  10608. }
  10609. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10610. #ifdef RENEWAL
  10611. clif_msg( sd, WORK_IN_PROGRESS );
  10612. #endif
  10613. return;
  10614. }
  10615. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10616. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10617. sd->idletime = last_tick;
  10618. if( skill_isNotOk(skill_id, sd) )
  10619. return;
  10620. if( skillmoreinfo != -1 ) {
  10621. if( pc_issit(sd) ) {
  10622. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10623. return;
  10624. }
  10625. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10626. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10627. }
  10628. if( sd->ud.skilltimer != INVALID_TIMER )
  10629. return;
  10630. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10631. if( sd->skillitem != skill_id ) {
  10632. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10633. return;
  10634. }
  10635. }
  10636. if( sd->sc.option&OPTION_COSTUME )
  10637. return;
  10638. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10639. return; // On basilica only caster can use Basilica again to stop it.
  10640. if( sd->menuskill_id ) {
  10641. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10642. clif_menuskill_clear(sd); //Cancel pet capture.
  10643. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10644. return; //Can't use skills while a menu is open.
  10645. }
  10646. pc_delinvincibletimer(sd);
  10647. if( sd->skillitem == skill_id ) {
  10648. if( skill_lv != sd->skillitemlv )
  10649. skill_lv = sd->skillitemlv;
  10650. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10651. } else {
  10652. int lv;
  10653. sd->skillitem = sd->skillitemlv = 0;
  10654. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10655. if( skill_lv > lv )
  10656. skill_lv = lv;
  10657. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10658. }
  10659. }
  10660. }
  10661. /// Request to use a ground skill.
  10662. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10663. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10664. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10665. /// There are various variants of this packet, some of them have padding between fields.
  10666. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10667. {
  10668. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10669. if (pc_cant_act(sd))
  10670. return;
  10671. if (pc_issit(sd))
  10672. return;
  10673. clif_parse_UseSkillToPosSub(fd, sd,
  10674. RFIFOW(fd,info->pos[0]), //skill lv
  10675. RFIFOW(fd,info->pos[1]), //skill num
  10676. RFIFOW(fd,info->pos[2]), //pos x
  10677. RFIFOW(fd,info->pos[3]), //pos y
  10678. // TODO: find out what this is intended to do
  10679. //RFIFOB(fd, info->pos[4])
  10680. -1 //Skill more info.
  10681. );
  10682. }
  10683. /// Request to use a ground skill with text.
  10684. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10685. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10686. /// There are various variants of this packet, some of them have padding between fields.
  10687. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10688. {
  10689. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10690. if (pc_cant_act(sd))
  10691. return;
  10692. if (pc_issit(sd))
  10693. return;
  10694. clif_parse_UseSkillToPosSub(fd, sd,
  10695. RFIFOW(fd,info->pos[0]), //Skill lv
  10696. RFIFOW(fd,info->pos[1]), //Skill num
  10697. RFIFOW(fd,info->pos[2]), //pos x
  10698. RFIFOW(fd,info->pos[3]), //pos y
  10699. info->pos[4] //skill more info
  10700. );
  10701. }
  10702. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10703. /// 011b <skill id>.W <map name>.16B
  10704. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10705. {
  10706. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10707. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10708. char map_name[MAP_NAME_LENGTH];
  10709. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10710. sd->state.workinprogress = WIP_DISABLE_NONE;
  10711. if(skill_id != sd->menuskill_id)
  10712. return;
  10713. //It is possible to use teleport with the storage window open bugreport:8027
  10714. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10715. clif_menuskill_clear(sd);
  10716. return;
  10717. }
  10718. pc_delinvincibletimer(sd);
  10719. skill_castend_map(sd,skill_id,map_name);
  10720. }
  10721. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10722. /// 011d
  10723. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10724. {
  10725. if (!pc_isdead(sd))
  10726. pc_memo(sd,-1);
  10727. }
  10728. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10729. /// 018e <name id>.W { <material id>.W }*3
  10730. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10731. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10732. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10733. int slot1 = RFIFOW(fd,info->pos[1]);
  10734. int slot2 = RFIFOW(fd,info->pos[2]);
  10735. int slot3 = RFIFOW(fd,info->pos[3]);
  10736. short produce_idx = -1;
  10737. switch( sd->menuskill_id ) {
  10738. case -1:
  10739. case AM_PHARMACY:
  10740. case RK_RUNEMASTERY:
  10741. case GC_RESEARCHNEWPOISON:
  10742. break;
  10743. default:
  10744. return;
  10745. }
  10746. if (pc_istrading(sd)) {
  10747. //Make it fail to avoid shop exploits where you sell something different than you see.
  10748. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10749. clif_menuskill_clear(sd);
  10750. return;
  10751. }
  10752. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10753. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10754. clif_menuskill_clear(sd);
  10755. }
  10756. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10757. /// 025b <mk type>.W <name id>.W
  10758. /// mk type:
  10759. /// 1 = cooking
  10760. /// 2 = arrow
  10761. /// 3 = elemental
  10762. /// 4 = GN_MIX_COOKING
  10763. /// 5 = GN_MAKEBOMB
  10764. /// 6 = GN_S_PHARMACY
  10765. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10766. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10767. int type = RFIFOW(fd,info->pos[0]);
  10768. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10769. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10770. short food_idx = -1;
  10771. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10772. return;
  10773. if (pc_istrading(sd)) {
  10774. //Make it fail to avoid shop exploits where you sell something different than you see.
  10775. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10776. clif_menuskill_clear(sd);
  10777. return;
  10778. }
  10779. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10780. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10781. clif_menuskill_clear(sd);
  10782. }
  10783. /// Answer to repair weapon item selection dialog
  10784. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10785. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10786. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10787. {
  10788. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10789. return;
  10790. if (pc_istrading(sd)) {
  10791. //Make it fail to avoid shop exploits where you sell something different than you see.
  10792. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10793. clif_menuskill_clear(sd);
  10794. return;
  10795. }
  10796. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10797. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10798. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10799. //for(i = 0; i<MAX_SLOTS; i++)
  10800. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10801. clif_menuskill_clear(sd);
  10802. }
  10803. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10804. /// 0222 <index>.L
  10805. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10806. {
  10807. int idx;
  10808. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  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. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10817. skill_weaponrefine(sd, idx-2);
  10818. clif_menuskill_clear(sd);
  10819. }
  10820. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10821. /// 00b8 <npc id>.L <choice>.B
  10822. /// choice:
  10823. /// 1~254 = menu item
  10824. /// 255 = cancel
  10825. /// NOTE: If there were more than 254 items in the list, choice
  10826. /// overflows to choice%256.
  10827. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10828. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10829. int npc_id = RFIFOL(fd,info->pos[0]);
  10830. uint8 select = RFIFOB(fd,info->pos[1]);
  10831. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10832. #ifdef SECURE_NPCTIMEOUT
  10833. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10834. #endif
  10835. TBL_NPC* nd = map_id2nd(npc_id);
  10836. 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);
  10837. clif_GM_kick(NULL,sd);
  10838. #ifdef SECURE_NPCTIMEOUT
  10839. }
  10840. #endif
  10841. return;
  10842. }
  10843. sd->npc_menu = select;
  10844. npc_scriptcont(sd,npc_id, false);
  10845. }
  10846. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10847. /// 00b9 <npc id>.L
  10848. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10849. {
  10850. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10851. }
  10852. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10853. /// 0143 <npc id>.L <value>.L
  10854. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10855. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10856. int npcid = RFIFOL(fd,info->pos[0]);
  10857. int amount = (int)RFIFOL(fd,info->pos[1]);
  10858. sd->npc_amount = amount;
  10859. npc_scriptcont(sd, npcid, false);
  10860. }
  10861. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10862. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10863. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10864. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10865. int message_len = RFIFOW(fd,info->pos[0])-8;
  10866. int npcid = RFIFOL(fd,info->pos[1]);
  10867. const char* message = RFIFOCP(fd,info->pos[2]);
  10868. if( message_len <= 0 )
  10869. return; // invalid input
  10870. #if PACKETVER >= 20151001
  10871. message_len++;
  10872. #endif
  10873. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10874. npc_scriptcont(sd, npcid, false);
  10875. }
  10876. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10877. /// 0146 <npc id>.L
  10878. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10879. {
  10880. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10881. return;
  10882. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10883. }
  10884. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10885. /// 0178 <index>.W
  10886. /// index:
  10887. /// -1 = cancel
  10888. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10889. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10890. if (sd->menuskill_id != MC_IDENTIFY)
  10891. return;
  10892. // Ignore the request
  10893. // - Invalid item index
  10894. // - Invalid item ID or item doesn't exist
  10895. // - Item is already identified
  10896. if (idx < 0 || idx >= MAX_INVENTORY ||
  10897. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10898. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10899. sd->state.workinprogress = WIP_DISABLE_NONE;
  10900. clif_menuskill_clear(sd);
  10901. return;
  10902. }
  10903. skill_identify(sd, idx);
  10904. clif_menuskill_clear(sd);
  10905. }
  10906. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10907. /// 01ae <name id>.W
  10908. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10909. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10910. if (pc_istrading(sd)) {
  10911. //Make it fail to avoid shop exploits where you sell something different than you see.
  10912. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10913. clif_menuskill_clear(sd);
  10914. return;
  10915. }
  10916. switch (sd->menuskill_id) {
  10917. case AC_MAKINGARROW:
  10918. skill_arrow_create(sd,nameid);
  10919. break;
  10920. case SA_CREATECON:
  10921. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10922. break;
  10923. case WL_READING_SB:
  10924. skill_spellbook(sd,nameid);
  10925. break;
  10926. case GC_POISONINGWEAPON:
  10927. skill_poisoningweapon(sd,nameid);
  10928. break;
  10929. case NC_MAGICDECOY:
  10930. skill_magicdecoy(sd,nameid);
  10931. break;
  10932. }
  10933. clif_menuskill_clear(sd);
  10934. }
  10935. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10936. /// 01ce <skill id>.L
  10937. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10938. {
  10939. if (sd->menuskill_id != SA_AUTOSPELL)
  10940. return;
  10941. sd->state.workinprogress = WIP_DISABLE_NONE;
  10942. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10943. clif_menuskill_clear(sd);
  10944. }
  10945. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10946. /// 017a <card index>.W
  10947. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10948. {
  10949. if (sd->state.trading != 0)
  10950. return;
  10951. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10952. }
  10953. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10954. /// 017c <card index>.W <equip index>.W
  10955. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10956. {
  10957. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10958. if (sd->state.trading != 0)
  10959. return;
  10960. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10961. }
  10962. /// Request of character's name by char ID.
  10963. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10964. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10965. /// There are various variants of this packet, some of them have padding between fields.
  10966. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10967. {
  10968. int charid;
  10969. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10970. map_reqnickdb(sd, charid);
  10971. }
  10972. /// /resetskill /resetstate (CZ_RESET).
  10973. /// Request to reset stats or skills.
  10974. /// 0197 <type>.W
  10975. /// type:
  10976. /// 0 = state
  10977. /// 1 = skill
  10978. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10979. char cmd[15];
  10980. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10981. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10982. else
  10983. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10984. is_atcommand(fd, sd, cmd, 1);
  10985. }
  10986. /// /lb /nlb (CZ_LOCALBROADCAST).
  10987. /// Request to broadcast a message on current map.
  10988. /// 019c <packet len>.W <text>.?B
  10989. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10990. {
  10991. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10992. char command[CHAT_SIZE_MAX+16];
  10993. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10994. char* msg = RFIFOCP(fd,info->pos[1]);
  10995. // as the length varies depending on the command used, just block unreasonably long strings
  10996. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10997. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10998. is_atcommand(fd, sd, command, 1);
  10999. }
  11000. /// Request to move an item from inventory to storage.
  11001. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11002. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11003. /// There are various variants of this packet, some of them have padding between fields.
  11004. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11005. {
  11006. int item_index, item_amount;
  11007. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11008. if (pc_istrading(sd))
  11009. return;
  11010. item_index = RFIFOW(fd,info->pos[0])-2;
  11011. item_amount = RFIFOL(fd,info->pos[1]);
  11012. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11013. return;
  11014. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11015. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11016. return;
  11017. }
  11018. if (sd->state.storage_flag == 1)
  11019. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11020. else
  11021. if (sd->state.storage_flag == 2)
  11022. storage_guild_storageadd(sd, item_index, item_amount);
  11023. else if (sd->state.storage_flag == 3)
  11024. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11025. }
  11026. /// Request to move an item from storage to inventory.
  11027. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11028. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11029. /// There are various variants of this packet, some of them have padding between fields.
  11030. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11031. {
  11032. int item_index, item_amount;
  11033. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11034. item_index = RFIFOW(fd,info->pos[0])-1;
  11035. item_amount = RFIFOL(fd,info->pos[1]);
  11036. if (sd->state.storage_flag == 1)
  11037. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11038. else if(sd->state.storage_flag == 2)
  11039. storage_guild_storageget(sd, item_index, item_amount);
  11040. else if(sd->state.storage_flag == 3)
  11041. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11042. }
  11043. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11044. /// 0129 <index>.W <amount>.L
  11045. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11046. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11047. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11048. int amount = RFIFOL(fd,info->pos[1]);
  11049. if( sd->state.vending )
  11050. return;
  11051. if (!pc_iscarton(sd))
  11052. return;
  11053. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11054. return;
  11055. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11056. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11057. return;
  11058. }
  11059. if (sd->state.storage_flag == 1)
  11060. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11061. else if (sd->state.storage_flag == 2)
  11062. storage_guild_storageaddfromcart(sd, idx, amount);
  11063. else if (sd->state.storage_flag == 3)
  11064. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11065. }
  11066. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11067. /// 0128 <index>.W <amount>.L
  11068. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11069. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11070. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11071. int amount = RFIFOL(fd,info->pos[1]);
  11072. if( sd->state.vending )
  11073. return;
  11074. if (!pc_iscarton(sd))
  11075. return;
  11076. if (sd->state.storage_flag == 1)
  11077. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11078. else
  11079. if (sd->state.storage_flag == 2)
  11080. storage_guild_storagegettocart(sd, idx, amount);
  11081. else if (sd->state.storage_flag == 3)
  11082. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11083. }
  11084. /// Request to close storage (CZ_CLOSE_STORE).
  11085. /// 00f7
  11086. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11087. {
  11088. if( sd->state.storage_flag == 1 )
  11089. storage_storageclose(sd);
  11090. else
  11091. if( sd->state.storage_flag == 2 )
  11092. storage_guild_storageclose(sd);
  11093. else if( sd->state.storage_flag == 3 )
  11094. storage_premiumStorage_close(sd);
  11095. }
  11096. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11097. /// 023a <info>.W
  11098. /// info:
  11099. /// 0 = password has not been set yet
  11100. /// 1 = storage is password-protected
  11101. /// 8 = too many wrong passwords
  11102. /// ? = ignored
  11103. /// NOTE: This packet is only available on certain non-kRO clients.
  11104. void clif_storagepassword(struct map_session_data* sd, short info)
  11105. {
  11106. int fd = sd->fd;
  11107. WFIFOHEAD(fd,packet_len(0x23a));
  11108. WFIFOW(fd,0) = 0x23a;
  11109. WFIFOW(fd,2) = info;
  11110. WFIFOSET(fd,packet_len(0x23a));
  11111. }
  11112. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11113. /// 023b <type>.W <password>.16B <new password>.16B
  11114. /// type:
  11115. /// 2 = change password
  11116. /// 3 = check password
  11117. /// NOTE: This packet is only available on certain non-kRO clients.
  11118. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11119. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11120. // int type = RFIFOW(fd,info->pos[0]);
  11121. // char* password = RFIFOP(fd,info->pos[1]);
  11122. // char* new_password = RFIFOP(fd,info->pos[2]);
  11123. // storage_changepass(sd,password,new_password);
  11124. }
  11125. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11126. /// 023c <result>.W <error count>.W
  11127. /// result:
  11128. /// 4 = password change success
  11129. /// 5 = password change failure
  11130. /// 6 = password check success
  11131. /// 7 = password check failure
  11132. /// 8 = too many wrong passwords
  11133. /// ? = ignored
  11134. /// NOTE: This packet is only available on certain non-kRO clients.
  11135. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11136. {
  11137. int fd = sd->fd;
  11138. WFIFOHEAD(fd,packet_len(0x23c));
  11139. WFIFOW(fd,0) = 0x23c;
  11140. WFIFOW(fd,2) = result;
  11141. WFIFOW(fd,4) = error_count;
  11142. WFIFOSET(fd,packet_len(0x23c));
  11143. }
  11144. /// Party creation request
  11145. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11146. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11147. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11148. name[NAME_LENGTH-1] = '\0';
  11149. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11150. clif_displaymessage(fd, msg_txt(sd,227));
  11151. return;
  11152. }
  11153. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11154. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11155. return;
  11156. }
  11157. party_create(sd,name,0,0);
  11158. }
  11159. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11160. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11161. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11162. char* name = RFIFOCP(fd,info->pos[0]);
  11163. int item1 = RFIFOB(fd,info->pos[1]);
  11164. int item2 = RFIFOB(fd,info->pos[2]);
  11165. name[NAME_LENGTH-1] = '\0';
  11166. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11167. clif_displaymessage(fd, msg_txt(sd,227));
  11168. return;
  11169. }
  11170. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11171. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11172. return;
  11173. }
  11174. party_create(sd,name,item1,item2);
  11175. }
  11176. /// Party invitation request
  11177. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11178. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11179. {
  11180. struct map_session_data *t_sd;
  11181. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11182. clif_displaymessage(fd, msg_txt(sd,227));
  11183. return;
  11184. }
  11185. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11186. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11187. clif_noask_sub(sd, t_sd, 1);
  11188. return;
  11189. }
  11190. party_invite(sd, t_sd);
  11191. }
  11192. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11193. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11194. struct map_session_data *t_sd;
  11195. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11196. name[NAME_LENGTH-1] = '\0';
  11197. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11198. clif_displaymessage(fd, msg_txt(sd,227));
  11199. return;
  11200. }
  11201. t_sd = map_nick2sd(name,false);
  11202. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11203. clif_noask_sub(sd, t_sd, 1);
  11204. return;
  11205. }
  11206. party_invite(sd, t_sd);
  11207. }
  11208. /// Party invitation reply
  11209. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11210. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11211. /// flag:
  11212. /// 0 = reject
  11213. /// 1 = accept
  11214. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11215. {
  11216. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11217. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11218. RFIFOL(fd,info->pos[1]));
  11219. }
  11220. //(CZ_PARTY_JOIN_REQ_ACK)
  11221. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11222. {
  11223. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11224. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11225. RFIFOB(fd,info->pos[1]));
  11226. }
  11227. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11228. /// 0100
  11229. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11230. {
  11231. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11232. clif_displaymessage(fd, msg_txt(sd,227));
  11233. return;
  11234. }
  11235. party_leave(sd);
  11236. }
  11237. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11238. /// 0103 <account id>.L <char name>.24B
  11239. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11240. {
  11241. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11242. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11243. clif_displaymessage(fd, msg_txt(sd,227));
  11244. return;
  11245. }
  11246. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11247. RFIFOCP(fd,info->pos[1]));
  11248. }
  11249. /// Request to change party options.
  11250. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11251. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11252. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11253. {
  11254. struct party_data *p;
  11255. int i,expflag;
  11256. int cmd = RFIFOW(fd,0);
  11257. struct s_packet_db* info = &packet_db[cmd];
  11258. if( !sd->status.party_id )
  11259. return;
  11260. p = party_search(sd->status.party_id);
  11261. if( p == NULL )
  11262. return;
  11263. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11264. if( i == MAX_PARTY )
  11265. return; //Shouldn't happen
  11266. if( !p->party.member[i].leader )
  11267. return;
  11268. expflag = RFIFOL(fd,info->pos[0]);
  11269. if(cmd == 0x0102){ //Client can't change the item-field
  11270. party_changeoption(sd, expflag, p->party.item);
  11271. }
  11272. else {
  11273. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11274. party_changeoption(sd, expflag, itemflag);
  11275. }
  11276. }
  11277. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11278. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11279. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11280. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11281. // validate packet and retrieve name and message
  11282. if( !clif_process_message( sd, false, name, message, output ) )
  11283. return;
  11284. party_send_message(sd, output, strlen(output) + 1 );
  11285. }
  11286. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11287. /// 07da <account id>.L
  11288. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11289. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11290. }
  11291. /// Party Booking in KRO [Spiria]
  11292. ///
  11293. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11294. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11295. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11296. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11297. short level = RFIFOW(fd,info->pos[0]);
  11298. short mapid = RFIFOW(fd,info->pos[1]);
  11299. int idxpbj = info->pos[2];
  11300. short job[MAX_PARTY_BOOKING_JOBS];
  11301. int i;
  11302. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11303. job[i] = RFIFOB(fd,idxpbj+i*2);
  11304. party_booking_register(sd, level, mapid, job);
  11305. }
  11306. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11307. /// 0803 <result>.W
  11308. /// result:
  11309. /// 0 = success
  11310. /// 1 = failure
  11311. /// 2 = already registered
  11312. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11313. {
  11314. int fd = sd->fd;
  11315. WFIFOHEAD(fd,packet_len(0x803));
  11316. WFIFOW(fd,0) = 0x803;
  11317. WFIFOW(fd,2) = flag;
  11318. WFIFOSET(fd,packet_len(0x803));
  11319. }
  11320. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11321. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11322. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11323. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11324. short level = RFIFOW(fd,info->pos[0]);
  11325. short mapid = RFIFOW(fd,info->pos[1]);
  11326. short job = RFIFOW(fd,info->pos[2]);
  11327. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11328. short resultcount = RFIFOW(fd,info->pos[4]);
  11329. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11330. }
  11331. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11332. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11333. /// more results:
  11334. /// 0 = no
  11335. /// 1 = yes
  11336. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11337. {
  11338. int i, j;
  11339. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11340. struct party_booking_ad_info *pb_ad;
  11341. WFIFOHEAD(fd,size*count + 5);
  11342. WFIFOW(fd,0) = 0x805;
  11343. WFIFOW(fd,2) = size*count + 5;
  11344. WFIFOB(fd,4) = more_result;
  11345. for(i=0; i<count; i++)
  11346. {
  11347. pb_ad = results[i];
  11348. WFIFOL(fd,i*size+5) = pb_ad->index;
  11349. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11350. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11351. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11352. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11353. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11354. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11355. }
  11356. WFIFOSET(fd,WFIFOW(fd,2));
  11357. }
  11358. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11359. /// 0806
  11360. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11361. {
  11362. if(party_booking_delete(sd))
  11363. clif_PartyBookingDeleteAck(sd, 0);
  11364. }
  11365. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11366. /// 0807 <result>.W
  11367. /// result:
  11368. /// 0 = success
  11369. /// 1 = success (auto-removed expired ad)
  11370. /// 2 = failure
  11371. /// 3 = nothing registered
  11372. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11373. {
  11374. int fd = sd->fd;
  11375. WFIFOHEAD(fd,packet_len(0x807));
  11376. WFIFOW(fd,0) = 0x807;
  11377. WFIFOW(fd,2) = flag;
  11378. WFIFOSET(fd,packet_len(0x807));
  11379. }
  11380. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11381. /// 0808 { <job>.W }*6
  11382. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11383. {
  11384. short job[MAX_PARTY_BOOKING_JOBS];
  11385. int i;
  11386. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11387. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11388. job[i] = RFIFOW(fd,idxpbu+i*2);
  11389. party_booking_update(sd, job);
  11390. }
  11391. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11392. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11393. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11394. {
  11395. int i;
  11396. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11397. if(pb_ad == NULL) return;
  11398. WBUFW(buf,0) = 0x809;
  11399. WBUFL(buf,2) = pb_ad->index;
  11400. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11401. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11402. WBUFW(buf,34) = pb_ad->p_detail.level;
  11403. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11404. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11405. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11406. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11407. }
  11408. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11409. /// 080a <index>.L { <job>.W }*6
  11410. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11411. {
  11412. int i;
  11413. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11414. if(pb_ad == NULL) return;
  11415. WBUFW(buf,0) = 0x80a;
  11416. WBUFL(buf,2) = pb_ad->index;
  11417. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11418. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11419. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11420. }
  11421. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11422. /// 080b <index>.L
  11423. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11424. {
  11425. uint8 buf[6];
  11426. WBUFW(buf,0) = 0x80b;
  11427. WBUFL(buf,2) = index;
  11428. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11429. }
  11430. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11431. /// 012e
  11432. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11433. {
  11434. vending_closevending(sd);
  11435. }
  11436. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11437. /// 0130 <account id>.L
  11438. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11439. {
  11440. if( sd->npc_id ) {// using an NPC
  11441. return;
  11442. }
  11443. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11444. }
  11445. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11446. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11447. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11448. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11449. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11450. int id = (int)RFIFOL(fd,info->pos[1]);
  11451. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11452. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11453. // whether it fails or not, the buy window is closed
  11454. sd->vended_id = 0;
  11455. }
  11456. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11457. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11458. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11459. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11460. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11461. int aid = (int)RFIFOL(fd,info->pos[1]);
  11462. int uid = (int)RFIFOL(fd,info->pos[2]);
  11463. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11464. vending_purchasereq(sd, aid, uid, data, len/4);
  11465. // whether it fails or not, the buy window is closed
  11466. sd->vended_id = 0;
  11467. }
  11468. /// Confirm or cancel the shop preparation window.
  11469. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11470. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11471. /// result:
  11472. /// 0 = canceled
  11473. /// 1 = open
  11474. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11475. int cmd = RFIFOW(fd,0);
  11476. struct s_packet_db* info = &packet_db[cmd];
  11477. short len = (short)RFIFOW(fd,info->pos[0]);
  11478. const char* message = RFIFOCP(fd,info->pos[1]);
  11479. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11480. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11481. len -= 84;
  11482. }
  11483. else { //(CZ_REQ_OPENSTORE2)
  11484. bool flag;
  11485. len -= 85;
  11486. flag = RFIFOB(fd,info->pos[2]) != 0;
  11487. if (!flag) {
  11488. sd->state.prevend = 0;
  11489. sd->state.workinprogress = WIP_DISABLE_NONE;
  11490. }
  11491. }
  11492. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11493. return;
  11494. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11495. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11496. return;
  11497. }
  11498. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11499. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11500. return;
  11501. }
  11502. if( message[0] == '\0' ) // invalid input
  11503. return;
  11504. vending_openvending(sd, message, data, len/8, NULL);
  11505. }
  11506. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11507. /// 0165 <char id>.L <guild name>.24B
  11508. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11509. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11510. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11511. name[NAME_LENGTH-1] = '\0';
  11512. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11513. clif_displaymessage(fd, msg_txt(sd,228));
  11514. return;
  11515. }
  11516. if(sd->clan){
  11517. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11518. return;
  11519. }
  11520. guild_create(sd, name);
  11521. }
  11522. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11523. /// 014d
  11524. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11525. {
  11526. clif_guild_masterormember(sd);
  11527. }
  11528. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11529. /// 014f <type>.L
  11530. /// type:
  11531. /// 0 = basic info
  11532. /// 1 = member manager
  11533. /// 2 = positions
  11534. /// 3 = skills
  11535. /// 4 = expulsion list
  11536. /// 5 = unknown (GM_ALLGUILDLIST)
  11537. /// 6 = notice
  11538. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11539. {
  11540. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11541. if( !sd->status.guild_id && !sd->bg_id )
  11542. return;
  11543. switch( type )
  11544. {
  11545. case 0: // Basic Information Guild, hostile alliance information
  11546. clif_guild_basicinfo(sd);
  11547. clif_guild_allianceinfo(sd);
  11548. break;
  11549. case 1: // Members list, list job title
  11550. clif_guild_positionnamelist(sd);
  11551. clif_guild_memberlist(sd);
  11552. break;
  11553. case 2: // List job title, title information list
  11554. clif_guild_positionnamelist(sd);
  11555. clif_guild_positioninfolist(sd);
  11556. break;
  11557. case 3: // Skill list
  11558. clif_guild_skillinfo(sd);
  11559. break;
  11560. case 4: // Expulsion list
  11561. clif_guild_expulsionlist(sd);
  11562. break;
  11563. default:
  11564. ShowError("clif: guild request info: unknown type %d\n", type);
  11565. break;
  11566. }
  11567. }
  11568. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11569. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11570. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11571. {
  11572. int i;
  11573. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11574. int len = RFIFOW(fd,info->pos[0]);
  11575. int idxgpos = info->pos[1];
  11576. if(!sd->state.gmaster_flag)
  11577. return;
  11578. for(i = idxgpos; i < len; i += 40 ){
  11579. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11580. }
  11581. }
  11582. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11583. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11584. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11585. {
  11586. int i;
  11587. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11588. int len = RFIFOW(fd,info->pos[0]);
  11589. int idxgpos = info->pos[1];
  11590. if(!sd->state.gmaster_flag)
  11591. return;
  11592. // Guild leadership change
  11593. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11594. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11595. clif_msg(sd, GUILD_MASTER_WOE);
  11596. return;
  11597. }
  11598. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11599. clif_msg(sd, GUILD_MASTER_DELAY);
  11600. return;
  11601. }
  11602. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11603. return;
  11604. }
  11605. for(i=idxgpos;i<len;i+=12){
  11606. int position = RFIFOL(fd,i+8);
  11607. if( position > 0 ){
  11608. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11609. }
  11610. }
  11611. }
  11612. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11613. /// 0151 <guild id>.L
  11614. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11615. {
  11616. struct guild* g;
  11617. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11618. if( (g = guild_search(guild_id)) != NULL )
  11619. clif_guild_emblem(sd,g);
  11620. }
  11621. /// Validates data of a guild emblem (compressed bitmap)
  11622. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11623. EMBVALIDATE_SUCCESS = 0,
  11624. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11625. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11626. };
  11627. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11628. {
  11629. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11630. unsigned long buf_len = sizeof(buf);
  11631. int offset = 0;
  11632. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11633. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11634. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11635. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11636. ))
  11637. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11638. if(battle_config.emblem_transparency_limit != 100) {
  11639. int i, transcount = 1, tmp[3];
  11640. for(i = offset; i < buf_len-1; i++) {
  11641. int j = i%3;
  11642. tmp[j] = RBUFL(buf,i);
  11643. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11644. transcount++;
  11645. }
  11646. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11647. return EMBVALIDATE_ERR_TRANSPARENCY;
  11648. }
  11649. return EMBVALIDATE_SUCCESS;
  11650. }
  11651. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11652. /// 0153 <packet len>.W <emblem data>.?B
  11653. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11654. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11655. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11656. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11657. int emb_val=0;
  11658. if( !emblem_len || !sd->state.gmaster_flag )
  11659. return;
  11660. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11661. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11662. return;
  11663. }
  11664. emb_val = clif_validate_emblem(emblem, emblem_len);
  11665. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11666. 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);
  11667. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11668. return;
  11669. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11670. char output[128];
  11671. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11672. 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"
  11673. return;
  11674. }
  11675. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11676. }
  11677. /// Guild notice update request (CZ_GUILD_NOTICE).
  11678. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11679. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11680. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11681. int guild_id = RFIFOL(fd,info->pos[0]);
  11682. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11683. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11684. if(!sd->state.gmaster_flag)
  11685. return;
  11686. // compensate for some client defects when using multilanguage mode
  11687. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11688. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11689. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11690. guild_change_notice(sd, guild_id, msg1, msg2);
  11691. }
  11692. // Helper function for guild invite functions
  11693. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11694. {
  11695. if (t_sd == NULL) // not online or does not exist
  11696. return 1;
  11697. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11698. clif_displaymessage(fd, msg_txt(sd,228));
  11699. return 1;
  11700. }
  11701. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11702. clif_noask_sub(sd, t_sd, 2);
  11703. return 1;
  11704. }
  11705. // Players in a clan can not join a guild
  11706. if(t_sd && t_sd->clan){
  11707. return 1;
  11708. }
  11709. guild_invite(sd, t_sd);
  11710. return 0;
  11711. }
  11712. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11713. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11714. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11715. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11716. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11717. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11718. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11719. if (clif_sub_guild_invite(fd, sd, t_sd))
  11720. return;
  11721. }
  11722. /// Guild invite request (/guildinvite)
  11723. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11724. void
  11725. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11726. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11727. if (clif_sub_guild_invite(fd, sd, t_sd))
  11728. return;
  11729. }
  11730. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11731. /// 016b <guild id>.L <answer>.L
  11732. /// answer:
  11733. /// 0 = refuse
  11734. /// 1 = accept
  11735. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11736. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11737. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11738. RFIFOL(fd,info->pos[1]));
  11739. }
  11740. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11741. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11742. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11743. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11744. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11745. clif_displaymessage(fd, msg_txt(sd,228));
  11746. return;
  11747. }
  11748. if( sd->bg_id ) {
  11749. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11750. return;
  11751. }
  11752. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11753. RFIFOL(fd,info->pos[1]),
  11754. RFIFOL(fd,info->pos[2]),
  11755. RFIFOCP(fd,info->pos[3]));
  11756. }
  11757. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11758. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11759. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11760. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11761. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11762. { // Guild locked.
  11763. clif_displaymessage(fd, msg_txt(sd,228));
  11764. return;
  11765. }
  11766. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11767. RFIFOL(fd,info->pos[1]),
  11768. RFIFOL(fd,info->pos[2]),
  11769. RFIFOCP(fd,info->pos[3]));
  11770. }
  11771. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11772. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11773. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11774. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11775. // validate packet and retrieve name and message
  11776. if( !clif_process_message( sd, false, name, message, output ) )
  11777. return;
  11778. if( sd->bg_id )
  11779. bg_send_message(sd, output, strlen(output) );
  11780. else
  11781. guild_send_message(sd, output, strlen(output) );
  11782. }
  11783. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11784. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11785. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11786. {
  11787. struct map_session_data *t_sd;
  11788. if(!sd->state.gmaster_flag)
  11789. return;
  11790. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11791. clif_displaymessage(fd, msg_txt(sd,228));
  11792. return;
  11793. }
  11794. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11795. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11796. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11797. // @noask [LuzZza]
  11798. if(t_sd && t_sd->state.noask) {
  11799. clif_noask_sub(sd, t_sd, 3);
  11800. return;
  11801. }
  11802. guild_reqalliance(sd,t_sd);
  11803. }
  11804. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11805. /// 0172 <inviter account id>.L <answer>.L
  11806. /// answer:
  11807. /// 0 = refuse
  11808. /// 1 = accept
  11809. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11810. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11811. guild_reply_reqalliance(sd,
  11812. RFIFOL(fd,info->pos[0]),
  11813. RFIFOL(fd,info->pos[1]));
  11814. }
  11815. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11816. /// 0183 <opponent guild id>.L <relation>.L
  11817. /// relation:
  11818. /// 0 = Ally
  11819. /// 1 = Enemy
  11820. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11821. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11822. if(!sd->state.gmaster_flag)
  11823. return;
  11824. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11825. clif_displaymessage(fd, msg_txt(sd,228));
  11826. return;
  11827. }
  11828. guild_delalliance(sd,
  11829. RFIFOL(fd,info->pos[0]),
  11830. RFIFOL(fd,info->pos[1]));
  11831. }
  11832. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11833. /// 0180 <account id>.L
  11834. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11835. {
  11836. struct map_session_data *t_sd;
  11837. if(!sd->state.gmaster_flag)
  11838. return;
  11839. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11840. clif_displaymessage(fd, msg_txt(sd,228));
  11841. return;
  11842. }
  11843. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11844. // @noask [LuzZza]
  11845. if(t_sd && t_sd->state.noask) {
  11846. clif_noask_sub(sd, t_sd, 4);
  11847. return;
  11848. }
  11849. guild_opposition(sd,t_sd);
  11850. }
  11851. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11852. /// 015d <key>.40B
  11853. /// key:
  11854. /// now guild name; might have been (intended) email, since the
  11855. /// field name and size is same as the one in CH_DELETE_CHAR.
  11856. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11857. {
  11858. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11859. clif_displaymessage(fd, msg_txt(sd,228));
  11860. return;
  11861. }
  11862. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11863. }
  11864. /// Pet
  11865. ///
  11866. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11867. /// 01a1 <type>.B
  11868. /// type:
  11869. /// 0 = pet information
  11870. /// 1 = feed
  11871. /// 2 = performance
  11872. /// 3 = return to egg
  11873. /// 4 = unequip accessory
  11874. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11875. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11876. }
  11877. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11878. /// 019f <id>.L
  11879. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11880. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11881. }
  11882. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11883. /// 01a7 <index>.W
  11884. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11885. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11886. return;
  11887. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11888. clif_menuskill_clear(sd);
  11889. }
  11890. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11891. /// 01a9 <data>.L
  11892. /// data:
  11893. /// is either emotion (@see enum emotion_type) or a compound value
  11894. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11895. /// entry (given in parentheses) in data\pettalktable.xml
  11896. /// act id:
  11897. /// 0 = feeding
  11898. /// 1 = hunting
  11899. /// 2 = danger
  11900. /// 3 = dead
  11901. /// 4 = normal (stand)
  11902. /// 5 = special performance (perfor_s)
  11903. /// 6 = level up (levelup)
  11904. /// 7 = performance 1 (perfor_1)
  11905. /// 8 = performance 2 (perfor_2)
  11906. /// 9 = performance 3 (perfor_3)
  11907. /// 10 = log-in greeting (connect)
  11908. /// hungry value:
  11909. /// 0 = very hungry (hungry)
  11910. /// 1 = hungry (bit_hungry)
  11911. /// 2 = satisfied (noting)
  11912. /// 3 = stuffed (full)
  11913. /// 4 = full (so_full)
  11914. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11915. {
  11916. if(sd->pd)
  11917. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11918. }
  11919. /// Request to change pet's name (CZ_RENAME_PET).
  11920. /// 01a5 <name>.24B
  11921. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11922. {
  11923. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11924. }
  11925. /// /kill (CZ_DISCONNECT_CHARACTER).
  11926. /// Request to disconnect a character.
  11927. /// 00cc <account id>.L
  11928. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11929. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11930. {
  11931. struct block_list *target;
  11932. int tid;
  11933. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11934. target = map_id2bl(tid);
  11935. if (!target) {
  11936. clif_GM_kickack(sd, 0);
  11937. return;
  11938. }
  11939. switch (target->type) {
  11940. case BL_PC:
  11941. {
  11942. char command[NAME_LENGTH+6];
  11943. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11944. is_atcommand(fd, sd, command, 1);
  11945. }
  11946. break;
  11947. /**
  11948. * This one does not invoke any atcommand, so we need to check for permissions.
  11949. */
  11950. case BL_MOB:
  11951. {
  11952. char command[100];
  11953. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11954. clif_GM_kickack(sd, 0);
  11955. return;
  11956. }
  11957. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11958. log_atcommand(sd, command);
  11959. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11960. }
  11961. break;
  11962. case BL_NPC:
  11963. {
  11964. struct npc_data* nd = (struct npc_data *)target;
  11965. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11966. npc_unload_duplicates(nd);
  11967. npc_unload(nd,true);
  11968. npc_read_event_script();
  11969. }
  11970. }
  11971. break;
  11972. default:
  11973. clif_GM_kickack(sd, 0);
  11974. }
  11975. }
  11976. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11977. /// Request to disconnect all characters.
  11978. /// 00ce
  11979. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11980. char cmd[15];
  11981. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11982. is_atcommand(fd, sd, cmd, 1);
  11983. }
  11984. /// /remove (CZ_REMOVE_AID).
  11985. /// Request to warp to a character with given login ID.
  11986. /// 01ba <account name>.24B
  11987. /// /shift (CZ_SHIFT).
  11988. /// Request to warp to a character with given name.
  11989. /// 01bb <char name>.24B
  11990. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11991. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11992. char *player_name;
  11993. char command[NAME_LENGTH+8];
  11994. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11995. player_name[NAME_LENGTH-1] = '\0';
  11996. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11997. is_atcommand(fd, sd, command, 1);
  11998. }
  11999. /// /remove (CZ_REMOVE_AID_SSO).
  12000. /// Request to warp to a character with given account ID.
  12001. /// 0843 <account id>.L
  12002. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12003. {
  12004. uint32 account_id;
  12005. struct map_session_data* pl_sd;
  12006. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12007. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12008. char command[NAME_LENGTH+8];
  12009. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12010. is_atcommand(fd, sd, command, 1);
  12011. }
  12012. }
  12013. /// /recall (CZ_RECALL).
  12014. /// Request to summon a player with given login ID to own position.
  12015. /// 01bc <account name>.24B
  12016. /// /summon (CZ_RECALL_GID).
  12017. /// Request to summon a player with given name to own position.
  12018. /// 01bd <char name>.24B
  12019. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12020. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12021. char *player_name;
  12022. char command [NAME_LENGTH+8];
  12023. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12024. player_name[NAME_LENGTH-1] = '\0';
  12025. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12026. is_atcommand(fd, sd, command, 1);
  12027. }
  12028. /// /recall (CZ_RECALL_SSO).
  12029. /// Request to summon a player with given account ID to own position.
  12030. /// 0842 <account id>.L
  12031. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12032. {
  12033. uint32 account_id;
  12034. struct map_session_data* pl_sd;
  12035. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12036. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12037. char command[NAME_LENGTH+8];
  12038. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12039. is_atcommand(fd, sd, command, 1);
  12040. }
  12041. }
  12042. /// /item /monster (CZ_ITEM_CREATE).
  12043. /// Request to execute GM commands.
  12044. /// Usage:
  12045. /// /item n - summon n monster or acquire n item/s
  12046. /// /item money - grants 2147483647 zenies
  12047. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12048. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12049. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12050. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12051. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12052. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12053. /// 013f <item/mob name>.24B
  12054. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12055. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12056. {
  12057. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12058. int mob_id = 0;
  12059. struct item_data *id = NULL;
  12060. struct mob_db *mob = NULL;
  12061. StringBuf command;
  12062. char *str;
  12063. //#if PACKETVER >= 20131218
  12064. // char str[100];
  12065. //#else
  12066. // char str[24];
  12067. //#endif
  12068. str = RFIFOCP(fd,info->pos[0]);
  12069. if (!str || str[0] == '\0')
  12070. return;
  12071. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12072. return;
  12073. trim(str);
  12074. // Zeny
  12075. if( strcmpi(str, "money") == 0 ) {
  12076. StringBuf_Init(&command);
  12077. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12078. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12079. StringBuf_Destroy(&command);
  12080. return;
  12081. }
  12082. // Item
  12083. if( (id = itemdb_searchname(str)) ) {
  12084. StringBuf_Init(&command);
  12085. if( !itemdb_isstackable2(id) ) //Nonstackable
  12086. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12087. else {
  12088. if (id->flag.guid)
  12089. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12090. else
  12091. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12092. }
  12093. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12094. StringBuf_Destroy(&command);
  12095. return;
  12096. }
  12097. // Monster
  12098. if ((mob_id = mobdb_searchname(str)) == 0)
  12099. mob_id = mobdb_checkid(atoi(str));
  12100. if( (mob = mob_db(mob_id)) ) {
  12101. StringBuf_Init(&command);
  12102. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12103. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12104. StringBuf_Destroy(&command);
  12105. return;
  12106. }
  12107. }
  12108. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12109. /// 019d <effect state>.L
  12110. /// effect state:
  12111. /// TODO: Any OPTION_* ?
  12112. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12113. char cmd[6];
  12114. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12115. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12116. is_atcommand(fd, sd, cmd, 1);
  12117. }
  12118. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12119. /// 0149 <account id>.L <type>.B <value>.W
  12120. /// type:
  12121. /// 0 = positive points
  12122. /// 1 = negative points
  12123. /// 2 = self mute (+10 minutes)
  12124. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12125. {
  12126. int id, type, value;
  12127. struct map_session_data *dstsd;
  12128. char command[NAME_LENGTH+15];
  12129. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12130. id = RFIFOL(fd,info->pos[0]);
  12131. type = RFIFOB(fd,info->pos[1]);
  12132. value = RFIFOW(fd,info->pos[2]);
  12133. if( type == 0 )
  12134. value = -value;
  12135. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12136. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12137. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12138. return;
  12139. dstsd = map_id2sd(id);
  12140. if( dstsd == NULL )
  12141. return;
  12142. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12143. is_atcommand(fd, sd, command, 1);
  12144. }
  12145. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12146. /// GM adjustment of a player's manner value by -60.
  12147. /// 0212 <char name>.24B
  12148. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12149. {
  12150. char command[NAME_LENGTH+15];
  12151. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12152. name[NAME_LENGTH-1] = '\0';
  12153. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12154. is_atcommand(fd, sd, command, 1);
  12155. }
  12156. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12157. /// 01e0 <account id>.L <account name>.24B
  12158. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12159. {
  12160. WFIFOHEAD(fd,packet_len(0x1e0));
  12161. WFIFOW(fd,0) = 0x1e0;
  12162. WFIFOL(fd,2) = account_id;
  12163. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12164. WFIFOSET(fd,packet_len(0x1e0));
  12165. }
  12166. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12167. /// 01df <account id>.L
  12168. //! TODO: Figure out how does this actually work
  12169. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12170. {
  12171. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12172. /*
  12173. char query[30];
  12174. safesnprintf(query,sizeof(query),"%d", account_id);
  12175. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12176. */
  12177. clif_account_name(fd, account_id, "");
  12178. }
  12179. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12180. /// GM single cell type change request.
  12181. /// 0198 <x>.W <y>.W <type>.W
  12182. /// type:
  12183. /// 0 = not walkable
  12184. /// 1 = walkable
  12185. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12186. {
  12187. int x,y,type;
  12188. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12189. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12190. return;
  12191. x = RFIFOW(fd,info->pos[0]);
  12192. y = RFIFOW(fd,info->pos[1]);
  12193. type = RFIFOW(fd,info->pos[2]);
  12194. map_setgatcell(sd->bl.m,x,y,type);
  12195. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12196. //FIXME: once players leave the map, the client 'forgets' this information.
  12197. }
  12198. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12199. /// Request to allow/deny whispers from a nick.
  12200. /// 00cf <nick>.24B <type>.B
  12201. /// type:
  12202. /// 0 = (/ex nick) deny speech from nick
  12203. /// 1 = (/in nick) allow speech from nick
  12204. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12205. {
  12206. char* nick;
  12207. uint8 type;
  12208. int i;
  12209. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12210. nick = RFIFOCP(fd,info->pos[0]);
  12211. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12212. type = RFIFOB(fd,info->pos[1]);
  12213. if( type == 0 ) { // Add name to ignore list (block)
  12214. if (strcmp(wisp_server_name, nick) == 0) {
  12215. clif_wisexin(sd, type, 1); // fail
  12216. return;
  12217. }
  12218. // try to find a free spot, while checking for duplicates at the same time
  12219. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12220. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12221. clif_wisexin(sd, type, 2); // too many blocks
  12222. return;
  12223. }
  12224. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12225. clif_wisexin(sd, type, 0); // Aegis reports success.
  12226. return;
  12227. }
  12228. //Insert in position i
  12229. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12230. } else { // Remove name from ignore list (unblock)
  12231. // find entry
  12232. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12233. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12234. clif_wisexin(sd, type, 1); // fail
  12235. return;
  12236. }
  12237. // move everything one place down to overwrite removed entry
  12238. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12239. // wipe last entry
  12240. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12241. }
  12242. clif_wisexin(sd, type, 0); // success
  12243. }
  12244. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12245. /// Request to allow/deny all whispers.
  12246. /// 00d0 <type>.B
  12247. /// type:
  12248. /// 0 = (/exall) deny all speech
  12249. /// 1 = (/inall) allow all speech
  12250. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12251. {
  12252. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12253. if( type == 0 ) {// Deny all
  12254. if( sd->state.ignoreAll ) {
  12255. flag = 1; // fail
  12256. } else {
  12257. sd->state.ignoreAll = 1;
  12258. flag = 0; // success
  12259. }
  12260. } else {//Unblock everyone
  12261. if( sd->state.ignoreAll ) {
  12262. sd->state.ignoreAll = 0;
  12263. flag = 0; // success
  12264. } else {
  12265. if (sd->ignore[0].name[0] != '\0')
  12266. { //Wipe the ignore list.
  12267. memset(sd->ignore, 0, sizeof(sd->ignore));
  12268. flag = 0; // success
  12269. } else {
  12270. flag = 1; // fail
  12271. }
  12272. }
  12273. }
  12274. clif_wisall(sd, type, flag);
  12275. }
  12276. /// Whisper ignore list (ZC_WHISPER_LIST).
  12277. /// 00d4 <packet len>.W { <char name>.24B }*
  12278. void clif_PMIgnoreList(struct map_session_data* sd)
  12279. {
  12280. int i, fd = sd->fd;
  12281. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12282. WFIFOW(fd,0) = 0xd4;
  12283. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12284. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12285. }
  12286. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12287. WFIFOSET(fd,WFIFOW(fd,2));
  12288. }
  12289. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12290. /// 00d3
  12291. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12292. {
  12293. clif_PMIgnoreList(sd);
  12294. }
  12295. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12296. /// 01e7
  12297. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12298. {
  12299. if (sd->state.doridori) return;
  12300. switch (sd->class_&MAPID_UPPERMASK) {
  12301. case MAPID_SOUL_LINKER:
  12302. case MAPID_STAR_GLADIATOR:
  12303. case MAPID_TAEKWON:
  12304. if (!sd->state.rest)
  12305. break;
  12306. case MAPID_SUPER_NOVICE:
  12307. case MAPID_SUPER_BABY:
  12308. case MAPID_SUPER_NOVICE_E:
  12309. case MAPID_SUPER_BABY_E:
  12310. sd->state.doridori=1;
  12311. break;
  12312. }
  12313. }
  12314. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12315. /// 01ed
  12316. /// Note: This packet is caused by 7 lines of any text, followed by
  12317. /// the prayer and an another line of any text. The prayer is
  12318. /// defined by lines 790~793 in data\msgstringtable.txt
  12319. /// "Dear angel, can you hear my voice?"
  12320. /// "I am" (space separated player name) "Super Novice~"
  12321. /// "Help me out~ Please~ T_T"
  12322. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12323. {
  12324. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12325. unsigned int next = pc_nextbaseexp(sd);
  12326. if( next ) {
  12327. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12328. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12329. 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]
  12330. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12331. }
  12332. }
  12333. }
  12334. }
  12335. /// Friends List
  12336. ///
  12337. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12338. /// 0206 <account id>.L <char id>.L <state>.B
  12339. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12340. /// state:
  12341. /// 0 = online
  12342. /// 1 = offline
  12343. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12344. {
  12345. int i, fd = sd->fd;
  12346. //Seek friend.
  12347. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12348. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12349. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12350. return; //Not found
  12351. WFIFOHEAD(fd,packet_len(0x206));
  12352. WFIFOW(fd, 0) = 0x206;
  12353. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12354. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12355. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12356. #if PACKETVER >= 20180221
  12357. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12358. #endif
  12359. WFIFOSET(fd, packet_len(0x206));
  12360. }
  12361. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12362. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12363. {
  12364. uint32 account_id, char_id, online;
  12365. account_id = va_arg(ap, int);
  12366. char_id = va_arg(ap, int);
  12367. online = va_arg(ap, int);
  12368. clif_friendslist_toggle(sd, account_id, char_id, online);
  12369. return 0;
  12370. }
  12371. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12372. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12373. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12374. void clif_friendslist_send(struct map_session_data *sd)
  12375. {
  12376. int i = 0, n, fd = sd->fd;
  12377. #if PACKETVER >= 20180221
  12378. const int size = 8;
  12379. #else
  12380. const int size = 8 + NAME_LENGTH;
  12381. #endif
  12382. // Send friends list
  12383. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12384. WFIFOW(fd, 0) = 0x201;
  12385. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12386. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12387. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12388. #if PACKETVER < 20180221
  12389. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12390. #endif
  12391. }
  12392. if (i) {
  12393. WFIFOW(fd,2) = 4 + size * i;
  12394. WFIFOSET(fd, WFIFOW(fd,2));
  12395. }
  12396. for (n = 0; n < i; n++) { //Sending the online players
  12397. if (map_charid2sd(sd->status.friends[n].char_id))
  12398. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12399. }
  12400. }
  12401. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12402. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12403. /// result:
  12404. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12405. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12406. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12407. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12408. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12409. {
  12410. int fd;
  12411. nullpo_retv(sd);
  12412. fd = sd->fd;
  12413. WFIFOHEAD(fd,packet_len(0x209));
  12414. WFIFOW(fd,0) = 0x209;
  12415. WFIFOW(fd,2) = type;
  12416. if (f_sd) {
  12417. WFIFOL(fd,4) = f_sd->status.account_id;
  12418. WFIFOL(fd,8) = f_sd->status.char_id;
  12419. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12420. }
  12421. WFIFOSET(fd, packet_len(0x209));
  12422. }
  12423. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12424. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12425. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12426. {
  12427. int fd = sd->fd;
  12428. WFIFOHEAD(fd,packet_len(0x207));
  12429. WFIFOW(fd,0) = 0x207;
  12430. WFIFOL(fd,2) = account_id;
  12431. WFIFOL(fd,6) = char_id;
  12432. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12433. WFIFOSET(fd,packet_len(0x207));
  12434. }
  12435. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12436. /// 0202 <name>.24B
  12437. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12438. {
  12439. struct map_session_data *f_sd;
  12440. int i;
  12441. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12442. // Friend doesn't exist (no player with this name)
  12443. if (f_sd == NULL) {
  12444. clif_displaymessage(fd, msg_txt(sd,3));
  12445. return;
  12446. }
  12447. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12448. return;
  12449. }
  12450. // ensure that the request player's friend list is not full
  12451. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12452. if( i == MAX_FRIENDS ){
  12453. clif_friendslist_reqack(sd, f_sd, 2);
  12454. return;
  12455. }
  12456. // @noask [LuzZza]
  12457. if(f_sd->state.noask) {
  12458. clif_noask_sub(sd, f_sd, 5);
  12459. return;
  12460. }
  12461. // Friend already exists
  12462. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12463. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12464. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12465. return;
  12466. }
  12467. }
  12468. f_sd->friend_req = sd->status.char_id;
  12469. sd->friend_req = f_sd->status.char_id;
  12470. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12471. }
  12472. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12473. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12474. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12475. /// reply:
  12476. /// 0 = rejected
  12477. /// 1 = accepted
  12478. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12479. {
  12480. struct map_session_data *f_sd;
  12481. uint32 account_id;
  12482. char reply;
  12483. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12484. account_id = RFIFOL(fd,info->pos[0]);
  12485. //char_id = RFIFOL(fd,info->pos[1]);
  12486. #if PACKETVER < 6
  12487. reply = RFIFOB(fd,info->pos[2]);
  12488. #else
  12489. reply = RFIFOL(fd,info->pos[2]);
  12490. #endif
  12491. if( sd->bl.id == account_id ) {// adding oneself as friend
  12492. return;
  12493. }
  12494. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12495. if (f_sd == NULL)
  12496. return;
  12497. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12498. clif_friendslist_reqack(f_sd, sd, 1);
  12499. else {
  12500. int i;
  12501. // Find an empty slot
  12502. for (i = 0; i < MAX_FRIENDS; i++)
  12503. if (f_sd->status.friends[i].char_id == 0)
  12504. break;
  12505. if (i == MAX_FRIENDS) {
  12506. clif_friendslist_reqack(f_sd, sd, 2);
  12507. return;
  12508. }
  12509. f_sd->status.friends[i].account_id = sd->status.account_id;
  12510. f_sd->status.friends[i].char_id = sd->status.char_id;
  12511. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12512. clif_friendslist_reqack(f_sd, sd, 0);
  12513. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12514. if (battle_config.friend_auto_add) {
  12515. // Also add f_sd to sd's friendlist.
  12516. for (i = 0; i < MAX_FRIENDS; i++) {
  12517. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12518. return; //No need to add anything.
  12519. if (sd->status.friends[i].char_id == 0)
  12520. break;
  12521. }
  12522. if (i == MAX_FRIENDS) {
  12523. clif_friendslist_reqack(sd, f_sd, 2);
  12524. return;
  12525. }
  12526. sd->status.friends[i].account_id = f_sd->status.account_id;
  12527. sd->status.friends[i].char_id = f_sd->status.char_id;
  12528. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12529. clif_friendslist_reqack(sd, f_sd, 0);
  12530. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12531. }
  12532. }
  12533. }
  12534. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12535. /// 0203 <account id>.L <char id>.L
  12536. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12537. {
  12538. struct map_session_data *f_sd = NULL;
  12539. uint32 account_id, char_id;
  12540. int i, j;
  12541. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12542. account_id = RFIFOL(fd,info->pos[0]);
  12543. char_id = RFIFOL(fd,info->pos[1]);
  12544. // Search friend
  12545. for (i = 0; i < MAX_FRIENDS &&
  12546. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12547. if (i == MAX_FRIENDS) {
  12548. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12549. return;
  12550. }
  12551. //remove from friend's list first
  12552. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12553. for (i = 0; i < MAX_FRIENDS &&
  12554. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12555. if (i != MAX_FRIENDS) {
  12556. // move all chars up
  12557. for(j = i + 1; j < MAX_FRIENDS; j++)
  12558. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12559. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12560. //should the guy be notified of some message? we should add it here if so
  12561. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12562. WFIFOW(f_sd->fd,0) = 0x20a;
  12563. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12564. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12565. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12566. }
  12567. } else { //friend not online -- ask char server to delete from his friendlist
  12568. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12569. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12570. return;
  12571. }
  12572. }
  12573. // We can now delete from original requester
  12574. for (i = 0; i < MAX_FRIENDS &&
  12575. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12576. // move all chars up
  12577. for(j = i + 1; j < MAX_FRIENDS; j++)
  12578. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12579. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12580. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12581. WFIFOHEAD(fd,packet_len(0x20a));
  12582. WFIFOW(fd,0) = 0x20a;
  12583. WFIFOL(fd,2) = account_id;
  12584. WFIFOL(fd,6) = char_id;
  12585. WFIFOSET(fd, packet_len(0x20a));
  12586. }
  12587. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12588. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12589. void clif_PVPInfo(struct map_session_data* sd)
  12590. {
  12591. int fd = sd->fd;
  12592. WFIFOHEAD(fd,packet_len(0x210));
  12593. WFIFOW(fd,0) = 0x210;
  12594. WFIFOL(fd,2) = sd->status.char_id;
  12595. WFIFOL(fd,6) = sd->status.account_id;
  12596. WFIFOL(fd,10) = sd->pvp_won; // times won
  12597. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12598. WFIFOL(fd,18) = sd->pvp_point;
  12599. WFIFOSET(fd, packet_len(0x210));
  12600. }
  12601. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12602. /// 020f <char id>.L <account id>.L
  12603. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12604. {
  12605. // TODO: Is there a way to use this on an another player (char/acc id)?
  12606. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12607. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12608. clif_PVPInfo(sd);
  12609. }
  12610. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12611. /// 0254 <which>.B
  12612. /// which: (unused atm for security purpose)
  12613. /// 0 = sun
  12614. /// 1 = moon
  12615. /// 2 = star
  12616. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12617. {
  12618. int i;
  12619. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12620. if (sd->menuskill_id != SG_FEEL)
  12621. return;
  12622. i = sd->menuskill_val-1;
  12623. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12624. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12625. sd->feel_map[i].m = sd->bl.m;
  12626. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12627. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12628. // clif_misceffect2(&sd->bl, 0x1b0);
  12629. // clif_misceffect2(&sd->bl, 0x21f);
  12630. clif_feel_info(sd, i, 0);
  12631. clif_menuskill_clear(sd);
  12632. }
  12633. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12634. /// 0253 <which>.B
  12635. /// which:
  12636. /// 0 = sun
  12637. /// 1 = moon
  12638. /// 2 = star
  12639. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12640. {
  12641. WFIFOHEAD(fd,packet_len(0x253));
  12642. WFIFOW(fd,0)=0x253;
  12643. WFIFOB(fd,2)=TOB(skill_lv-1);
  12644. WFIFOSET(fd, packet_len(0x253));
  12645. sd->menuskill_id = SG_FEEL;
  12646. sd->menuskill_val = skill_lv;
  12647. }
  12648. /// Request to change homunculus' name (CZ_RENAME_MER).
  12649. /// 0231 <name>.24B
  12650. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12651. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12652. }
  12653. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12654. /// 0234 <id>.L
  12655. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12656. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12657. struct block_list *bl = NULL;
  12658. struct unit_data *ud = NULL;
  12659. if( sd->md && sd->md->bl.id == id )
  12660. bl = &sd->md->bl;
  12661. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12662. bl = &sd->hd->bl; // Moving Homunculus
  12663. else
  12664. return;
  12665. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12666. ud = unit_bl2ud(bl);
  12667. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12668. }
  12669. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12670. /// 0232 <id>.L <position data>.3B
  12671. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12672. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12673. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12674. struct block_list *bl = NULL;
  12675. short x, y;
  12676. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12677. if( sd->md && sd->md->bl.id == id )
  12678. bl = &sd->md->bl; // Moving Mercenary
  12679. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12680. bl = &sd->hd->bl; // Moving Homunculus
  12681. else
  12682. return;
  12683. unit_walktoxy(bl, x, y, 4);
  12684. }
  12685. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12686. /// 0233 <id>.L <target id>.L <action>.B
  12687. /// action:
  12688. /// always 0
  12689. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12690. {
  12691. struct block_list *bl = NULL;
  12692. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12693. int id = RFIFOL(fd,info->pos[0]);
  12694. int target_id = RFIFOL(fd,info->pos[1]);
  12695. int action_type = RFIFOB(fd,info->pos[2]);
  12696. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12697. bl = &sd->hd->bl;
  12698. else if( sd->md && sd->md->bl.id == id )
  12699. bl = &sd->md->bl;
  12700. else return;
  12701. unit_stop_attack(bl);
  12702. unit_attack(bl, target_id, action_type != 0);
  12703. }
  12704. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12705. /// 022d <type>.W <command>.B
  12706. /// type:
  12707. /// always 0
  12708. /// command:
  12709. /// 0 = homunculus information
  12710. /// 1 = feed
  12711. /// 2 = delete
  12712. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12713. { //[orn]
  12714. int cmd = RFIFOW(fd,0);
  12715. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12716. if(!hom_is_active(sd->hd))
  12717. return;
  12718. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12719. }
  12720. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12721. /// 0292
  12722. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12723. {
  12724. pc_revive_item(sd);
  12725. }
  12726. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12727. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12728. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12729. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12730. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12731. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12732. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12733. void clif_check(int fd, struct map_session_data* pl_sd)
  12734. {
  12735. WFIFOHEAD(fd,packet_len(0x214));
  12736. WFIFOW(fd, 0) = 0x214;
  12737. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12738. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12739. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12740. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12741. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12742. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12743. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12744. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12745. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12746. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12747. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12748. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12749. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12750. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12751. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12752. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12753. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12754. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12755. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12756. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12757. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12758. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12759. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12760. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12761. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12762. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12763. WFIFOSET(fd,packet_len(0x214));
  12764. }
  12765. /// /check (CZ_REQ_STATUS_GM).
  12766. /// Request character's status values.
  12767. /// 0213 <char name>.24B
  12768. void clif_parse_Check(int fd, struct map_session_data *sd)
  12769. {
  12770. char charname[NAME_LENGTH];
  12771. struct map_session_data* pl_sd;
  12772. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12773. return;
  12774. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12775. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12776. {
  12777. return;
  12778. }
  12779. clif_check(fd, pl_sd);
  12780. }
  12781. /// MAIL SYSTEM
  12782. /// By Zephyrus
  12783. ///
  12784. /// Notification about the result of adding an item to mail
  12785. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12786. /// result:
  12787. /// 0 = success
  12788. /// 1 = failure
  12789. /// 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)
  12790. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12791. /// result:
  12792. /// 0 = success
  12793. /// 1 = over weight
  12794. /// 2 = fatal error
  12795. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12796. {
  12797. int fd = sd->fd;
  12798. #if PACKETVER < 20150513
  12799. WFIFOHEAD(fd,packet_len(0x255));
  12800. WFIFOW(fd,0) = 0x255;
  12801. WFIFOW(fd,2) = index;
  12802. WFIFOB(fd,4) = flag;
  12803. WFIFOSET(fd,packet_len(0x255));
  12804. #else
  12805. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12806. int i, total = 0;
  12807. WFIFOHEAD(fd, 53);
  12808. WFIFOW(fd, 0) = 0xa05;
  12809. WFIFOB(fd, 2) = flag;
  12810. WFIFOW(fd, 3) = index;
  12811. WFIFOW(fd, 5) = amount;
  12812. WFIFOW(fd, 7) = item->nameid;
  12813. WFIFOB(fd, 9) = itemtype(item->nameid);
  12814. WFIFOB(fd, 10) = item->identify;
  12815. WFIFOB(fd, 11) = item->attribute;
  12816. WFIFOB(fd, 12) = item->refine;
  12817. clif_addcards(WFIFOP(fd,13), item);
  12818. clif_add_random_options(WFIFOP(fd,21), item);
  12819. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12820. if( sd->mail.item[i].nameid == 0 ){
  12821. break;
  12822. }
  12823. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12824. }
  12825. WFIFOW(fd, 46) = total;
  12826. // 5 empty unknown bytes
  12827. memset(WFIFOP(fd, 48), 0, 5);
  12828. WFIFOSET(fd, 53);
  12829. #endif
  12830. }
  12831. /// Notification about the result of retrieving a mail attachment
  12832. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12833. /// result:
  12834. /// 0 = success
  12835. /// 1 = failure
  12836. /// 2 = too many items
  12837. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12838. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12839. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12840. int fd = sd->fd;
  12841. #if PACKETVER < 20150513
  12842. WFIFOHEAD(fd,packet_len(0x245));
  12843. WFIFOW(fd,0) = 0x245;
  12844. WFIFOB(fd,2) = result;
  12845. WFIFOSET(fd,packet_len(0x245));
  12846. #else
  12847. switch( type ){
  12848. case MAIL_ATT_ITEM:
  12849. case MAIL_ATT_ZENY:
  12850. break;
  12851. default:
  12852. return;
  12853. }
  12854. WFIFOHEAD(fd, 12);
  12855. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12856. WFIFOQ(fd, 2) = msg->id;
  12857. WFIFOB(fd, 10) = msg->type;
  12858. WFIFOB(fd, 11) = result;
  12859. WFIFOSET(fd, 12);
  12860. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12861. #endif
  12862. }
  12863. /// Notification about the result of sending a mail
  12864. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12865. /// result:
  12866. /// 0 = success
  12867. /// 1 = recipinent does not exist
  12868. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12869. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12870. int fd = sd->fd;
  12871. #if PACKETVER < 20150513
  12872. WFIFOHEAD(fd,packet_len(0x249));
  12873. WFIFOW(fd,0) = 0x249;
  12874. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12875. WFIFOSET(fd,packet_len(0x249));
  12876. #else
  12877. WFIFOHEAD(fd, 3);
  12878. WFIFOW(fd, 0) = 0x9ed;
  12879. WFIFOB(fd, 2) = result;
  12880. WFIFOSET(fd, 3);
  12881. #endif
  12882. }
  12883. /// Notification about the result of deleting a mail.
  12884. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12885. /// result:
  12886. /// 0 = success
  12887. /// 1 = failure
  12888. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12889. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12890. int fd = sd->fd;
  12891. #if PACKETVER < 20150513
  12892. WFIFOHEAD(fd, packet_len(0x257));
  12893. WFIFOW(fd,0) = 0x257;
  12894. WFIFOL(fd,2) = msg->id;
  12895. WFIFOW(fd,6) = !success;
  12896. WFIFOSET(fd, packet_len(0x257));
  12897. #else
  12898. // This is only a success notification
  12899. if( success ){
  12900. WFIFOHEAD(fd, 11);
  12901. WFIFOW(fd, 0) = 0x9f6;
  12902. WFIFOB(fd, 2) = msg->type;
  12903. WFIFOQ(fd, 3) = msg->id;
  12904. WFIFOSET(fd, 11);
  12905. }
  12906. #endif
  12907. }
  12908. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12909. /// 0274 <mail id>.L <result>.W
  12910. /// result:
  12911. /// 0 = success
  12912. /// 1 = failure
  12913. void clif_Mail_return(int fd, int mail_id, short fail)
  12914. {
  12915. WFIFOHEAD(fd,packet_len(0x274));
  12916. WFIFOW(fd,0) = 0x274;
  12917. WFIFOL(fd,2) = mail_id;
  12918. WFIFOW(fd,6) = fail;
  12919. WFIFOSET(fd,packet_len(0x274));
  12920. }
  12921. /// Notification about new mail.
  12922. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12923. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12924. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12925. int fd = sd->fd;
  12926. #if PACKETVER < 20150513
  12927. WFIFOHEAD(fd,packet_len(0x24a));
  12928. WFIFOW(fd,0) = 0x24a;
  12929. WFIFOL(fd,2) = mail_id;
  12930. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12931. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12932. WFIFOSET(fd,packet_len(0x24a));
  12933. #else
  12934. WFIFOHEAD(fd,3);
  12935. WFIFOW(fd,0) = 0x9e7;
  12936. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12937. WFIFOSET(fd,3);
  12938. #endif
  12939. }
  12940. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12941. /// 0260 <type>.L
  12942. /// type:
  12943. /// 0 = open
  12944. /// 1 = close
  12945. void clif_Mail_window(int fd, int flag)
  12946. {
  12947. WFIFOHEAD(fd,packet_len(0x260));
  12948. WFIFOW(fd,0) = 0x260;
  12949. WFIFOL(fd,2) = flag;
  12950. WFIFOSET(fd,packet_len(0x260));
  12951. }
  12952. /// Lists mails stored in inbox.
  12953. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12954. /// read:
  12955. /// 0 = unread
  12956. /// 1 = read
  12957. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12958. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12959. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12960. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12961. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12962. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12963. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12964. #if PACKETVER < 20150513
  12965. int fd = sd->fd;
  12966. struct mail_data *md = &sd->mail.inbox;
  12967. struct mail_message *msg;
  12968. int len, i, j;
  12969. len = 8 + (73 * md->amount);
  12970. WFIFOHEAD(fd,len);
  12971. WFIFOW(fd,0) = 0x240;
  12972. WFIFOW(fd,2) = len;
  12973. WFIFOL(fd,4) = md->amount;
  12974. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12975. {
  12976. msg = &md->msg[i];
  12977. if (msg->id < 1)
  12978. continue;
  12979. WFIFOL(fd,8+73*j) = msg->id;
  12980. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12981. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12982. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12983. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12984. j++;
  12985. }
  12986. WFIFOSET(fd,len);
  12987. if( md->full ) {// TODO: is this official?
  12988. char output[100];
  12989. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12990. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12991. }
  12992. #else
  12993. int fd = sd->fd;
  12994. struct mail_data *md = &sd->mail.inbox;
  12995. struct mail_message *msg;
  12996. int i, j, k, offset, titleLength;
  12997. uint8 mailType, amount, remaining;
  12998. uint32 now = (uint32)time(NULL);
  12999. #if PACKETVER >= 20170419
  13000. int cmd = 0xac2;
  13001. #elif PACKETVER >= 20160601
  13002. int cmd = 0xa7d;
  13003. #else
  13004. int cmd = 0x9f0;
  13005. #endif
  13006. if( battle_config.mail_daily_count ){
  13007. mail_refresh_remaining_amount(sd);
  13008. }
  13009. #if PACKETVER >= 20170419
  13010. // Always send all
  13011. i = md->amount;
  13012. #else
  13013. // If a starting mail id was sent
  13014. if( mailID != 0 ){
  13015. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13016. // Unknown mail
  13017. if( i == md->amount ){
  13018. // Ignore the request for now
  13019. return; // TODO: Should we just show the first page instead?
  13020. }
  13021. // It was actually the oldest/first mail, there is no further page
  13022. if( i == 0 ){
  13023. return;
  13024. }
  13025. // We actually want the next/older mail
  13026. i -= 1;
  13027. }else{
  13028. i = md->amount;
  13029. }
  13030. #endif
  13031. // Count the remaining mails from the starting mail or the beginning
  13032. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13033. for( j = i, remaining = 0; j >= 0; j-- ){
  13034. msg = &md->msg[j];
  13035. if (msg->id < 1)
  13036. continue;
  13037. #if PACKETVER < 20170419
  13038. if (msg->type != type)
  13039. continue;
  13040. #endif
  13041. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13042. continue;
  13043. remaining++;
  13044. }
  13045. #if PACKETVER >= 20170419
  13046. // Always send all
  13047. amount = remaining;
  13048. #else
  13049. if( remaining > MAIL_PAGE_SIZE ){
  13050. amount = MAIL_PAGE_SIZE;
  13051. }else{
  13052. amount = remaining;
  13053. }
  13054. #endif
  13055. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13056. WFIFOW(fd, 0) = cmd;
  13057. #if PACKETVER >= 20170419
  13058. WFIFOB(fd, 4) = 1; // Unknown
  13059. offset = 5;
  13060. #else
  13061. WFIFOB(fd, 4) = type;
  13062. WFIFOB(fd, 5) = amount;
  13063. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13064. offset = 7;
  13065. #endif
  13066. for( amount = 0; i >= 0; i-- ){
  13067. msg = &md->msg[i];
  13068. if (msg->id < 1)
  13069. continue;
  13070. #if PACKETVER < 20170419
  13071. if (msg->type != type)
  13072. continue;
  13073. #endif
  13074. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13075. continue;
  13076. #if PACKETVER >= 20170419
  13077. WFIFOB(fd, offset) = msg->type;
  13078. offset += 1;
  13079. #endif
  13080. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13081. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13082. mailType = MAIL_TYPE_TEXT; // Normal letter
  13083. if( msg->zeny > 0 ){
  13084. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13085. }
  13086. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13087. if( msg->item[k].nameid > 0 ){
  13088. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13089. break;
  13090. }
  13091. }
  13092. #if PACKETVER >= 20170419
  13093. // If it came from an npc?
  13094. if( !msg->send_id ){
  13095. mailType |= MAIL_TYPE_NPC;
  13096. }
  13097. #endif
  13098. WFIFOB(fd, offset + 9) = mailType;
  13099. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13100. #if PACKETVER < 20170419
  13101. // How much time has passed since you received the mail
  13102. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13103. offset += 4;
  13104. #endif
  13105. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13106. if( msg->scheduled_deletion > 0 ){
  13107. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13108. }else{
  13109. // Fake the scheduled deletion to one year in the future
  13110. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13111. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13112. }
  13113. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13114. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13115. offset += 40 + titleLength;
  13116. }
  13117. WFIFOW(fd, 2) = (int16)offset;
  13118. WFIFOSET(fd, offset);
  13119. #endif
  13120. }
  13121. /// Mail inbox list request.
  13122. /// 023f (CZ_MAIL_GET_LIST)
  13123. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13124. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13125. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13126. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13127. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13128. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13129. #if PACKETVER < 20150513
  13130. struct mail_data* md = &sd->mail.inbox;
  13131. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13132. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13133. else
  13134. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13135. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13136. mail_removezeny(sd, false);
  13137. #else
  13138. int cmd = RFIFOW(fd, 0);
  13139. #if PACKETVER < 20170419
  13140. uint8 openType = RFIFOB(fd, 2);
  13141. uint64 mailId = RFIFOQ(fd, 3);
  13142. #else
  13143. uint8 openType;
  13144. uint64 mailId = RFIFOQ(fd, 2);
  13145. int i;
  13146. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13147. if( i == MAIL_MAX_INBOX ){
  13148. openType = MAIL_INBOX_NORMAL;
  13149. mailId = 0;
  13150. }else{
  13151. openType = sd->mail.inbox.msg[i].type;
  13152. mailId = 0;
  13153. }
  13154. #endif
  13155. switch( openType ){
  13156. case MAIL_INBOX_NORMAL:
  13157. case MAIL_INBOX_ACCOUNT:
  13158. case MAIL_INBOX_RETURNED:
  13159. break;
  13160. default:
  13161. // Unknown type: ignore request
  13162. return;
  13163. }
  13164. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13165. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13166. return;
  13167. }
  13168. // If it is not a next page request
  13169. if( cmd != 0x9ee ){
  13170. mailId = 0;
  13171. }
  13172. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13173. #endif
  13174. }
  13175. /// Opens a mail
  13176. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13177. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13178. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13179. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13180. /// { }*n
  13181. // TODO: Packet description => for repeated block
  13182. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13183. {
  13184. int i, fd = sd->fd;
  13185. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13186. if( i == MAIL_MAX_INBOX ) {
  13187. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13188. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13189. return;
  13190. } else {
  13191. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13192. struct item *item;
  13193. struct item_data *data;
  13194. int msg_len = strlen(msg->body), len;
  13195. #if PACKETVER >= 20150513
  13196. int offset, j, itemsize, count = 0;
  13197. #endif
  13198. if( msg_len == 0 ) {
  13199. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13200. msg_len = strlen(msg->body);
  13201. }
  13202. #if PACKETVER < 20150513
  13203. item = &msg->item[0];
  13204. len = 101 + msg_len;
  13205. WFIFOHEAD(fd,len);
  13206. WFIFOW(fd,0) = 0x242;
  13207. WFIFOW(fd,2) = len;
  13208. WFIFOL(fd,4) = msg->id;
  13209. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13210. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13211. WFIFOL(fd,72) = 0;
  13212. WFIFOL(fd,76) = msg->zeny;
  13213. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13214. WFIFOL(fd,80) = item->amount;
  13215. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13216. WFIFOW(fd,86) = data->type;
  13217. WFIFOB(fd,88) = item->identify;
  13218. WFIFOB(fd,89) = item->attribute;
  13219. WFIFOB(fd,90) = item->refine;
  13220. WFIFOW(fd,91) = item->card[0];
  13221. WFIFOW(fd,93) = item->card[1];
  13222. WFIFOW(fd,95) = item->card[2];
  13223. WFIFOW(fd,97) = item->card[3];
  13224. } else // no item, set all to zero
  13225. memset(WFIFOP(fd,80), 0x00, 19);
  13226. WFIFOB(fd,99) = (unsigned char)msg_len;
  13227. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13228. WFIFOSET(fd,len);
  13229. #else
  13230. // Count the attached items
  13231. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13232. msg_len += 1; // Zero Termination
  13233. itemsize = 24 + 5 * 5;
  13234. len = 24 + msg_len+1 + itemsize * count;
  13235. WFIFOHEAD(fd, len);
  13236. WFIFOW(fd, 0) = 0x9eb;
  13237. WFIFOW(fd, 2) = len;
  13238. WFIFOB(fd, 4) = msg->type;
  13239. WFIFOQ(fd, 5) = msg->id;
  13240. WFIFOW(fd, 13) = msg_len;
  13241. WFIFOQ(fd, 15) = msg->zeny;
  13242. WFIFOB(fd, 23) = (uint8)count; // item count
  13243. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13244. offset = 24 + msg_len;
  13245. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13246. item = &msg->item[j];
  13247. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13248. WFIFOW(fd, offset) = item->amount;
  13249. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13250. WFIFOB(fd, offset + 4) = item->identify;
  13251. WFIFOB(fd, offset + 5) = item->attribute;
  13252. WFIFOB(fd, offset + 6) = item->refine;
  13253. clif_addcards(WFIFOP(fd, offset + 7), item);
  13254. // 4B unsigned long location
  13255. WFIFOB(fd, offset + 15 + 4) = data->type;
  13256. // 2B unsigned short wItemSpriteNumber
  13257. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13258. // 2B unsigned short bindOnEquipType
  13259. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13260. offset += itemsize;
  13261. }
  13262. }
  13263. WFIFOSET(fd, len);
  13264. #endif
  13265. if (msg->status == MAIL_UNREAD) {
  13266. msg->status = MAIL_READ;
  13267. intif_Mail_read(mail_id);
  13268. clif_parse_Mail_refreshinbox(fd, sd);
  13269. sd->mail.inbox.unread--;
  13270. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13271. }
  13272. }
  13273. }
  13274. /// Request to open a mail.
  13275. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13276. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13277. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13278. #if PACKETVER < 20150513
  13279. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13280. #else
  13281. //uint8 openType = RFIFOB(fd, 2);
  13282. int mail_id = (int)RFIFOQ(fd, 3);
  13283. #endif
  13284. if( mail_id <= 0 )
  13285. return;
  13286. if( mail_invalid_operation(sd) )
  13287. return;
  13288. clif_Mail_read(sd, mail_id);
  13289. }
  13290. /// Allow a player to begin writing a mail
  13291. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13292. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13293. int fd = sd->fd;
  13294. WFIFOHEAD(fd, 27);
  13295. WFIFOW(fd, 0) = 0xa12;
  13296. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13297. WFIFOB(fd, 26) = success;
  13298. WFIFOSET(fd, 27);
  13299. }
  13300. /// Request to start writing a mail
  13301. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13302. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13303. char name[NAME_LENGTH];
  13304. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13305. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13306. clif_send_Mail_beginwrite_ack(sd, name, false);
  13307. return;
  13308. }
  13309. mail_clear(sd);
  13310. sd->state.mail_writing = true;
  13311. clif_send_Mail_beginwrite_ack(sd, name,true);
  13312. }
  13313. /// Notification that the client cancelled writing a mail
  13314. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13315. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13316. sd->state.mail_writing = false;
  13317. }
  13318. /// Give the client information about the recipient, if available
  13319. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13320. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13321. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13322. int fd = sd->fd;
  13323. #if PACKETVER <= 20160302
  13324. int cmd = 0xa14;
  13325. #else
  13326. int cmd = 0xa51;
  13327. #endif
  13328. WFIFOHEAD(fd, packet_len(cmd));
  13329. WFIFOW(fd, 0) = cmd;
  13330. WFIFOL(fd, 2) = char_id;
  13331. WFIFOW(fd, 6) = class_;
  13332. WFIFOW(fd, 8) = level;
  13333. #if PACKETVER >= 20160302
  13334. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13335. #endif
  13336. WFIFOSET(fd, packet_len(cmd));
  13337. }
  13338. /// Request information about the recipient
  13339. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13340. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13341. static char name[NAME_LENGTH];
  13342. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13343. intif_mail_checkreceiver(sd, name);
  13344. }
  13345. /// Request to receive mail's attachment.
  13346. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13347. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13348. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13349. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13350. int i;
  13351. struct mail_message* msg;
  13352. #if PACKETVER < 20150513
  13353. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13354. int attachment = MAIL_ATT_ALL;
  13355. #else
  13356. uint16 packet_id = RFIFOW(fd, 0);
  13357. int mail_id = (int)RFIFOQ(fd, 2);
  13358. //int openType = RFIFOB(fd, 10);
  13359. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13360. #endif
  13361. if( !chrif_isconnected() )
  13362. return;
  13363. if( mail_id <= 0 )
  13364. return;
  13365. if( mail_invalid_operation(sd) )
  13366. return;
  13367. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13368. if( i == MAIL_MAX_INBOX )
  13369. return;
  13370. msg = &sd->mail.inbox.msg[i];
  13371. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13372. attachment &= ~MAIL_ATT_ZENY;
  13373. }
  13374. if( attachment&MAIL_ATT_ITEM ){
  13375. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13376. // No items were found
  13377. if( i == MAIL_MAX_ITEM ){
  13378. attachment &= ~MAIL_ATT_ITEM;
  13379. }
  13380. }
  13381. // Either no attachment requested at all or there are no zeny or items in the mail
  13382. if( attachment == MAIL_ATT_NONE ){
  13383. return;
  13384. }
  13385. if( attachment&MAIL_ATT_ZENY ){
  13386. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13387. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13388. return;
  13389. }else{
  13390. // To make sure another request fails
  13391. msg->zeny = 0;
  13392. }
  13393. }
  13394. if( attachment&MAIL_ATT_ITEM ){
  13395. int new_ = 0, totalweight = 0;
  13396. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13397. struct item* item = &msg->item[i];
  13398. if( item->nameid > 0 && item->amount > 0 ){
  13399. struct item_data *data;
  13400. if((data = itemdb_exists(item->nameid)) == NULL)
  13401. continue;
  13402. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13403. case CHKADDITEM_NEW:
  13404. new_++;
  13405. break;
  13406. case CHKADDITEM_OVERAMOUNT:
  13407. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13408. return;
  13409. }
  13410. totalweight += data->weight * item->amount;
  13411. }
  13412. }
  13413. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13414. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13415. return;
  13416. }else if( pc_inventoryblank(sd) < new_ ){
  13417. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13418. return;
  13419. }
  13420. // To make sure another request fails
  13421. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13422. }
  13423. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13424. clif_Mail_read(sd, mail_id);
  13425. }
  13426. /// Request to delete a mail.
  13427. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13428. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13429. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13430. #if PACKETVER < 20150513
  13431. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13432. #else
  13433. //int openType = RFIFOB(fd, 2);
  13434. int mail_id = (int)RFIFOQ(fd, 3);
  13435. #endif
  13436. int i, j;
  13437. if( !chrif_isconnected() )
  13438. return;
  13439. if( mail_id <= 0 )
  13440. return;
  13441. if( mail_invalid_operation(sd) )
  13442. return;
  13443. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13444. if (i < MAIL_MAX_INBOX) {
  13445. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13446. // can't delete mail without removing zeny first
  13447. if( msg->zeny > 0 ){
  13448. clif_mail_delete(sd, msg, false);
  13449. return;
  13450. }
  13451. // can't delete mail without removing attachment(s) first
  13452. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13453. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13454. clif_mail_delete(sd, msg, false);
  13455. return;
  13456. }
  13457. }
  13458. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13459. sd->mail.inbox.unread--;
  13460. clif_Mail_new(sd,0,NULL,NULL);
  13461. }
  13462. }
  13463. }
  13464. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13465. /// 0273 <mail id>.L <receive name>.24B
  13466. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13467. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13468. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13469. int i;
  13470. if( mail_id <= 0 )
  13471. return;
  13472. if( mail_invalid_operation(sd) )
  13473. return;
  13474. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13475. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13476. intif_Mail_return(sd->status.char_id, mail_id);
  13477. else
  13478. clif_Mail_return(sd->fd, mail_id, 1);
  13479. }
  13480. /// Request to add an item or Zeny to mail.
  13481. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13482. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13483. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13484. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13485. int idx = RFIFOW(fd,info->pos[0]);
  13486. #if PACKETVER < 20150513
  13487. int amount = RFIFOL(fd,info->pos[1]);
  13488. #else
  13489. int amount = RFIFOW(fd,info->pos[1]);
  13490. #endif
  13491. unsigned char flag;
  13492. if( !chrif_isconnected() )
  13493. return;
  13494. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13495. return;
  13496. flag = mail_setitem(sd, idx, amount);
  13497. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13498. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13499. }else{
  13500. clif_Mail_setattachment(sd,idx,amount,flag);
  13501. }
  13502. }
  13503. /// Remove an item from a mail
  13504. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13505. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13506. int fd = sd->fd;
  13507. WFIFOHEAD(fd, 9);
  13508. WFIFOW(fd, 0) = 0xa07;
  13509. WFIFOB(fd, 2) = success;
  13510. WFIFOW(fd, 3) = index;
  13511. WFIFOW(fd, 5) = amount;
  13512. int total = 0;
  13513. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13514. if( sd->mail.item[i].nameid == 0 ){
  13515. break;
  13516. }
  13517. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13518. }
  13519. WFIFOW(fd, 7) = total;
  13520. WFIFOSET(fd, 9);
  13521. }
  13522. /// Request to reset mail item and/or Zeny
  13523. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13524. /// type:
  13525. /// 0 = reset all
  13526. /// 1 = remove item
  13527. /// 2 = remove zeny
  13528. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13529. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13530. {
  13531. #if PACKETVER < 20150513
  13532. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13533. if (type == 0 || type == 1)
  13534. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13535. if (type == 0 || type == 2)
  13536. mail_removezeny(sd, false);
  13537. #else
  13538. uint16 index = RFIFOW(fd, 2);
  13539. uint16 count = RFIFOW(fd, 4);
  13540. mail_removeitem(sd,0,index,count);
  13541. #endif
  13542. }
  13543. /// Request to send mail
  13544. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13545. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13546. /// 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)
  13547. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13548. #if PACKETVER < 20150513
  13549. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13550. if( !chrif_isconnected() )
  13551. return;
  13552. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13553. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13554. return;
  13555. }
  13556. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13557. #else
  13558. uint16 length = RFIFOW(fd, 2);
  13559. if( length < 0x3e ){
  13560. ShowWarning("Too short...\n");
  13561. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13562. return;
  13563. }
  13564. // Forged request without a begin writing packet?
  13565. if( !sd->state.mail_writing ){
  13566. return; // Ignore it
  13567. }
  13568. char receiver[NAME_LENGTH];
  13569. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13570. // char sender[NAME_LENGTH];
  13571. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13572. uint64 zeny = RFIFOQ(fd, 52);
  13573. uint16 titleLength = RFIFOW(fd, 60);
  13574. uint16 textLength = RFIFOW(fd, 62);
  13575. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13576. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13577. char title[MAIL_TITLE_LENGTH];
  13578. char text[MAIL_BODY_LENGTH];
  13579. #if PACKETVER <= 20160330
  13580. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13581. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13582. #else
  13583. // 64 = <char id>.L
  13584. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13585. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13586. #endif
  13587. if( zeny > 0 ){
  13588. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13589. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13590. return;
  13591. }
  13592. }
  13593. mail_send(sd, receiver, title, text, realTextLength);
  13594. #endif
  13595. }
  13596. /// AUCTION SYSTEM
  13597. /// By Zephyrus
  13598. ///
  13599. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13600. /// 025f <type>.L
  13601. /// type:
  13602. /// 0 = open
  13603. /// 1 = close
  13604. void clif_Auction_openwindow(struct map_session_data *sd)
  13605. {
  13606. int fd = sd->fd;
  13607. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13608. return;
  13609. if( !battle_config.feature_auction )
  13610. return;
  13611. WFIFOHEAD(fd,packet_len(0x25f));
  13612. WFIFOW(fd,0) = 0x25f;
  13613. WFIFOL(fd,2) = 0;
  13614. WFIFOSET(fd,packet_len(0x25f));
  13615. }
  13616. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13617. /// 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 }*
  13618. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13619. {
  13620. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13621. struct auction_data auction;
  13622. struct item_data *item;
  13623. WFIFOHEAD(fd,12 + (count * 83));
  13624. WFIFOW(fd,0) = 0x252;
  13625. WFIFOW(fd,2) = 12 + (count * 83);
  13626. WFIFOL(fd,4) = pages;
  13627. WFIFOL(fd,8) = count;
  13628. for( i = 0; i < count; i++ ) {
  13629. int k = 12 + (i * 83);
  13630. memcpy(&auction, RBUFP(buf,i * len), len);
  13631. WFIFOL(fd,k) = auction.auction_id;
  13632. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13633. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13634. WFIFOW(fd,28+k) = item->view_id;
  13635. else
  13636. WFIFOW(fd,28+k) = auction.item.nameid;
  13637. WFIFOL(fd,30+k) = auction.type;
  13638. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13639. WFIFOB(fd,36+k) = auction.item.identify;
  13640. WFIFOB(fd,37+k) = auction.item.attribute;
  13641. WFIFOB(fd,38+k) = auction.item.refine;
  13642. WFIFOW(fd,39+k) = auction.item.card[0];
  13643. WFIFOW(fd,41+k) = auction.item.card[1];
  13644. WFIFOW(fd,43+k) = auction.item.card[2];
  13645. WFIFOW(fd,45+k) = auction.item.card[3];
  13646. WFIFOL(fd,47+k) = auction.price;
  13647. WFIFOL(fd,51+k) = auction.buynow;
  13648. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13649. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13650. }
  13651. WFIFOSET(fd,WFIFOW(fd,2));
  13652. }
  13653. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13654. /// 0256 <index>.W <result>.B
  13655. /// result:
  13656. /// 0 = success
  13657. /// 1 = failure
  13658. static void clif_Auction_setitem(int fd, int index, bool fail)
  13659. {
  13660. WFIFOHEAD(fd,packet_len(0x256));
  13661. WFIFOW(fd,0) = 0x256;
  13662. WFIFOW(fd,2) = index;
  13663. WFIFOB(fd,4) = fail;
  13664. WFIFOSET(fd,packet_len(0x256));
  13665. }
  13666. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13667. /// 024b <type>.W
  13668. /// type:
  13669. /// 0 = create (any other action in auction window)
  13670. /// 1 = cancel (cancel pressed on register tab)
  13671. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13672. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13673. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13674. if( sd->auction.amount > 0 )
  13675. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13676. sd->auction.amount = 0;
  13677. }
  13678. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13679. /// 024c <index>.W <count>.L
  13680. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13681. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13682. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13683. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13684. struct item_data *item;
  13685. if( !battle_config.feature_auction )
  13686. return;
  13687. if( sd->auction.amount > 0 )
  13688. sd->auction.amount = 0;
  13689. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13690. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13691. return;
  13692. }
  13693. 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.
  13694. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13695. return;
  13696. }
  13697. 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) )
  13698. { // Consumable or pets are not allowed
  13699. clif_Auction_setitem(sd->fd, idx, true);
  13700. return;
  13701. }
  13702. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13703. !sd->inventory.u.items_inventory[idx].identify ||
  13704. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13705. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13706. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13707. clif_Auction_setitem(sd->fd, idx, true);
  13708. return;
  13709. }
  13710. sd->auction.index = idx;
  13711. sd->auction.amount = amount;
  13712. clif_Auction_setitem(fd, idx + 2, false);
  13713. }
  13714. /// Result from an auction action (ZC_AUCTION_RESULT).
  13715. /// 0250 <result>.B
  13716. /// result:
  13717. /// 0 = You have failed to bid into the auction
  13718. /// 1 = You have successfully bid in the auction
  13719. /// 2 = The auction has been canceled
  13720. /// 3 = An auction with at least one bidder cannot be canceled
  13721. /// 4 = You cannot register more than 5 items in an auction at a time
  13722. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13723. /// 6 = You have won the auction
  13724. /// 7 = You have failed to win the auction
  13725. /// 8 = You do not have enough Zeny
  13726. /// 9 = You cannot place more than 5 bids at a time
  13727. void clif_Auction_message(int fd, unsigned char flag)
  13728. {
  13729. WFIFOHEAD(fd,packet_len(0x250));
  13730. WFIFOW(fd,0) = 0x250;
  13731. WFIFOB(fd,2) = flag;
  13732. WFIFOSET(fd,packet_len(0x250));
  13733. }
  13734. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13735. /// 025e <result>.W
  13736. /// result:
  13737. /// 0 = You have ended the auction
  13738. /// 1 = You cannot end the auction
  13739. /// 2 = Auction ID is incorrect
  13740. void clif_Auction_close(int fd, unsigned char flag)
  13741. {
  13742. WFIFOHEAD(fd,packet_len(0x25e));
  13743. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13744. WFIFOW(fd,2) = flag;
  13745. WFIFOSET(fd,packet_len(0x25e));
  13746. }
  13747. /// Request to add an auction (CZ_AUCTION_ADD).
  13748. /// 024d <now money>.L <max money>.L <delete hour>.W
  13749. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13750. {
  13751. struct auction_data auction;
  13752. struct item_data *item;
  13753. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13754. if( !battle_config.feature_auction )
  13755. return;
  13756. auction.price = RFIFOL(fd,info->pos[0]);
  13757. auction.buynow = RFIFOL(fd,info->pos[1]);
  13758. auction.hours = RFIFOW(fd,info->pos[2]);
  13759. // Invalid Situations...
  13760. if( sd->auction.amount < 1 ) {
  13761. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13762. return;
  13763. }
  13764. if( auction.price >= auction.buynow ) {
  13765. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13766. return;
  13767. }
  13768. if( auction.hours < 1 || auction.hours > 48 ) {
  13769. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13770. return;
  13771. }
  13772. // Auction checks...
  13773. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13774. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13775. clif_Auction_message(fd, 2); // The auction has been canceled
  13776. return;
  13777. }
  13778. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13779. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13780. return;
  13781. }
  13782. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13783. auction.buynow = battle_config.auction_maximumprice;
  13784. if( auction.price >= auction.buynow )
  13785. auction.price = auction.buynow - 1;
  13786. }
  13787. auction.auction_id = 0;
  13788. auction.seller_id = sd->status.char_id;
  13789. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13790. auction.buyer_id = 0;
  13791. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13792. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13793. {
  13794. clif_Auction_message(fd, 2); // The auction has been canceled
  13795. return;
  13796. }
  13797. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13798. { // Just in case
  13799. clif_Auction_message(fd, 2); // The auction has been canceled
  13800. return;
  13801. }
  13802. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13803. auction.type = item->type;
  13804. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13805. auction.item.amount = 1;
  13806. auction.timestamp = 0;
  13807. if( !intif_Auction_register(&auction) )
  13808. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13809. else
  13810. {
  13811. int zeny = auction.hours*battle_config.auction_feeperhour;
  13812. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13813. sd->auction.amount = 0;
  13814. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13815. }
  13816. }
  13817. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13818. /// 024e <auction id>.L
  13819. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13820. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13821. intif_Auction_cancel(sd->status.char_id, auction_id);
  13822. }
  13823. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13824. /// 025d <auction id>.L
  13825. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13826. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13827. intif_Auction_close(sd->status.char_id, auction_id);
  13828. }
  13829. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13830. /// 024f <auction id>.L <money>.L
  13831. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13832. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13833. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13834. int bid = RFIFOL(fd,info->pos[1]);
  13835. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13836. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13837. return;
  13838. }
  13839. if( bid <= 0 )
  13840. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13841. else if( bid > sd->status.zeny )
  13842. clif_Auction_message(fd, 8); // You do not have enough zeny
  13843. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13844. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13845. else {
  13846. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13847. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13848. }
  13849. }
  13850. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13851. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13852. /// search type:
  13853. /// 0 = armor
  13854. /// 1 = weapon
  13855. /// 2 = card
  13856. /// 3 = misc
  13857. /// 4 = name search
  13858. /// 5 = auction id search
  13859. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13860. char search_text[NAME_LENGTH];
  13861. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13862. short type = RFIFOW(fd,info->pos[0]);
  13863. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13864. int page = RFIFOW(fd,info->pos[3]);
  13865. if( !battle_config.feature_auction )
  13866. return;
  13867. clif_parse_Auction_cancelreg(fd, sd);
  13868. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13869. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13870. }
  13871. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13872. /// 025c <type>.W
  13873. /// type:
  13874. /// 0 = sell (own auctions)
  13875. /// 1 = buy (own bids)
  13876. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13877. {
  13878. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13879. if( !battle_config.feature_auction )
  13880. return;
  13881. clif_parse_Auction_cancelreg(fd, sd);
  13882. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13883. }
  13884. /// CASH/POINT SHOP
  13885. ///
  13886. void clif_cashshop_open( struct map_session_data* sd ){
  13887. WFIFOHEAD( sd->fd, 10 );
  13888. WFIFOW( sd->fd, 0 ) = 0x845;
  13889. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13890. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13891. WFIFOSET( sd->fd, 10 );
  13892. }
  13893. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13894. sd->state.cashshop_open = true;
  13895. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13896. clif_cashshop_open( sd );
  13897. }
  13898. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13899. sd->state.cashshop_open = false;
  13900. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13901. // No need to do anything here
  13902. }
  13903. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13904. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13905. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13906. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13907. int j;
  13908. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13909. return;
  13910. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13911. WFIFOW(fd, 0) = 0x8c0;
  13912. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13913. WFIFOL(fd, 4) = tab;
  13914. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13915. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13916. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13917. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13918. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13919. }
  13920. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13921. }
  13922. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13923. void clif_cashshop_list( int fd ){
  13924. int tab;
  13925. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13926. int length = 8 + cash_shop_items[tab].count * 6;
  13927. int i, offset;
  13928. WFIFOHEAD( fd, length );
  13929. WFIFOW( fd, 0 ) = 0x8ca;
  13930. WFIFOW( fd, 2 ) = length;
  13931. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13932. WFIFOW( fd, 6 ) = tab;
  13933. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13934. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13935. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13936. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13937. }
  13938. WFIFOSET( fd, length );
  13939. }
  13940. }
  13941. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13942. if( !sd->status.cashshop_sent ) {
  13943. clif_cashshop_list( fd );
  13944. #if PACKETVER_SUPPORTS_SALES
  13945. sale_notify_login(sd);
  13946. #endif
  13947. sd->status.cashshop_sent = true;
  13948. }
  13949. }
  13950. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13951. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13952. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13953. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13954. {
  13955. int fd, i, cost[2] = { 0, 0 };
  13956. #if PACKETVER < 20070711
  13957. const int offset = 8;
  13958. #else
  13959. const int offset = 12;
  13960. #endif
  13961. nullpo_retv(sd);
  13962. nullpo_retv(nd);
  13963. fd = sd->fd;
  13964. sd->npc_shopid = nd->bl.id;
  13965. npc_shop_currency_type(sd, nd, cost, true);
  13966. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13967. WFIFOW(fd,0) = 0x287;
  13968. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13969. WFIFOL(fd,4) = cost[0];
  13970. #if PACKETVER >= 20070711
  13971. WFIFOL(fd,8) = cost[1];
  13972. #endif
  13973. for( i = 0; i < nd->u.shop.count; i++ ) {
  13974. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13975. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13976. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13977. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13978. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13979. }
  13980. WFIFOSET(fd,WFIFOW(fd,2));
  13981. }
  13982. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13983. /// 0289 <cash point>.L <error>.W
  13984. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13985. /// error:
  13986. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13987. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13988. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13989. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13990. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13991. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13992. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13993. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13994. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13995. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13996. {
  13997. int fd, cost[2] = { 0, 0 };
  13998. struct npc_data *nd;
  13999. nullpo_retv(sd);
  14000. fd = sd->fd;
  14001. nd = map_id2nd(sd->npc_shopid);
  14002. npc_shop_currency_type(sd, nd, cost, false);
  14003. WFIFOHEAD(fd, packet_len(0x289));
  14004. WFIFOW(fd,0) = 0x289;
  14005. WFIFOL(fd,2) = cost[0];
  14006. #if PACKETVER < 20070711
  14007. WFIFOW(fd,6) = TOW(error);
  14008. #else
  14009. WFIFOL(fd,6) = cost[1];
  14010. WFIFOW(fd,10) = TOW(error);
  14011. #endif
  14012. WFIFOSET(fd, packet_len(0x289));
  14013. }
  14014. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  14015. WFIFOHEAD( sd->fd, 16 );
  14016. WFIFOW( sd->fd, 0 ) = 0x849;
  14017. WFIFOL( sd->fd, 2 ) = item_id;
  14018. WFIFOW( sd->fd, 6 ) = result;
  14019. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  14020. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  14021. WFIFOSET( sd->fd, 16 );
  14022. }
  14023. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  14024. /// 0288 <name id>.W <amount>.W
  14025. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14026. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14027. /// 0848 <packet len>.W <count>.W <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W <tab>.W }.6B*count (PACKETVER >= 20130000)
  14028. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  14029. struct s_packet_db* info;
  14030. int cmd = RFIFOW(fd,0);
  14031. nullpo_retv(sd);
  14032. info = &packet_db[cmd];
  14033. if( sd->state.trading || !sd->npc_shopid ) {
  14034. clif_cashshop_ack(sd,1);
  14035. return;
  14036. }
  14037. else {
  14038. #if PACKETVER < 20101116
  14039. short nameid = RFIFOW(fd,info->pos[0]);
  14040. short amount = RFIFOW(fd,info->pos[1]);
  14041. int points = RFIFOL(fd,info->pos[2]);
  14042. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  14043. #else
  14044. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  14045. int len = RFIFOW(fd,info->pos[0]);
  14046. int points = RFIFOL(fd,info->pos[1]);
  14047. int count = RFIFOW(fd,info->pos[2]);
  14048. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14049. if( len < 10 || len != 10 + count * s_itl){
  14050. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  14051. return;
  14052. }
  14053. if(cmd==0x848){
  14054. if (cashshop_buylist( sd, points, count, item_list))
  14055. clif_cashshop_ack(sd,0);
  14056. return;
  14057. } else {
  14058. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  14059. return;
  14060. }
  14061. #endif
  14062. }
  14063. }
  14064. /// Adoption System
  14065. ///
  14066. /// Adoption message (ZC_BABYMSG).
  14067. /// 0216 <msg>.L
  14068. /// msg:
  14069. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14070. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14071. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14072. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14073. {
  14074. int fd = sd->fd;
  14075. WFIFOHEAD(fd,6);
  14076. WFIFOW(fd,0) = 0x216;
  14077. WFIFOL(fd,2) = type;
  14078. WFIFOSET(fd,6);
  14079. }
  14080. /// Adoption confirmation (ZC_REQ_BABY).
  14081. /// 01f6 <account id>.L <char id>.L <name>.B
  14082. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14083. {
  14084. int fd = sd->fd;
  14085. WFIFOHEAD(fd,34);
  14086. WFIFOW(fd,0) = 0x1f6;
  14087. WFIFOL(fd,2) = src->status.account_id;
  14088. WFIFOL(fd,6) = p_id;
  14089. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14090. WFIFOSET(fd,34);
  14091. }
  14092. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14093. /// 01f9 <account id>.L
  14094. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14095. {
  14096. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14097. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14098. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14099. {
  14100. tsd->adopt_invite = sd->status.account_id;
  14101. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14102. }
  14103. }
  14104. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14105. /// 01f7 <account id>.L <char id>.L <answer>.L
  14106. /// answer:
  14107. /// 0 = rejected
  14108. /// 1 = accepted
  14109. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14110. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14111. int p1_id = RFIFOL(fd,info->pos[0]);
  14112. int p2_id = RFIFOL(fd,info->pos[1]);
  14113. int result = RFIFOL(fd,info->pos[2]);
  14114. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14115. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14116. int pid = sd->adopt_invite;
  14117. sd->adopt_invite = 0;
  14118. if( p1_sd == NULL || p2_sd == NULL )
  14119. return; // Both players need to be online
  14120. if( pid != p1_sd->status.account_id )
  14121. return; // Incorrect values
  14122. if( result == 0 )
  14123. return; // Rejected
  14124. pc_adoption(p1_sd, p2_sd, sd);
  14125. }
  14126. /// Convex Mirror (ZC_BOSS_INFO).
  14127. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14128. /// infoType:
  14129. /// BOSS_INFO_NOT = No boss on this map.
  14130. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14131. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14132. /// BOSS_INFO_DEAD = Boss is dead.
  14133. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14134. {
  14135. int fd = sd->fd;
  14136. WFIFOHEAD(fd,70);
  14137. memset(WFIFOP(fd,0),0,70);
  14138. WFIFOW(fd,0) = 0x293;
  14139. switch (flag) {
  14140. case BOSS_INFO_NOT:
  14141. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14142. // No data required
  14143. break;
  14144. case BOSS_INFO_ALIVE:
  14145. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14146. // Update X/Y
  14147. WFIFOL(fd,3) = md->bl.x;
  14148. WFIFOL(fd,7) = md->bl.y;
  14149. break;
  14150. case BOSS_INFO_ALIVE_WITHMSG:
  14151. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14152. // Current X/Y
  14153. WFIFOL(fd,3) = md->bl.x;
  14154. WFIFOL(fd,7) = md->bl.y;
  14155. break;
  14156. case BOSS_INFO_DEAD:
  14157. {
  14158. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14159. unsigned int seconds;
  14160. int hours, minutes;
  14161. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14162. hours = seconds / (60 * 60);
  14163. seconds = seconds - (60 * 60 * hours);
  14164. minutes = seconds / 60;
  14165. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14166. // Add respawn info
  14167. WFIFOW(fd,11) = hours; // Hours
  14168. WFIFOW(fd,13) = minutes; // Minutes
  14169. }
  14170. break;
  14171. }
  14172. if (md != NULL)
  14173. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14174. WFIFOSET(fd,70);
  14175. }
  14176. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14177. /// 02d6 <account id>.L
  14178. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14179. {
  14180. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14181. struct map_session_data* tsd = map_id2sd(aid);
  14182. if (!tsd)
  14183. return;
  14184. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14185. clif_viewequip_ack(sd, tsd);
  14186. else
  14187. clif_msg(sd, VIEW_EQUIP_FAIL);
  14188. }
  14189. /// Request to a configuration.
  14190. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14191. /// type: see enum e_config_type
  14192. /// flag:
  14193. /// false = disabled
  14194. /// true = enabled
  14195. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14196. int cmd = RFIFOW(fd,0);
  14197. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14198. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14199. switch( type ){
  14200. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14201. sd->status.show_equip = flag;
  14202. break;
  14203. case CONFIG_PET_AUTOFEED:
  14204. // Player can not click this if he does not have a pet
  14205. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14206. return;
  14207. }
  14208. sd->pd->pet.autofeed = flag;
  14209. break;
  14210. case CONFIG_HOMUNCULUS_AUTOFEED:
  14211. // Player can not click this if he does not have a homunculus or it is vaporized
  14212. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14213. return;
  14214. }
  14215. sd->hd->homunculus.autofeed = flag;
  14216. break;
  14217. default:
  14218. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14219. return;
  14220. }
  14221. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14222. }
  14223. /// Request to change party invitation tick.
  14224. /// value:
  14225. /// 0 = disabled
  14226. /// 1 = enabled
  14227. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14228. {
  14229. bool flag = RFIFOB(fd,6) ? true : false;
  14230. sd->status.allow_party = flag;
  14231. clif_partytickack(sd, flag);
  14232. }
  14233. /// Questlog System [Kevin] [Inkfish]
  14234. ///
  14235. /**
  14236. * Safe check to init packet len & quest num for player.
  14237. * @param def_len
  14238. * @param info_len Length of each quest info.
  14239. * @param avail_quests Avail quests that player has.
  14240. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14241. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14242. **/
  14243. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14244. (*limit_out) = (0xFFFF - def_len) / info_len;
  14245. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14246. (*len_out) = ((*limit_out) * info_len) + def_len;
  14247. }
  14248. /// Sends list of all quest states
  14249. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14250. /// 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)
  14251. /// 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)
  14252. void clif_quest_send_list(struct map_session_data *sd)
  14253. {
  14254. int fd = sd->fd;
  14255. int i;
  14256. int offset = 8;
  14257. int limit = 0;
  14258. #if PACKETVER >= 20141022
  14259. #if PACKETVER >= 20150513
  14260. int size = 22 + NAME_LENGTH;
  14261. #else
  14262. int size = 10 + NAME_LENGTH;
  14263. #endif
  14264. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14265. WFIFOHEAD(fd,i);
  14266. #if PACKETVER >= 20150513
  14267. WFIFOW(fd, 0) = 0x9f8;
  14268. #else
  14269. WFIFOW(fd, 0) = 0x97a;
  14270. #endif
  14271. WFIFOL(fd, 4) = limit;
  14272. for (i = 0; i < limit; i++) {
  14273. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14274. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14275. offset += 4;
  14276. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14277. offset++;
  14278. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14279. offset += 4;
  14280. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14281. offset += 4;
  14282. WFIFOW(fd, offset) = qi->objectives_count;
  14283. offset += 2;
  14284. if( qi->objectives_count > 0 ){
  14285. int j;
  14286. struct mob_db *mob;
  14287. for( j = 0; j < qi->objectives_count; j++ ){
  14288. mob = mob_db(qi->objectives[j].mob);
  14289. #if PACKETVER >= 20150513
  14290. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14291. offset += 4;
  14292. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14293. offset += 4;
  14294. #endif
  14295. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14296. offset += 4;
  14297. #if PACKETVER >= 20150513
  14298. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14299. offset += 2;
  14300. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14301. offset += 2;
  14302. #endif
  14303. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14304. offset += 2;
  14305. WFIFOW(fd, offset) = qi->objectives[j].count;
  14306. offset += 2;
  14307. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14308. offset += NAME_LENGTH;
  14309. }
  14310. }
  14311. }
  14312. WFIFOW(fd, 2) = offset;
  14313. WFIFOSET(fd, offset);
  14314. #else
  14315. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14316. WFIFOHEAD(fd,i);
  14317. WFIFOW(fd, 0) = 0x2b1;
  14318. WFIFOL(fd, 4) = limit;
  14319. for (i = 0; i < limit; i++) {
  14320. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14321. offset += 4;
  14322. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14323. offset += 1;
  14324. }
  14325. WFIFOW(fd, 2) = offset;
  14326. WFIFOSET(fd, offset);
  14327. #endif
  14328. }
  14329. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14330. /// 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
  14331. void clif_quest_send_mission(struct map_session_data *sd)
  14332. {
  14333. int fd = sd->fd;
  14334. int i, j, limit = 0;
  14335. int len = sd->avail_quests*104+8;
  14336. struct mob_db *mob;
  14337. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14338. WFIFOHEAD(fd, len);
  14339. WFIFOW(fd, 0) = 0x2b2;
  14340. WFIFOW(fd, 2) = len;
  14341. WFIFOL(fd, 4) = limit;
  14342. for (i = 0; i < limit; i++) {
  14343. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14344. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14345. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14346. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14347. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14348. for (j = 0 ; j < qi->objectives_count; j++) {
  14349. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14350. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14351. mob = mob_db(qi->objectives[j].mob);
  14352. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14353. }
  14354. }
  14355. WFIFOSET(fd, len);
  14356. }
  14357. /// Notification about a new quest
  14358. /// 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)
  14359. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14360. /// 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)
  14361. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14362. {
  14363. int fd = sd->fd;
  14364. int i, offset;
  14365. struct quest_db *qi = quest_search(qd->quest_id);
  14366. #if PACKETVER >= 20150513
  14367. int cmd = 0x9f9;
  14368. #else
  14369. int cmd = 0x2b3;
  14370. #endif
  14371. WFIFOHEAD(fd, packet_len(cmd));
  14372. WFIFOW(fd, 0) = cmd;
  14373. WFIFOL(fd, 2) = qd->quest_id;
  14374. WFIFOB(fd, 6) = qd->state;
  14375. WFIFOB(fd, 7) = qd->time - qi->time;
  14376. WFIFOL(fd, 11) = qd->time;
  14377. WFIFOW(fd, 15) = qi->objectives_count;
  14378. for (i = 0, offset = 17; i < qi->objectives_count; i++) {
  14379. struct mob_db *mob;
  14380. #if PACKETVER >= 20150513
  14381. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14382. offset += 4;
  14383. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14384. offset += 4;
  14385. #endif
  14386. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14387. offset += 4;
  14388. #if PACKETVER >= 20150513
  14389. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14390. offset += 2;
  14391. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14392. offset += 2;
  14393. #endif
  14394. WFIFOW(fd, offset) = qd->count[i];
  14395. offset += 2;
  14396. mob = mob_db(qi->objectives[i].mob);
  14397. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14398. offset += NAME_LENGTH;
  14399. }
  14400. WFIFOSET(fd, packet_len(cmd));
  14401. #if PACKETVER >= 20150513
  14402. int len = 4 + qi->objectives_count * 12;
  14403. WFIFOHEAD(fd, len);
  14404. WFIFOW(fd, 0) = 0x8fe;
  14405. WFIFOW(fd, 2) = len;
  14406. for( i = 0, offset = 4; i < qi->objectives_count; i++, offset += 12 ){
  14407. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14408. WFIFOL(fd, offset+4) = qi->objectives[i].mob;
  14409. WFIFOW(fd, offset + 10) = qi->objectives[i].count;
  14410. WFIFOW(fd, offset + 12) = qd->count[i];
  14411. }
  14412. WFIFOSET(fd, len);
  14413. #endif
  14414. }
  14415. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14416. /// 02b4 <quest id>.L
  14417. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14418. {
  14419. int fd = sd->fd;
  14420. WFIFOHEAD(fd, packet_len(0x2b4));
  14421. WFIFOW(fd, 0) = 0x2b4;
  14422. WFIFOL(fd, 2) = quest_id;
  14423. WFIFOSET(fd, packet_len(0x2b4));
  14424. }
  14425. /// Notification of an update to the hunting mission counter
  14426. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14427. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14428. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14429. {
  14430. int fd = sd->fd;
  14431. int i, offset;
  14432. struct quest_db *qi = quest_search(qd->quest_id);
  14433. int len = qi->objectives_count * 12 + 6;
  14434. #if PACKETVER >= 20150513
  14435. int cmd = 0x9fa;
  14436. #else
  14437. int cmd = 0x2b5;
  14438. #endif
  14439. WFIFOHEAD(fd, len);
  14440. WFIFOW(fd, 0) = cmd;
  14441. WFIFOW(fd, 4) = qi->objectives_count;
  14442. for (i = 0, offset = 6; i < qi->objectives_count; i++) {
  14443. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14444. WFIFOL(fd, offset) = qd->quest_id;
  14445. offset += 4;
  14446. #if PACKETVER >= 20150513
  14447. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14448. offset += 4;
  14449. #else
  14450. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14451. offset += 4;
  14452. #endif
  14453. WFIFOW(fd, offset) = qi->objectives[i].count;
  14454. offset += 2;
  14455. WFIFOW(fd, offset) = qd->count[i];
  14456. offset += 2;
  14457. }
  14458. }
  14459. WFIFOW(fd, 2) = offset;
  14460. WFIFOSET(fd, offset);
  14461. }
  14462. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14463. /// 02b6 <quest id>.L <active>.B
  14464. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14465. {
  14466. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14467. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14468. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14469. }
  14470. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14471. /// 02b7 <quest id>.L <active>.B
  14472. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14473. {
  14474. int fd = sd->fd;
  14475. WFIFOHEAD(fd, packet_len(0x2b7));
  14476. WFIFOW(fd, 0) = 0x2b7;
  14477. WFIFOL(fd, 2) = quest_id;
  14478. WFIFOB(fd, 6) = active;
  14479. WFIFOSET(fd, packet_len(0x2b7));
  14480. }
  14481. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14482. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14483. /// effect:
  14484. /// 0 = none
  14485. /// 1 = exclamation mark icon
  14486. /// 2 = question mark icon
  14487. /// color:
  14488. /// 0 = yellow
  14489. /// 1 = orange
  14490. /// 2 = green
  14491. /// 3 = purple
  14492. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  14493. {
  14494. #if PACKETVER >= 20090218
  14495. int fd = sd->fd;
  14496. WFIFOHEAD(fd, packet_len(0x446));
  14497. WFIFOW(fd, 0) = 0x446;
  14498. WFIFOL(fd, 2) = bl->id;
  14499. WFIFOW(fd, 6) = bl->x;
  14500. WFIFOW(fd, 8) = bl->y;
  14501. WFIFOW(fd, 10) = effect;
  14502. WFIFOW(fd, 12) = color;
  14503. WFIFOSET(fd, packet_len(0x446));
  14504. #endif
  14505. }
  14506. /// Mercenary System
  14507. ///
  14508. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14509. /// 02a2 <var id>.W <value>.L
  14510. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14511. {
  14512. struct mercenary_data *md;
  14513. struct status_data *status;
  14514. int fd;
  14515. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14516. return;
  14517. fd = sd->fd;
  14518. status = &md->battle_status;
  14519. WFIFOHEAD(fd,packet_len(0x2a2));
  14520. WFIFOW(fd,0) = 0x2a2;
  14521. WFIFOW(fd,2) = type;
  14522. switch( type ) {
  14523. case SP_ATK1:
  14524. {
  14525. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14526. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14527. }
  14528. break;
  14529. case SP_MATK1:
  14530. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14531. break;
  14532. case SP_HIT:
  14533. WFIFOL(fd,4) = status->hit;
  14534. break;
  14535. case SP_CRITICAL:
  14536. WFIFOL(fd,4) = status->cri/10;
  14537. break;
  14538. case SP_DEF1:
  14539. WFIFOL(fd,4) = status->def;
  14540. break;
  14541. case SP_MDEF1:
  14542. WFIFOL(fd,4) = status->mdef;
  14543. break;
  14544. case SP_MERCFLEE:
  14545. WFIFOL(fd,4) = status->flee;
  14546. break;
  14547. case SP_ASPD:
  14548. WFIFOL(fd,4) = status->amotion;
  14549. break;
  14550. case SP_HP:
  14551. WFIFOL(fd,4) = status->hp;
  14552. break;
  14553. case SP_MAXHP:
  14554. WFIFOL(fd,4) = status->max_hp;
  14555. break;
  14556. case SP_SP:
  14557. WFIFOL(fd,4) = status->sp;
  14558. break;
  14559. case SP_MAXSP:
  14560. WFIFOL(fd,4) = status->max_sp;
  14561. break;
  14562. case SP_MERCKILLS:
  14563. WFIFOL(fd,4) = md->mercenary.kill_count;
  14564. break;
  14565. case SP_MERCFAITH:
  14566. WFIFOL(fd,4) = mercenary_get_faith(md);
  14567. break;
  14568. }
  14569. WFIFOSET(fd,packet_len(0x2a2));
  14570. }
  14571. /// Mercenary base status data (ZC_MER_INIT).
  14572. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14573. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14574. /// <calls>.L <kills>.L <atk range>.W
  14575. void clif_mercenary_info(struct map_session_data *sd)
  14576. {
  14577. int fd;
  14578. struct mercenary_data *md;
  14579. struct status_data *status;
  14580. int atk;
  14581. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14582. return;
  14583. fd = sd->fd;
  14584. status = &md->battle_status;
  14585. WFIFOHEAD(fd,packet_len(0x29b));
  14586. WFIFOW(fd,0) = 0x29b;
  14587. WFIFOL(fd,2) = md->bl.id;
  14588. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14589. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14590. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14591. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14592. WFIFOW(fd,10) = status->hit;
  14593. WFIFOW(fd,12) = status->cri/10;
  14594. WFIFOW(fd,14) = status->def;
  14595. WFIFOW(fd,16) = status->mdef;
  14596. WFIFOW(fd,18) = status->flee;
  14597. WFIFOW(fd,20) = status->amotion;
  14598. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14599. WFIFOW(fd,46) = md->db->lv;
  14600. WFIFOL(fd,48) = status->hp;
  14601. WFIFOL(fd,52) = status->max_hp;
  14602. WFIFOL(fd,56) = status->sp;
  14603. WFIFOL(fd,60) = status->max_sp;
  14604. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14605. WFIFOW(fd,68) = mercenary_get_faith(md);
  14606. WFIFOL(fd,70) = mercenary_get_calls(md);
  14607. WFIFOL(fd,74) = md->mercenary.kill_count;
  14608. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14609. WFIFOSET(fd,packet_len(0x29b));
  14610. }
  14611. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14612. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14613. void clif_mercenary_skillblock(struct map_session_data *sd)
  14614. {
  14615. struct mercenary_data *md;
  14616. int fd, i, len = 4;
  14617. if( sd == NULL || (md = sd->md) == NULL )
  14618. return;
  14619. fd = sd->fd;
  14620. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14621. WFIFOW(fd,0) = 0x29d;
  14622. for( i = 0; i < MAX_MERCSKILL; i++ )
  14623. {
  14624. uint16 id;
  14625. short idx = -1;
  14626. if( (id = md->db->skill[i].id) == 0 )
  14627. continue;
  14628. if ((idx = mercenary_skill_get_index(id)) == -1)
  14629. continue;
  14630. WFIFOW(fd,len) = id;
  14631. WFIFOL(fd,len+2) = skill_get_inf(id);
  14632. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14633. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14634. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14635. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14636. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14637. len += 37;
  14638. }
  14639. WFIFOW(fd,2) = len;
  14640. WFIFOSET(fd,len);
  14641. }
  14642. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14643. /// 029f <command>.B
  14644. /// 1 = mercenary information
  14645. /// 2 = delete
  14646. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14647. {
  14648. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14649. if( sd->md == NULL )
  14650. return;
  14651. if( option == 2 ) mercenary_delete(sd->md, 2);
  14652. }
  14653. /// Mercenary Message
  14654. /// message:
  14655. /// 0 = Mercenary soldier's duty hour is over.
  14656. /// 1 = Your mercenary soldier has been killed.
  14657. /// 2 = Your mercenary soldier has been fired.
  14658. /// 3 = Your mercenary soldier has ran away.
  14659. void clif_mercenary_message(struct map_session_data* sd, int message){
  14660. clif_msg(sd, MERC_MSG_BASE + message);
  14661. }
  14662. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14663. /// 0298 <name id>.W <seconds>.L
  14664. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14665. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14666. WFIFOHEAD(fd,packet_len(0x298));
  14667. WFIFOW(fd,0) = 0x298;
  14668. WFIFOW(fd,2) = nameid;
  14669. WFIFOL(fd,4) = seconds;
  14670. WFIFOSET(fd,packet_len(0x298));
  14671. }
  14672. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14673. /// 0299 <index>.W <name id>.W
  14674. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14675. { // '<ItemName>' item has been deleted from the Inventory
  14676. WFIFOHEAD(fd,packet_len(0x299));
  14677. WFIFOW(fd,0) = 0x299;
  14678. WFIFOW(fd,2) = index+2;
  14679. WFIFOW(fd,4) = nameid;
  14680. WFIFOSET(fd,packet_len(0x299));
  14681. }
  14682. /// Book Reading (ZC_READ_BOOK).
  14683. /// 0294 <book id>.L <page>.L
  14684. void clif_readbook(int fd, int book_id, int page)
  14685. {
  14686. WFIFOHEAD(fd,packet_len(0x294));
  14687. WFIFOW(fd,0) = 0x294;
  14688. WFIFOL(fd,2) = book_id;
  14689. WFIFOL(fd,6) = page;
  14690. WFIFOSET(fd,packet_len(0x294));
  14691. }
  14692. /// Battlegrounds
  14693. ///
  14694. /// Updates HP bar of a camp member.
  14695. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14696. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14697. void clif_bg_hp(struct map_session_data *sd) {
  14698. #if PACKETVER < 20140613
  14699. unsigned char buf[34];
  14700. const int cmd = 0x2e0;
  14701. #else
  14702. unsigned char buf[14];
  14703. const int cmd = 0xa0e;
  14704. #endif
  14705. nullpo_retv(sd);
  14706. WBUFW(buf,0) = cmd;
  14707. WBUFL(buf,2) = sd->status.account_id;
  14708. #if PACKETVER < 20140613
  14709. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14710. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14711. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14712. WBUFW(buf,32) = 100;
  14713. } else {
  14714. WBUFW(buf,30) = sd->battle_status.hp;
  14715. WBUFW(buf,32) = sd->battle_status.max_hp;
  14716. }
  14717. #else
  14718. if( sd->battle_status.max_hp > INT32_MAX ) {
  14719. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14720. WBUFL(buf,10) = 100;
  14721. } else {
  14722. WBUFL(buf,6) = sd->battle_status.hp;
  14723. WBUFL(buf,10) = sd->battle_status.max_hp;
  14724. }
  14725. #endif
  14726. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14727. }
  14728. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14729. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14730. void clif_bg_xy(struct map_session_data *sd)
  14731. {
  14732. unsigned char buf[36];
  14733. nullpo_retv(sd);
  14734. WBUFW(buf,0)=0x2df;
  14735. WBUFL(buf,2)=sd->status.account_id;
  14736. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14737. WBUFW(buf,30)=sd->status.class_;
  14738. WBUFW(buf,32)=sd->bl.x;
  14739. WBUFW(buf,34)=sd->bl.y;
  14740. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14741. }
  14742. void clif_bg_xy_remove(struct map_session_data *sd)
  14743. {
  14744. unsigned char buf[36];
  14745. nullpo_retv(sd);
  14746. WBUFW(buf,0)=0x2df;
  14747. WBUFL(buf,2)=sd->status.account_id;
  14748. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14749. WBUFW(buf,30)=0;
  14750. WBUFW(buf,32)=-1;
  14751. WBUFW(buf,34)=-1;
  14752. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14753. }
  14754. /// Notifies clients of a battleground message.
  14755. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14756. void clif_bg_message( struct battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14757. struct map_session_data *sd = bg_getavailablesd( bg );
  14758. if( sd == nullptr ){
  14759. return;
  14760. }
  14761. // limit length
  14762. len = min( len + 1, CHAT_SIZE_MAX );
  14763. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14764. WBUFW(buf,0) = 0x2dc;
  14765. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14766. WBUFL(buf,4) = src_id;
  14767. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14768. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14769. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14770. }
  14771. /// Validates and processes battlechat messages.
  14772. /// All messages that are sent after enabling battleground chat with /battlechat.
  14773. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14774. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14775. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14776. if( !clif_process_message( sd, false, name, message, output ) )
  14777. return;
  14778. bg_send_message(sd, output, strlen(output) );
  14779. }
  14780. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14781. /// 02de <camp A points>.W <camp B points>.W
  14782. void clif_bg_updatescore(int16 m)
  14783. {
  14784. struct block_list bl;
  14785. unsigned char buf[6];
  14786. struct map_data *mapdata = map_getmapdata(m);
  14787. bl.id = 0;
  14788. bl.type = BL_NUL;
  14789. bl.m = m;
  14790. WBUFW(buf,0) = 0x2de;
  14791. WBUFW(buf,2) = mapdata->bgscore_lion;
  14792. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14793. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14794. }
  14795. void clif_bg_updatescore_single(struct map_session_data *sd)
  14796. {
  14797. int fd;
  14798. nullpo_retv(sd);
  14799. fd = sd->fd;
  14800. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14801. WFIFOHEAD(fd,packet_len(0x2de));
  14802. WFIFOW(fd,0) = 0x2de;
  14803. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14804. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14805. WFIFOSET(fd,packet_len(0x2de));
  14806. }
  14807. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14808. /// 02dd <account id>.L <name>.24B <camp>.W
  14809. void clif_sendbgemblem_area(struct map_session_data *sd)
  14810. {
  14811. unsigned char buf[33];
  14812. nullpo_retv(sd);
  14813. WBUFW(buf, 0) = 0x2dd;
  14814. WBUFL(buf,2) = sd->bl.id;
  14815. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14816. WBUFW(buf,30) = sd->bg_id;
  14817. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14818. }
  14819. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14820. {
  14821. nullpo_retv(sd);
  14822. WFIFOHEAD(fd,32);
  14823. WFIFOW(fd,0) = 0x2dd;
  14824. WFIFOL(fd,2) = sd->bl.id;
  14825. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14826. WFIFOW(fd,30) = sd->bg_id;
  14827. WFIFOSET(fd,packet_len(0x2dd));
  14828. }
  14829. /// Custom Fonts (ZC_NOTIFY_FONT).
  14830. /// 02ef <account_id>.L <font id>.W
  14831. void clif_font(struct map_session_data *sd)
  14832. {
  14833. #if PACKETVER >= 20080102
  14834. unsigned char buf[8];
  14835. nullpo_retv(sd);
  14836. WBUFW(buf,0) = 0x2ef;
  14837. WBUFL(buf,2) = sd->bl.id;
  14838. WBUFW(buf,6) = sd->status.font;
  14839. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14840. #endif
  14841. }
  14842. /// Required to start the instancing information window on Client
  14843. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14844. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14845. void clif_instance_create(unsigned short instance_id, int num)
  14846. {
  14847. #if PACKETVER >= 20071128
  14848. struct instance_db *db = NULL;
  14849. struct map_session_data *sd = NULL;
  14850. enum send_target target = PARTY;
  14851. unsigned char buf[65];
  14852. instance_getsd(instance_id, &sd, &target);
  14853. if (!sd)
  14854. return;
  14855. db = instance_searchtype_db(instance_data[instance_id].type);
  14856. if (!db)
  14857. return;
  14858. WBUFW(buf,0) = 0x2cb;
  14859. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14860. WBUFW(buf,63) = num;
  14861. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14862. #endif
  14863. return;
  14864. }
  14865. /// To announce Instancing queue creation if no maps available
  14866. /// S 0x2cc <Standby Position>.W
  14867. void clif_instance_changewait(unsigned short instance_id, int num)
  14868. {
  14869. #if PACKETVER >= 20071128
  14870. struct map_session_data *sd = NULL;
  14871. enum send_target target = PARTY;
  14872. unsigned char buf[4];
  14873. instance_getsd(instance_id, &sd, &target);
  14874. if (!sd)
  14875. return;
  14876. WBUFW(buf,0) = 0x2cc;
  14877. WBUFW(buf,2) = num;
  14878. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14879. #endif
  14880. return;
  14881. }
  14882. /// Notify the current status to members
  14883. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14884. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14885. {
  14886. #if PACKETVER >= 20071128
  14887. struct instance_db *db = NULL;
  14888. struct map_session_data *sd = NULL;
  14889. enum send_target target = PARTY;
  14890. unsigned char buf[71];
  14891. instance_getsd(instance_id, &sd, &target);
  14892. if (!sd)
  14893. return;
  14894. db = instance_searchtype_db(instance_data[instance_id].type);
  14895. if (!db)
  14896. return;
  14897. WBUFW(buf,0) = 0x2cd;
  14898. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14899. WBUFL(buf,63) = limit1;
  14900. WBUFL(buf,67) = limit2;
  14901. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14902. #endif
  14903. return;
  14904. }
  14905. /// Notify a status change to members
  14906. /// S 0x2ce <Message ID>.L
  14907. /// 0 = Notification (EnterLimitDate update?)
  14908. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14909. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14910. /// 3 = The Memorial Dungeon has been removed.
  14911. /// 4 = Create failure (removes the instance window)
  14912. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14913. {
  14914. #if PACKETVER >= 20071128
  14915. struct map_session_data *sd = NULL;
  14916. enum send_target target = PARTY;
  14917. unsigned char buf[10];
  14918. instance_getsd(instance_id, &sd, &target);
  14919. if (!sd)
  14920. return;
  14921. WBUFW(buf,0) = 0x2ce;
  14922. WBUFL(buf,2) = type;
  14923. WBUFL(buf,6) = limit;
  14924. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14925. #endif
  14926. return;
  14927. }
  14928. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14929. /// 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
  14930. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14931. {
  14932. #if PACKETVER >= 20071002
  14933. unsigned char buf[22];
  14934. struct item_data* id = itemdb_search(item_data->nameid);
  14935. WBUFW(buf,0) = 0x2b8;
  14936. WBUFL(buf,2) = sd->status.account_id;
  14937. WBUFW(buf,6) = item_data->nameid;
  14938. WBUFB(buf,8) = item_data->identify;
  14939. WBUFB(buf,9) = item_data->attribute;
  14940. WBUFB(buf,10) = item_data->refine;
  14941. clif_addcards(WBUFP(buf,11), item_data);
  14942. WBUFW(buf,19) = id->equip; // equip location
  14943. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14944. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14945. #endif
  14946. }
  14947. /** Display gained exp.
  14948. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14949. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14950. * amount: INT32_MIN ~ INT32_MAX
  14951. * var id:
  14952. * SP_BASEEXP, SP_JOBEXP
  14953. * exp type:
  14954. * 0 = normal exp gained/lost
  14955. * 1 = quest exp gained/lost
  14956. * @param sd Player
  14957. * @param exp EXP value gained/loss
  14958. * @param type SP_BASEEXP, SP_JOBEXP
  14959. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14960. * @param lost True:if lossing EXP
  14961. */
  14962. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14963. {
  14964. int fd;
  14965. int offset;
  14966. #if PACKETVER >= 20170830
  14967. int cmd = 0xacc;
  14968. #else
  14969. int cmd = 0x7f6;
  14970. #endif
  14971. nullpo_retv(sd);
  14972. fd = sd->fd;
  14973. WFIFOHEAD(fd, packet_len(cmd));
  14974. WFIFOW(fd,0) = cmd;
  14975. WFIFOL(fd,2) = sd->bl.id;
  14976. #if PACKETVER >= 20170830
  14977. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14978. offset = 4;
  14979. #else
  14980. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14981. offset = 0;
  14982. #endif
  14983. WFIFOW(fd,10+offset) = type;
  14984. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14985. WFIFOSET(fd,packet_len(cmd));
  14986. }
  14987. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14988. /// type:
  14989. /// 0 = Displays 'value' for 5 seconds.
  14990. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14991. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14992. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14993. /// value:
  14994. /// 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).
  14995. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14996. {
  14997. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14998. WFIFOW(sd->fd,0) = 0x1b1;
  14999. WFIFOB(sd->fd,2) = type;
  15000. WFIFOL(sd->fd,3) = value;
  15001. WFIFOSET(sd->fd, packet_len(0x1b1));
  15002. }
  15003. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15004. /// 021d <state>.L
  15005. /// state:
  15006. /// 0 = Full effects
  15007. /// 1 = Reduced effects
  15008. ///
  15009. /// NOTE: The state is used on Aegis for sending skill unit packet
  15010. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15011. /// whenever possible. Due to the way the decision check is
  15012. /// constructed, this state tracking was rendered useless,
  15013. /// as the only skill unit, that is sent with 0x1c9 is
  15014. /// Graffiti.
  15015. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15016. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15017. sd->state.lesseffect = ( isLess != 0 );
  15018. }
  15019. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15020. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15021. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15022. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15023. int type = RFIFOL(fd,info->pos[1]);
  15024. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15025. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15026. if( sd->state.trading || sd->npc_shopid )
  15027. return;
  15028. if( flag == 0 || n == 0) {
  15029. clif_menuskill_clear(sd);
  15030. return; // Canceled by player.
  15031. }
  15032. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15033. clif_menuskill_clear(sd);
  15034. return; // Prevent hacking.
  15035. }
  15036. switch( type ) {
  15037. case 0: // Change Material
  15038. skill_changematerial(sd,n,item_list);
  15039. break;
  15040. case 1: // Level 1: Pure to Rough
  15041. case 2: // Level 2: Rough to Pure
  15042. skill_elementalanalysis(sd,n,type,item_list);
  15043. break;
  15044. }
  15045. clif_menuskill_clear(sd);
  15046. return;
  15047. }
  15048. /*==========================================
  15049. * Elemental System
  15050. *==========================================*/
  15051. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15052. struct elemental_data *ed;
  15053. struct status_data *status;
  15054. int fd;
  15055. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15056. return;
  15057. fd = sd->fd;
  15058. status = &ed->battle_status;
  15059. WFIFOHEAD(fd,8);
  15060. WFIFOW(fd,0) = 0x81e;
  15061. WFIFOW(fd,2) = type;
  15062. switch( type ) {
  15063. case SP_HP:
  15064. WFIFOL(fd,4) = status->hp;
  15065. break;
  15066. case SP_MAXHP:
  15067. WFIFOL(fd,4) = status->max_hp;
  15068. break;
  15069. case SP_SP:
  15070. WFIFOL(fd,4) = status->sp;
  15071. break;
  15072. case SP_MAXSP:
  15073. WFIFOL(fd,4) = status->max_sp;
  15074. break;
  15075. }
  15076. WFIFOSET(fd,8);
  15077. }
  15078. void clif_elemental_info(struct map_session_data *sd) {
  15079. int fd;
  15080. struct elemental_data *ed;
  15081. struct status_data *status;
  15082. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15083. return;
  15084. fd = sd->fd;
  15085. status = &ed->battle_status;
  15086. WFIFOHEAD(fd,22);
  15087. WFIFOW(fd, 0) = 0x81d;
  15088. WFIFOL(fd, 2) = ed->bl.id;
  15089. WFIFOL(fd, 6) = status->hp;
  15090. WFIFOL(fd,10) = status->max_hp;
  15091. WFIFOL(fd,14) = status->sp;
  15092. WFIFOL(fd,18) = status->max_sp;
  15093. WFIFOSET(fd,22);
  15094. }
  15095. /// Buying Store System
  15096. ///
  15097. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15098. /// 0810 <slots>.B
  15099. void clif_buyingstore_open(struct map_session_data* sd)
  15100. {
  15101. int fd = sd->fd;
  15102. WFIFOHEAD(fd,packet_len(0x810));
  15103. WFIFOW(fd,0) = 0x810;
  15104. WFIFOB(fd,2) = sd->buyingstore.slots;
  15105. WFIFOSET(fd,packet_len(0x810));
  15106. }
  15107. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15108. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15109. /// result:
  15110. /// 0 = cancel
  15111. /// 1 = open
  15112. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  15113. {
  15114. const unsigned int blocksize = 8;
  15115. uint8* itemlist;
  15116. char storename[MESSAGE_SIZE];
  15117. unsigned char result;
  15118. int zenylimit;
  15119. unsigned int count, packet_len;
  15120. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15121. packet_len = RFIFOW(fd,info->pos[0]);
  15122. // TODO: Make this check global for all variable length packets.
  15123. if( packet_len < 89 )
  15124. {// minimum packet length
  15125. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  15126. return;
  15127. }
  15128. zenylimit = RFIFOL(fd,info->pos[1]);
  15129. result = RFIFOL(fd,info->pos[2]);
  15130. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  15131. itemlist = RFIFOP(fd,info->pos[4]);
  15132. // so that buyingstore_create knows, how many elements it has access to
  15133. packet_len-= info->pos[4];
  15134. if( packet_len%blocksize )
  15135. {
  15136. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15137. return;
  15138. }
  15139. count = packet_len/blocksize;
  15140. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  15141. }
  15142. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15143. /// 0812 <result>.W <total weight>.L
  15144. /// result:
  15145. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15146. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15147. /// 8 = "No sale (purchase) information available." (0x705)
  15148. /// ? = nothing
  15149. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15150. {
  15151. int fd = sd->fd;
  15152. WFIFOHEAD(fd,packet_len(0x812));
  15153. WFIFOW(fd,0) = 0x812;
  15154. WFIFOW(fd,2) = result;
  15155. WFIFOL(fd,4) = weight;
  15156. WFIFOSET(fd,packet_len(0x812));
  15157. }
  15158. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15159. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15160. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  15161. {
  15162. int fd = sd->fd;
  15163. unsigned int i;
  15164. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  15165. WFIFOW(fd,0) = 0x813;
  15166. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  15167. WFIFOL(fd,4) = sd->bl.id;
  15168. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  15169. for( i = 0; i < sd->buyingstore.slots; i++ )
  15170. {
  15171. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  15172. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  15173. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  15174. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  15175. }
  15176. WFIFOSET(fd,WFIFOW(fd,2));
  15177. }
  15178. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15179. /// 0814 <account id>.L <store name>.80B
  15180. void clif_buyingstore_entry(struct map_session_data* sd)
  15181. {
  15182. uint8 buf[MESSAGE_SIZE+6];
  15183. WBUFW(buf,0) = 0x814;
  15184. WBUFL(buf,2) = sd->bl.id;
  15185. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15186. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15187. }
  15188. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15189. {
  15190. int fd = sd->fd;
  15191. WFIFOHEAD(fd,packet_len(0x814));
  15192. WFIFOW(fd,0) = 0x814;
  15193. WFIFOL(fd,2) = pl_sd->bl.id;
  15194. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15195. WFIFOSET(fd,packet_len(0x814));
  15196. }
  15197. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15198. /// 0815
  15199. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15200. {
  15201. buyingstore_close(sd);
  15202. }
  15203. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15204. /// 0816 <account id>.L
  15205. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15206. {
  15207. uint8 buf[6];
  15208. WBUFW(buf,0) = 0x816;
  15209. WBUFL(buf,2) = sd->bl.id;
  15210. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15211. }
  15212. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15213. {
  15214. int fd = sd->fd;
  15215. WFIFOHEAD(fd,packet_len(0x816));
  15216. WFIFOW(fd,0) = 0x816;
  15217. WFIFOL(fd,2) = pl_sd->bl.id;
  15218. WFIFOSET(fd,packet_len(0x816));
  15219. }
  15220. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15221. /// 0817 <account id>.L
  15222. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15223. {
  15224. uint32 account_id;
  15225. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15226. buyingstore_open(sd, account_id);
  15227. }
  15228. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  15229. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  15230. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  15231. {
  15232. int fd = sd->fd;
  15233. unsigned int i;
  15234. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  15235. WFIFOW(fd,0) = 0x818;
  15236. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  15237. WFIFOL(fd,4) = pl_sd->bl.id;
  15238. WFIFOL(fd,8) = pl_sd->buyer_id;
  15239. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  15240. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  15241. {
  15242. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  15243. WFIFOW(fd,20+i*9) = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15244. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  15245. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  15246. }
  15247. WFIFOSET(fd,WFIFOW(fd,2));
  15248. }
  15249. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  15250. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  15251. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  15252. {
  15253. const unsigned int blocksize = 6;
  15254. uint8* itemlist;
  15255. uint32 account_id;
  15256. unsigned int count, packet_len, buyer_id;
  15257. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15258. packet_len = RFIFOW(fd,info->pos[0]);
  15259. if( packet_len < 12 )
  15260. {// minimum packet length
  15261. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15262. return;
  15263. }
  15264. account_id = RFIFOL(fd,info->pos[1]);
  15265. buyer_id = RFIFOL(fd,info->pos[2]);
  15266. itemlist = RFIFOP(fd,info->pos[3]);
  15267. // so that buyingstore_trade knows, how many elements it has access to
  15268. packet_len-= info->pos[3];
  15269. if( packet_len%blocksize )
  15270. {
  15271. ShowError("clif_parse_ReqTradeBuyingStore: Unexpected item list size %u (account_id=%d, buyer_id=%d, block size=%u)\n", packet_len, sd->bl.id, account_id, blocksize);
  15272. return;
  15273. }
  15274. count = packet_len/blocksize;
  15275. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15276. }
  15277. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15278. /// 081a <result>.W
  15279. /// result:
  15280. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15281. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15282. /// ? = nothing
  15283. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15284. {
  15285. int fd = sd->fd;
  15286. WFIFOHEAD(fd,packet_len(0x81a));
  15287. WFIFOW(fd,0) = 0x81a;
  15288. WFIFOW(fd,2) = result;
  15289. WFIFOSET(fd,packet_len(0x81a));
  15290. }
  15291. /// Updates the zeny limit and an item in the buying store item list.
  15292. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15293. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15294. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15295. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15296. const int cmd = 0x81b;
  15297. #else
  15298. const int cmd = 0x9e6;
  15299. #endif
  15300. int offset = 0;
  15301. int fd = sd->fd;
  15302. WFIFOHEAD(fd,packet_len(cmd));
  15303. WFIFOW(fd,0) = cmd;
  15304. WFIFOW(fd,2) = nameid;
  15305. WFIFOW(fd,4) = amount; // amount of nameid received
  15306. #if PACKETVER >= 20141016
  15307. WFIFOL(fd,6) = zeny; // zeny
  15308. offset += 4;
  15309. #endif
  15310. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15311. #if PACKETVER >= 20141016
  15312. WFIFOL(fd,10+offset) = char_id; // GID
  15313. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15314. #endif
  15315. WFIFOSET(fd,packet_len(cmd));
  15316. }
  15317. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15318. /// 081c <index>.W <amount>.W <price>.L
  15319. /// message:
  15320. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15321. ///
  15322. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15323. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15324. {
  15325. int fd = sd->fd;
  15326. WFIFOHEAD(fd,packet_len(0x81c));
  15327. WFIFOW(fd,0) = 0x81c;
  15328. WFIFOW(fd,2) = index+2;
  15329. WFIFOW(fd,4) = amount;
  15330. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15331. WFIFOSET(fd,packet_len(0x81c));
  15332. }
  15333. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15334. /// 0824 <result>.W <name id>.W
  15335. /// result:
  15336. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15337. /// 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)
  15338. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15339. /// ? = nothing
  15340. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15341. {
  15342. int fd = sd->fd;
  15343. WFIFOHEAD(fd,packet_len(0x824));
  15344. WFIFOW(fd,0) = 0x824;
  15345. WFIFOW(fd,2) = result;
  15346. WFIFOW(fd,4) = nameid;
  15347. WFIFOSET(fd,packet_len(0x824));
  15348. }
  15349. /// Search Store Info System
  15350. ///
  15351. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15352. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15353. /// type:
  15354. /// 0 = Vending
  15355. /// 1 = Buying Store
  15356. ///
  15357. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15358. /// amount of card slots. If the client does not know about the item it
  15359. /// cannot be searched.
  15360. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15361. {
  15362. const unsigned int blocksize = 2;
  15363. const uint8* itemlist;
  15364. const uint8* cardlist;
  15365. unsigned char type;
  15366. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15367. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15368. packet_len = RFIFOW(fd,info->pos[0]);
  15369. if( packet_len < 15 )
  15370. {// minimum packet length
  15371. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15372. return;
  15373. }
  15374. type = RFIFOB(fd,info->pos[1]);
  15375. max_price = RFIFOL(fd,info->pos[2]);
  15376. min_price = RFIFOL(fd,info->pos[3]);
  15377. item_count = RFIFOB(fd,info->pos[4]);
  15378. card_count = RFIFOB(fd,info->pos[5]);
  15379. itemlist = RFIFOP(fd,info->pos[6]);
  15380. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15381. // check, if there is enough data for the claimed count of items
  15382. packet_len-= info->pos[6];
  15383. if( packet_len%blocksize )
  15384. {
  15385. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15386. return;
  15387. }
  15388. count = packet_len/blocksize;
  15389. if( count < item_count+card_count )
  15390. {
  15391. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15392. return;
  15393. }
  15394. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15395. }
  15396. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15397. /// 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 }*
  15398. /// is first page:
  15399. /// 0 = appends to existing results
  15400. /// 1 = clears previous results before displaying this result set
  15401. /// is next page:
  15402. /// 0 = no "next" label
  15403. /// 1 = "next" label to retrieve more results
  15404. void clif_search_store_info_ack(struct map_session_data* sd)
  15405. {
  15406. #if PACKETVER >= 20150225
  15407. const unsigned int blocksize = MESSAGE_SIZE+26+5*5;
  15408. #else
  15409. const unsigned int blocksize = MESSAGE_SIZE+26;
  15410. #endif
  15411. int fd = sd->fd;
  15412. unsigned int i, start, end;
  15413. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15414. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15415. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15416. WFIFOW(fd,0) = 0x836;
  15417. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15418. WFIFOB(fd,4) = !sd->searchstore.pages;
  15419. WFIFOB(fd,5) = searchstore_querynext(sd);
  15420. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15421. for( i = start; i < end; i++ ) {
  15422. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15423. struct item it;
  15424. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15425. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15426. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15427. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15428. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15429. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15430. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15431. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15432. // make-up an item for clif_addcards
  15433. memset(&it, 0, sizeof(it));
  15434. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15435. it.nameid = ssitem->nameid;
  15436. it.amount = ssitem->amount;
  15437. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15438. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15439. }
  15440. WFIFOSET(fd,WFIFOW(fd,2));
  15441. }
  15442. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15443. /// 0837 <reason>.B
  15444. /// reason:
  15445. /// 0 = "No matching stores were found." (0x70b)
  15446. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15447. /// 2 = "You cannot search anymore." (0x706)
  15448. /// 3 = "You cannot search yet." (0x708)
  15449. /// 4 = "No sale (purchase) information available." (0x705)
  15450. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15451. {
  15452. int fd = sd->fd;
  15453. WFIFOHEAD(fd,packet_len(0x837));
  15454. WFIFOW(fd,0) = 0x837;
  15455. WFIFOB(fd,2) = reason;
  15456. WFIFOSET(fd,packet_len(0x837));
  15457. }
  15458. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15459. /// 0838
  15460. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15461. {
  15462. searchstore_next(sd);
  15463. }
  15464. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15465. /// 083a <type>.W <remaining uses>.B
  15466. /// type:
  15467. /// 0 = Search Stores
  15468. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15469. void clif_open_search_store_info(struct map_session_data* sd)
  15470. {
  15471. int fd = sd->fd;
  15472. WFIFOHEAD(fd,packet_len(0x83a));
  15473. WFIFOW(fd,0) = 0x83a;
  15474. WFIFOW(fd,2) = sd->searchstore.effect;
  15475. #if PACKETVER > 20100701
  15476. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15477. #endif
  15478. WFIFOSET(fd,packet_len(0x83a));
  15479. }
  15480. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15481. /// 083b
  15482. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15483. {
  15484. searchstore_close(sd);
  15485. }
  15486. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15487. /// 083c <account id>.L <store id>.L <nameid>.W
  15488. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15489. {
  15490. unsigned short nameid;
  15491. uint32 account_id, store_id;
  15492. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15493. account_id = RFIFOL(fd,info->pos[0]);
  15494. store_id = RFIFOL(fd,info->pos[1]);
  15495. nameid = RFIFOW(fd,info->pos[2]);
  15496. searchstore_click(sd, account_id, store_id, nameid);
  15497. }
  15498. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15499. /// 083d <xPos>.W <yPos>.W
  15500. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15501. {
  15502. int fd = sd->fd;
  15503. WFIFOHEAD(fd,packet_len(0x83d));
  15504. WFIFOW(fd,0) = 0x83d;
  15505. WFIFOW(fd,2) = x;
  15506. WFIFOW(fd,4) = y;
  15507. WFIFOSET(fd,packet_len(0x83d));
  15508. }
  15509. /// Parse function for packet debugging.
  15510. void clif_parse_debug(int fd,struct map_session_data *sd)
  15511. {
  15512. int cmd, packet_len;
  15513. // clif_parse ensures, that there is at least 2 bytes of data
  15514. cmd = RFIFOW(fd,0);
  15515. if( sd ) {
  15516. packet_len = packet_db[cmd].len;
  15517. if( packet_len == 0 )
  15518. {// unknown
  15519. packet_len = RFIFOREST(fd);
  15520. }
  15521. else if( packet_len == -1 )
  15522. {// variable length
  15523. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15524. }
  15525. 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);
  15526. }
  15527. else
  15528. {
  15529. packet_len = RFIFOREST(fd);
  15530. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15531. }
  15532. ShowDump(RFIFOP(fd,0), packet_len);
  15533. }
  15534. /*==========================================
  15535. * Server tells client to display a window similar to Magnifier (item) one
  15536. * Server populates the window with avilable elemental converter options according to player's inventory
  15537. *------------------------------------------*/
  15538. int clif_elementalconverter_list(struct map_session_data *sd) {
  15539. int i,c,view,fd;
  15540. nullpo_ret(sd);
  15541. /// Main client packet processing function
  15542. fd=sd->fd;
  15543. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15544. WFIFOW(fd, 0)=0x1ad;
  15545. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15546. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15547. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15548. WFIFOW(fd,c*2+ 4)= view;
  15549. else
  15550. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15551. c++;
  15552. }
  15553. }
  15554. WFIFOW(fd,2) = c*2+4;
  15555. WFIFOSET(fd, WFIFOW(fd,2));
  15556. if (c > 0) {
  15557. sd->menuskill_id = SA_CREATECON;
  15558. sd->menuskill_val = c;
  15559. }
  15560. return 0;
  15561. }
  15562. /**
  15563. * Rune Knight
  15564. **/
  15565. void clif_millenniumshield(struct block_list *bl, short shields) {
  15566. #if PACKETVER >= 20081217
  15567. unsigned char buf[10];
  15568. WBUFW(buf,0) = 0x440;
  15569. WBUFL(buf,2) = bl->id;
  15570. WBUFW(buf,6) = shields;
  15571. WBUFW(buf,8) = 0;
  15572. clif_send(buf,packet_len(0x440),bl,AREA);
  15573. #endif
  15574. }
  15575. /**
  15576. * Warlock
  15577. **/
  15578. /*==========================================
  15579. * Spellbook list [LimitLine/3CeAM]
  15580. *------------------------------------------*/
  15581. int clif_spellbook_list(struct map_session_data *sd)
  15582. {
  15583. int i, c;
  15584. int fd;
  15585. nullpo_ret(sd);
  15586. fd = sd->fd;
  15587. WFIFOHEAD(fd, 8 * 8 + 8);
  15588. WFIFOW(fd,0) = 0x1ad;
  15589. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15590. {
  15591. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15592. {
  15593. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15594. c++;
  15595. }
  15596. }
  15597. if( c > 0 )
  15598. {
  15599. WFIFOW(fd,2) = c * 2 + 4;
  15600. WFIFOSET(fd, WFIFOW(fd, 2));
  15601. sd->menuskill_id = WL_READING_SB;
  15602. sd->menuskill_val = c;
  15603. }
  15604. else{
  15605. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15606. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15607. }
  15608. return 1;
  15609. }
  15610. /**
  15611. * Mechanic
  15612. **/
  15613. /*==========================================
  15614. * Magic Decoy Material List
  15615. *------------------------------------------*/
  15616. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15617. int i, c;
  15618. int fd;
  15619. nullpo_ret(sd);
  15620. fd = sd->fd;
  15621. WFIFOHEAD(fd, 8 * 8 + 8);
  15622. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15623. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15624. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15625. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15626. c ++;
  15627. }
  15628. }
  15629. if( c > 0 ) {
  15630. sd->menuskill_id = NC_MAGICDECOY;
  15631. sd->menuskill_val = skill_lv;
  15632. sd->sc.comet_x = x;
  15633. sd->sc.comet_y = y;
  15634. WFIFOW(fd,2) = c * 2 + 4;
  15635. WFIFOSET(fd, WFIFOW(fd, 2));
  15636. } else {
  15637. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15638. return 0;
  15639. }
  15640. return 1;
  15641. }
  15642. /*==========================================
  15643. * Guillotine Cross Poisons List
  15644. *------------------------------------------*/
  15645. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15646. int i, c;
  15647. int fd;
  15648. nullpo_ret(sd);
  15649. fd = sd->fd;
  15650. WFIFOHEAD(fd, 8 * 8 + 8);
  15651. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15652. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15653. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15654. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15655. c ++;
  15656. }
  15657. }
  15658. if( c > 0 ) {
  15659. sd->menuskill_id = GC_POISONINGWEAPON;
  15660. sd->menuskill_val = skill_lv;
  15661. WFIFOW(fd,2) = c * 2 + 4;
  15662. WFIFOSET(fd, WFIFOW(fd, 2));
  15663. } else {
  15664. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15665. return 0;
  15666. }
  15667. return 1;
  15668. }
  15669. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15670. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15671. int fd, i, c;
  15672. nullpo_ret(sd);
  15673. fd = sd->fd;
  15674. if( !fd )
  15675. return 0;
  15676. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15677. return 0;
  15678. WFIFOHEAD(fd, 2 * 6 + 4);
  15679. WFIFOW(fd,0) = 0x442;
  15680. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15681. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15682. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15683. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15684. {
  15685. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15686. c++;
  15687. }
  15688. if( c > 0 ) {
  15689. WFIFOW(fd,2) = 8 + c * 2;
  15690. WFIFOL(fd,4) = c;
  15691. WFIFOSET(fd,WFIFOW(fd,2));
  15692. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15693. sd->menuskill_val = c;
  15694. } else {
  15695. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15696. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15697. }
  15698. return 1;
  15699. }
  15700. /*===========================================
  15701. * Skill list for Four Elemental Analysis
  15702. * and Change Material skills.
  15703. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15704. *------------------------------------------*/
  15705. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15706. #if PACKETVER >= 20090922
  15707. int fd = sd->fd;
  15708. nullpo_ret(sd);
  15709. sd->menuskill_id = skill_id; // To prevent hacking.
  15710. sd->menuskill_val = skill_lv;
  15711. if( skill_id == GN_CHANGEMATERIAL )
  15712. skill_lv = 0; // Changematerial
  15713. WFIFOHEAD(fd, packet_len(0x7e3));
  15714. WFIFOW(fd,0) = 0x7e3;
  15715. WFIFOL(fd,2) = skill_lv;
  15716. WFIFOL(fd,4) = 0;
  15717. WFIFOSET(fd, packet_len(0x7e3));
  15718. #endif
  15719. return 1;
  15720. }
  15721. /*==========================================
  15722. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15723. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15724. * RFIFOL(fd,2) - type (currently not used)
  15725. *------------------------------------------*/
  15726. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15727. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15728. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15729. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15730. return;
  15731. if( pc_istrading(sd) ) {
  15732. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15733. clif_menuskill_clear(sd);
  15734. return;
  15735. }
  15736. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15737. clif_menuskill_clear(sd);
  15738. }
  15739. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15740. /// 08cf <id>.L <type>.W <num>.W
  15741. void clif_spiritcharm(struct map_session_data *sd) {
  15742. unsigned char buf[10];
  15743. nullpo_retv(sd);
  15744. WBUFW(buf,0) = 0x08cf;
  15745. WBUFL(buf,2) = sd->bl.id;
  15746. WBUFW(buf,6) = sd->spiritcharm_type;
  15747. WBUFW(buf,8) = sd->spiritcharm;
  15748. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15749. }
  15750. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15751. /// 0907 <index>.W
  15752. ///
  15753. /// R 0908 <index>.w <type>.b
  15754. /// type:
  15755. /// 0 = move item to personal tab
  15756. /// 1 = move item to normal tab
  15757. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15758. #if PACKETVER >= 20111122
  15759. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15760. int index = RFIFOW(fd,info->pos[0]) - 2;
  15761. int type = RFIFOB(fd, info->pos[1]);
  15762. /* can't move while dead. */
  15763. if(pc_isdead(sd)) {
  15764. return;
  15765. }
  15766. if (index < 0 || index >= MAX_INVENTORY)
  15767. return;
  15768. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15769. sd->inventory.u.items_inventory[index].favorite = 0;
  15770. else if( type == 0 )
  15771. sd->inventory.u.items_inventory[index].favorite = 1;
  15772. else
  15773. return;/* nothing to do. */
  15774. clif_favorite_item(sd, index);
  15775. #endif
  15776. }
  15777. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15778. /// 0900 <index>.W <favorite>.B
  15779. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15780. int fd = sd->fd;
  15781. WFIFOHEAD(fd,packet_len(0x908));
  15782. WFIFOW(fd,0) = 0x908;
  15783. WFIFOW(fd,2) = index+2;
  15784. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15785. WFIFOSET(fd,packet_len(0x908));
  15786. }
  15787. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15788. void clif_snap( struct block_list *bl, short x, short y ) {
  15789. unsigned char buf[10];
  15790. WBUFW(buf,0) = 0x8d2;
  15791. WBUFL(buf,2) = bl->id;
  15792. WBUFW(buf,6) = x;
  15793. WBUFW(buf,8) = y;
  15794. if( disguised(bl) )
  15795. {
  15796. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15797. WBUFL(buf,2) = -bl->id;
  15798. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15799. } else
  15800. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15801. }
  15802. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15803. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15804. #if PACKETVER >= 20120404
  15805. WFIFOHEAD(fd,packet_len(0x977));
  15806. WFIFOW(fd,0) = 0x977;
  15807. WFIFOL(fd,2) = md->bl.id;
  15808. WFIFOL(fd,6) = md->status.hp;
  15809. WFIFOL(fd,10) = md->status.max_hp;
  15810. WFIFOSET(fd,packet_len(0x977));
  15811. #endif
  15812. }
  15813. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15814. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15815. return;
  15816. }
  15817. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15818. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15819. WFIFOW(sd->fd,0) = 0x2c9;
  15820. WFIFOB(sd->fd,2) = flag;
  15821. WFIFOSET(sd->fd, packet_len(0x2c9));
  15822. }
  15823. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15824. /// 0979 <world name>.24B <char name>.24B
  15825. void clif_ackworldinfo(struct map_session_data* sd) {
  15826. int fd;
  15827. nullpo_retv(sd);
  15828. fd = sd->fd;
  15829. WFIFOHEAD(fd,packet_len(0x979));
  15830. WFIFOW(fd,0)=0x979;
  15831. //AID -> world name ?
  15832. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15833. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15834. WFIFOSET(fd,packet_len(0x979));
  15835. }
  15836. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15837. /// 0978 <AID>.L
  15838. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15839. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15840. if(sd)
  15841. clif_ackworldinfo(sd);
  15842. }
  15843. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15844. /// 0447
  15845. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15846. //if(sd)
  15847. ;
  15848. }
  15849. /// req world info (CZ_CLIENT_VERSION)
  15850. /// 044A <version>.L
  15851. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15852. //if(sd)
  15853. ;
  15854. }
  15855. /// Ranking list
  15856. /// ranking pointlist { <name>.24B <point>.L }*10
  15857. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15858. struct fame_list* list;
  15859. int i, size = MAX_FAME_LIST;
  15860. switch(rankingtype) {
  15861. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15862. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15863. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15864. // PK currently unsupported
  15865. case RANK_KILLER: list = NULL; size = 0; break;
  15866. default:
  15867. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15868. return;
  15869. }
  15870. //Packet size limits this list to 10 elements. [Skotlex]
  15871. for (i = 0; i < min(10,size); i++) {
  15872. if (list[i].id > 0) {
  15873. const char* name;
  15874. if (strcmp(list[i].name, "-") == 0 &&
  15875. (name = map_charid2nick(list[i].id)) != NULL)
  15876. {
  15877. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15878. } else {
  15879. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15880. }
  15881. } else {
  15882. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15883. }
  15884. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15885. }
  15886. for(;i < 10; i++) { //In case the MAX is less than 10.
  15887. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15888. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15889. }
  15890. }
  15891. /// Request for the blacksmith ranklist.
  15892. /// /blacksmith command sends this packet to the server.
  15893. /// 0217 (CZ_BLACKSMITH_RANK)
  15894. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15895. clif_ranklist(sd,RANK_BLACKSMITH);
  15896. }
  15897. /// Request for the alchemist ranklist.
  15898. /// /alchemist command sends this packet to the server.
  15899. /// 0218 (CZ_ALCHEMIST_RANK)
  15900. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15901. clif_ranklist(sd,RANK_ALCHEMIST);
  15902. }
  15903. /// Request for the taekwon ranklist.
  15904. /// /taekwon command sends this packet to the server.
  15905. /// 0225 (CZ_TAEKWON_RANK)
  15906. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15907. clif_ranklist(sd,RANK_TAEKWON);
  15908. }
  15909. /// Request for the killer ranklist.
  15910. /// /pk command sends this packet to the server.
  15911. /// 0237 (CZ_KILLER_RANK)
  15912. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15913. clif_ranklist(sd,RANK_KILLER);
  15914. }
  15915. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15916. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15917. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15918. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15919. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15920. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15921. enum e_rank rank;
  15922. #if PACKETVER < 20130710
  15923. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15924. short cmd;
  15925. switch( rankingType ){
  15926. case RANK_BLACKSMITH: cmd = 0x219; break;
  15927. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15928. case RANK_TAEKWON: cmd = 0x226; break;
  15929. case RANK_KILLER: cmd = 0x238; break;
  15930. default:
  15931. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15932. return;
  15933. }
  15934. // Can be safely casted here, since we validated it before
  15935. rank = (enum e_rank)rankingType;
  15936. WBUFW(buf,0) = cmd;
  15937. clif_sub_ranklist(buf,2,sd,rank);
  15938. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15939. #else
  15940. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15941. int mypoint = 0;
  15942. switch( rankingType ){
  15943. case RANK_BLACKSMITH:
  15944. case RANK_ALCHEMIST:
  15945. case RANK_TAEKWON:
  15946. case RANK_KILLER:
  15947. break;
  15948. default:
  15949. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15950. return;
  15951. }
  15952. // Can be safely casted here, since we validated it before
  15953. rank = (enum e_rank)rankingType;
  15954. WBUFW(buf,0) = 0x97d;
  15955. WBUFW(buf,2) = rank;
  15956. clif_sub_ranklist(buf,4,sd,rank);
  15957. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15958. case MAPID_BLACKSMITH:
  15959. case MAPID_ALCHEMIST:
  15960. case MAPID_TAEKWON:
  15961. mypoint = sd->status.fame;
  15962. }
  15963. WBUFL(buf,284) = mypoint; //mypoint
  15964. clif_send(buf, 288, &sd->bl, SELF);
  15965. #endif
  15966. }
  15967. /*
  15968. * 097c <type> (CZ_REQ_RANKING)
  15969. * type
  15970. * 0: /blacksmith
  15971. * 1: /alchemist
  15972. * 2: /taekwon
  15973. * 3: /pk
  15974. * */
  15975. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15976. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15977. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15978. clif_ranklist(sd,rankingtype);
  15979. }
  15980. /// Updates the fame rank points for the given ranking.
  15981. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15982. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15983. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15984. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15985. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15986. int fd=sd->fd;
  15987. #if PACKETVER < 20130710
  15988. short cmd;
  15989. switch(rankingtype){
  15990. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15991. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15992. case RANK_TAEKWON: cmd = 0x224; break;
  15993. default:
  15994. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15995. return;
  15996. }
  15997. WFIFOHEAD(fd,packet_len(cmd));
  15998. WFIFOW(fd,0) = cmd;
  15999. WFIFOL(fd,2) = point;
  16000. WFIFOL(fd,6) = sd->status.fame;
  16001. WFIFOSET(fd, packet_len(cmd));
  16002. #else
  16003. WFIFOHEAD(fd,packet_len(0x97e));
  16004. WFIFOW(fd,0) = 0x97e;
  16005. WFIFOW(fd,2) = rankingtype;
  16006. WFIFOL(fd,4) = point;
  16007. WFIFOL(fd,8) = sd->status.fame;
  16008. WFIFOSET(fd,packet_len(0x97e));
  16009. #endif
  16010. }
  16011. /**
  16012. * Transmit personal information to player. (rates)
  16013. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16014. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16015. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16016. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16017. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16018. * FIXME!
  16019. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16020. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16021. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16022. */
  16023. #ifdef VIP_ENABLE
  16024. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16025. if (sd) {
  16026. struct s_packet_db* info;
  16027. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16028. int cmd = 0, fd, i = 0;
  16029. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16030. int details_bexp[PINFO_MAX];
  16031. int details_drop[PINFO_MAX];
  16032. int details_penalty[PINFO_MAX];
  16033. /**
  16034. * Set for EXP
  16035. */
  16036. //0:PCRoom
  16037. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16038. if (details_bexp[0] == 100 || !details_bexp[0])
  16039. details_bexp[0] = 0;
  16040. else {
  16041. if (details_bexp[0] < 100) {
  16042. details_bexp[0] = 100 - details_bexp[0];
  16043. details_bexp[0] = 0 - details_bexp[0];
  16044. }
  16045. else
  16046. details_bexp[0] = details_bexp[0] - 100;
  16047. }
  16048. //1:Premium
  16049. if (pc_isvip(sd)) {
  16050. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16051. if (details_bexp[1] < 0)
  16052. details_bexp[1] = 0 - details_bexp[1];
  16053. }
  16054. else
  16055. details_bexp[1] = 0;
  16056. //2:Server
  16057. details_bexp[2] = battle_config.base_exp_rate;
  16058. if (details_bexp[2] == 100)
  16059. details_bexp[2] = 0;
  16060. else {
  16061. if (details_bexp[2] < 100) {
  16062. details_bexp[2] = 100 - details_bexp[2];
  16063. details_bexp[2] = 0 - details_bexp[2];
  16064. }
  16065. else
  16066. details_bexp[2] = details_bexp[2] - 100;
  16067. }
  16068. //3:TPLUS
  16069. details_bexp[3] = 0;
  16070. /* End - EXP set*/
  16071. /**
  16072. * Set for Drop rate
  16073. */
  16074. //0:PCRoom
  16075. details_drop[0] = 0;
  16076. //1:Premium
  16077. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16078. if (pc_isvip(sd)) {
  16079. if (details_drop[1] < 0)
  16080. details_drop[1] = 0 - details_drop[1];
  16081. }
  16082. else
  16083. details_drop[1] = 0;
  16084. //2:Server
  16085. details_drop[2] = battle_config.item_rate_common;
  16086. if (details_drop[2] == 100)
  16087. details_drop[2] = 0;
  16088. else {
  16089. if (details_drop[2] < 100) {
  16090. details_drop[2] = 100 - details_drop[2];
  16091. details_drop[2] = 0 - details_drop[2];
  16092. }
  16093. else
  16094. details_drop[2] = details_drop[2] - 100;
  16095. }
  16096. //3:TPLUS
  16097. details_drop[3] = 0;
  16098. /* End - Drop set*/
  16099. /**
  16100. * Set for Penalty rate
  16101. */
  16102. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16103. //0:PCRoom
  16104. details_penalty[0] = 0;
  16105. //1:Premium
  16106. if (pc_isvip(sd)) {
  16107. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16108. if (details_penalty[1] == 100)
  16109. details_penalty[1] = 0;
  16110. else {
  16111. if (details_penalty[1] < 100) {
  16112. details_penalty[1] = 100 - details_penalty[1];
  16113. details_penalty[1] = 0 - details_penalty[1];
  16114. }
  16115. else
  16116. details_penalty[1] = details_penalty[1] - 100;
  16117. }
  16118. }
  16119. else
  16120. details_penalty[1] = 0;
  16121. //2:Server
  16122. details_penalty[2] = battle_config.death_penalty_base;
  16123. if (details_penalty[2] == 100)
  16124. details_penalty[2] = 0;
  16125. else {
  16126. if (details_penalty[2] < 100) {
  16127. details_penalty[2] = 100 - details_penalty[2];
  16128. details_penalty[2] = 0 - details_penalty[2];
  16129. }
  16130. else
  16131. details_penalty[2] = details_penalty[2] - 100;
  16132. }
  16133. //3:TPLUS
  16134. details_penalty[3] = 0;
  16135. /* End - Penalty set*/
  16136. cmd = packet_db_ack[cmdtype];
  16137. info = &packet_db[cmd];
  16138. len = info->len; //this is the base len without details
  16139. if(!len) return; //version as packet disable
  16140. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16141. szdetails = 7;
  16142. factor = 1;
  16143. }
  16144. else if (cmd == 0x097b) {
  16145. tot_baseexp *= factor;
  16146. tot_drop *= factor;
  16147. tot_penalty *= factor;
  16148. }
  16149. fd = sd->fd;
  16150. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16151. WFIFOW(fd,0) = cmd;
  16152. for (i = 0; i < maxinfotype; i++) {
  16153. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16154. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16155. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16156. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16157. tot_baseexp += details_bexp[i]*factor;
  16158. tot_drop += details_penalty[i]*factor;
  16159. tot_penalty += details_drop[i]*factor;
  16160. len += szdetails;
  16161. }
  16162. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16163. if (cmd == 0x08cb) { //0x08cb version
  16164. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16165. WFIFOW(fd,info->pos[2]) = tot_drop;
  16166. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16167. }
  16168. else { //2013-08-07aRagexe uses 0x097b
  16169. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16170. WFIFOL(fd,info->pos[2]) = tot_drop;
  16171. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16172. }
  16173. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16174. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16175. WFIFOSET(fd,len);
  16176. }
  16177. }
  16178. #endif
  16179. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16180. char cmd[30];
  16181. int t_aid = RFIFOL(fd,2);
  16182. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16183. is_atcommand(fd, sd, cmd, 1);
  16184. }
  16185. /**
  16186. * Marks Crimson Marker target on mini-map to the caster
  16187. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16188. * @param fd
  16189. * @param bl Crimson Marker target
  16190. **/
  16191. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16192. struct s_packet_db* info;
  16193. int cmd = 0;
  16194. int16 len;
  16195. unsigned char buf[11];
  16196. nullpo_retv(sd);
  16197. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16198. if (!cmd)
  16199. cmd = 0x09C1; //default
  16200. info = &packet_db[cmd];
  16201. if (!(len = info->len))
  16202. return;
  16203. WBUFW(buf, 0) = cmd;
  16204. WBUFL(buf, info->pos[0]) = bl->id;
  16205. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16206. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16207. clif_send(buf, len, &sd->bl, SELF);
  16208. }
  16209. /**
  16210. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16211. **/
  16212. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16213. struct s_packet_db *info = NULL;
  16214. int cmd = 0;
  16215. nullpo_retv(sd);
  16216. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16217. info = &packet_db[cmd];
  16218. if (!cmd || !info->len)
  16219. return;
  16220. WFIFOHEAD(sd->fd, info->len);
  16221. WFIFOW(sd->fd, 0) = cmd;
  16222. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16223. WFIFOSET(sd->fd, info->len);
  16224. }
  16225. /**
  16226. * [Ind/Hercules]
  16227. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16228. **/
  16229. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16230. char buf[256];
  16231. size_t len;
  16232. nullpo_retv(bl);
  16233. if(!message)
  16234. return;
  16235. len = strlen(message)+1;
  16236. if( len > sizeof(buf)-8 ) {
  16237. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16238. len = sizeof(buf)-8;
  16239. }
  16240. WBUFW(buf,0) = 0x8b3;
  16241. WBUFW(buf,2) = (uint16)(len+8);
  16242. WBUFL(buf,4) = bl->id;
  16243. safestrncpy(WBUFCP(buf,8), message, len);
  16244. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16245. }
  16246. /**
  16247. * [Ind/Hercules]
  16248. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16249. **/
  16250. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16251. unsigned char buf[10];
  16252. nullpo_retv(sd);
  16253. WBUFW(buf,0) = 0x7fc;
  16254. WBUFL(buf,2) = prev_leader_aid;
  16255. WBUFL(buf,6) = new_leader_aid;
  16256. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16257. }
  16258. /**
  16259. * Sends a clan message to a player
  16260. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16261. **/
  16262. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16263. #if PACKETVER >= 20131223
  16264. struct map_session_data *sd;
  16265. uint8 buf[256];
  16266. if( len == 0 ){
  16267. return;
  16268. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16269. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16270. len = sizeof(buf)-5-NAME_LENGTH;
  16271. }
  16272. WBUFW(buf, 0) = 0x98e;
  16273. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16274. // 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
  16275. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16276. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16277. if((sd = clan_getavailablesd(clan)) != NULL)
  16278. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16279. #endif
  16280. }
  16281. /**
  16282. * Parses a clan message from a player.
  16283. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16284. **/
  16285. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16286. #if PACKETVER >= 20131223
  16287. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16288. // validate packet and retrieve name and message
  16289. if( !clif_process_message(sd, false, name, message, output ) )
  16290. return;
  16291. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16292. #endif
  16293. }
  16294. /**
  16295. * Sends the basic clan informations to the client.
  16296. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16297. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16298. **/
  16299. void clif_clan_basicinfo( struct map_session_data *sd ){
  16300. #if PACKETVER >= 20131223
  16301. int fd, offset, length, i, flag;
  16302. struct clan* clan;
  16303. char mapname[MAP_NAME_LENGTH_EXT];
  16304. nullpo_retv( sd );
  16305. nullpo_retv( clan = sd->clan );
  16306. // Check if the player has a valid session and is not autotrading
  16307. if( !clif_session_isValid( sd ) ){
  16308. return;
  16309. }
  16310. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16311. fd = sd->fd;
  16312. WFIFOHEAD(fd,length);
  16313. memset( WFIFOP(fd, 0), 0, length );
  16314. WFIFOW( fd, 0 ) = 0x98a;
  16315. WFIFOL( fd, 4 ) = clan->id;
  16316. offset = 8;
  16317. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16318. offset += NAME_LENGTH;
  16319. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16320. offset += NAME_LENGTH;
  16321. mapindex_getmapname_ext( clan->map, mapname );
  16322. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16323. offset += MAP_NAME_LENGTH_EXT;
  16324. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16325. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16326. for( flag = 0; flag < 2; flag++ ){
  16327. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16328. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16329. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16330. offset += NAME_LENGTH;
  16331. }
  16332. }
  16333. }
  16334. WFIFOW( fd, 2 ) = offset;
  16335. WFIFOSET(fd,offset);
  16336. #endif
  16337. }
  16338. /**
  16339. * Updates the online and maximum player count of a clan.
  16340. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16341. **/
  16342. void clif_clan_onlinecount( struct clan* clan ){
  16343. #if PACKETVER >= 20131223
  16344. uint8 buf[6];
  16345. struct map_session_data *sd;
  16346. WBUFW(buf,0) = 0x988;
  16347. WBUFW(buf,2) = clan->connect_member;
  16348. WBUFW(buf,4) = clan->max_member;
  16349. if((sd = clan_getavailablesd(clan)) != NULL)
  16350. clif_send(buf, 6, &sd->bl, CLAN);
  16351. #endif
  16352. }
  16353. /**
  16354. * Notifies the client that the player has left his clan.
  16355. * 0989 (ZC_ACK_CLAN_LEAVE)
  16356. **/
  16357. void clif_clan_leave( struct map_session_data* sd ){
  16358. #if PACKETVER >= 20131223
  16359. int fd;
  16360. nullpo_retv( sd );
  16361. if( !clif_session_isValid( sd ) ){
  16362. return;
  16363. }
  16364. fd = sd->fd;
  16365. WFIFOHEAD(fd,2);
  16366. WFIFOW(fd,0) = 0x989;
  16367. WFIFOSET(fd,2);
  16368. #endif
  16369. }
  16370. /**
  16371. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16372. * 0A2F <result>.B <title_id>.L
  16373. */
  16374. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16375. {
  16376. #if PACKETVER >= 20150513
  16377. int fd;
  16378. nullpo_retv(sd);
  16379. if (!clif_session_isValid(sd))
  16380. return;
  16381. fd = sd->fd;
  16382. WFIFOHEAD(fd, packet_len(0xa2f));
  16383. WFIFOW(fd, 0) = 0xa2f;
  16384. WFIFOB(fd, 2) = result;
  16385. WFIFOL(fd, 3) = title_id;
  16386. WFIFOSET(fd, packet_len(0xa2f));
  16387. #endif
  16388. }
  16389. /**
  16390. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16391. * 0A2E <title_id>.L
  16392. */
  16393. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16394. {
  16395. int title_id;
  16396. nullpo_retv(sd);
  16397. title_id = RFIFOL(fd, 2);
  16398. if( title_id == sd->status.title_id ){
  16399. // It is exactly the same as the old one
  16400. return;
  16401. }else if( title_id <= 0 ){
  16402. sd->status.title_id = 0;
  16403. }else{
  16404. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16405. clif_change_title_ack(sd, 1, title_id);
  16406. return;
  16407. }
  16408. sd->status.title_id = title_id;
  16409. }
  16410. clif_name_area(&sd->bl);
  16411. clif_change_title_ack(sd, 0, title_id);
  16412. }
  16413. #ifdef DUMP_UNKNOWN_PACKET
  16414. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16415. {
  16416. const char* packet_txt = "save/packet.txt";
  16417. FILE* fp;
  16418. time_t time_server;
  16419. struct tm *datetime;
  16420. char datestr[512];
  16421. time(&time_server); // get time in seconds since 1/1/1970
  16422. datetime = localtime(&time_server); // convert seconds in structure
  16423. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16424. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16425. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16426. if( sd ) {
  16427. 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);
  16428. } else {
  16429. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16430. }
  16431. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16432. fprintf(fp, "\n");
  16433. fclose(fp);
  16434. } else {
  16435. ShowError("Failed to write '%s'.\n", packet_txt);
  16436. // Dump on console instead
  16437. if( sd ) {
  16438. 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);
  16439. } else {
  16440. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16441. }
  16442. ShowDump(RFIFOP(fd,0), packet_len);
  16443. }
  16444. }
  16445. #endif
  16446. /// Roulette System
  16447. /// Author: Yommy
  16448. /// Opens the roulette window
  16449. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16450. void clif_roulette_open( struct map_session_data* sd ){
  16451. nullpo_retv(sd);
  16452. int fd = sd->fd;
  16453. WFIFOHEAD(fd,packet_len(0xa1a));
  16454. WFIFOW(fd,0) = 0xa1a;
  16455. WFIFOB(fd,2) = 0; // result
  16456. WFIFOL(fd,3) = 0; // serial
  16457. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16458. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16459. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16460. WFIFOL(fd,11) = sd->roulette_point.gold;
  16461. WFIFOL(fd,15) = sd->roulette_point.silver;
  16462. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16463. WFIFOSET(fd,packet_len(0xa1a));
  16464. }
  16465. /// Request to open the roulette window
  16466. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16467. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16468. nullpo_retv(sd);
  16469. if (!battle_config.feature_roulette) {
  16470. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16471. return;
  16472. }
  16473. clif_roulette_open(sd);
  16474. }
  16475. /// Sends the info about the available roulette rewards to the client
  16476. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16477. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16478. void clif_roulette_info( struct map_session_data* sd ){
  16479. nullpo_retv(sd);
  16480. int fd = sd->fd;
  16481. int len = 8; // Initialize to header size
  16482. #if PACKETVER < 20180516
  16483. int size = 8;
  16484. #else
  16485. int size = 12;
  16486. #endif
  16487. for( int i = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16488. len += (MAX_ROULETTE_COLUMNS - i) * size;
  16489. }
  16490. WFIFOHEAD(fd,len);
  16491. WFIFOW(fd,0) = 0xa1c;
  16492. WFIFOW(fd,2) = len;
  16493. WFIFOL(fd,4) = 1; // serial
  16494. for(int i = 0, offset = 8; i < MAX_ROULETTE_LEVEL; i++) {
  16495. for(int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16496. WFIFOW(fd,offset + 0) = i;
  16497. WFIFOW(fd,offset + 2) = j;
  16498. #if PACKETVER < 20180516
  16499. WFIFOW(fd,offset + 4) = rd.nameid[i][j];
  16500. WFIFOW(fd,offset + 6) = rd.qty[i][j];
  16501. #else
  16502. WFIFOL(fd,offset + 4) = rd.nameid[i][j];
  16503. WFIFOL(fd,offset + 8) = rd.qty[i][j];
  16504. #endif
  16505. offset += size;
  16506. }
  16507. }
  16508. WFIFOSET(fd,len);
  16509. }
  16510. /// Request the roulette reward data
  16511. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16512. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16513. nullpo_retv(sd);
  16514. if (!battle_config.feature_roulette) {
  16515. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16516. return;
  16517. }
  16518. clif_roulette_info(sd);
  16519. }
  16520. /// Notification of the client that the roulette window was closed
  16521. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16522. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16523. nullpo_retv(sd);
  16524. if (!battle_config.feature_roulette) {
  16525. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16526. return;
  16527. }
  16528. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16529. }
  16530. /// Response to a item reward request
  16531. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16532. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16533. #if PACKETVER >= 20141016
  16534. nullpo_retv(sd);
  16535. int fd = sd->fd;
  16536. WFIFOHEAD(fd,packet_len(0xa22));
  16537. WFIFOW(fd,0) = 0xa22;
  16538. WFIFOB(fd,2) = type;
  16539. WFIFOW(fd,3) = 0; //! TODO: Additional item
  16540. WFIFOSET(fd,packet_len(0xa22));
  16541. #endif
  16542. }
  16543. /**
  16544. * Claim roulette reward
  16545. * @param sd Player
  16546. * @return 0:Success
  16547. **/
  16548. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16549. struct item it;
  16550. uint8 res = 1;
  16551. nullpo_retr(1, sd);
  16552. if (sd->roulette.prizeIdx < 0)
  16553. return RECV_ITEM_FAILED;
  16554. memset(&it, 0, sizeof(it));
  16555. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16556. it.identify = 1;
  16557. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16558. ; // onSuccess
  16559. }
  16560. sd->roulette.claimPrize = false;
  16561. sd->roulette.prizeStage = 0;
  16562. sd->roulette.prizeIdx = -1;
  16563. sd->roulette.stage = 0;
  16564. return res;
  16565. }
  16566. /// Update Roulette window with current stats
  16567. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16568. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16569. nullpo_retv(sd);
  16570. int fd = sd->fd;
  16571. WFIFOHEAD(fd,packet_len(0xa20));
  16572. WFIFOW(fd,0) = 0xa20;
  16573. WFIFOB(fd,2) = result;
  16574. WFIFOW(fd,3) = stage;
  16575. WFIFOW(fd,5) = prizeIdx;
  16576. WFIFOW(fd,7) = bonusItemID;
  16577. WFIFOL(fd,9) = sd->roulette_point.gold;
  16578. WFIFOL(fd,13) = sd->roulette_point.silver;
  16579. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16580. WFIFOSET(fd,packet_len(0xa20));
  16581. }
  16582. /// Request to start the roulette
  16583. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16584. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16585. enum GENERATE_ROULETTE_ACK result;
  16586. nullpo_retv(sd);
  16587. if (!battle_config.feature_roulette) {
  16588. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16589. return;
  16590. }
  16591. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16592. return;
  16593. }
  16594. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16595. sd->roulette.stage = 0;
  16596. sd->roulette.claimPrize = false;
  16597. sd->roulette.prizeStage = 0;
  16598. sd->roulette.prizeIdx = -1;
  16599. }
  16600. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16601. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16602. }else{
  16603. if (!sd->roulette.stage) {
  16604. if (sd->roulette_point.bronze > 0) {
  16605. sd->roulette_point.bronze -= 1;
  16606. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16607. } else if (sd->roulette_point.silver > 9) {
  16608. sd->roulette_point.silver -= 10;
  16609. sd->roulette.stage = 2;
  16610. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16611. } else if (sd->roulette_point.gold > 9) {
  16612. sd->roulette_point.gold -= 10;
  16613. sd->roulette.stage = 4;
  16614. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16615. }
  16616. }
  16617. sd->roulette.prizeStage = sd->roulette.stage;
  16618. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16619. sd->roulette.claimPrize = true;
  16620. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16621. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16622. result = GENERATE_ROULETTE_LOSING;
  16623. sd->roulette.stage = 0;
  16624. }else{
  16625. result = GENERATE_ROULETTE_SUCCESS;
  16626. sd->roulette.stage++;
  16627. }
  16628. }
  16629. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16630. }
  16631. /// Request to claim a prize
  16632. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16633. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16634. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16635. nullpo_retv(sd);
  16636. if (!battle_config.feature_roulette) {
  16637. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16638. return;
  16639. }
  16640. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16641. return;
  16642. }
  16643. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16644. switch (clif_roulette_getitem(sd)) {
  16645. case ADDITEM_SUCCESS:
  16646. type = RECV_ITEM_SUCCESS;
  16647. break;
  16648. case ADDITEM_INVALID:
  16649. case ADDITEM_OVERITEM:
  16650. case ADDITEM_OVERAMOUNT:
  16651. type = RECV_ITEM_OVERCOUNT;
  16652. break;
  16653. case ADDITEM_OVERWEIGHT:
  16654. type = RECV_ITEM_OVERWEIGHT;
  16655. break;
  16656. case ADDITEM_STACKLIMIT:
  16657. default:
  16658. type = RECV_ITEM_FAILED;
  16659. break;
  16660. }
  16661. }
  16662. clif_roulette_recvitem_ack(sd,type);
  16663. }
  16664. /// MERGE ITEM
  16665. /**
  16666. * Acknowledge the client about item merger result
  16667. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16668. * @param fd
  16669. * @param sd
  16670. **/
  16671. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16672. unsigned char buf[9];
  16673. struct s_packet_db *info = NULL;
  16674. short cmd = 0;
  16675. nullpo_retv(sd);
  16676. if (!clif_session_isValid(sd))
  16677. return;
  16678. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16679. return;
  16680. if (!(info = &packet_db[cmd]) || info->len == 0)
  16681. return;
  16682. WBUFW(buf, 0) = cmd;
  16683. WBUFW(buf, info->pos[0]) = index;
  16684. WBUFW(buf, info->pos[1]) = count;
  16685. WBUFB(buf, info->pos[2]) = type;
  16686. clif_send(buf, info->len, &sd->bl, SELF);
  16687. }
  16688. /**
  16689. * Check if item has the pair to be merged
  16690. * @param sd
  16691. * @param it Item
  16692. * @return True if has pair, False if not
  16693. **/
  16694. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16695. struct item *it_;
  16696. unsigned short i;
  16697. nullpo_retr(false, sd);
  16698. 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);
  16699. if (i < MAX_INVENTORY)
  16700. return true;
  16701. return false;
  16702. }
  16703. /**
  16704. * Check if item can be merged
  16705. * @param id Item Data
  16706. * @param it Item
  16707. * @return True if can be merged, False if not
  16708. **/
  16709. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16710. if (!id || !it)
  16711. return false;
  16712. if (id->type == IT_CASH)
  16713. return false;
  16714. if (!itemdb_isstackable2(id))
  16715. return false;
  16716. if (itemdb_isspecial(it->card[0]))
  16717. return false;
  16718. if (!it->unique_id)
  16719. return false;
  16720. return true;
  16721. }
  16722. /**
  16723. * Open available item to be merged.
  16724. * Only show 1 item in 1 process.
  16725. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16726. * @param sd
  16727. **/
  16728. void clif_merge_item_open(struct map_session_data *sd) {
  16729. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16730. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16731. int len = 0;
  16732. struct s_packet_db *info = NULL;
  16733. struct item *it;
  16734. nullpo_retv(sd);
  16735. if (!clif_session_isValid(sd))
  16736. return;
  16737. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16738. return;
  16739. if (!(info = &packet_db[cmd]) || info->len == 0)
  16740. return;
  16741. // Get entries
  16742. for (i = 0; i < MAX_INVENTORY; i++) {
  16743. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16744. continue;
  16745. if (clif_merge_item_has_pair(sd, it))
  16746. indexes[n++] = i;
  16747. }
  16748. if (n < 2) { // No item need to be merged
  16749. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16750. return;
  16751. }
  16752. WBUFW(buf, 0) = cmd;
  16753. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16754. for (i = 0; i < n; i++) {
  16755. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16756. }
  16757. clif_send(buf, len, &sd->bl, SELF);
  16758. }
  16759. /**
  16760. * Process item merger
  16761. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16762. * @param fd
  16763. * @param sd
  16764. **/
  16765. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16766. struct s_packet_db *info = NULL;
  16767. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16768. unsigned int count = 0;
  16769. struct item_data *id = NULL;
  16770. nullpo_retv(sd);
  16771. if (!clif_session_isValid(sd))
  16772. return;
  16773. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16774. return;
  16775. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16776. if (n < 2) { // No item need to be merged
  16777. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16778. return;
  16779. }
  16780. for (i = 0, j = 0; i < n; i++) {
  16781. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16782. if( idx < 0 || idx >= MAX_INVENTORY ){
  16783. return;
  16784. }
  16785. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16786. continue;
  16787. indexes[j] = idx;
  16788. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16789. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16790. return;
  16791. }
  16792. count += sd->inventory.u.items_inventory[idx].amount;
  16793. j++;
  16794. }
  16795. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16796. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16797. return;
  16798. }
  16799. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16800. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16801. return;
  16802. }
  16803. // Merrrrge!!!!
  16804. for (i = 1; i < n; i++) {
  16805. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16806. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16807. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16808. sd->inventory_data[idx] = NULL;
  16809. clif_delitem(sd, idx, amt, 0);
  16810. }
  16811. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16812. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16813. }
  16814. /**
  16815. * Cancel item merge
  16816. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16817. * @param fd
  16818. * @param sd
  16819. **/
  16820. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16821. return; // Nothing todo yet
  16822. }
  16823. /**
  16824. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16825. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16826. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16827. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16828. **/
  16829. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type) {
  16830. unsigned char buf[9 + NAME_LENGTH * 2];
  16831. unsigned short cmd = 0;
  16832. struct s_packet_db *info = NULL;
  16833. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16834. return;
  16835. if (!(info = &packet_db[cmd]) || info->len == 0)
  16836. return;
  16837. WBUFW(buf, 0) = 0x7fd;
  16838. WBUFB(buf, 4) = type;
  16839. WBUFW(buf, 5) = nameid;
  16840. WBUFB(buf, 7) = NAME_LENGTH;
  16841. if (battle_config.broadcast_hide_name) {
  16842. std::string dispname = std::string(char_name);
  16843. int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
  16844. dispname.replace(dispname.length() - hide, hide, hide, '*');
  16845. safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
  16846. }
  16847. else
  16848. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16849. switch (type) {
  16850. case ITEMOBTAIN_TYPE_BOXITEM:
  16851. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16852. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16853. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16854. break;
  16855. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16856. {
  16857. struct mob_db *db = mob_db(container);
  16858. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16859. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16860. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16861. }
  16862. break;
  16863. case ITEMOBTAIN_TYPE_NPC:
  16864. default:
  16865. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16866. break;
  16867. }
  16868. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16869. }
  16870. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16871. /// 0A02 <view>.W
  16872. /// Value <flag> has the following effects:
  16873. /// 1: Open a Dress Room window.
  16874. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16875. #if PACKETVER >= 20150513
  16876. int fd = sd->fd;
  16877. nullpo_retv(sd);
  16878. WFIFOHEAD(fd, packet_len(0xa02));
  16879. WFIFOW(fd,0) = 0xa02;
  16880. WFIFOW(fd,2) = flag;
  16881. WFIFOSET(fd, packet_len(0xa02));
  16882. #endif
  16883. }
  16884. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16885. /// 0A35 <result>.W
  16886. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16887. #if PACKETVER >= 20150513
  16888. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16889. // Ignore the request
  16890. // - Invalid item index
  16891. // - Invalid item ID or item doesn't exist
  16892. // - Item is already identified
  16893. if (idx < 0 || idx >= MAX_INVENTORY ||
  16894. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16895. sd->inventory.u.items_inventory[idx].identify)
  16896. return;
  16897. // Ignore the request - No magnifiers in inventory
  16898. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16899. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16900. return;
  16901. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16902. return;
  16903. skill_identify(sd, idx);
  16904. #endif
  16905. }
  16906. /// Starts navigation to the given target on client side
  16907. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16908. #if PACKETVER >= 20111010
  16909. int fd = sd->fd;
  16910. WFIFOHEAD(fd,27);
  16911. WFIFOW(fd,0) = 0x08e2;
  16912. // How detailed will our navigation be?
  16913. if( mob_id > 0 ){
  16914. x = 0;
  16915. y = 0;
  16916. WFIFOB(fd,2) = 3; // monster with destination field
  16917. }else if( x > 0 && y > 0 ){
  16918. WFIFOB(fd,2) = 0; // with coordinates
  16919. }else{
  16920. x = 0;
  16921. y = 0;
  16922. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16923. }
  16924. // Which services can be used for transportation?
  16925. WFIFOB(fd,3) = flag;
  16926. // If this flag is set, the navigation window will not be opened up
  16927. WFIFOB(fd,4) = hideWindow;
  16928. // Target map
  16929. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16930. // Target x
  16931. WFIFOW(fd,21) = x;
  16932. // Target y
  16933. WFIFOW(fd,23) = y;
  16934. // Target monster ID
  16935. WFIFOW(fd,25) = mob_id;
  16936. WFIFOSET(fd,27);
  16937. #endif
  16938. }
  16939. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16940. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16941. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16942. #if PACKETVER >= 20150513
  16943. unsigned char* buf;
  16944. int len,i;
  16945. struct map_session_data *tsd;
  16946. struct block_list* tbl;
  16947. if( target == SELF ){
  16948. tsd = BL_CAST(BL_PC,bl);
  16949. tbl = &sd->bl;
  16950. }else{
  16951. tsd = sd;
  16952. tbl = bl;
  16953. }
  16954. if( !tsd->hatEffectCount )
  16955. return;
  16956. len = 9 + tsd->hatEffectCount * 2;
  16957. buf = (unsigned char*)aMalloc( len );
  16958. WBUFW(buf,0) = 0xa3b;
  16959. WBUFW(buf,2) = len;
  16960. WBUFL(buf,4) = tsd->bl.id;
  16961. WBUFB(buf,8) = 1;
  16962. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16963. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16964. }
  16965. clif_send(buf, len,tbl,target);
  16966. aFree(buf);
  16967. #endif
  16968. }
  16969. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16970. #if PACKETVER >= 20150513
  16971. unsigned char buf[13];
  16972. WBUFW(buf,0) = 0xa3b;
  16973. WBUFW(buf,2) = 13;
  16974. WBUFL(buf,4) = sd->bl.id;
  16975. WBUFB(buf,8) = enable;
  16976. WBUFL(buf,9) = effectId;
  16977. clif_send(buf,13,&sd->bl,AREA);
  16978. #endif
  16979. }
  16980. /// Notify the client that a sale has started
  16981. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16982. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16983. #if PACKETVER_SUPPORTS_SALES
  16984. unsigned char buf[8];
  16985. WBUFW(buf, 0) = 0x9b2;
  16986. WBUFW(buf, 2) = sale_item->nameid;
  16987. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16988. clif_send(buf, 8, bl, target);
  16989. #endif
  16990. }
  16991. /// Notify the clien that a sale has ended
  16992. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16993. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16994. #if PACKETVER_SUPPORTS_SALES
  16995. unsigned char buf[4];
  16996. WBUFW(buf, 0) = 0x9b3;
  16997. WBUFW(buf, 2) = sale_item->nameid;
  16998. clif_send(buf, 4, bl, target);
  16999. #endif
  17000. }
  17001. /// Update the remaining amount of a sale item.
  17002. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17003. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17004. #if PACKETVER_SUPPORTS_SALES
  17005. unsigned char buf[8];
  17006. WBUFW(buf, 0) = 0x9c4;
  17007. WBUFW(buf, 2) = sale_item->nameid;
  17008. WBUFL(buf, 4) = sale_item->amount;
  17009. clif_send(buf, 8, bl, target);
  17010. #endif
  17011. }
  17012. /// The client requested a refresh of the current remaining count of a sale item
  17013. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17014. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17015. #if PACKETVER_SUPPORTS_SALES
  17016. struct sale_item_data* sale;
  17017. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17018. return;
  17019. }
  17020. sale = sale_find_item( RFIFOW(fd, 6), true );
  17021. if( sale == NULL ){
  17022. return;
  17023. }
  17024. clif_sale_amount(sale, &sd->bl, SELF);
  17025. #endif
  17026. }
  17027. /// Opens the sale administration window on the client
  17028. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17029. void clif_sale_open( struct map_session_data* sd ){
  17030. #if PACKETVER_SUPPORTS_SALES
  17031. nullpo_retv(sd);
  17032. if( sd->state.sale_open ){
  17033. return;
  17034. }
  17035. sd->state.sale_open = true;
  17036. int fd = sd->fd;
  17037. WFIFOHEAD(fd, 2);
  17038. WFIFOW(fd, 0) = 0x9b5;
  17039. WFIFOSET(fd, 2);
  17040. #endif
  17041. }
  17042. /// Client request to open the sale administration window.
  17043. /// This is sent by /limitedsale
  17044. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17045. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17046. #if PACKETVER_SUPPORTS_SALES
  17047. nullpo_retv(sd);
  17048. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17049. return;
  17050. }
  17051. char command[CHAT_SIZE_MAX];
  17052. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17053. is_atcommand(fd, sd, command, 1);
  17054. #endif
  17055. }
  17056. /// Closes the sale administration window on the client.
  17057. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17058. void clif_sale_close(struct map_session_data* sd) {
  17059. #if PACKETVER_SUPPORTS_SALES
  17060. nullpo_retv(sd);
  17061. if( !sd->state.sale_open ){
  17062. return;
  17063. }
  17064. sd->state.sale_open = false;
  17065. int fd = sd->fd;
  17066. WFIFOHEAD(fd, 2);
  17067. WFIFOW(fd, 0) = 0x9bd;
  17068. WFIFOSET(fd, 2);
  17069. #endif
  17070. }
  17071. /// Client request to close the sale administration window.
  17072. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17073. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17074. #if PACKETVER_SUPPORTS_SALES
  17075. nullpo_retv(sd);
  17076. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17077. return;
  17078. }
  17079. clif_sale_close(sd);
  17080. #endif
  17081. }
  17082. /// Reply to a item search request for item sale administration.
  17083. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17084. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17085. #if PACKETVER_SUPPORTS_SALES
  17086. int fd = sd->fd;
  17087. WFIFOHEAD(fd, 10);
  17088. WFIFOW(fd, 0) = 0x9ad;
  17089. if( item != NULL ){
  17090. WFIFOW(fd, 2) = 0;
  17091. WFIFOW(fd, 4) = item->nameid;
  17092. WFIFOL(fd, 6) = item->price;
  17093. }else{
  17094. WFIFOW(fd, 2) = 1;
  17095. WFIFOW(fd, 4) = 0;
  17096. WFIFOL(fd, 6) = 0;
  17097. }
  17098. WFIFOSET(fd, 10);
  17099. #endif
  17100. }
  17101. /// Search request for an item sale administration.
  17102. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17103. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17104. #if PACKETVER_SUPPORTS_SALES
  17105. char item_name[ITEM_NAME_LENGTH];
  17106. struct item_data *id = NULL;
  17107. nullpo_retv(sd);
  17108. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17109. return;
  17110. }
  17111. if( !sd->state.sale_open ){
  17112. return;
  17113. }
  17114. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17115. id = itemdb_searchname(item_name);
  17116. if( id ){
  17117. int i;
  17118. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17119. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17120. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17121. return;
  17122. }
  17123. }
  17124. }
  17125. // not found
  17126. clif_sale_search_reply( sd, NULL );
  17127. #endif
  17128. }
  17129. /// Reply if an item was successfully put on sale or not.
  17130. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17131. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17132. #if PACKETVER_SUPPORTS_SALES
  17133. int fd = sd->fd;
  17134. WFIFOHEAD(fd, 4);
  17135. WFIFOW(fd, 0) = 0x9af;
  17136. WFIFOW(fd, 2) = (uint16)result;
  17137. WFIFOSET(fd, 4);
  17138. #endif
  17139. }
  17140. /// A client request to put an item on sale.
  17141. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17142. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  17143. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17144. #if PACKETVER_SUPPORTS_SALES
  17145. int32 count;
  17146. int16 nameid;
  17147. int startTime;
  17148. int endTime;
  17149. uint16 sellingHours;
  17150. nullpo_retv(sd);
  17151. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17152. return;
  17153. }
  17154. if( !sd->state.sale_open ){
  17155. return;
  17156. }
  17157. nameid = RFIFOW(fd, 6);
  17158. count = RFIFOL(fd, 8);
  17159. startTime = RFIFOL(fd, 12);
  17160. #if PACKETVER >= 20150520
  17161. if( RFIFOW(fd,0) == 0xa3d )
  17162. sellingHours = RFIFOW(fd, 16);
  17163. else
  17164. #endif
  17165. sellingHours = RFIFOB(fd, 16);
  17166. endTime = startTime + sellingHours * 60 * 60;
  17167. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  17168. #endif
  17169. }
  17170. /// Reply to an item removal from sale.
  17171. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17172. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17173. #if PACKETVER_SUPPORTS_SALES
  17174. int fd = sd->fd;
  17175. WFIFOHEAD(fd, 4);
  17176. WFIFOW(fd, 0) = 0x9b1;
  17177. WFIFOW(fd, 2) = failed;
  17178. WFIFOSET(fd, 4);
  17179. #endif
  17180. }
  17181. /// Request to remove an item from sale.
  17182. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17183. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17184. #if PACKETVER_SUPPORTS_SALES
  17185. nullpo_retv(sd);
  17186. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17187. return;
  17188. }
  17189. if( !sd->state.sale_open ){
  17190. return;
  17191. }
  17192. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  17193. #endif
  17194. }
  17195. /// Achievement System
  17196. /// Author: Luxuri, Aleos
  17197. /**
  17198. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17199. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17200. */
  17201. void clif_achievement_list_all(struct map_session_data *sd)
  17202. {
  17203. nullpo_retv(sd);
  17204. if (!battle_config.feature_achievement) {
  17205. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17206. return;
  17207. }
  17208. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17209. if (count == 0)
  17210. return;
  17211. int len = (50 * count) + 22;
  17212. int fd = sd->fd;
  17213. int *info = achievement_level(sd, true);
  17214. WFIFOHEAD(fd,len);
  17215. WFIFOW(fd, 0) = 0xa23;
  17216. WFIFOW(fd, 2) = len;
  17217. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17218. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17219. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17220. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17221. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17222. for (int i = 0; i < count; i++) {
  17223. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17224. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17225. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17226. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17227. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17228. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17229. }
  17230. WFIFOSET(fd, len);
  17231. }
  17232. /**
  17233. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17234. * 0a24 <packetType>.W <ACHPoint>.L
  17235. */
  17236. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17237. {
  17238. nullpo_retv(sd);
  17239. if (!battle_config.feature_achievement) {
  17240. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17241. return;
  17242. }
  17243. int fd = sd->fd;
  17244. int *info = achievement_level(sd, true);
  17245. WFIFOHEAD(fd, packet_len(0xa24));
  17246. WFIFOW(fd, 0) = 0xa24;
  17247. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17248. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17249. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17250. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17251. if (ach) {
  17252. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17253. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17254. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17255. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17256. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17257. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17258. } else
  17259. memset(WFIFOP(fd, 16), 0, 40);
  17260. WFIFOSET(fd, packet_len(0xa24));
  17261. }
  17262. /**
  17263. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17264. * 0a25 <packetType>.W <achievementID>.L
  17265. */
  17266. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17267. {
  17268. nullpo_retv(sd);
  17269. if( sd->achievement_data.save )
  17270. intif_achievement_save(sd);
  17271. achievement_check_reward(sd, RFIFOL(fd,2));
  17272. }
  17273. /**
  17274. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17275. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17276. */
  17277. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17278. {
  17279. WFIFOHEAD(fd, packet_len(0xa26));
  17280. WFIFOW(fd, 0) = 0xa26;
  17281. WFIFOB(fd, 2) = result;
  17282. WFIFOL(fd, 3) = achievement_id;
  17283. WFIFOSET(fd, packet_len(0xa26));
  17284. }
  17285. /// Process the pet evolution request
  17286. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17287. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17288. #if PACKETVER >= 20141008
  17289. auto pet = pet_db_search(RFIFOW(fd, 4), PET_EGG);
  17290. if (!pet) {
  17291. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17292. return;
  17293. }
  17294. pet_evolution(sd, pet->class_);
  17295. #endif
  17296. }
  17297. /// Sends the result of the evolution to the client.
  17298. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17299. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17300. #if PACKETVER >= 20141008
  17301. int fd = sd->fd;
  17302. WFIFOHEAD(fd, packet_len(0x9fc));
  17303. WFIFOW(fd, 0) = 0x9fc;
  17304. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17305. WFIFOSET(fd, packet_len(0x9fc));
  17306. #endif
  17307. }
  17308. /*
  17309. * This packet is sent by /changedress or /nocosplay
  17310. *
  17311. * 0ae8
  17312. */
  17313. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17314. #if PACKETVER >= 20180103
  17315. char command[CHAT_SIZE_MAX];
  17316. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17317. is_atcommand( fd, sd, command, 1 );
  17318. #endif
  17319. }
  17320. /// Opens an UI window of the given type and initializes it with the given data
  17321. /// 0AE2 <type>.B <data>.L
  17322. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17323. nullpo_retv(sd);
  17324. int fd = sd->fd;
  17325. WFIFOHEAD(fd,packet_len(0xae2));
  17326. WFIFOW(fd,0) = 0xae2;
  17327. WFIFOB(fd,2) = ui_type;
  17328. WFIFOL(fd,3) = data;
  17329. WFIFOSET(fd,packet_len(0xae2));
  17330. }
  17331. /// Request to open an UI window of the given type
  17332. /// 0A68 <type>.B
  17333. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17334. switch( RFIFOB(fd,2) ){
  17335. case IN_UI_ATTENDANCE:
  17336. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17337. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17338. }else if( pc_attendance_enabled() ){
  17339. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17340. }else{
  17341. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17342. }
  17343. break;
  17344. }
  17345. }
  17346. /// Response for attedance request
  17347. /// 0AF0 <unknown>.L <data>.L
  17348. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17349. nullpo_retv(sd);
  17350. int fd = sd->fd;
  17351. WFIFOHEAD(fd,packet_len(0xAF0));
  17352. WFIFOW(fd,0) = 0xAF0;
  17353. WFIFOL(fd,2) = 0;
  17354. WFIFOL(fd,6) = data;
  17355. WFIFOSET(fd,packet_len(0xAF0));
  17356. }
  17357. /// Request from the client to retrieve today's attendance reward
  17358. /// 0AEF
  17359. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17360. pc_attendance_claim_reward(sd);
  17361. }
  17362. /// Send out the percentage of weight that causes it to be displayed in red.
  17363. /// 0ADE <percentage>.L
  17364. void clif_weight_limit( struct map_session_data* sd ){
  17365. #if PACKETVER >= 20171025
  17366. nullpo_retv(sd);
  17367. int fd = sd->fd;
  17368. WFIFOHEAD(fd, packet_len(0xADE));
  17369. WFIFOW(fd, 0) = 0xADE;
  17370. #ifdef RENEWAL
  17371. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17372. #else
  17373. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17374. #endif
  17375. WFIFOSET(fd, packet_len(0xADE));
  17376. #endif
  17377. }
  17378. enum e_private_airship_response : uint32{
  17379. PRIVATEAIRSHIP_OK,
  17380. PRIVATEAIRSHIP_RETRY,
  17381. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17382. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17383. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17384. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17385. };
  17386. /// Send out the response to a private airship request
  17387. /// 0A4A <response>.L
  17388. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17389. #if PACKETVER >= 20180321
  17390. nullpo_retv( sd );
  17391. int fd = sd->fd;
  17392. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17393. WFIFOW( fd, 0 ) = 0xA4A;
  17394. WFIFOL( fd, 2 ) = response;
  17395. WFIFOSET( fd, packet_len( 0xA4A ) );
  17396. #endif
  17397. }
  17398. /// Parses a request for a private airship
  17399. /// 0A49 <mapname>.16B <itemid>.W
  17400. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17401. #if PACKETVER >= 20180321
  17402. // Check if the feature is enabled
  17403. if( !battle_config.feature_privateairship ){
  17404. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17405. return;
  17406. }
  17407. // Check if the player is allowed to warp from the source map
  17408. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17409. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17410. return;
  17411. }
  17412. char mapname[MAP_NAME_LENGTH_EXT];
  17413. safestrncpy( mapname, RFIFOCP( fd, 2 ), MAP_NAME_LENGTH_EXT );
  17414. int16 mapindex = mapindex_name2id( mapname );
  17415. // Check if we know the mapname
  17416. if( mapindex < 0 ){
  17417. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17418. return;
  17419. }
  17420. int16 mapid = map_mapindex2mapid( mapindex );
  17421. // Check if the map is available on this server
  17422. if( mapid < 0 ){
  17423. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17424. return;
  17425. }
  17426. // Check if the player tried to warp to the map he is on
  17427. if( sd->bl.m == mapid ){
  17428. // This is blocked by the client, but just to be sure
  17429. return;
  17430. }
  17431. // This can only be a hack, so we prevent it
  17432. if( map_getmapdata( mapid )->instance_id ){
  17433. // Ignore requests to warp directly into a running instance
  17434. return;
  17435. }
  17436. // Check if the player is allowed to warp to the target map
  17437. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17438. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17439. return;
  17440. }
  17441. uint16 item_id = RFIFOW( fd, 2 + MAP_NAME_LENGTH_EXT );
  17442. // Check if the item sent by the client is known to us
  17443. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17444. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17445. return;
  17446. }
  17447. int idx = pc_search_inventory( sd, item_id );
  17448. // Check if the player has the item at all
  17449. if( idx < 0 ){
  17450. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17451. return;
  17452. }
  17453. // Delete the chosen item
  17454. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17455. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17456. return;
  17457. }
  17458. // Warp the player to a random spot on the destination map
  17459. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17460. #endif
  17461. }
  17462. /// Sends out the usage history of the guild storage
  17463. /// 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
  17464. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17465. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17466. #if PACKETVER >= 20140205
  17467. nullpo_retv( sd );
  17468. int fd = sd->fd;
  17469. int size = 8;
  17470. int sub = 83;
  17471. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17472. size += log.size() * sub;
  17473. }else{
  17474. log.clear();
  17475. }
  17476. WFIFOHEAD(fd, size);
  17477. WFIFOW(fd, 0) = 0x9DA;
  17478. WFIFOW(fd, 2) = size;
  17479. WFIFOW(fd, 4) = result;
  17480. WFIFOW(fd, 6) = (uint16)log.size();
  17481. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17482. for (int offset = 8, i = 0; i < log.size(); i++, offset += sub) {
  17483. struct guild_log_entry& entry = log[i];
  17484. uint16 viewid = itemdb_viewid( entry.item.nameid );
  17485. WFIFOL(fd, offset) = entry.id;
  17486. WFIFOW(fd, offset + 4) = viewid > 0 ? viewid : entry.item.nameid;
  17487. WFIFOL(fd, offset + 6) = (uint16)(entry.amount > 0 ? entry.amount : (entry.amount * -1));
  17488. WFIFOB(fd, offset + 10) = entry.amount > 0; // action = true(put), false(get)
  17489. WFIFOL(fd, offset + 11) = entry.item.refine;
  17490. WFIFOQ(fd, offset + 15) = entry.item.unique_id;
  17491. WFIFOB(fd, offset + 23) = entry.item.identify;
  17492. WFIFOW(fd, offset + 24) = itemtype(entry.item.nameid);
  17493. clif_addcards(WFIFOP(fd, offset + 26), &entry.item);
  17494. safestrncpy(WFIFOCP(fd, offset + 34), entry.name, NAME_LENGTH);
  17495. safestrncpy(WFIFOCP(fd, offset + 34 + NAME_LENGTH), entry.time, NAME_LENGTH);
  17496. WFIFOB(fd, offset + 34 + 2 * NAME_LENGTH) = entry.item.attribute;
  17497. }
  17498. }
  17499. WFIFOSET(fd, size);
  17500. #endif
  17501. }
  17502. /// Activates the client camera info or updates the client camera with the given values.
  17503. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17504. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17505. #if PACKETVER >= 20160525
  17506. int fd = sd->fd;
  17507. WFIFOHEAD(fd, packet_len(0xa78));
  17508. WFIFOW(fd, 0) = 0xa78;
  17509. WFIFOB(fd, 2) = show;
  17510. WFIFOF(fd, 3) = range;
  17511. WFIFOF(fd, 7) = rotation;
  17512. WFIFOF(fd, 11) = latitude;
  17513. WFIFOSET(fd, packet_len(0xa78));
  17514. #endif
  17515. }
  17516. /// Activates or deactives the client camera info or updates the camera settings.
  17517. /// This packet is triggered by /viewpointvalue or /setcamera
  17518. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17519. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17520. char command[CHAT_SIZE_MAX];
  17521. // /viewpointvalue
  17522. if( RFIFOB( fd, 2 ) == 1 ){
  17523. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17524. // /setcamera
  17525. }else{
  17526. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17527. }
  17528. is_atcommand( fd, sd, command, 1 );
  17529. }
  17530. /// Send the full list of items in the equip switch window
  17531. /// 0a9b <length>.W { <index>.W <position>.L }*
  17532. void clif_equipswitch_list( struct map_session_data* sd ){
  17533. #if PACKETVER >= 20170208
  17534. int fd = sd->fd;
  17535. int offset, i, position;
  17536. WFIFOW(fd, 0) = 0xa9b;
  17537. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17538. short index = sd->equip_switch_index[i];
  17539. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17540. WFIFOW(fd, offset) = index + 2;
  17541. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17542. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17543. offset += 6;
  17544. }
  17545. }
  17546. WFIFOW(fd, 2) = offset;
  17547. WFIFOSET(fd, offset);
  17548. #endif
  17549. }
  17550. /// Acknowledgement for removing an equip to the equip switch window
  17551. /// 0a9a <index>.W <position.>.L <failure>.W
  17552. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17553. #if PACKETVER >= 20170208
  17554. int fd = sd->fd;
  17555. WFIFOHEAD(fd, packet_len(0xa9a));
  17556. WFIFOW(fd, 0) = 0xa9a;
  17557. WFIFOW(fd, 2) = index + 2;
  17558. WFIFOL(fd, 4) = pos;
  17559. WFIFOW(fd, 8) = failed;
  17560. WFIFOSET(fd, packet_len(0xa9a));
  17561. #endif
  17562. }
  17563. /// Request to remove an equip from the equip switch window
  17564. /// 0a99 <index>.W <position>.L <= 20170502
  17565. /// 0a99 <index>.W
  17566. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17567. #if PACKETVER >= 20170208
  17568. uint16 index = RFIFOW(fd, 2) - 2;
  17569. bool removed = false;
  17570. if( !battle_config.feature_equipswitch ){
  17571. return;
  17572. }
  17573. // Check if the index is valid
  17574. if( index >= MAX_INVENTORY ){
  17575. return;
  17576. }
  17577. pc_equipswitch_remove( sd, index );
  17578. #endif
  17579. }
  17580. /// Acknowledgement for adding an equip to the equip switch window
  17581. /// 0a98 <index>.W <position.>.L <failure>.L <= 20170502
  17582. /// 0a98 <index>.W <position.>.L <failure>.W
  17583. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17584. #if PACKETVER >= 20170208
  17585. int fd = sd->fd;
  17586. WFIFOHEAD(fd, packet_len(0xa98));
  17587. WFIFOW(fd, 0) = 0xa98;
  17588. WFIFOW(fd, 2) = index + 2;
  17589. WFIFOL(fd, 4) = pos;
  17590. #if PACKETVER <= 20170502
  17591. WFIFOL(fd, 8) = failed;
  17592. #else
  17593. WFIFOW(fd, 8) = failed;
  17594. #endif
  17595. WFIFOSET(fd,packet_len(0xa98));
  17596. #endif
  17597. }
  17598. /// Request to add an equip to the equip switch window
  17599. /// 0a97 <index>.W <position>.L
  17600. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17601. #if PACKETVER >= 20170208
  17602. uint16 index = RFIFOW(fd, 2) - 2;
  17603. uint32 position = RFIFOL(fd, 4);
  17604. if( !battle_config.feature_equipswitch ){
  17605. return;
  17606. }
  17607. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17608. return;
  17609. }
  17610. if( sd->state.trading || sd->npc_shopid ){
  17611. clif_equipswitch_add( sd, index, position, true );
  17612. return;
  17613. }
  17614. if( sd->inventory_data[index]->type == IT_AMMO ){
  17615. position = EQP_AMMO;
  17616. }
  17617. pc_equipitem( sd, index, position, true );
  17618. #endif
  17619. }
  17620. /// Acknowledgement packet for the full equip switch
  17621. /// 0a9d <failed>.W
  17622. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17623. #if PACKETVER >= 20170208
  17624. int fd = sd->fd;
  17625. WFIFOHEAD(fd, packet_len(0xa9d));
  17626. WFIFOW(fd, 0) = 0xa9d;
  17627. WFIFOW(fd, 2) = failed;
  17628. WFIFOSET(fd, packet_len(0xa9d));
  17629. #endif
  17630. }
  17631. /// Request to do a full equip switch
  17632. /// 0a9c
  17633. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17634. #if PACKETVER >= 20170208
  17635. int i;
  17636. t_tick tick = gettick();
  17637. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17638. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17639. // Client will not let you send a request
  17640. return;
  17641. }
  17642. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17643. if( !battle_config.feature_equipswitch ){
  17644. return;
  17645. }
  17646. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17647. if( i == EQI_MAX ){
  17648. // client will show: "There is no item to replace." and should not even come here
  17649. clif_equipswitch_reply( sd, false );
  17650. return;
  17651. }
  17652. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17653. return;
  17654. }
  17655. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17656. #endif
  17657. }
  17658. /// Request to do a single equip switch
  17659. /// 0ace <index>.W
  17660. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17661. #if PACKETVER >= 20170502
  17662. uint16 index = RFIFOW(fd, 2) - 2;
  17663. if( !battle_config.feature_equipswitch ){
  17664. return;
  17665. }
  17666. // Check if the index is valid
  17667. if( index >= MAX_INVENTORY ){
  17668. return;
  17669. }
  17670. // Check if the item exists
  17671. if (sd->inventory_data[index] == nullptr)
  17672. return;
  17673. // Check if the item was already added to equip switch
  17674. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17675. if( sd->npc_id ){
  17676. #ifdef RENEWAL
  17677. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17678. clif_msg( sd, WORK_IN_PROGRESS );
  17679. return;
  17680. }
  17681. #endif
  17682. if( !sd->npc_item_flag ){
  17683. return;
  17684. }
  17685. }
  17686. pc_equipswitch( sd, index );
  17687. return;
  17688. }
  17689. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  17690. #endif
  17691. }
  17692. /*==========================================
  17693. * Main client packet processing function
  17694. *------------------------------------------*/
  17695. static int clif_parse(int fd)
  17696. {
  17697. int cmd, packet_len;
  17698. TBL_PC* sd;
  17699. int pnum;
  17700. #ifdef PACKET_OBFUSCATION
  17701. int cmd2;
  17702. #endif
  17703. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17704. // Note: "click masters" can do 80+ clicks in 10 seconds
  17705. 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]
  17706. { // begin main client packet processing loop
  17707. sd = (TBL_PC *)session[fd]->session_data;
  17708. if (session[fd]->flag.eof) {
  17709. if (sd) {
  17710. if (sd->state.autotrade) {
  17711. //Disassociate character from the socket connection.
  17712. session[fd]->session_data = NULL;
  17713. sd->fd = 0;
  17714. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17715. } else
  17716. if (sd->state.active) {
  17717. // Player logout display [Valaris]
  17718. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17719. clif_quitsave(fd, sd);
  17720. } else {
  17721. //Unusual logout (during log on/off/map-changer procedure)
  17722. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17723. map_quit(sd);
  17724. }
  17725. } else {
  17726. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17727. }
  17728. do_close(fd);
  17729. return 0;
  17730. }
  17731. if (RFIFOREST(fd) < 2)
  17732. return 0;
  17733. cmd = RFIFOW(fd, 0);
  17734. #ifdef PACKET_OBFUSCATION
  17735. // Check if it is a player that tries to connect to the map server.
  17736. if( sd ){
  17737. // Decrypt the current packet ID with the last key stored in the session.
  17738. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17739. }else{
  17740. // Store the original value for checking
  17741. cmd2 = cmd;
  17742. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17743. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17744. }
  17745. #endif
  17746. // filter out invalid / unsupported packets
  17747. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17748. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17749. #ifdef DUMP_INVALID_PACKET
  17750. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17751. #endif
  17752. #ifdef PACKET_OBFUSCATION_WARN
  17753. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17754. if( !sd ){
  17755. #ifdef PACKET_OBFUSCATION
  17756. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17757. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17758. }
  17759. #else
  17760. // Try to use the initial keys for the decryption of the packet ID.
  17761. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17762. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17763. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17764. }
  17765. #endif
  17766. }
  17767. #endif
  17768. set_eof(fd);
  17769. return 0;
  17770. }
  17771. // determine real packet length
  17772. packet_len = packet_db[cmd].len;
  17773. if (packet_len == -1) { // variable-length packet
  17774. if (RFIFOREST(fd) < 4)
  17775. return 0;
  17776. packet_len = RFIFOW(fd,2);
  17777. if (packet_len < 4 || packet_len > 32768) {
  17778. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17779. #ifdef DUMP_INVALID_PACKET
  17780. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17781. #endif
  17782. set_eof(fd);
  17783. return 0;
  17784. }
  17785. }
  17786. if ((int)RFIFOREST(fd) < packet_len)
  17787. return 0; // not enough data received to form the packet
  17788. #ifdef PACKET_OBFUSCATION
  17789. RFIFOW(fd, 0) = cmd;
  17790. if (sd)
  17791. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17792. #endif
  17793. if( packet_db[cmd].func == clif_parse_debug )
  17794. packet_db[cmd].func(fd, sd);
  17795. else if( packet_db[cmd].func != NULL ) {
  17796. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17797. ; //Only valid packet when there is no session
  17798. else
  17799. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17800. ; //Only valid packet when player is not on a map
  17801. else
  17802. packet_db[cmd].func(fd, sd);
  17803. }
  17804. #ifdef DUMP_UNKNOWN_PACKET
  17805. else DumpUnknown(fd,sd,cmd,packet_len);
  17806. #endif
  17807. RFIFOSKIP(fd, packet_len);
  17808. }; // main loop end
  17809. return 0;
  17810. }
  17811. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17812. va_list argp;
  17813. int i;
  17814. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17815. return;
  17816. packet_db[cmd].len = length;
  17817. packet_db[cmd].func = func;
  17818. va_start(argp, func);
  17819. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17820. int offset = va_arg(argp, int);
  17821. if( offset == 0 ){
  17822. break;
  17823. }
  17824. packet_db[cmd].pos[i] = offset;
  17825. }
  17826. if( i == MAX_PACKET_POS ){
  17827. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17828. }
  17829. va_end(argp);
  17830. }
  17831. /*==========================================
  17832. * Reads packets and setups its array reference
  17833. *------------------------------------------*/
  17834. void packetdb_readdb(){
  17835. memset(packet_db,0,sizeof(packet_db));
  17836. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17837. #include "clif_packetdb.hpp"
  17838. #include "clif_shuffle.hpp"
  17839. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17840. #ifdef PACKET_OBFUSCATION
  17841. 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]);
  17842. #else
  17843. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17844. #endif
  17845. }
  17846. /*==========================================
  17847. *
  17848. *------------------------------------------*/
  17849. void do_init_clif(void) {
  17850. const char* colors[COLOR_MAX] = {
  17851. "0x00FF00",
  17852. "0xFF0000",
  17853. "0xFFFFFF",
  17854. "0xFFFF00",
  17855. "0x00FFFF",
  17856. "0xB5FFB5",
  17857. };
  17858. int i;
  17859. /**
  17860. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17861. **/
  17862. for(i = 0; i < COLOR_MAX; i++) {
  17863. color_table[i] = strtoul(colors[i],NULL,0);
  17864. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17865. }
  17866. packetdb_readdb();
  17867. set_defaultparse(clif_parse);
  17868. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17869. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17870. exit(EXIT_FAILURE);
  17871. }
  17872. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17873. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17874. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17875. }
  17876. void do_final_clif(void) {
  17877. ers_destroy(delay_clearunit_ers);
  17878. }