clif.cpp 595 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125
  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. /// 13 = multi-hit critical
  4227. 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)
  4228. {
  4229. unsigned char buf[34];
  4230. struct status_change *sc;
  4231. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4232. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4233. #if PACKETVER < 20071113
  4234. const int cmd = 0x8a;
  4235. int offset = 0;
  4236. #elif PACKETVER < 20131223
  4237. const int cmd = 0x2e1;
  4238. int offset = 2;
  4239. #else
  4240. const int cmd = 0x8c8;
  4241. int offset = 3;
  4242. #endif
  4243. nullpo_ret(src);
  4244. nullpo_ret(dst);
  4245. if (type != DMG_MULTI_HIT_CRITICAL)
  4246. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4247. sc = status_get_sc(dst);
  4248. if(sc && sc->count) {
  4249. if(sc->data[SC_HALLUCINATION]) {
  4250. if(damage) damage = clif_hallucination_damage();
  4251. if(damage2) damage2 = clif_hallucination_damage();
  4252. }
  4253. }
  4254. WBUFW(buf,0) = cmd;
  4255. WBUFL(buf,2) = src->id;
  4256. WBUFL(buf,6) = dst->id;
  4257. WBUFL(buf,10) = client_tick(tick);
  4258. WBUFL(buf,14) = sdelay;
  4259. WBUFL(buf,18) = ddelay;
  4260. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4261. #if PACKETVER < 20071113
  4262. WBUFW(buf,22) = damage ? div : 0;
  4263. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4264. #else
  4265. WBUFL(buf, 22) = damage ? div : 0;
  4266. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4267. #endif
  4268. } else {
  4269. #if PACKETVER < 20071113
  4270. WBUFW(buf,22) = min(damage, INT16_MAX);
  4271. WBUFW(buf,27+offset) = damage2;
  4272. #else
  4273. WBUFL(buf,22) = damage;
  4274. WBUFL(buf,27+offset) = damage2;
  4275. #endif
  4276. }
  4277. #if PACKETVER >= 20131223
  4278. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4279. #endif
  4280. WBUFW(buf,24+offset) = div;
  4281. WBUFB(buf,26+offset) = type;
  4282. if(disguised(dst)) {
  4283. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4284. WBUFL(buf,6) = -dst->id;
  4285. clif_send(buf, packet_len(cmd), dst, SELF);
  4286. } else
  4287. clif_send(buf, packet_len(cmd), dst, AREA);
  4288. if(disguised(src)) {
  4289. WBUFL(buf,2) = -src->id;
  4290. if (disguised(dst))
  4291. WBUFL(buf,6) = dst->id;
  4292. #if PACKETVER < 20071113
  4293. if(damage > 0) WBUFW(buf,22) = -1;
  4294. if(damage2 > 0) WBUFW(buf,27) = -1;
  4295. #else
  4296. if(damage > 0) WBUFL(buf,22) = -1;
  4297. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4298. #endif
  4299. clif_send(buf,packet_len(cmd),src,SELF);
  4300. }
  4301. if(src == dst) {
  4302. unit_setdir(src, unit_getdir(src));
  4303. }
  4304. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4305. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4306. //Return adjusted can't walk delay for further processing.
  4307. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4308. }
  4309. /*==========================================
  4310. * src picks up dst
  4311. *------------------------------------------*/
  4312. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4313. {
  4314. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4315. unsigned char buf[32];
  4316. nullpo_retv(src);
  4317. nullpo_retv(dst);
  4318. WBUFW(buf, 0) = 0x8a;
  4319. WBUFL(buf, 2) = src->id;
  4320. WBUFL(buf, 6) = dst->id;
  4321. WBUFB(buf,26) = 1;
  4322. clif_send(buf, packet_len(0x8a), src, AREA);
  4323. }
  4324. /*==========================================
  4325. * inform clients in area that `bl` is sitting
  4326. *------------------------------------------*/
  4327. void clif_sitting(struct block_list* bl)
  4328. {
  4329. unsigned char buf[32];
  4330. nullpo_retv(bl);
  4331. WBUFW(buf, 0) = 0x8a;
  4332. WBUFL(buf, 2) = bl->id;
  4333. WBUFB(buf,26) = 2;
  4334. clif_send(buf, packet_len(0x8a), bl, AREA);
  4335. if(disguised(bl)) {
  4336. WBUFL(buf, 2) = - bl->id;
  4337. clif_send(buf, packet_len(0x8a), bl, SELF);
  4338. }
  4339. }
  4340. /*==========================================
  4341. * inform clients in area that `bl` is standing
  4342. *------------------------------------------*/
  4343. void clif_standing(struct block_list* bl)
  4344. {
  4345. unsigned char buf[32];
  4346. nullpo_retv(bl);
  4347. WBUFW(buf, 0) = 0x8a;
  4348. WBUFL(buf, 2) = bl->id;
  4349. WBUFB(buf,26) = 3;
  4350. clif_send(buf, packet_len(0x8a), bl, AREA);
  4351. if(disguised(bl)) {
  4352. WBUFL(buf, 2) = - bl->id;
  4353. clif_send(buf, packet_len(0x8a), bl, SELF);
  4354. }
  4355. }
  4356. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4357. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4358. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4359. {
  4360. unsigned char buf[32];
  4361. WBUFW(buf,0) = 0x192;
  4362. WBUFW(buf,2) = x;
  4363. WBUFW(buf,4) = y;
  4364. WBUFW(buf,6) = type;
  4365. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4366. if( fd )
  4367. {
  4368. WFIFOHEAD(fd,packet_len(0x192));
  4369. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4370. WFIFOSET(fd,packet_len(0x192));
  4371. }
  4372. else
  4373. {
  4374. struct block_list dummy_bl;
  4375. dummy_bl.type = BL_NUL;
  4376. dummy_bl.x = x;
  4377. dummy_bl.y = y;
  4378. dummy_bl.m = m;
  4379. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4380. }
  4381. }
  4382. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4383. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4384. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4385. {
  4386. int view,fd;
  4387. fd=sd->fd;
  4388. WFIFOHEAD(fd,packet_len(0x9d));
  4389. WFIFOW(fd,0)=0x9d;
  4390. WFIFOL(fd,2)=fitem->bl.id;
  4391. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4392. WFIFOW(fd,6)=view;
  4393. else
  4394. WFIFOW(fd,6)=fitem->item.nameid;
  4395. WFIFOB(fd,8)=fitem->item.identify;
  4396. WFIFOW(fd,9)=fitem->bl.x;
  4397. WFIFOW(fd,11)=fitem->bl.y;
  4398. WFIFOW(fd,13)=fitem->item.amount;
  4399. WFIFOB(fd,15)=fitem->subx;
  4400. WFIFOB(fd,16)=fitem->suby;
  4401. WFIFOSET(fd,packet_len(0x9d));
  4402. }
  4403. /// Notifes client about Graffiti
  4404. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4405. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4406. unsigned char buf[128];
  4407. nullpo_retv(bl);
  4408. nullpo_retv(unit);
  4409. WBUFW(buf, 0) = 0x1c9;
  4410. WBUFL(buf, 2) = unit->bl.id;
  4411. WBUFL(buf, 6) = unit->group->src_id;
  4412. WBUFW(buf,10) = unit->bl.x;
  4413. WBUFW(buf,12) = unit->bl.y;
  4414. WBUFB(buf,14) = unit->group->unit_id;
  4415. WBUFB(buf,15) = 1;
  4416. WBUFB(buf,16) = 1;
  4417. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4418. clif_send(buf,packet_len(0x1c9),bl,target);
  4419. }
  4420. /// Notifies the client of a skill unit.
  4421. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4422. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4423. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4424. /// 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)
  4425. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4426. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4427. unsigned char buf[128];
  4428. nullpo_retv(bl);
  4429. nullpo_retv(unit);
  4430. if (bl->type == BL_PC)
  4431. fd = ((TBL_PC*)bl)->fd;
  4432. if (unit->group->state.guildaura)
  4433. return;
  4434. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4435. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4436. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4437. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4438. else
  4439. unit_id = unit->group->unit_id;
  4440. if (!visible)
  4441. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4442. #if PACKETVER >= 3
  4443. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4444. clif_graffiti(bl, unit, target);
  4445. return;
  4446. }
  4447. #endif
  4448. #if PACKETVER <= 20120702
  4449. header = 0x011f;
  4450. //#if PACKETVER < 20110718
  4451. // header = 0x011f;
  4452. //#elif PACKETVER < 20121212
  4453. // header = 0x08c7;
  4454. #elif PACKETVER < 20130731
  4455. header = 0x099f;
  4456. #else
  4457. header = 0x09ca;
  4458. #endif
  4459. len = packet_len(header);
  4460. WBUFW(buf,pos) = header;
  4461. if (header != 0x011f) {
  4462. WBUFW(buf, pos+2) = len;
  4463. pos += 2;
  4464. }
  4465. WBUFL(buf,pos+2) = unit->bl.id;
  4466. WBUFL(buf,pos+6) = unit->group->src_id;
  4467. WBUFW(buf,pos+10) = unit->bl.x;
  4468. WBUFW(buf,pos+12) = unit->bl.y;
  4469. switch (header) {
  4470. case 0x011f:
  4471. WBUFB(buf,pos+14) = unit_id;
  4472. WBUFB(buf,pos+15) = visible;
  4473. break;
  4474. case 0x08c7:
  4475. WBUFB(buf,pos+14) = unit_id;
  4476. WBUFW(buf,pos+15) = unit->range;
  4477. WBUFB(buf,pos+17) = visible;
  4478. break;
  4479. case 0x099f:
  4480. WBUFL(buf,pos+14) = unit_id;
  4481. WBUFW(buf,pos+18) = unit->range;
  4482. WBUFB(buf,pos+20) = visible;
  4483. break;
  4484. case 0x09ca:
  4485. WBUFL(buf,pos+14) = unit_id;
  4486. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4487. WBUFB(buf,pos+19) = visible;
  4488. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4489. break;
  4490. }
  4491. clif_send(buf, len, bl, target);
  4492. if (unit->group->skill_id == WZ_ICEWALL)
  4493. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4494. }
  4495. /*==========================================
  4496. * Server tells client to remove unit of id 'unit->bl.id'
  4497. *------------------------------------------*/
  4498. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4499. {
  4500. nullpo_retv(unit);
  4501. WFIFOHEAD(fd,packet_len(0x120));
  4502. WFIFOW(fd, 0)=0x120;
  4503. WFIFOL(fd, 2)=unit->bl.id;
  4504. WFIFOSET(fd,packet_len(0x120));
  4505. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4506. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4507. }
  4508. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4509. /// 0120 <id>.L
  4510. void clif_skill_delunit(struct skill_unit *unit)
  4511. {
  4512. unsigned char buf[16];
  4513. nullpo_retv(unit);
  4514. WBUFW(buf, 0)=0x120;
  4515. WBUFL(buf, 2)=unit->bl.id;
  4516. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4517. }
  4518. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4519. /// 01ac <id>.L
  4520. /// Only affects units with class [139,153] client-side.
  4521. void clif_skillunit_update(struct block_list* bl)
  4522. {
  4523. unsigned char buf[6];
  4524. nullpo_retv(bl);
  4525. WBUFW(buf,0) = 0x1ac;
  4526. WBUFL(buf,2) = bl->id;
  4527. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4528. }
  4529. /*==========================================
  4530. *
  4531. *------------------------------------------*/
  4532. static int clif_getareachar(struct block_list* bl,va_list ap)
  4533. {
  4534. struct map_session_data *sd;
  4535. nullpo_ret(bl);
  4536. sd=va_arg(ap,struct map_session_data*);
  4537. if (sd == NULL || !sd->fd)
  4538. return 0;
  4539. switch(bl->type){
  4540. case BL_ITEM:
  4541. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4542. break;
  4543. case BL_SKILL:
  4544. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4545. break;
  4546. default:
  4547. if(&sd->bl == bl)
  4548. break;
  4549. clif_getareachar_unit(sd,bl);
  4550. break;
  4551. }
  4552. return 0;
  4553. }
  4554. /*==========================================
  4555. * tbl has gone out of view-size of bl
  4556. *------------------------------------------*/
  4557. int clif_outsight(struct block_list *bl,va_list ap)
  4558. {
  4559. struct block_list *tbl;
  4560. struct view_data *vd;
  4561. TBL_PC *sd, *tsd;
  4562. tbl=va_arg(ap,struct block_list*);
  4563. if(bl == tbl) return 0;
  4564. sd = BL_CAST(BL_PC, bl);
  4565. tsd = BL_CAST(BL_PC, tbl);
  4566. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4567. nullpo_ret(bl);
  4568. switch(bl->type){
  4569. case BL_PC:
  4570. if(sd->vd.class_ != JT_INVISIBLE)
  4571. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4572. if(sd->chatID){
  4573. struct chat_data *cd;
  4574. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4575. if(cd->usersd[0]==sd)
  4576. clif_dispchat(cd,tsd->fd);
  4577. }
  4578. if(sd->state.vending)
  4579. clif_closevendingboard(bl,tsd->fd);
  4580. if(sd->state.buyingstore)
  4581. clif_buyingstore_disappear_entry_single(tsd, sd);
  4582. break;
  4583. case BL_ITEM:
  4584. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4585. break;
  4586. case BL_SKILL:
  4587. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4588. break;
  4589. case BL_NPC:
  4590. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4591. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4592. break;
  4593. default:
  4594. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4595. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4596. break;
  4597. }
  4598. }
  4599. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4600. nullpo_ret(tbl);
  4601. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4602. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4603. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4604. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4605. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4606. }
  4607. return 0;
  4608. }
  4609. /*==========================================
  4610. * tbl has come into view of bl
  4611. *------------------------------------------*/
  4612. int clif_insight(struct block_list *bl,va_list ap)
  4613. {
  4614. struct block_list *tbl;
  4615. TBL_PC *sd, *tsd;
  4616. tbl=va_arg(ap,struct block_list*);
  4617. if (bl == tbl) return 0;
  4618. sd = BL_CAST(BL_PC, bl);
  4619. tsd = BL_CAST(BL_PC, tbl);
  4620. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4621. switch(bl->type){
  4622. case BL_ITEM:
  4623. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4624. break;
  4625. case BL_SKILL:
  4626. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4627. break;
  4628. default:
  4629. clif_getareachar_unit(tsd,bl);
  4630. break;
  4631. }
  4632. }
  4633. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4634. clif_getareachar_unit(sd,tbl);
  4635. }
  4636. return 0;
  4637. }
  4638. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4639. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4640. void clif_skillinfoblock(struct map_session_data *sd)
  4641. {
  4642. int fd;
  4643. int i,len,id;
  4644. nullpo_retv(sd);
  4645. fd = sd->fd;
  4646. if (!fd)
  4647. return;
  4648. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4649. WFIFOW(fd,0) = 0x10f;
  4650. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4651. {
  4652. if( (id = sd->status.skill[i].id) != 0 )
  4653. {
  4654. // workaround for bugreport:5348
  4655. if (len + 37 > 8192)
  4656. break;
  4657. WFIFOW(fd,len) = id;
  4658. WFIFOL(fd,len+2) = skill_get_inf(id);
  4659. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4660. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4661. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4662. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4663. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4664. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4665. else
  4666. WFIFOB(fd,len+36) = 0;
  4667. len += 37;
  4668. }
  4669. }
  4670. WFIFOW(fd,2)=len;
  4671. WFIFOSET(fd,len);
  4672. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4673. for ( ; i < MAX_SKILL; i++)
  4674. {
  4675. if( (id = sd->status.skill[i].id) != 0 )
  4676. {
  4677. clif_addskill(sd, id);
  4678. clif_skillinfo(sd, id, 0);
  4679. }
  4680. }
  4681. }
  4682. /**
  4683. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4684. **/
  4685. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4686. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4687. void clif_addskill(struct map_session_data *sd, int skill_id)
  4688. {
  4689. int fd;
  4690. uint16 idx = 0;
  4691. nullpo_retv(sd);
  4692. fd = sd->fd;
  4693. if (!fd || !(idx = skill_get_index(skill_id)))
  4694. return;
  4695. if( sd->status.skill[idx].id <= 0 )
  4696. return;
  4697. WFIFOHEAD(fd, packet_len(0x111));
  4698. WFIFOW(fd,0) = 0x111;
  4699. WFIFOW(fd,2) = skill_id;
  4700. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4701. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4702. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4703. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4704. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4705. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4706. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4707. else
  4708. WFIFOB(fd,38) = 0;
  4709. WFIFOSET(fd,packet_len(0x111));
  4710. }
  4711. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4712. /// 0441 <skill id>.W
  4713. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4714. {
  4715. #if PACKETVER >= 20081217
  4716. int fd;
  4717. uint16 idx = 0;
  4718. nullpo_retv(sd);
  4719. fd = sd->fd;
  4720. if (!fd || !(idx = skill_get_index(skill_id)))
  4721. return;
  4722. WFIFOHEAD(fd,packet_len(0x441));
  4723. WFIFOW(fd,0) = 0x441;
  4724. WFIFOW(fd,2) = skill_id;
  4725. WFIFOSET(fd,packet_len(0x441));
  4726. #endif
  4727. clif_skillinfoblock(sd);
  4728. }
  4729. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4730. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4731. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4732. int fd;
  4733. nullpo_retv(sd);
  4734. fd = sd->fd;
  4735. WFIFOHEAD(fd, packet_len(0x10e));
  4736. WFIFOW(fd, 0) = 0x10e;
  4737. WFIFOW(fd, 2) = skill_id;
  4738. WFIFOW(fd, 4) = lv;
  4739. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4740. WFIFOW(fd, 8) = range;
  4741. WFIFOB(fd, 10) = upgradable;
  4742. WFIFOSET(fd, packet_len(0x10e));
  4743. }
  4744. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4745. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4746. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4747. {
  4748. const int fd = sd->fd;
  4749. uint16 idx = skill_get_index(skill_id);
  4750. if (!idx)
  4751. return;
  4752. WFIFOHEAD(fd,packet_len(0x7e1));
  4753. WFIFOW(fd,0) = 0x7e1;
  4754. WFIFOW(fd,2) = skill_id;
  4755. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4756. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4757. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4758. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4759. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4760. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4761. else
  4762. WFIFOB(fd,14) = 0;
  4763. WFIFOSET(fd,packet_len(0x7e1));
  4764. }
  4765. /// Notifies clients in area, that an object is about to use a skill.
  4766. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4767. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4768. /// property:
  4769. /// 0 = Yellow cast aura
  4770. /// 1 = Water elemental cast aura
  4771. /// 2 = Earth elemental cast aura
  4772. /// 3 = Fire elemental cast aura
  4773. /// 4 = Wind elemental cast aura
  4774. /// 5 = Poison elemental cast aura
  4775. /// 6 = Holy elemental cast aura
  4776. /// ? = like 0
  4777. /// is disposable:
  4778. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4779. /// 1 = no text
  4780. 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)
  4781. {
  4782. #if PACKETVER < 20091124
  4783. const int cmd = 0x13e;
  4784. #else
  4785. const int cmd = 0x7fb;
  4786. #endif
  4787. unsigned char buf[32];
  4788. WBUFW(buf,0) = cmd;
  4789. WBUFL(buf,2) = src_id;
  4790. WBUFL(buf,6) = dst_id;
  4791. WBUFW(buf,10) = dst_x;
  4792. WBUFW(buf,12) = dst_y;
  4793. WBUFW(buf,14) = skill_id;
  4794. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4795. WBUFL(buf,20) = casttime;
  4796. #if PACKETVER >= 20091124
  4797. WBUFB(buf,24) = 0; // isDisposable
  4798. #endif
  4799. if (disguised(bl)) {
  4800. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4801. WBUFL(buf,2) = -src_id;
  4802. clif_send(buf,packet_len(cmd), bl, SELF);
  4803. } else
  4804. clif_send(buf,packet_len(cmd), bl, AREA);
  4805. }
  4806. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4807. /// 01b9 <id>.L
  4808. void clif_skillcastcancel(struct block_list* bl)
  4809. {
  4810. unsigned char buf[16];
  4811. nullpo_retv(bl);
  4812. WBUFW(buf,0) = 0x1b9;
  4813. WBUFL(buf,2) = bl->id;
  4814. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4815. }
  4816. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4817. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4818. /// num (only used when skill id = NV_BASIC and cause = 0):
  4819. /// 0 = "skill failed" MsgStringTable[159]
  4820. /// 1 = "no emotions" MsgStringTable[160]
  4821. /// 2 = "no sit" MsgStringTable[161]
  4822. /// 3 = "no chat" MsgStringTable[162]
  4823. /// 4 = "no party" MsgStringTable[163]
  4824. /// 5 = "no shout" MsgStringTable[164]
  4825. /// 6 = "no PKing" MsgStringTable[165]
  4826. /// 7 = "no alligning" MsgStringTable[383]
  4827. /// ? = ignored
  4828. /// cause:
  4829. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4830. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4831. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4832. /// "skill failed" MsgStringTable[204] (otherwise)
  4833. /// ... = @see enum useskill_fail_cause
  4834. /// ? = ignored
  4835. ///
  4836. /// if(result!=0) doesn't display any of the previous messages
  4837. /// Note: when this packet is received an unknown flag is always set to 0,
  4838. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4839. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4840. {
  4841. int fd;
  4842. if (!sd) { //Since this is the most common nullpo....
  4843. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4844. return;
  4845. }
  4846. fd=sd->fd;
  4847. if (!fd) return;
  4848. if(battle_config.display_skill_fail&1)
  4849. return; //Disable all skill failed messages
  4850. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4851. return; //Disable delay failed messages
  4852. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4853. return;
  4854. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4855. return;
  4856. WFIFOHEAD(fd,packet_len(0x110));
  4857. WFIFOW(fd,0) = 0x110;
  4858. WFIFOW(fd,2) = skill_id;
  4859. WFIFOL(fd,4) = btype;
  4860. WFIFOB(fd,8) = 0;// success
  4861. WFIFOB(fd,9) = cause;
  4862. WFIFOSET(fd,packet_len(0x110));
  4863. }
  4864. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4865. /// 043d <skill ID>.W <tick>.L
  4866. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, t_tick tick)
  4867. {
  4868. #if PACKETVER>=20081112
  4869. int fd;
  4870. nullpo_retv(sd);
  4871. fd=sd->fd;
  4872. WFIFOHEAD(fd,packet_len(0x43d));
  4873. WFIFOW(fd,0) = 0x43d;
  4874. WFIFOW(fd,2) = skill_id;
  4875. WFIFOL(fd,4) = client_tick(tick);
  4876. WFIFOSET(fd,packet_len(0x43d));
  4877. #endif
  4878. }
  4879. /// Skill attack effect and damage.
  4880. /// 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)
  4881. /// 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)
  4882. 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)
  4883. {
  4884. unsigned char buf[64];
  4885. struct status_change *sc;
  4886. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4887. nullpo_ret(src);
  4888. nullpo_ret(dst);
  4889. type = clif_calc_delay(type,div,damage,ddelay);
  4890. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4891. if(sc->data[SC_HALLUCINATION] && damage)
  4892. damage = clif_hallucination_damage();
  4893. }
  4894. #if PACKETVER < 3
  4895. WBUFW(buf,0)=0x114;
  4896. WBUFW(buf,2)=skill_id;
  4897. WBUFL(buf,4)=src->id;
  4898. WBUFL(buf,8)=dst->id;
  4899. WBUFL(buf,12)=client_tick(tick);
  4900. WBUFL(buf,16)=sdelay;
  4901. WBUFL(buf,20)=ddelay;
  4902. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4903. WBUFW(buf,24)=damage?div:0;
  4904. } else {
  4905. WBUFW(buf,24)=damage;
  4906. }
  4907. WBUFW(buf,26)=skill_lv;
  4908. WBUFW(buf,28)=div;
  4909. WBUFB(buf,30)=type;
  4910. if (disguised(dst)) {
  4911. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4912. WBUFL(buf,8)=-dst->id;
  4913. clif_send(buf,packet_len(0x114),dst,SELF);
  4914. } else
  4915. clif_send(buf,packet_len(0x114),dst,AREA);
  4916. if(disguised(src)) {
  4917. WBUFL(buf,4)=-src->id;
  4918. if (disguised(dst))
  4919. WBUFL(buf,8)=dst->id;
  4920. if(damage > 0)
  4921. WBUFW(buf,24)=-1;
  4922. clif_send(buf,packet_len(0x114),src,SELF);
  4923. }
  4924. #else
  4925. WBUFW(buf,0)=0x1de;
  4926. WBUFW(buf,2)=skill_id;
  4927. WBUFL(buf,4)=src->id;
  4928. WBUFL(buf,8)=dst->id;
  4929. WBUFL(buf,12)=client_tick(tick);
  4930. WBUFL(buf,16)=sdelay;
  4931. WBUFL(buf,20)=ddelay;
  4932. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4933. WBUFL(buf,24)=damage?div:0;
  4934. } else {
  4935. WBUFL(buf,24)=damage;
  4936. }
  4937. WBUFW(buf,28)=skill_lv;
  4938. WBUFW(buf,30)=div;
  4939. // For some reason, late 2013 and newer clients have
  4940. // a issue that causes players and monsters to endure
  4941. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4942. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4943. #if PACKETVER < 20131223
  4944. WBUFB(buf,32)=type;
  4945. #else
  4946. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4947. #endif
  4948. if (disguised(dst)) {
  4949. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4950. WBUFL(buf,8)=-dst->id;
  4951. clif_send(buf,packet_len(0x1de),dst,SELF);
  4952. } else
  4953. clif_send(buf,packet_len(0x1de),dst,AREA);
  4954. if(disguised(src)) {
  4955. WBUFL(buf,4)=-src->id;
  4956. if (disguised(dst))
  4957. WBUFL(buf,8)=dst->id;
  4958. if(damage > 0)
  4959. WBUFL(buf,24)=-1;
  4960. clif_send(buf,packet_len(0x1de),src,SELF);
  4961. }
  4962. #endif
  4963. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4964. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4965. }
  4966. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4967. /// 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
  4968. /*
  4969. 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)
  4970. {
  4971. unsigned char buf[64];
  4972. struct status_change *sc;
  4973. nullpo_ret(src);
  4974. nullpo_ret(dst);
  4975. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4976. type = clif_calc_delay(type,div,damage,ddelay);
  4977. sc = status_get_sc(dst);
  4978. if(sc && sc->count) {
  4979. if(sc->data[SC_HALLUCINATION] && damage)
  4980. damage = clif_hallucination_damage();
  4981. }
  4982. WBUFW(buf,0)=0x115;
  4983. WBUFW(buf,2)=skill_id;
  4984. WBUFL(buf,4)=src->id;
  4985. WBUFL(buf,8)=dst->id;
  4986. WBUFL(buf,12)=client_tick(tick);
  4987. WBUFL(buf,16)=sdelay;
  4988. WBUFL(buf,20)=ddelay;
  4989. WBUFW(buf,24)=dst->x;
  4990. WBUFW(buf,26)=dst->y;
  4991. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4992. WBUFW(buf,28)=damage?div:0;
  4993. } else {
  4994. WBUFW(buf,28)=damage;
  4995. }
  4996. WBUFW(buf,30)=skill_lv;
  4997. WBUFW(buf,32)=div;
  4998. WBUFB(buf,34)=type;
  4999. clif_send(buf,packet_len(0x115),src,AREA);
  5000. if(disguised(src)) {
  5001. WBUFL(buf,4)=-src->id;
  5002. if(damage > 0)
  5003. WBUFW(buf,28)=-1;
  5004. clif_send(buf,packet_len(0x115),src,SELF);
  5005. }
  5006. if (disguised(dst)) {
  5007. WBUFL(buf,8)=-dst->id;
  5008. if (disguised(src))
  5009. WBUFL(buf,4)=src->id;
  5010. else if(damage > 0)
  5011. WBUFW(buf,28)=-1;
  5012. clif_send(buf,packet_len(0x115),dst,SELF);
  5013. }
  5014. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5015. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5016. }
  5017. */
  5018. /// Non-damaging skill effect
  5019. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5020. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5021. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5022. {
  5023. unsigned char buf[17];
  5024. #if PACKETVER < 20130731
  5025. const int cmd = 0x11a;
  5026. #else
  5027. const int cmd = 0x9cb;
  5028. #endif
  5029. int offset = 0;
  5030. bool success = ( tick != 0 );
  5031. nullpo_ret(dst);
  5032. WBUFW(buf,0) = cmd;
  5033. WBUFW(buf,2) = skill_id;
  5034. #if PACKETVER < 20130731
  5035. WBUFW(buf,4) = min(heal, INT16_MAX);
  5036. #else
  5037. WBUFL(buf,4) = min(heal, INT32_MAX);
  5038. offset += 2;
  5039. #endif
  5040. WBUFL(buf,6+offset) = dst->id;
  5041. WBUFL(buf,10+offset) = src ? src->id : 0;
  5042. WBUFB(buf,14+offset) = success;
  5043. if (disguised(dst)) {
  5044. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5045. WBUFL(buf,6+offset) = -dst->id;
  5046. clif_send(buf, packet_len(cmd), dst, SELF);
  5047. } else
  5048. clif_send(buf, packet_len(cmd), dst, AREA);
  5049. if(src && disguised(src)) {
  5050. WBUFL(buf,10+offset) = -src->id;
  5051. if (disguised(dst))
  5052. WBUFL(buf,6+offset) = dst->id;
  5053. clif_send(buf, packet_len(cmd), src, SELF);
  5054. }
  5055. return success;
  5056. }
  5057. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5058. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5059. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5060. {
  5061. unsigned char buf[32];
  5062. nullpo_retv(src);
  5063. WBUFW(buf,0)=0x117;
  5064. WBUFW(buf,2)=skill_id;
  5065. WBUFL(buf,4)=src->id;
  5066. WBUFW(buf,8)=val;
  5067. WBUFW(buf,10)=x;
  5068. WBUFW(buf,12)=y;
  5069. WBUFL(buf,14)=client_tick(tick);
  5070. if(disguised(src)) {
  5071. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5072. WBUFL(buf,4)=-src->id;
  5073. clif_send(buf,packet_len(0x117),src,SELF);
  5074. } else
  5075. clif_send(buf,packet_len(0x117),src,AREA);
  5076. }
  5077. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5078. /// 011c <skill id>.W { <map name>.16B }*4
  5079. 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)
  5080. {
  5081. int fd;
  5082. nullpo_retv(sd);
  5083. fd = sd->fd;
  5084. WFIFOHEAD(fd,packet_len(0x11c));
  5085. WFIFOW(fd,0) = 0x11c;
  5086. WFIFOW(fd,2) = skill_id;
  5087. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5088. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5089. else // normal map name
  5090. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5091. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5092. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5093. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5094. WFIFOSET(fd,packet_len(0x11c));
  5095. sd->menuskill_id = skill_id;
  5096. if (skill_id == AL_WARP) {
  5097. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5098. sd->state.workinprogress = WIP_DISABLE_ALL;
  5099. } else
  5100. sd->menuskill_val = skill_lv;
  5101. }
  5102. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5103. /// 011e <type>.B
  5104. /// type:
  5105. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5106. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5107. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5108. ///
  5109. /// @param sd Who receives the message
  5110. /// @param type What message
  5111. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5112. {
  5113. int fd;
  5114. nullpo_retv(sd);
  5115. fd=sd->fd;
  5116. WFIFOHEAD(fd,packet_len(0x11e));
  5117. WFIFOW(fd,0)=0x11e;
  5118. WFIFOB(fd,2)=type;
  5119. WFIFOSET(fd,packet_len(0x11e));
  5120. }
  5121. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5122. /// 0189 <type>.W
  5123. /// type:
  5124. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5125. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5126. ///
  5127. /// @param sd Who receives the message
  5128. /// @param type What message
  5129. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5130. {
  5131. int fd;
  5132. nullpo_retv(sd);
  5133. fd=sd->fd;
  5134. WFIFOHEAD(fd,packet_len(0x189));
  5135. WFIFOW(fd,0)=0x189;
  5136. WFIFOW(fd,2)=type;
  5137. WFIFOSET(fd,packet_len(0x189));
  5138. }
  5139. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5140. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5141. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5142. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5143. {
  5144. struct status_data *status;
  5145. unsigned char buf[64];
  5146. int i, fix;
  5147. nullpo_retv(sd);
  5148. nullpo_retv(dst);
  5149. if( dst->type != BL_MOB )
  5150. return;
  5151. status = status_get_status_data(dst);
  5152. WBUFW(buf, 0)=0x18c;
  5153. WBUFW(buf, 2)=status_get_class(dst);
  5154. WBUFW(buf, 4)=status_get_lv(dst);
  5155. WBUFW(buf, 6)=status->size;
  5156. WBUFL(buf, 8)=status->hp;
  5157. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5158. +(battle_config.estimation_type&2?status->def2:0);
  5159. WBUFW(buf,14)=status->race;
  5160. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5161. +(battle_config.estimation_type&2?status->mdef2:0);
  5162. WBUFW(buf,18)= status->def_ele;
  5163. for(i=0;i<9;i++)
  5164. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5165. WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5166. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5167. }
  5168. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5169. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5170. /// material id:
  5171. /// unused by the client
  5172. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5173. {
  5174. int i,c,view,fd;
  5175. nullpo_retv(sd);
  5176. if (sd->menuskill_id == skill_id)
  5177. return; //Avoid resending the menu twice or more times...
  5178. if (skill_id == GC_CREATENEWPOISON)
  5179. skill_id = GC_RESEARCHNEWPOISON;
  5180. fd = sd->fd;
  5181. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5182. WFIFOW(fd, 0) = 0x18d;
  5183. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5184. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5185. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5186. )
  5187. {
  5188. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5189. WFIFOW(fd,c*8+ 4) = view;
  5190. else
  5191. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5192. WFIFOW(fd,c*8+ 6) = 0;
  5193. WFIFOW(fd,c*8+ 8) = 0;
  5194. WFIFOW(fd,c*8+10) = 0;
  5195. c++;
  5196. }
  5197. }
  5198. WFIFOW(fd, 2) = c*8+8;
  5199. WFIFOSET(fd,WFIFOW(fd,2));
  5200. if (c > 0) {
  5201. sd->menuskill_id = skill_id;
  5202. sd->menuskill_val = trigger;
  5203. return;
  5204. }
  5205. }
  5206. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5207. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5208. /// mk type:
  5209. /// 1 = cooking
  5210. /// 2 = arrow
  5211. /// 3 = elemental
  5212. /// 4 = GN_MIX_COOKING
  5213. /// 5 = GN_MAKEBOMB
  5214. /// 6 = GN_S_PHARMACY
  5215. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5216. {
  5217. int fd;
  5218. int i, c;
  5219. int view;
  5220. nullpo_retv(sd);
  5221. fd = sd->fd;
  5222. if(sd->menuskill_id == skill_id)
  5223. return; //Avoid resending the menu twice or more times...
  5224. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5225. WFIFOW(fd,0) = 0x25a;
  5226. WFIFOW(fd,4) = list_type; // list type
  5227. c = 0;
  5228. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5229. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5230. continue;
  5231. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5232. WFIFOW(fd, 6 + 2 * c) = view;
  5233. else
  5234. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5235. c++;
  5236. }
  5237. if( c > 0 || skill_id == AM_PHARMACY) {
  5238. sd->menuskill_id = skill_id;
  5239. sd->menuskill_val = trigger;
  5240. sd->menuskill_val2 = qty; // amount.
  5241. WFIFOW(fd,2) = 6 + 2 * c;
  5242. WFIFOSET(fd,WFIFOW(fd,2));
  5243. } else {
  5244. clif_menuskill_clear(sd);
  5245. #if PACKETVER >= 20090922
  5246. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5247. #else
  5248. WFIFOW(fd,2) = 6 + 2 * c;
  5249. WFIFOSET(fd,WFIFOW(fd,2));
  5250. #endif
  5251. }
  5252. }
  5253. /// Notifies clients of a status change.
  5254. /// 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)]
  5255. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5256. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5257. /// @param bl Sends packet to clients around this object
  5258. /// @param id ID of object that has this effect
  5259. /// @param type Status icon see enum efst_types
  5260. /// @param flag 1:Active, 0:Deactive
  5261. /// @param tick Duration in ms
  5262. /// @param val1
  5263. /// @param val2
  5264. /// @param val3
  5265. 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)
  5266. {
  5267. unsigned char buf[32];
  5268. if (type == EFST_BLANK) //It shows nothing on the client...
  5269. return;
  5270. if (type == EFST_POSTDELAY && tick == 0)
  5271. return;
  5272. nullpo_retv(bl);
  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 (!tsd->inventory.u.items_inventory[i].equip)
  8579. continue;
  8580. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8581. continue;
  8582. // Add item info : refine, identify flag, element, etc.
  8583. 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));
  8584. n++;
  8585. }
  8586. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8587. WFIFOSET(fd, WFIFOW(fd, 2));
  8588. }
  8589. /// Display msgstringtable.txt string (ZC_MSG).
  8590. /// 0291 <message>.W
  8591. void clif_msg(struct map_session_data* sd, unsigned short id)
  8592. {
  8593. int fd;
  8594. nullpo_retv(sd);
  8595. fd = sd->fd;
  8596. WFIFOHEAD(fd, packet_len(0x291));
  8597. WFIFOW(fd, 0) = 0x291;
  8598. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8599. WFIFOSET(fd, packet_len(0x291));
  8600. }
  8601. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8602. /// 0x7e2 <message>.W <value>.L
  8603. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8604. {
  8605. int fd = sd->fd;
  8606. WFIFOHEAD(fd, packet_len(0x7e2));
  8607. WFIFOW(fd,0) = 0x7e2;
  8608. WFIFOW(fd,2) = id;
  8609. WFIFOL(fd,4) = value;
  8610. WFIFOSET(fd, packet_len(0x7e2));
  8611. }
  8612. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8613. /// 07e6 <skill id>.W <msg id>.L
  8614. ///
  8615. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8616. /// "[SkillName] Message"
  8617. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8618. {
  8619. int fd = sd->fd;
  8620. WFIFOHEAD(fd, packet_len(0x7e6));
  8621. WFIFOW(fd,0) = 0x7e6;
  8622. WFIFOW(fd,2) = skill_id;
  8623. WFIFOL(fd,4) = msg_id;
  8624. WFIFOSET(fd, packet_len(0x7e6));
  8625. }
  8626. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8627. /// 09cd <msg id>.W <color>.L
  8628. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8629. nullpo_retv(sd);
  8630. int fd = sd->fd;
  8631. WFIFOHEAD(fd, packet_len(0x9cd));
  8632. WFIFOW(fd, 0) = 0x9cd;
  8633. WFIFOW(fd, 2) = msg_id;
  8634. WFIFOL(fd, 4) = color;
  8635. WFIFOSET(fd, packet_len(0x9cd));
  8636. }
  8637. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8638. /// Returns true if the packet was parsed successfully.
  8639. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8640. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8641. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8642. const char* seperator = " : ";
  8643. int fd;
  8644. struct s_packet_db* info;
  8645. uint16 packetLength, inputLength;
  8646. const char *input, *name, *message;
  8647. size_t nameLength, messageLength;
  8648. fd = sd->fd;
  8649. info = &packet_db[RFIFOW(fd,0)];
  8650. packetLength = RFIFOW(fd,info->pos[0]);
  8651. input = RFIFOCP(fd,info->pos[1]);
  8652. // basic structure check for the 4-byte header
  8653. if( packetLength < 4 ){
  8654. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8655. return false;
  8656. }else{
  8657. inputLength = packetLength - 4;
  8658. }
  8659. // process <name> part of the packet
  8660. if( whisperFormat ) {
  8661. // name has fixed width
  8662. if( inputLength < NAME_LENGTH + 1 ) {
  8663. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8664. return false;
  8665. }
  8666. name = input;
  8667. // validate name
  8668. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8669. // only restriction is that the name must be zero-terminated
  8670. if( name[nameLength] != '\0' ) {
  8671. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8672. return false;
  8673. }
  8674. message = input + NAME_LENGTH;
  8675. messageLength = inputLength - NAME_LENGTH;
  8676. }else{
  8677. // name and message are separated by ' : '
  8678. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8679. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8680. // check if there's enough data provided
  8681. if( inputLength < nameLength + seperatorLength + 1 ){
  8682. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8683. return false;
  8684. }
  8685. name = input;
  8686. // validate name
  8687. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8688. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8689. {
  8690. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8691. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8692. set_eof(sd->fd); // Just kick them out to correct it.
  8693. return false;
  8694. }
  8695. message = input + nameLength + seperatorLength;
  8696. messageLength = inputLength - nameLength - seperatorLength;
  8697. }
  8698. #if PACKETVER < 20151001
  8699. // the declared length must match real length
  8700. if( messageLength != strnlen(message, messageLength)+1 ) {
  8701. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8702. return false;
  8703. }
  8704. // verify <message> part of the packet
  8705. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8706. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8707. return false;
  8708. }
  8709. #else
  8710. // No zero termination anymore
  8711. messageLength += 1;
  8712. #endif
  8713. // messages mustn't be too long
  8714. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8715. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8716. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8717. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8718. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8719. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8720. return false;
  8721. }
  8722. // If it is not a whisper message, set the name to the fakename of the player
  8723. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8724. strcpy( out_name, sd->fakename );
  8725. }else{
  8726. safestrncpy( out_name, name, nameLength + 1 );
  8727. }
  8728. safestrncpy( out_message, message, messageLength );
  8729. if( whisperFormat ){
  8730. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8731. out_full_message[nameLength] = '\0';
  8732. }else{
  8733. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8734. }
  8735. if( is_atcommand( fd, sd, out_message, 1 ) )
  8736. return false;
  8737. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8738. return false; //no "chatting" while muted.
  8739. if( battle_config.min_chat_delay ) { //[Skotlex]
  8740. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8741. return false;
  8742. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8743. }
  8744. if (battle_config.idletime_option&IDLE_CHAT)
  8745. sd->idletime = last_tick;
  8746. return true;
  8747. }
  8748. /**
  8749. * Displays a message if the player enters a PK Zone (during pk_mode)
  8750. * @param sd: Player data
  8751. */
  8752. inline void clif_pk_mode_message(struct map_session_data * sd)
  8753. {
  8754. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8755. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8756. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8757. char output[CHAT_SIZE_MAX];
  8758. // 1504: You've entered a PK Zone (safe until level %d).
  8759. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8760. battle_config.pk_min_level);
  8761. clif_showscript(&sd->bl, output, SELF);
  8762. } else {
  8763. // 1503: You've entered a PK Zone.
  8764. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8765. }
  8766. }
  8767. return;
  8768. }
  8769. // ---------------------
  8770. // clif_parse_wanttoconnect
  8771. // ---------------------
  8772. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8773. // error codes:
  8774. // 0 - Success
  8775. // 1 - Unknown packet_ver
  8776. // 2 - Invalid account_id
  8777. // 3 - Invalid char_id
  8778. // 4 - Invalid login_id1 (reserved)
  8779. // 5 - Invalid client_tick (reserved)
  8780. // 6 - Invalid sex
  8781. // Only the first 'invalid' error that appears is used.
  8782. static int clif_parse_WantToConnection_sub(int fd)
  8783. {
  8784. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8785. unsigned short cmd;
  8786. //By default, start searching on the default one.
  8787. cmd = RFIFOW(fd, 0);
  8788. packet_len = RFIFOREST(fd);
  8789. // FIXME: If the packet is not received at once, this will FAIL.
  8790. // Figure out, when it happens, that only part of the packet is
  8791. // received, or fix the function to be able to deal with that
  8792. // case.
  8793. if( packet_len != packet_db[cmd].len )
  8794. return 1; /* wrong length */
  8795. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8796. return 2; /* invalid account_id */
  8797. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8798. return 3; /* invalid char_id */
  8799. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8800. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8801. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8802. return 6; /* invalid sex */
  8803. else
  8804. return 0;
  8805. }
  8806. /// Request to connect to map-server.
  8807. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8808. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8809. /// There are various variants of this packet, some of them have padding between fields.
  8810. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8811. {
  8812. struct block_list* bl;
  8813. struct auth_node* node;
  8814. int cmd, account_id, char_id, login_id1, sex, err;
  8815. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8816. if (sd) {
  8817. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8818. return;
  8819. }
  8820. cmd = RFIFOW(fd, 0);
  8821. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8822. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8823. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8824. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8825. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8826. err = clif_parse_WantToConnection_sub(fd);
  8827. if( err ){ // connection rejected
  8828. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8829. err == 1 ? "." :
  8830. err == 2 ? ", possibly for having an invalid account_id." :
  8831. err == 3 ? ", possibly for having an invalid char_id." :
  8832. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8833. err == 4 ? ", possibly for having an invalid login_id1." :
  8834. err == 5 ? ", possibly for having an invalid client_tick." :
  8835. */
  8836. err == 6 ? ", possibly for having an invalid sex." :
  8837. ". ERROR invalid error code"));
  8838. WFIFOHEAD(fd,packet_len(0x6a));
  8839. WFIFOW(fd,0) = 0x6a;
  8840. WFIFOB(fd,2) = err;
  8841. WFIFOSET(fd,packet_len(0x6a));
  8842. #ifdef DUMP_INVALID_PACKET
  8843. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8844. #endif
  8845. RFIFOSKIP(fd, RFIFOREST(fd));
  8846. set_eof(fd);
  8847. return;
  8848. }
  8849. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8850. clif_authfail_fd(fd,1);// server closed
  8851. return;
  8852. }
  8853. //Check for double login.
  8854. bl = map_id2bl(account_id);
  8855. if(bl && bl->type != BL_PC) {
  8856. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8857. WFIFOHEAD(fd,packet_len(0x6a));
  8858. WFIFOW(fd,0) = 0x6a;
  8859. WFIFOB(fd,2) = 3; // Rejected by server
  8860. WFIFOSET(fd,packet_len(0x6a));
  8861. set_eof(fd);
  8862. return;
  8863. }
  8864. if (bl ||
  8865. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8866. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8867. {
  8868. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8869. return;
  8870. }
  8871. CREATE(sd, TBL_PC, 1);
  8872. sd->fd = fd;
  8873. #ifdef PACKET_OBFUSCATION
  8874. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8875. #endif
  8876. session[fd]->session_data = sd;
  8877. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8878. #if PACKETVER < 20070521
  8879. WFIFOHEAD(fd,4);
  8880. WFIFOL(fd,0) = sd->bl.id;
  8881. WFIFOSET(fd,4);
  8882. #else
  8883. WFIFOHEAD(fd,packet_len(0x283));
  8884. WFIFOW(fd,0) = 0x283;
  8885. WFIFOL(fd,2) = sd->bl.id;
  8886. WFIFOSET(fd,packet_len(0x283));
  8887. #endif
  8888. chrif_authreq(sd,false);
  8889. }
  8890. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8891. /// 007d
  8892. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8893. {
  8894. bool guild_notice = false;
  8895. if(sd->bl.prev != NULL)
  8896. return;
  8897. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8898. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8899. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8900. sd->state.connect_new = 0;
  8901. return;
  8902. }
  8903. if (sd->state.rewarp) { //Rewarp player.
  8904. sd->state.rewarp = 0;
  8905. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8906. return;
  8907. }
  8908. sd->state.warping = 0;
  8909. // look
  8910. #if PACKETVER < 4
  8911. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8912. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8913. #else
  8914. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8915. #endif
  8916. pc_set_costume_view(sd);
  8917. if(sd->vd.cloth_color)
  8918. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8919. if(sd->vd.body_style)
  8920. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8921. // item
  8922. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8923. pc_checkitem(sd);
  8924. clif_equipswitch_list(sd);
  8925. // cart
  8926. if(pc_iscarton(sd)) {
  8927. clif_cartlist(sd);
  8928. clif_updatestatus(sd,SP_CARTINFO);
  8929. }
  8930. // weight
  8931. clif_updatestatus(sd,SP_WEIGHT);
  8932. clif_updatestatus(sd,SP_MAXWEIGHT);
  8933. // guild
  8934. // (needs to go before clif_spawn() to show guild emblems correctly)
  8935. if(sd->status.guild_id)
  8936. guild_send_memberinfoshort(sd,1);
  8937. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8938. if(battle_config.pc_invincible_time > 0) {
  8939. if(mapdata_flag_gvg(mapdata))
  8940. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8941. else
  8942. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8943. }
  8944. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8945. map_spawnmobs(sd->bl.m);
  8946. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8947. mapdata->users_pvp++;
  8948. }
  8949. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8950. // reset the callshop flag if the player changes map
  8951. sd->state.callshop = 0;
  8952. if(map_addblock(&sd->bl))
  8953. return;
  8954. clif_spawn(&sd->bl);
  8955. // Party
  8956. // (needs to go after clif_spawn() to show hp bars correctly)
  8957. if(sd->status.party_id) {
  8958. party_send_movemap(sd);
  8959. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8960. }
  8961. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8962. if(!pc_isinvisible(sd) && mapdata->flag[MF_PVP]) {
  8963. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8964. if (!mapdata->flag[MF_PVP_NOCALCRANK])
  8965. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8966. sd->pvp_rank = 0;
  8967. sd->pvp_lastusers = 0;
  8968. sd->pvp_point = 5;
  8969. sd->pvp_won = 0;
  8970. sd->pvp_lost = 0;
  8971. }
  8972. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8973. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8974. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8975. else if (mapdata->flag[MF_GVG_DUNGEON])
  8976. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8977. else if( mapdata_flag_gvg(mapdata) )
  8978. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8979. else
  8980. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8981. // info about nearby objects
  8982. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8983. 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);
  8984. // pet
  8985. if( sd->pd ) {
  8986. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8987. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8988. pet_return_egg( sd, sd->pd );
  8989. } else {
  8990. if(map_addblock(&sd->pd->bl))
  8991. return;
  8992. clif_spawn(&sd->pd->bl);
  8993. clif_send_petdata(sd,sd->pd,0,0);
  8994. clif_send_petstatus(sd);
  8995. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8996. }
  8997. }
  8998. //homunculus [blackhole89]
  8999. if( hom_is_active(sd->hd) ) {
  9000. if(map_addblock(&sd->hd->bl))
  9001. return;
  9002. clif_spawn(&sd->hd->bl);
  9003. clif_send_homdata(sd,SP_ACK,0);
  9004. clif_hominfo(sd,sd->hd,1);
  9005. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9006. clif_homskillinfoblock(sd);
  9007. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9008. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  9009. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9010. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9011. }
  9012. if( sd->md ) {
  9013. if(map_addblock(&sd->md->bl))
  9014. return;
  9015. clif_spawn(&sd->md->bl);
  9016. clif_mercenary_info(sd);
  9017. clif_mercenary_skillblock(sd);
  9018. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  9019. }
  9020. if( sd->ed ) {
  9021. if (map_addblock(&sd->ed->bl))
  9022. return;
  9023. clif_spawn(&sd->ed->bl);
  9024. clif_elemental_info(sd);
  9025. clif_elemental_updatestatus(sd,SP_HP);
  9026. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  9027. clif_elemental_updatestatus(sd,SP_SP);
  9028. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9029. }
  9030. if(sd->state.connect_new) {
  9031. int lv;
  9032. guild_notice = true;
  9033. clif_skillinfoblock(sd);
  9034. clif_hotkeys_send(sd);
  9035. clif_updatestatus(sd,SP_BASEEXP);
  9036. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9037. clif_updatestatus(sd,SP_JOBEXP);
  9038. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9039. clif_updatestatus(sd,SP_SKILLPOINT);
  9040. clif_initialstatus(sd);
  9041. if (sd->sc.option&OPTION_FALCON)
  9042. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9043. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  9044. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9045. else if (sd->sc.option&OPTION_WUGRIDER)
  9046. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9047. else if (sd->sc.data[SC_ALL_RIDING])
  9048. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9049. if(sd->status.manner < 0)
  9050. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9051. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9052. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9053. if(sd->bl.m == sd->feel_map[0].m
  9054. || sd->bl.m == sd->feel_map[1].m
  9055. || sd->bl.m == sd->feel_map[2].m)
  9056. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9057. }
  9058. if(sd->pd && sd->pd->pet.intimate > 900)
  9059. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9060. if(hom_is_active(sd->hd))
  9061. hom_init_timers(sd->hd);
  9062. if (night_flag && mapdata->flag[MF_NIGHTENABLED]) {
  9063. sd->state.night = 1;
  9064. clif_status_load(&sd->bl, EFST_SKE, 1);
  9065. }
  9066. // Notify everyone that this char logged in [Skotlex].
  9067. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9068. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9069. //Login Event
  9070. npc_script_event(sd, NPCE_LOGIN);
  9071. }
  9072. } else {
  9073. //For some reason the client "loses" these on warp/map-change.
  9074. clif_updatestatus(sd,SP_STR);
  9075. clif_updatestatus(sd,SP_AGI);
  9076. clif_updatestatus(sd,SP_VIT);
  9077. clif_updatestatus(sd,SP_INT);
  9078. clif_updatestatus(sd,SP_DEX);
  9079. clif_updatestatus(sd,SP_LUK);
  9080. // abort currently running script
  9081. sd->state.using_fake_npc = 0;
  9082. sd->state.menu_or_input = 0;
  9083. sd->npc_menu = 0;
  9084. if(sd->npc_id)
  9085. npc_event_dequeue(sd);
  9086. }
  9087. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9088. #if PACKETVER >= 20070918
  9089. clif_partyinvitationstate(sd);
  9090. clif_equipcheckbox(sd);
  9091. #endif
  9092. #if PACKETVER >= 20141008
  9093. if( battle_config.pet_autofeed_always ){
  9094. // Always send ON or OFF
  9095. if( sd->pd && battle_config.feature_pet_autofeed ){
  9096. clif_configuration( sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed );
  9097. }else{
  9098. clif_configuration( sd, CONFIG_PET_AUTOFEED, false );
  9099. }
  9100. }else{
  9101. // Only send when enabled
  9102. if( sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed ){
  9103. clif_configuration( sd, CONFIG_PET_AUTOFEED, true );
  9104. }
  9105. }
  9106. #endif
  9107. #if PACKETVER >= 20170920
  9108. if( battle_config.homunculus_autofeed_always ){
  9109. // Always send ON or OFF
  9110. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9111. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9112. }else{
  9113. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9114. }
  9115. }else{
  9116. // Only send when enabled
  9117. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9118. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9119. }
  9120. }
  9121. #endif
  9122. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9123. clif_guild_notice(sd); // Displays after VIP
  9124. guild_notice = false; // Do not display it twice
  9125. }
  9126. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9127. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9128. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->flag[MF_BATTLEGROUND])) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->flag[MF_BATTLEGROUND])))
  9129. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9130. }
  9131. if( night_flag && mapdata->flag[MF_NIGHTENABLED] )
  9132. { //Display night.
  9133. if( !sd->state.night )
  9134. {
  9135. sd->state.night = 1;
  9136. clif_status_load(&sd->bl, EFST_SKE, 1);
  9137. }
  9138. }
  9139. else if( sd->state.night )
  9140. { //Clear night display.
  9141. sd->state.night = 0;
  9142. clif_status_load(&sd->bl, EFST_SKE, 0);
  9143. }
  9144. if( mapdata->flag[MF_BATTLEGROUND] )
  9145. {
  9146. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9147. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9148. clif_bg_updatescore_single(sd);
  9149. }
  9150. if( mapdata->flag[MF_ALLOWKS] && !mapdata_flag_ks(mapdata) )
  9151. {
  9152. char output[128];
  9153. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9154. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9155. }
  9156. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9157. mapdata->hpmeter_visible++;
  9158. sd->state.hpmeter_visible = 1;
  9159. }
  9160. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9161. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9162. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9163. #ifdef VIP_ENABLE
  9164. if (!sd->state.connect_new &&
  9165. !sd->vip.disableshowrate &&
  9166. sd->state.pmap != sd->bl.m &&
  9167. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->flag[MF_BEXP]
  9168. )
  9169. {
  9170. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9171. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9172. }
  9173. #endif
  9174. // Instances do not need their own channels
  9175. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->flag[MF_NOMAPCHANNELAUTOJOIN] )
  9176. channel_mjoin(sd); //join new map
  9177. clif_pk_mode_message(sd);
  9178. }
  9179. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9180. clif_guild_notice(sd); // Displays at end
  9181. }
  9182. mail_clear(sd);
  9183. /* Guild Aura Init */
  9184. if( sd->guild && sd->state.gmaster_flag ) {
  9185. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9186. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9187. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9188. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9189. }
  9190. if( sd->state.vending ) { /* show we have a vending */
  9191. clif_openvending(sd,sd->bl.id,sd->vending);
  9192. clif_showvendingboard(&sd->bl,sd->message,0);
  9193. }
  9194. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9195. if(!sd->state.autotrade && mapdata->flag[MF_LOADEVENT]) // Lance
  9196. npc_script_event(sd, NPCE_LOADMAP);
  9197. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9198. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9199. if (sd->sc.opt2) //Client loses these on warp.
  9200. clif_changeoption(&sd->bl);
  9201. 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)) {
  9202. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9203. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9204. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9205. }
  9206. clif_weather_check(sd);
  9207. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9208. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9209. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9210. else
  9211. sd->areanpc.clear();
  9212. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9213. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9214. pc_setdead(sd);
  9215. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9216. if(pc_isdead(sd))
  9217. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9218. else {
  9219. skill_usave_trigger(sd);
  9220. if (battle_config.spawn_direction)
  9221. clif_changed_dir(&sd->bl, SELF);
  9222. }
  9223. // Trigger skill effects if you appear standing on them
  9224. if(!battle_config.pc_invincible_time)
  9225. skill_unit_move(&sd->bl,gettick(),1);
  9226. pc_show_questinfo_reinit(sd);
  9227. pc_show_questinfo(sd);
  9228. #if PACKETVER >= 20150513
  9229. if( sd->mail.inbox.unread ){
  9230. clif_Mail_new(sd, 0, NULL, NULL);
  9231. }
  9232. #endif
  9233. sd->state.connect_new = 0;
  9234. sd->state.changemap = false;
  9235. }
  9236. /// Server's tick (ZC_NOTIFY_TIME).
  9237. /// 007f <time>.L
  9238. void clif_notify_time(struct map_session_data* sd, t_tick time)
  9239. {
  9240. int fd = sd->fd;
  9241. WFIFOHEAD(fd,packet_len(0x7f));
  9242. WFIFOW(fd,0) = 0x7f;
  9243. WFIFOL(fd,2) = client_tick(time);
  9244. WFIFOSET(fd,packet_len(0x7f));
  9245. }
  9246. /// Request for server's tick.
  9247. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9248. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9249. /// There are various variants of this packet, some of them have padding between fields.
  9250. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9251. {
  9252. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9253. clif_notify_time(sd, gettick());
  9254. }
  9255. /// Sends hotkey bar.
  9256. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9257. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9258. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9259. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9260. void clif_hotkeys_send(struct map_session_data *sd) {
  9261. #ifdef HOTKEY_SAVING
  9262. const int fd = sd->fd;
  9263. int i;
  9264. int offset = 2;
  9265. #if PACKETVER < 20090603
  9266. const int cmd = 0x2b9;
  9267. #elif PACKETVER < 20141022
  9268. const int cmd = 0x7d9;
  9269. #else
  9270. char Rotate = sd->status.hotkey_rowshift;
  9271. const int cmd = 0xa00;
  9272. offset = 3;
  9273. #endif
  9274. if (!fd) return;
  9275. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9276. WFIFOW(fd, 0) = cmd;
  9277. #if PACKETVER >= 20141022
  9278. WFIFOB(fd, 2) = Rotate;
  9279. #endif
  9280. for(i = 0; i < MAX_HOTKEYS; i++) {
  9281. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9282. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9283. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9284. }
  9285. WFIFOSET(fd, packet_len(cmd));
  9286. #endif
  9287. }
  9288. /// Request to update a position on the hotkey row bar
  9289. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9290. int cmd = RFIFOW(fd, 0);
  9291. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9292. }
  9293. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9294. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9295. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9296. #ifdef HOTKEY_SAVING
  9297. unsigned short idx;
  9298. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9299. idx = RFIFOW(fd, info->pos[0]);
  9300. if (idx >= MAX_HOTKEYS) return;
  9301. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9302. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9303. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9304. #endif
  9305. }
  9306. /// Displays cast-like progress bar (ZC_PROGRESS).
  9307. /// 02f0 <color>.L <time>.L
  9308. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9309. {
  9310. int fd = sd->fd;
  9311. WFIFOHEAD(fd,packet_len(0x2f0));
  9312. WFIFOW(fd,0) = 0x2f0;
  9313. WFIFOL(fd,2) = color;
  9314. WFIFOL(fd,6) = second;
  9315. WFIFOSET(fd,packet_len(0x2f0));
  9316. }
  9317. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9318. /// 02f2
  9319. void clif_progressbar_abort(struct map_session_data * sd)
  9320. {
  9321. int fd = sd->fd;
  9322. WFIFOHEAD(fd,packet_len(0x2f2));
  9323. WFIFOW(fd,0) = 0x2f2;
  9324. WFIFOSET(fd,packet_len(0x2f2));
  9325. }
  9326. /// Notification from the client, that the progress bar has reached 100%.
  9327. /// 02f1 (CZ_PROGRESS)
  9328. void clif_parse_progressbar(int fd, struct map_session_data * sd){
  9329. // No progressbar active, ignore it
  9330. if( !sd->progressbar.npc_id ){
  9331. return;
  9332. }
  9333. int npc_id = sd->progressbar.npc_id;
  9334. bool closing = false;
  9335. // Check if the progress was canceled
  9336. if( gettick() < sd->progressbar.timeout && sd->st ){
  9337. closing = true;
  9338. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9339. // If a message window was open, offer a close button to the user
  9340. if( sd->st->mes_active ){
  9341. clif_scriptclose( sd, npc_id );
  9342. }
  9343. }
  9344. sd->progressbar.npc_id = 0;
  9345. sd->progressbar.timeout = 0;
  9346. sd->state.workinprogress = WIP_DISABLE_NONE;
  9347. npc_scriptcont(sd, npc_id, closing);
  9348. }
  9349. /// Displays cast-like progress bar on a NPC
  9350. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9351. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9352. #if PACKETVER >= 20130821
  9353. unsigned char buf[14];
  9354. if( nd->progressbar.timeout > 0 ){
  9355. WBUFW(buf,0) = 0x9d1;
  9356. WBUFL(buf,2) = nd->bl.id;
  9357. WBUFL(buf,6) = nd->progressbar.color;
  9358. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9359. if( sd ){
  9360. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9361. }else{
  9362. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9363. }
  9364. }
  9365. #endif
  9366. }
  9367. /// Request to walk to a certain position on the current map.
  9368. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9369. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9370. /// There are various variants of this packet, some of them have padding between fields.
  9371. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9372. {
  9373. short x, y;
  9374. if (pc_isdead(sd)) {
  9375. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9376. return;
  9377. }
  9378. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9379. ; //You CAN walk on this OPT1 value.
  9380. else if (sd->progressbar.npc_id) {
  9381. clif_progressbar_abort(sd);
  9382. return; // First walk attempt cancels the progress bar
  9383. } else if (pc_cant_act(sd))
  9384. return;
  9385. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9386. return;
  9387. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9388. //A move command one cell west is only valid if the target cell is free
  9389. if(battle_config.official_cell_stack_limit > 0
  9390. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9391. return;
  9392. // Cloaking wall check is actually updated when you click to process next movement
  9393. // not when you move each cell. This is official behaviour.
  9394. if (sd->sc.data[SC_CLOAKING])
  9395. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9396. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9397. pc_delinvincibletimer(sd);
  9398. //Set last idle time... [Skotlex]
  9399. if (battle_config.idletime_option&IDLE_WALK)
  9400. sd->idletime = last_tick;
  9401. unit_walktoxy(&sd->bl, x, y, 4);
  9402. }
  9403. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9404. /// 018b <result>.W
  9405. /// result:
  9406. /// 0 = disconnect (quit)
  9407. /// 1 = cannot disconnect (wait 10 seconds)
  9408. /// ? = ignored
  9409. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9410. {
  9411. int fd = sd->fd;
  9412. WFIFOHEAD(fd,packet_len(0x18b));
  9413. WFIFOW(fd,0) = 0x18b;
  9414. WFIFOW(fd,2) = result;
  9415. WFIFOSET(fd,packet_len(0x18b));
  9416. }
  9417. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9418. /// 018a <type>.W
  9419. /// type:
  9420. /// 0 = quit
  9421. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9422. {
  9423. /* Rovert's prevent logout option fixed [Valaris] */
  9424. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9425. 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] &&
  9426. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9427. {
  9428. set_eof(fd);
  9429. pc_damage_log_clear(sd,0);
  9430. clif_disconnect_ack(sd, 0);
  9431. } else {
  9432. clif_disconnect_ack(sd, 1);
  9433. }
  9434. }
  9435. /// Requesting unit's name.
  9436. /// 0094 <id>.L (CZ_REQNAME)
  9437. /// 0368 <id>.L (CZ_REQNAME2)
  9438. /// There are various variants of this packet, some of them have padding between fields.
  9439. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9440. {
  9441. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9442. struct block_list* bl;
  9443. //struct status_change *sc;
  9444. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9445. id = sd->bl.id;
  9446. bl = map_id2bl(id);
  9447. if( bl == NULL )
  9448. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9449. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9450. return; // Block namerequests past view range
  9451. // 'see people in GM hide' cheat detection
  9452. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9453. sc = status_get_sc(bl);
  9454. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9455. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9456. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9457. ) {
  9458. char gm_msg[256];
  9459. 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);
  9460. ShowWarning(gm_msg);
  9461. // information is sent to all online GMs
  9462. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9463. return;
  9464. }
  9465. */
  9466. clif_name(&sd->bl,bl,SELF);
  9467. }
  9468. /// Validates and processes global messages
  9469. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9470. /// There are various variants of this packet.
  9471. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9472. {
  9473. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9474. size_t length;
  9475. // validate packet and retrieve name and message
  9476. if( !clif_process_message(sd, false, name, message, output ) )
  9477. return;
  9478. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9479. channel_send(sd->gcbind,sd,message);
  9480. return;
  9481. }
  9482. // send message to others (using the send buffer for temp. storage)
  9483. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9484. length = strlen(output) + 1;
  9485. // send back message to the speaker
  9486. WFIFOHEAD(fd,4+length);
  9487. WFIFOW(fd,0) = 0x8e;
  9488. WFIFOW(fd,2) = (uint16)(4+length);
  9489. safestrncpy(WFIFOCP(fd,4), output, length );
  9490. WFIFOSET(fd, WFIFOW(fd,2));
  9491. #ifdef PCRE_SUPPORT
  9492. // trigger listening npcs
  9493. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9494. #endif
  9495. // Chat logging type 'O' / Global Chat
  9496. 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);
  9497. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9498. }
  9499. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9500. /// Request to warp to a map on given coordinates.
  9501. /// 0140 <map name>.16B <x>.W <y>.W
  9502. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9503. {
  9504. char command[MAP_NAME_LENGTH_EXT+25];
  9505. char* map_name;
  9506. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9507. map_name = RFIFOCP(fd,info->pos[0]);
  9508. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9509. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9510. RFIFOW(fd,info->pos[1]), //x
  9511. RFIFOW(fd,info->pos[2])); //y
  9512. is_atcommand(fd, sd, command, 1);
  9513. }
  9514. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9515. /// 009c <id>.L <head dir>.W <dir>.B
  9516. /// head dir:
  9517. /// 0 = straight
  9518. /// 1 = turned CW
  9519. /// 2 = turned CCW
  9520. /// dir:
  9521. /// 0 = north
  9522. /// 1 = northwest
  9523. /// 2 = west
  9524. /// 3 = southwest
  9525. /// 4 = south
  9526. /// 5 = southeast
  9527. /// 6 = east
  9528. /// 7 = northeast
  9529. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9530. {
  9531. unsigned char buf[64];
  9532. WBUFW(buf,0) = 0x9c;
  9533. WBUFL(buf,2) = bl->id;
  9534. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9535. WBUFB(buf,8) = unit_getdir(bl);
  9536. clif_send(buf, packet_len(0x9c), bl, target);
  9537. if (disguised(bl)) {
  9538. WBUFL(buf,2) = -bl->id;
  9539. WBUFW(buf,6) = 0;
  9540. clif_send(buf, packet_len(0x9c), bl, SELF);
  9541. }
  9542. }
  9543. /// Request to change own body and head direction.
  9544. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9545. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9546. /// There are various variants of this packet, some of them have padding between fields.
  9547. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9548. {
  9549. unsigned char headdir, dir;
  9550. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9551. headdir = RFIFOB(fd,info->pos[0]);
  9552. dir = RFIFOB(fd,info->pos[1]);
  9553. pc_setdir(sd, dir, headdir);
  9554. clif_changed_dir(&sd->bl, AREA_WOS);
  9555. }
  9556. /// Request to show an emotion (CZ_REQ_EMOTION).
  9557. /// 00bf <type>.B
  9558. /// type:
  9559. /// @see enum emotion_type
  9560. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9561. {
  9562. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9563. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9564. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9565. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9566. return;
  9567. }
  9568. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9569. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9570. sd->emotionlasttime = time(NULL);
  9571. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9572. return;
  9573. }
  9574. sd->emotionlasttime = time(NULL);
  9575. if (battle_config.idletime_option&IDLE_EMOTION)
  9576. sd->idletime = last_tick;
  9577. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9578. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9579. return;
  9580. }
  9581. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9582. emoticon = rnd()%6+ET_DICE1;
  9583. }
  9584. clif_emotion(&sd->bl, emoticon);
  9585. } else
  9586. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9587. }
  9588. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9589. /// 00c2 <count>.L
  9590. void clif_user_count(struct map_session_data* sd, int count)
  9591. {
  9592. int fd = sd->fd;
  9593. WFIFOHEAD(fd,packet_len(0xc2));
  9594. WFIFOW(fd,0) = 0xc2;
  9595. WFIFOL(fd,2) = count;
  9596. WFIFOSET(fd,packet_len(0xc2));
  9597. }
  9598. /// /w /who (CZ_REQ_USER_COUNT).
  9599. /// Request to display amount of currently connected players.
  9600. /// 00c1
  9601. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9602. {
  9603. clif_user_count(sd, map_getusers());
  9604. }
  9605. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, t_tick tick)
  9606. {
  9607. if (pc_isdead(sd)) {
  9608. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9609. return;
  9610. }
  9611. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9612. // (not all are included in pc_can_attack)
  9613. if (sd->sc.count &&
  9614. (sd->sc.data[SC_TRICKDEAD] ||
  9615. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9616. sd->sc.data[SC_BLADESTOP] ||
  9617. sd->sc.data[SC__MANHOLE] ||
  9618. sd->sc.data[SC_SUHIDE] ))
  9619. return;
  9620. if(action_type != 0x00 && action_type != 0x07)
  9621. pc_stop_walking(sd, 1);
  9622. pc_stop_attack(sd);
  9623. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9624. target_id = sd->bl.id;
  9625. switch(action_type)
  9626. {
  9627. case 0x00: // once attack
  9628. case 0x07: // continuous attack
  9629. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9630. return;
  9631. if( sd->sc.option&OPTION_COSTUME )
  9632. return;
  9633. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9634. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9635. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9636. return;
  9637. }
  9638. }
  9639. pc_delinvincibletimer(sd);
  9640. if (battle_config.idletime_option&IDLE_ATTACK)
  9641. sd->idletime = last_tick;
  9642. unit_attack(&sd->bl, target_id, action_type != 0);
  9643. break;
  9644. case 0x02: // sitdown
  9645. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9646. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9647. break;
  9648. }
  9649. if(pc_issit(sd)) {
  9650. //Bugged client? Just refresh them.
  9651. clif_sitting(&sd->bl);
  9652. return;
  9653. }
  9654. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9655. break;
  9656. if (sd->sc.count && (
  9657. sd->sc.data[SC_DANCING] ||
  9658. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9659. )) //No sitting during these states either.
  9660. break;
  9661. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9662. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9663. break;
  9664. }
  9665. if (battle_config.idletime_option&IDLE_SIT)
  9666. sd->idletime = last_tick;
  9667. pc_setsit(sd);
  9668. skill_sit(sd, true);
  9669. clif_sitting(&sd->bl);
  9670. break;
  9671. case 0x03: // standup
  9672. if (!pc_issit(sd)) {
  9673. //Bugged client? Just refresh them.
  9674. clif_standing(&sd->bl);
  9675. return;
  9676. }
  9677. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9678. break;
  9679. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9680. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9681. break;
  9682. }
  9683. if (pc_setstand(sd, false)) {
  9684. if (battle_config.idletime_option&IDLE_SIT)
  9685. sd->idletime = last_tick;
  9686. skill_sit(sd, false);
  9687. clif_standing(&sd->bl);
  9688. }
  9689. break;
  9690. }
  9691. }
  9692. /// Request for an action.
  9693. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9694. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9695. /// action:
  9696. /// 0 = attack
  9697. /// 1 = pick up item
  9698. /// 2 = sit down
  9699. /// 3 = stand up
  9700. /// 7 = continous attack
  9701. /// 12 = (touch skill?)
  9702. /// There are various variants of this packet, some of them have padding between fields.
  9703. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9704. {
  9705. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9706. clif_parse_ActionRequest_sub(sd,
  9707. RFIFOB(fd,info->pos[1]),
  9708. RFIFOL(fd,info->pos[0]),
  9709. gettick()
  9710. );
  9711. }
  9712. /// Response to the death/system menu (CZ_RESTART).
  9713. /// 00b2 <type>.B
  9714. /// type:
  9715. /// 0 = restart (respawn)
  9716. /// 1 = char-select (disconnect)
  9717. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9718. {
  9719. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9720. case 0x00:
  9721. pc_respawn(sd,CLR_OUTSIGHT);
  9722. break;
  9723. case 0x01:
  9724. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9725. 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] &&
  9726. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9727. { //Send to char-server for character selection.
  9728. pc_damage_log_clear(sd,0);
  9729. chrif_charselectreq(sd, session[fd]->client_addr);
  9730. } else {
  9731. clif_disconnect_ack(sd, 1);
  9732. }
  9733. break;
  9734. }
  9735. }
  9736. /// Validates and processes whispered messages (CZ_WHISPER).
  9737. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9738. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9739. {
  9740. struct map_session_data* dstsd;
  9741. int i;
  9742. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9743. // validate packet and retrieve name and message
  9744. if( !clif_process_message( sd, true, target, message, output ) )
  9745. return;
  9746. // Chat logging type 'W' / Whisper
  9747. 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);
  9748. //-------------------------------------------------------//
  9749. // Lordalfa - Paperboy - To whisper NPC commands //
  9750. //-------------------------------------------------------//
  9751. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9752. {
  9753. char* str = target+4; //Skip the NPC: string part.
  9754. struct npc_data* npc;
  9755. if ((npc = npc_name2id(str))) {
  9756. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9757. char *split;
  9758. char event[EVENT_NAME_LENGTH];
  9759. str = message;
  9760. // skip codepage indicator, if detected
  9761. if( str[0] == '|' && strlen(str) >= 4 )
  9762. str += 3;
  9763. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9764. split = strchr(str,'#');
  9765. if( split == NULL ) { // use the remaining string
  9766. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9767. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9768. split_data[i][0] = '\0';
  9769. break;
  9770. }
  9771. *split = '\0';
  9772. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9773. str = split+1;
  9774. }
  9775. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9776. char variablename[CHAT_SIZE_MAX];
  9777. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9778. set_var(sd,variablename,(char *) split_data[i]);
  9779. }
  9780. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9781. npc_event(sd,event,0); // Calls the NPC label
  9782. return;
  9783. }
  9784. } else if( target[0] == '#' ) {
  9785. struct Channel *channel = NULL;
  9786. char* chname = target;
  9787. channel = channel_name2channel(chname,sd,3);
  9788. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9789. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9790. channel_send(channel,sd,message);
  9791. }
  9792. else if( channel->pass[0] == '\0') { //no pass needed
  9793. if (channel_join(channel,sd)==0)
  9794. channel_send(channel,sd,message); //join success
  9795. }
  9796. else {
  9797. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9798. }
  9799. return;
  9800. }
  9801. }
  9802. // searching destination character
  9803. dstsd = map_nick2sd(target,false);
  9804. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9805. // player is not on this map-server
  9806. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9807. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9808. // and if we ask for 'Test', we must not contact 'test' player
  9809. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9810. intif_wis_message(sd, target, message, strlen(message) + 1);
  9811. return;
  9812. }
  9813. // if player ignores everyone
  9814. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9815. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9816. clif_wis_end(fd, 1); // 1: target character is not logged in
  9817. else
  9818. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9819. return;
  9820. }
  9821. // if player is autotrading
  9822. if (dstsd->state.autotrade == 1){
  9823. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9824. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9825. return;
  9826. }
  9827. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9828. // if player ignores the source character
  9829. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9830. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9831. clif_wis_end(fd, 2); // 2: ignored by target
  9832. return;
  9833. }
  9834. }
  9835. // notify sender of success
  9836. clif_wis_end(fd, 0); // 0: success to send wisper
  9837. // Normal message
  9838. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9839. }
  9840. /// /b /nb (CZ_BROADCAST).
  9841. /// Request to broadcast a message on whole server.
  9842. /// 0099 <packet len>.W <text>.?B 00
  9843. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9844. char command[CHAT_SIZE_MAX+11];
  9845. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9846. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9847. char* msg = RFIFOCP(fd,info->pos[1]);
  9848. // as the length varies depending on the command used, just block unreasonably long strings
  9849. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9850. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9851. is_atcommand(fd, sd, command, 1);
  9852. }
  9853. /// Request to pick up an item.
  9854. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9855. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9856. /// There are various variants of this packet, some of them have padding between fields.
  9857. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9858. {
  9859. struct flooritem_data *fitem;
  9860. int map_object_id;
  9861. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9862. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9863. do {
  9864. if (pc_isdead(sd)) {
  9865. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9866. break;
  9867. }
  9868. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9869. break;
  9870. if (pc_cant_act(sd))
  9871. break;
  9872. if (!pc_takeitem(sd, fitem))
  9873. break;
  9874. return;
  9875. } while (0);
  9876. // Client REQUIRES a fail packet or you can no longer pick items.
  9877. clif_additem(sd,0,0,6);
  9878. }
  9879. /// Request to drop an item.
  9880. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9881. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9882. /// There are various variants of this packet, some of them have padding between fields.
  9883. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9884. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9885. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9886. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9887. for(;;) {
  9888. if (pc_isdead(sd))
  9889. break;
  9890. if (pc_cant_act2(sd) || sd->npc_id)
  9891. break;
  9892. if (sd->sc.count && (
  9893. sd->sc.data[SC_AUTOCOUNTER] ||
  9894. sd->sc.data[SC_BLADESTOP] ||
  9895. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9896. ))
  9897. break;
  9898. if (!pc_dropitem(sd, item_index, item_amount))
  9899. break;
  9900. if (battle_config.idletime_option&IDLE_DROPITEM)
  9901. sd->idletime = last_tick;
  9902. return;
  9903. }
  9904. //Because the client does not like being ignored.
  9905. clif_dropitem(sd, item_index,0);
  9906. }
  9907. /// Request to use an item.
  9908. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9909. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9910. /// There are various variants of this packet, some of them have padding between fields.
  9911. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9912. {
  9913. int n;
  9914. if (pc_isdead(sd)) {
  9915. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9916. return;
  9917. }
  9918. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9919. clif_msg(sd, WORK_IN_PROGRESS);
  9920. return;
  9921. }
  9922. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9923. if (battle_config.idletime_option&IDLE_USEITEM)
  9924. sd->idletime = last_tick;
  9925. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9926. if(n <0 || n >= MAX_INVENTORY)
  9927. return;
  9928. if (!pc_useitem(sd,n))
  9929. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9930. }
  9931. /// Request to equip an item
  9932. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9933. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9934. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9935. {
  9936. int index;
  9937. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9938. if(pc_isdead(sd)) {
  9939. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9940. return;
  9941. }
  9942. index = RFIFOW(fd,info->pos[0])-2;
  9943. if (index < 0 || index >= MAX_INVENTORY)
  9944. return; //Out of bounds check.
  9945. if(sd->npc_id && !sd->npc_item_flag) {
  9946. return;
  9947. } else if (sd->state.storage_flag || sd->sc.opt1)
  9948. ; //You can equip/unequip stuff while storage is open/under status changes
  9949. else if (pc_cant_act2(sd))
  9950. return;
  9951. if(!sd->inventory.u.items_inventory[index].identify) {
  9952. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9953. return;
  9954. }
  9955. if(!sd->inventory_data[index])
  9956. return;
  9957. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9958. pet_equipitem(sd,index);
  9959. return;
  9960. }
  9961. if (battle_config.idletime_option&IDLE_USEITEM)
  9962. sd->idletime = last_tick;
  9963. //Client doesn't send the position for ammo.
  9964. if(sd->inventory_data[index]->type == IT_AMMO)
  9965. pc_equipitem(sd,index,EQP_AMMO);
  9966. else {
  9967. int req_pos;
  9968. #if PACKETVER >= 20120925
  9969. req_pos = RFIFOL(fd,info->pos[1]);
  9970. #else
  9971. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9972. #endif
  9973. pc_equipitem(sd,index,req_pos);
  9974. }
  9975. }
  9976. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9977. /// 00ab <index>.W
  9978. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9979. {
  9980. int index;
  9981. if(pc_isdead(sd)) {
  9982. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9983. return;
  9984. }
  9985. if (sd->npc_id && !sd->npc_item_flag) {
  9986. return;
  9987. } else if (sd->state.storage_flag || sd->sc.opt1)
  9988. ; //You can equip/unequip stuff while storage is open/under status changes
  9989. else if (pc_cant_act2(sd))
  9990. return;
  9991. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9992. if (battle_config.idletime_option&IDLE_USEITEM)
  9993. sd->idletime = last_tick;
  9994. pc_unequipitem(sd,index,1);
  9995. }
  9996. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9997. /// 0090 <id>.L <type>.B
  9998. /// type:
  9999. /// 1 = click
  10000. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  10001. {
  10002. struct block_list *bl;
  10003. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10004. if(pc_isdead(sd)) {
  10005. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10006. return;
  10007. }
  10008. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10009. #ifdef RENEWAL
  10010. clif_msg( sd, WORK_IN_PROGRESS );
  10011. #endif
  10012. return;
  10013. }
  10014. if( sd->state.mail_writing )
  10015. return;
  10016. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10017. //type = RFIFOB(fd,info->pos[1]);
  10018. if (!bl) return;
  10019. switch (bl->type) {
  10020. case BL_MOB:
  10021. case BL_PC:
  10022. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10023. break;
  10024. case BL_NPC:
  10025. #ifdef RENEWAL
  10026. 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
  10027. clif_msg(sd, WORK_IN_PROGRESS);
  10028. break;
  10029. }
  10030. #endif
  10031. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10032. struct npc_data* nd = (struct npc_data*)bl;
  10033. // Progressbar is running
  10034. if( nd->progressbar.timeout > 0 ){
  10035. return;
  10036. }
  10037. npc_click(sd,nd);
  10038. }
  10039. break;
  10040. }
  10041. }
  10042. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10043. /// 00c5 <id>.L <type>.B
  10044. /// type:
  10045. /// 0 = buy
  10046. /// 1 = sell
  10047. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  10048. {
  10049. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10050. if (sd->state.trading)
  10051. return;
  10052. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10053. }
  10054. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10055. /// 00ca <result>.B
  10056. /// result:
  10057. /// 0 = "The deal has successfully completed."
  10058. /// 1 = "You do not have enough zeny."
  10059. /// 2 = "You are over your Weight Limit."
  10060. /// 3 = "Out of the maximum capacity, you have too many items."
  10061. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  10062. {
  10063. int fd = sd->fd;
  10064. WFIFOHEAD(fd,packet_len(0xca));
  10065. WFIFOW(fd,0) = 0xca;
  10066. WFIFOB(fd,2) = result;
  10067. WFIFOSET(fd,packet_len(0xca));
  10068. }
  10069. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10070. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10071. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  10072. {
  10073. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10074. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  10075. int result;
  10076. if( sd->state.trading || !sd->npc_shopid )
  10077. result = 1;
  10078. else
  10079. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  10080. sd->npc_shopid = 0; //Clear shop data.
  10081. clif_npc_buy_result(sd, result);
  10082. }
  10083. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10084. /// 00cb <result>.B
  10085. /// result:
  10086. /// 0 = "The deal has successfully completed."
  10087. /// 1 = "The deal has failed."
  10088. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10089. {
  10090. int fd = sd->fd;
  10091. WFIFOHEAD(fd,packet_len(0xcb));
  10092. WFIFOW(fd,0) = 0xcb;
  10093. WFIFOB(fd,2) = result;
  10094. WFIFOSET(fd,packet_len(0xcb));
  10095. }
  10096. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10097. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10098. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10099. {
  10100. int fail=0,n;
  10101. unsigned short *item_list;
  10102. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10103. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10104. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10105. if (sd->state.trading || !sd->npc_shopid)
  10106. fail = 1;
  10107. else
  10108. fail = npc_selllist(sd,n,item_list);
  10109. sd->npc_shopid = 0; //Clear shop data.
  10110. clif_npc_sell_result(sd, fail);
  10111. }
  10112. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10113. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10114. /// type:
  10115. /// 0 = private
  10116. /// 1 = public
  10117. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10118. {
  10119. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10120. int len = RFIFOW(fd,info->pos[0])-15;
  10121. int limit = RFIFOW(fd,info->pos[1]);
  10122. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10123. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10124. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10125. char s_password[CHATROOM_PASS_SIZE];
  10126. char s_title[CHATROOM_TITLE_SIZE];
  10127. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10128. return;
  10129. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10130. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10131. return;
  10132. }
  10133. if( npc_isnear(&sd->bl) ) {
  10134. // uncomment to send msg_txt.
  10135. //char output[150];
  10136. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10137. //clif_displaymessage(sd->fd, output);
  10138. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10139. return;
  10140. }
  10141. if( len <= 0 )
  10142. return; // invalid input
  10143. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10144. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10145. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10146. }
  10147. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10148. /// 00d9 <chat ID>.L <passwd>.8B
  10149. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10150. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10151. int chatid = RFIFOL(fd,info->pos[0]);
  10152. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10153. chat_joinchat(sd,chatid,password);
  10154. }
  10155. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10156. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10157. /// type:
  10158. /// 0 = private
  10159. /// 1 = public
  10160. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10161. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10162. int len = RFIFOW(fd,info->pos[0])-15;
  10163. int limit = RFIFOW(fd,info->pos[1]);
  10164. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10165. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10166. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10167. char s_password[CHATROOM_PASS_SIZE];
  10168. char s_title[CHATROOM_TITLE_SIZE];
  10169. if( len <= 0 )
  10170. return; // invalid input
  10171. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10172. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10173. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10174. }
  10175. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10176. /// 00e0 <role>.L <nick>.24B
  10177. /// role:
  10178. /// 0 = owner
  10179. /// 1 = normal
  10180. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10181. {
  10182. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10183. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10184. }
  10185. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10186. /// 00e2 <name>.24B
  10187. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10188. {
  10189. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10190. }
  10191. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10192. /// 00e3
  10193. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10194. {
  10195. chat_leavechat(sd,0);
  10196. }
  10197. //Handles notifying asker and rejecter of what has just ocurred.
  10198. //Type is used to determine the correct msg_txt to use:
  10199. //0:
  10200. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10201. {
  10202. const char* msg;
  10203. char output[256];
  10204. // Your request has been rejected by autoreject option.
  10205. msg = msg_txt(sd,392);
  10206. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10207. //Notice that a request was rejected.
  10208. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10209. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10210. }
  10211. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10212. /// 00e4 <account id>.L
  10213. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10214. {
  10215. struct map_session_data *t_sd;
  10216. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10217. if(!sd->chatID && pc_cant_act(sd))
  10218. return; //You can trade while in a chatroom.
  10219. if(t_sd){
  10220. // @noask [LuzZza]
  10221. if(t_sd->state.noask) {
  10222. clif_noask_sub(sd, t_sd, 0);
  10223. return;
  10224. }
  10225. if (t_sd->state.mail_writing) {
  10226. int old = sd->trade_partner;
  10227. // Fake trading
  10228. sd->trade_partner = t_sd->status.account_id;
  10229. clif_tradestart(sd, 5);
  10230. // Restore old state
  10231. sd->trade_partner = old;
  10232. return;
  10233. }
  10234. }
  10235. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10236. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10237. return;
  10238. }
  10239. trade_traderequest(sd,t_sd);
  10240. }
  10241. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10242. /// 00e6 <result>.B
  10243. /// result:
  10244. /// 3 = accepted
  10245. /// 4 = rejected
  10246. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10247. {
  10248. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10249. }
  10250. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10251. /// 00e8 <index>.W <amount>.L
  10252. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10253. {
  10254. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10255. short index = RFIFOW(fd,info->pos[0]);
  10256. int amount = RFIFOL(fd,info->pos[1]);
  10257. if( index == 0 )
  10258. trade_tradeaddzeny(sd, amount);
  10259. else
  10260. trade_tradeadditem(sd, index, (short)amount);
  10261. }
  10262. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10263. /// 00eb
  10264. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10265. {
  10266. trade_tradeok(sd);
  10267. }
  10268. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10269. /// 00ed
  10270. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10271. {
  10272. trade_tradecancel(sd);
  10273. }
  10274. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10275. /// 00ef
  10276. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10277. {
  10278. trade_tradecommit(sd);
  10279. }
  10280. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10281. /// 0118
  10282. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10283. {
  10284. pc_stop_attack(sd);
  10285. if (sd) sd->ud.state.attack_continue = 0;
  10286. }
  10287. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10288. /// 0126 <index>.W <amount>.L
  10289. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10290. {
  10291. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10292. if (pc_istrading(sd))
  10293. return;
  10294. if (!pc_iscarton(sd))
  10295. return;
  10296. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10297. }
  10298. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10299. /// 0127 <index>.W <amount>.L
  10300. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10301. {
  10302. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10303. if (!pc_iscarton(sd))
  10304. return;
  10305. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10306. }
  10307. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10308. /// 012a
  10309. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10310. {
  10311. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10312. #ifdef NEW_CARTS
  10313. && sd->sc.data[SC_PUSH_CART] )
  10314. pc_setcart(sd,0);
  10315. #else
  10316. )
  10317. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10318. #endif
  10319. else // priority to remove this option before we can clear cart
  10320. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10321. }
  10322. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10323. /// 097f <Length>.W <identity>.L <type>.B
  10324. void clif_SelectCart(struct map_session_data *sd) {
  10325. #if PACKETVER >= 20150826
  10326. int i = 0, carts = 3;
  10327. int fd = sd->fd;
  10328. WFIFOHEAD(fd,8 + carts);
  10329. WFIFOW(fd,0) = 0x97f;
  10330. WFIFOW(fd,2) = 8 + carts;
  10331. WFIFOL(fd,4) = sd->status.account_id;
  10332. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10333. for( i = 0; i < carts; i++ ) {
  10334. WFIFOB(fd,8 + i) = 10 + i;
  10335. }
  10336. WFIFOSET(fd,8 + carts);
  10337. #endif
  10338. }
  10339. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10340. /// 0980 <identity>.L <type>.B
  10341. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10342. #if PACKETVER >= 20150826
  10343. int type;
  10344. // Check identity
  10345. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10346. return;
  10347. type = (int)RFIFOB(fd,6);
  10348. // Check type
  10349. if( type < 10 || type > MAX_CARTS )
  10350. return;
  10351. pc_setcart(sd, type);
  10352. #endif
  10353. }
  10354. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10355. /// 01af <num>.W
  10356. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10357. {// TODO: State tracking?
  10358. int type;
  10359. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10360. return;
  10361. #ifdef RENEWAL
  10362. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10363. clif_msg(sd, WORK_IN_PROGRESS);
  10364. return;
  10365. }
  10366. #endif
  10367. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10368. if(
  10369. #ifdef NEW_CARTS
  10370. (type == 9 && sd->status.base_level > 130) ||
  10371. (type == 8 && sd->status.base_level > 120) ||
  10372. (type == 7 && sd->status.base_level > 110) ||
  10373. (type == 6 && sd->status.base_level > 100) ||
  10374. #endif
  10375. (type == 5 && sd->status.base_level > 90) ||
  10376. (type == 4 && sd->status.base_level > 80) ||
  10377. (type == 3 && sd->status.base_level > 65) ||
  10378. (type == 2 && sd->status.base_level > 40) ||
  10379. (type == 1))
  10380. pc_setcart(sd, type);
  10381. }
  10382. /// Request to increase status (CZ_STATUS_CHANGE).
  10383. /// 00bb <status id>.W <amount>.B
  10384. /// status id:
  10385. /// SP_STR ~ SP_LUK
  10386. /// amount:
  10387. /// Old clients always send 1 for this, even when using /str+ and the like.
  10388. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10389. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10390. {
  10391. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10392. if( increase_amount < 0 ) {
  10393. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10394. fd, increase_amount);
  10395. }
  10396. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10397. }
  10398. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10399. /// 0112 <skill id>.W
  10400. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10401. {
  10402. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10403. }
  10404. 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)
  10405. {
  10406. int lv;
  10407. if( !hd )
  10408. return;
  10409. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10410. clif_emotion(&hd->bl, ET_THINK);
  10411. return;
  10412. }
  10413. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10414. target_id = hd->bl.id;
  10415. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10416. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10417. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10418. clif_emotion(&hd->bl, ET_THINK);
  10419. if (hd->master)
  10420. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10421. return;
  10422. }
  10423. lv = hom_checkskill(hd, skill_id);
  10424. if( skill_lv > lv )
  10425. skill_lv = lv;
  10426. if( skill_lv )
  10427. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10428. }
  10429. 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)
  10430. {
  10431. int lv;
  10432. if( !hd )
  10433. return;
  10434. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10435. clif_emotion(&hd->bl, ET_THINK);
  10436. return;
  10437. }
  10438. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10439. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10440. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10441. clif_emotion(&hd->bl, ET_THINK);
  10442. if (hd->master)
  10443. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10444. return;
  10445. }
  10446. if( hd->sc.data[SC_BASILICA] )
  10447. return;
  10448. lv = hom_checkskill(hd, skill_id);
  10449. if( skill_lv > lv )
  10450. skill_lv = lv;
  10451. if( skill_lv )
  10452. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10453. }
  10454. 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)
  10455. {
  10456. int lv;
  10457. if( !md )
  10458. return;
  10459. if( skill_isNotOk_mercenary(skill_id, md) )
  10460. return;
  10461. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10462. target_id = md->bl.id;
  10463. if( md->ud.skilltimer != INVALID_TIMER )
  10464. {
  10465. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10466. }
  10467. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10468. return;
  10469. lv = mercenary_checkskill(md, skill_id);
  10470. if( skill_lv > lv )
  10471. skill_lv = lv;
  10472. if( skill_lv )
  10473. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10474. }
  10475. 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)
  10476. {
  10477. int lv;
  10478. if( !md )
  10479. return;
  10480. if( skill_isNotOk_mercenary(skill_id, md) )
  10481. return;
  10482. if( md->ud.skilltimer != INVALID_TIMER )
  10483. return;
  10484. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10485. {
  10486. if (md->master)
  10487. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10488. return;
  10489. }
  10490. if( md->sc.data[SC_BASILICA] )
  10491. return;
  10492. lv = mercenary_checkskill(md, skill_id);
  10493. if( skill_lv > lv )
  10494. skill_lv = lv;
  10495. if( skill_lv )
  10496. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10497. }
  10498. void clif_parse_skill_toid( struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10499. t_tick tick = gettick();
  10500. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10501. int inf = skill_get_inf(skill_id);
  10502. if (inf&INF_GROUND_SKILL || !inf)
  10503. return; //Using a ground/passive skill on a target? WRONG.
  10504. if (sd->state.block_action & PCBLOCK_SKILL) {
  10505. clif_msg(sd, WORK_IN_PROGRESS);
  10506. return;
  10507. }
  10508. if( SKILL_CHK_HOMUN(skill_id) ) {
  10509. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10510. return;
  10511. }
  10512. if( SKILL_CHK_MERC(skill_id) ) {
  10513. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10514. return;
  10515. }
  10516. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10517. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10518. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10519. sd->idletime = last_tick;
  10520. if( sd->npc_id ){
  10521. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10522. #ifdef RENEWAL
  10523. clif_msg( sd, WORK_IN_PROGRESS );
  10524. #endif
  10525. return;
  10526. }
  10527. }
  10528. if ((pc_cant_act2(sd) || sd->chatID) &&
  10529. skill_id != RK_REFRESH &&
  10530. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10531. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10532. return;
  10533. if( pc_issit(sd) )
  10534. return;
  10535. if( skill_isNotOk(skill_id, sd) )
  10536. return;
  10537. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10538. target_id = sd->bl.id; // never trust the client
  10539. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10540. target_id = sd->bl.id;
  10541. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10542. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10543. return;
  10544. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10545. if( sd->skillitem != skill_id ) {
  10546. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10547. return;
  10548. }
  10549. }
  10550. if( sd->sc.option&OPTION_COSTUME )
  10551. return;
  10552. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10553. return; // On basilica only caster can use Basilica again to stop it.
  10554. if( sd->menuskill_id ) {
  10555. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10556. clif_menuskill_clear(sd); //Cancel pet capture.
  10557. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10558. return; //Can't use skills while a menu is open.
  10559. }
  10560. if( sd->skillitem == skill_id ) {
  10561. if( skill_lv != sd->skillitemlv )
  10562. skill_lv = sd->skillitemlv;
  10563. if( !(inf&INF_SELF_SKILL) )
  10564. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10565. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10566. return;
  10567. }
  10568. sd->skillitem = sd->skillitemlv = 0;
  10569. if( SKILL_CHK_GUILD(skill_id) ) {
  10570. if( sd->state.gmaster_flag )
  10571. skill_lv = guild_checkskill(sd->guild, skill_id);
  10572. else
  10573. skill_lv = 0;
  10574. } else {
  10575. if( skill_id != ALL_EQSWITCH ){
  10576. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10577. }
  10578. }
  10579. pc_delinvincibletimer(sd);
  10580. if( skill_lv )
  10581. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10582. }
  10583. /// Request to use a targeted skill.
  10584. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10585. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10586. /// There are various variants of this packet, some of them have padding between fields.
  10587. void clif_parse_UseSkillToId( int fd, struct map_session_data *sd ){
  10588. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10589. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10590. }
  10591. /*==========================================
  10592. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10593. *------------------------------------------*/
  10594. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10595. {
  10596. t_tick tick = gettick();
  10597. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10598. return; //Using a target skill on the ground? WRONG.
  10599. if (sd->state.block_action & PCBLOCK_SKILL) {
  10600. clif_msg(sd, WORK_IN_PROGRESS);
  10601. return;
  10602. }
  10603. if( SKILL_CHK_HOMUN(skill_id) ) {
  10604. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10605. return;
  10606. }
  10607. if( SKILL_CHK_MERC(skill_id) ) {
  10608. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10609. return;
  10610. }
  10611. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10612. #ifdef RENEWAL
  10613. clif_msg( sd, WORK_IN_PROGRESS );
  10614. #endif
  10615. return;
  10616. }
  10617. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10618. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10619. sd->idletime = last_tick;
  10620. if( skill_isNotOk(skill_id, sd) )
  10621. return;
  10622. if( skillmoreinfo != -1 ) {
  10623. if( pc_issit(sd) ) {
  10624. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10625. return;
  10626. }
  10627. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10628. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10629. }
  10630. if( sd->ud.skilltimer != INVALID_TIMER )
  10631. return;
  10632. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10633. if( sd->skillitem != skill_id ) {
  10634. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10635. return;
  10636. }
  10637. }
  10638. if( sd->sc.option&OPTION_COSTUME )
  10639. return;
  10640. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10641. return; // On basilica only caster can use Basilica again to stop it.
  10642. if( sd->menuskill_id ) {
  10643. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10644. clif_menuskill_clear(sd); //Cancel pet capture.
  10645. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10646. return; //Can't use skills while a menu is open.
  10647. }
  10648. pc_delinvincibletimer(sd);
  10649. if( sd->skillitem == skill_id ) {
  10650. if( skill_lv != sd->skillitemlv )
  10651. skill_lv = sd->skillitemlv;
  10652. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10653. } else {
  10654. int lv;
  10655. sd->skillitem = sd->skillitemlv = 0;
  10656. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10657. if( skill_lv > lv )
  10658. skill_lv = lv;
  10659. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10660. }
  10661. }
  10662. }
  10663. /// Request to use a ground skill.
  10664. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10665. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10666. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10667. /// There are various variants of this packet, some of them have padding between fields.
  10668. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10669. {
  10670. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10671. if (pc_cant_act(sd))
  10672. return;
  10673. if (pc_issit(sd))
  10674. return;
  10675. clif_parse_UseSkillToPosSub(fd, sd,
  10676. RFIFOW(fd,info->pos[0]), //skill lv
  10677. RFIFOW(fd,info->pos[1]), //skill num
  10678. RFIFOW(fd,info->pos[2]), //pos x
  10679. RFIFOW(fd,info->pos[3]), //pos y
  10680. // TODO: find out what this is intended to do
  10681. //RFIFOB(fd, info->pos[4])
  10682. -1 //Skill more info.
  10683. );
  10684. }
  10685. /// Request to use a ground skill with text.
  10686. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10687. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10688. /// There are various variants of this packet, some of them have padding between fields.
  10689. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10690. {
  10691. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10692. if (pc_cant_act(sd))
  10693. return;
  10694. if (pc_issit(sd))
  10695. return;
  10696. clif_parse_UseSkillToPosSub(fd, sd,
  10697. RFIFOW(fd,info->pos[0]), //Skill lv
  10698. RFIFOW(fd,info->pos[1]), //Skill num
  10699. RFIFOW(fd,info->pos[2]), //pos x
  10700. RFIFOW(fd,info->pos[3]), //pos y
  10701. info->pos[4] //skill more info
  10702. );
  10703. }
  10704. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10705. /// 011b <skill id>.W <map name>.16B
  10706. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10707. {
  10708. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10709. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10710. char map_name[MAP_NAME_LENGTH];
  10711. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10712. sd->state.workinprogress = WIP_DISABLE_NONE;
  10713. if(skill_id != sd->menuskill_id)
  10714. return;
  10715. //It is possible to use teleport with the storage window open bugreport:8027
  10716. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10717. clif_menuskill_clear(sd);
  10718. return;
  10719. }
  10720. pc_delinvincibletimer(sd);
  10721. skill_castend_map(sd,skill_id,map_name);
  10722. }
  10723. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10724. /// 011d
  10725. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10726. {
  10727. if (!pc_isdead(sd))
  10728. pc_memo(sd,-1);
  10729. }
  10730. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10731. /// 018e <name id>.W { <material id>.W }*3
  10732. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10733. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10734. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10735. int slot1 = RFIFOW(fd,info->pos[1]);
  10736. int slot2 = RFIFOW(fd,info->pos[2]);
  10737. int slot3 = RFIFOW(fd,info->pos[3]);
  10738. short produce_idx = -1;
  10739. switch( sd->menuskill_id ) {
  10740. case -1:
  10741. case AM_PHARMACY:
  10742. case RK_RUNEMASTERY:
  10743. case GC_RESEARCHNEWPOISON:
  10744. break;
  10745. default:
  10746. return;
  10747. }
  10748. if (pc_istrading(sd)) {
  10749. //Make it fail to avoid shop exploits where you sell something different than you see.
  10750. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10751. clif_menuskill_clear(sd);
  10752. return;
  10753. }
  10754. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10755. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10756. clif_menuskill_clear(sd);
  10757. }
  10758. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10759. /// 025b <mk type>.W <name id>.W
  10760. /// mk type:
  10761. /// 1 = cooking
  10762. /// 2 = arrow
  10763. /// 3 = elemental
  10764. /// 4 = GN_MIX_COOKING
  10765. /// 5 = GN_MAKEBOMB
  10766. /// 6 = GN_S_PHARMACY
  10767. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10768. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10769. int type = RFIFOW(fd,info->pos[0]);
  10770. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10771. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10772. short food_idx = -1;
  10773. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10774. return;
  10775. if (pc_istrading(sd)) {
  10776. //Make it fail to avoid shop exploits where you sell something different than you see.
  10777. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10778. clif_menuskill_clear(sd);
  10779. return;
  10780. }
  10781. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10782. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10783. clif_menuskill_clear(sd);
  10784. }
  10785. /// Answer to repair weapon item selection dialog
  10786. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10787. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10788. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10789. {
  10790. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10791. return;
  10792. if (pc_istrading(sd)) {
  10793. //Make it fail to avoid shop exploits where you sell something different than you see.
  10794. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10795. clif_menuskill_clear(sd);
  10796. return;
  10797. }
  10798. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10799. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10800. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10801. //for(i = 0; i<MAX_SLOTS; i++)
  10802. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10803. clif_menuskill_clear(sd);
  10804. }
  10805. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10806. /// 0222 <index>.L
  10807. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10808. {
  10809. int idx;
  10810. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10811. return;
  10812. if (pc_istrading(sd)) {
  10813. //Make it fail to avoid shop exploits where you sell something different than you see.
  10814. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10815. clif_menuskill_clear(sd);
  10816. return;
  10817. }
  10818. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10819. skill_weaponrefine(sd, idx-2);
  10820. clif_menuskill_clear(sd);
  10821. }
  10822. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10823. /// 00b8 <npc id>.L <choice>.B
  10824. /// choice:
  10825. /// 1~254 = menu item
  10826. /// 255 = cancel
  10827. /// NOTE: If there were more than 254 items in the list, choice
  10828. /// overflows to choice%256.
  10829. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10830. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10831. int npc_id = RFIFOL(fd,info->pos[0]);
  10832. uint8 select = RFIFOB(fd,info->pos[1]);
  10833. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10834. #ifdef SECURE_NPCTIMEOUT
  10835. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10836. #endif
  10837. TBL_NPC* nd = map_id2nd(npc_id);
  10838. 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);
  10839. clif_GM_kick(NULL,sd);
  10840. #ifdef SECURE_NPCTIMEOUT
  10841. }
  10842. #endif
  10843. return;
  10844. }
  10845. sd->npc_menu = select;
  10846. npc_scriptcont(sd,npc_id, false);
  10847. }
  10848. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10849. /// 00b9 <npc id>.L
  10850. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10851. {
  10852. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10853. }
  10854. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10855. /// 0143 <npc id>.L <value>.L
  10856. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10857. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10858. int npcid = RFIFOL(fd,info->pos[0]);
  10859. int amount = (int)RFIFOL(fd,info->pos[1]);
  10860. sd->npc_amount = amount;
  10861. npc_scriptcont(sd, npcid, false);
  10862. }
  10863. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10864. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10865. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10866. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10867. int message_len = RFIFOW(fd,info->pos[0])-8;
  10868. int npcid = RFIFOL(fd,info->pos[1]);
  10869. const char* message = RFIFOCP(fd,info->pos[2]);
  10870. if( message_len <= 0 )
  10871. return; // invalid input
  10872. #if PACKETVER >= 20151001
  10873. message_len++;
  10874. #endif
  10875. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10876. npc_scriptcont(sd, npcid, false);
  10877. }
  10878. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10879. /// 0146 <npc id>.L
  10880. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10881. {
  10882. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10883. return;
  10884. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10885. }
  10886. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10887. /// 0178 <index>.W
  10888. /// index:
  10889. /// -1 = cancel
  10890. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10891. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10892. if (sd->menuskill_id != MC_IDENTIFY)
  10893. return;
  10894. // Ignore the request
  10895. // - Invalid item index
  10896. // - Invalid item ID or item doesn't exist
  10897. // - Item is already identified
  10898. if (idx < 0 || idx >= MAX_INVENTORY ||
  10899. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10900. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10901. sd->state.workinprogress = WIP_DISABLE_NONE;
  10902. clif_menuskill_clear(sd);
  10903. return;
  10904. }
  10905. skill_identify(sd, idx);
  10906. clif_menuskill_clear(sd);
  10907. }
  10908. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10909. /// 01ae <name id>.W
  10910. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10911. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10912. if (pc_istrading(sd)) {
  10913. //Make it fail to avoid shop exploits where you sell something different than you see.
  10914. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10915. clif_menuskill_clear(sd);
  10916. return;
  10917. }
  10918. switch (sd->menuskill_id) {
  10919. case AC_MAKINGARROW:
  10920. skill_arrow_create(sd,nameid);
  10921. break;
  10922. case SA_CREATECON:
  10923. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10924. break;
  10925. case WL_READING_SB:
  10926. skill_spellbook(sd,nameid);
  10927. break;
  10928. case GC_POISONINGWEAPON:
  10929. skill_poisoningweapon(sd,nameid);
  10930. break;
  10931. case NC_MAGICDECOY:
  10932. skill_magicdecoy(sd,nameid);
  10933. break;
  10934. }
  10935. clif_menuskill_clear(sd);
  10936. }
  10937. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10938. /// 01ce <skill id>.L
  10939. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10940. {
  10941. if (sd->menuskill_id != SA_AUTOSPELL)
  10942. return;
  10943. sd->state.workinprogress = WIP_DISABLE_NONE;
  10944. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10945. clif_menuskill_clear(sd);
  10946. }
  10947. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10948. /// 017a <card index>.W
  10949. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10950. {
  10951. if (sd->state.trading != 0)
  10952. return;
  10953. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10954. }
  10955. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10956. /// 017c <card index>.W <equip index>.W
  10957. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10958. {
  10959. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10960. if (sd->state.trading != 0)
  10961. return;
  10962. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10963. }
  10964. /// Request of character's name by char ID.
  10965. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10966. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10967. /// There are various variants of this packet, some of them have padding between fields.
  10968. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10969. {
  10970. int charid;
  10971. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10972. map_reqnickdb(sd, charid);
  10973. }
  10974. /// /resetskill /resetstate (CZ_RESET).
  10975. /// Request to reset stats or skills.
  10976. /// 0197 <type>.W
  10977. /// type:
  10978. /// 0 = state
  10979. /// 1 = skill
  10980. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10981. char cmd[15];
  10982. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10983. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10984. else
  10985. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10986. is_atcommand(fd, sd, cmd, 1);
  10987. }
  10988. /// /lb /nlb (CZ_LOCALBROADCAST).
  10989. /// Request to broadcast a message on current map.
  10990. /// 019c <packet len>.W <text>.?B
  10991. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10992. {
  10993. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10994. char command[CHAT_SIZE_MAX+16];
  10995. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10996. char* msg = RFIFOCP(fd,info->pos[1]);
  10997. // as the length varies depending on the command used, just block unreasonably long strings
  10998. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10999. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11000. is_atcommand(fd, sd, command, 1);
  11001. }
  11002. /// Request to move an item from inventory to storage.
  11003. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11004. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11005. /// There are various variants of this packet, some of them have padding between fields.
  11006. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  11007. {
  11008. int item_index, item_amount;
  11009. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11010. if (pc_istrading(sd))
  11011. return;
  11012. item_index = RFIFOW(fd,info->pos[0])-2;
  11013. item_amount = RFIFOL(fd,info->pos[1]);
  11014. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11015. return;
  11016. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11017. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11018. return;
  11019. }
  11020. if (sd->state.storage_flag == 1)
  11021. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11022. else
  11023. if (sd->state.storage_flag == 2)
  11024. storage_guild_storageadd(sd, item_index, item_amount);
  11025. else if (sd->state.storage_flag == 3)
  11026. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11027. }
  11028. /// Request to move an item from storage to inventory.
  11029. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11030. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11031. /// There are various variants of this packet, some of them have padding between fields.
  11032. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  11033. {
  11034. int item_index, item_amount;
  11035. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11036. item_index = RFIFOW(fd,info->pos[0])-1;
  11037. item_amount = RFIFOL(fd,info->pos[1]);
  11038. if (sd->state.storage_flag == 1)
  11039. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11040. else if(sd->state.storage_flag == 2)
  11041. storage_guild_storageget(sd, item_index, item_amount);
  11042. else if(sd->state.storage_flag == 3)
  11043. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11044. }
  11045. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11046. /// 0129 <index>.W <amount>.L
  11047. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  11048. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11049. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11050. int amount = RFIFOL(fd,info->pos[1]);
  11051. if( sd->state.vending )
  11052. return;
  11053. if (!pc_iscarton(sd))
  11054. return;
  11055. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11056. return;
  11057. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11058. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11059. return;
  11060. }
  11061. if (sd->state.storage_flag == 1)
  11062. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11063. else if (sd->state.storage_flag == 2)
  11064. storage_guild_storageaddfromcart(sd, idx, amount);
  11065. else if (sd->state.storage_flag == 3)
  11066. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11067. }
  11068. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11069. /// 0128 <index>.W <amount>.L
  11070. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  11071. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11072. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11073. int amount = RFIFOL(fd,info->pos[1]);
  11074. if( sd->state.vending )
  11075. return;
  11076. if (!pc_iscarton(sd))
  11077. return;
  11078. if (sd->state.storage_flag == 1)
  11079. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11080. else
  11081. if (sd->state.storage_flag == 2)
  11082. storage_guild_storagegettocart(sd, idx, amount);
  11083. else if (sd->state.storage_flag == 3)
  11084. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11085. }
  11086. /// Request to close storage (CZ_CLOSE_STORE).
  11087. /// 00f7
  11088. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11089. {
  11090. if( sd->state.storage_flag == 1 )
  11091. storage_storageclose(sd);
  11092. else
  11093. if( sd->state.storage_flag == 2 )
  11094. storage_guild_storageclose(sd);
  11095. else if( sd->state.storage_flag == 3 )
  11096. storage_premiumStorage_close(sd);
  11097. }
  11098. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11099. /// 023a <info>.W
  11100. /// info:
  11101. /// 0 = password has not been set yet
  11102. /// 1 = storage is password-protected
  11103. /// 8 = too many wrong passwords
  11104. /// ? = ignored
  11105. /// NOTE: This packet is only available on certain non-kRO clients.
  11106. void clif_storagepassword(struct map_session_data* sd, short info)
  11107. {
  11108. int fd = sd->fd;
  11109. WFIFOHEAD(fd,packet_len(0x23a));
  11110. WFIFOW(fd,0) = 0x23a;
  11111. WFIFOW(fd,2) = info;
  11112. WFIFOSET(fd,packet_len(0x23a));
  11113. }
  11114. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11115. /// 023b <type>.W <password>.16B <new password>.16B
  11116. /// type:
  11117. /// 2 = change password
  11118. /// 3 = check password
  11119. /// NOTE: This packet is only available on certain non-kRO clients.
  11120. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11121. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11122. // int type = RFIFOW(fd,info->pos[0]);
  11123. // char* password = RFIFOP(fd,info->pos[1]);
  11124. // char* new_password = RFIFOP(fd,info->pos[2]);
  11125. // storage_changepass(sd,password,new_password);
  11126. }
  11127. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11128. /// 023c <result>.W <error count>.W
  11129. /// result:
  11130. /// 4 = password change success
  11131. /// 5 = password change failure
  11132. /// 6 = password check success
  11133. /// 7 = password check failure
  11134. /// 8 = too many wrong passwords
  11135. /// ? = ignored
  11136. /// NOTE: This packet is only available on certain non-kRO clients.
  11137. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11138. {
  11139. int fd = sd->fd;
  11140. WFIFOHEAD(fd,packet_len(0x23c));
  11141. WFIFOW(fd,0) = 0x23c;
  11142. WFIFOW(fd,2) = result;
  11143. WFIFOW(fd,4) = error_count;
  11144. WFIFOSET(fd,packet_len(0x23c));
  11145. }
  11146. /// Party creation request
  11147. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11148. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11149. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11150. name[NAME_LENGTH-1] = '\0';
  11151. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11152. clif_displaymessage(fd, msg_txt(sd,227));
  11153. return;
  11154. }
  11155. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11156. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11157. return;
  11158. }
  11159. party_create(sd,name,0,0);
  11160. }
  11161. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11162. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11163. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11164. char* name = RFIFOCP(fd,info->pos[0]);
  11165. int item1 = RFIFOB(fd,info->pos[1]);
  11166. int item2 = RFIFOB(fd,info->pos[2]);
  11167. name[NAME_LENGTH-1] = '\0';
  11168. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11169. clif_displaymessage(fd, msg_txt(sd,227));
  11170. return;
  11171. }
  11172. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11173. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11174. return;
  11175. }
  11176. party_create(sd,name,item1,item2);
  11177. }
  11178. /// Party invitation request
  11179. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11180. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11181. {
  11182. struct map_session_data *t_sd;
  11183. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11184. clif_displaymessage(fd, msg_txt(sd,227));
  11185. return;
  11186. }
  11187. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11188. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11189. clif_noask_sub(sd, t_sd, 1);
  11190. return;
  11191. }
  11192. party_invite(sd, t_sd);
  11193. }
  11194. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11195. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11196. struct map_session_data *t_sd;
  11197. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11198. name[NAME_LENGTH-1] = '\0';
  11199. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11200. clif_displaymessage(fd, msg_txt(sd,227));
  11201. return;
  11202. }
  11203. t_sd = map_nick2sd(name,false);
  11204. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11205. clif_noask_sub(sd, t_sd, 1);
  11206. return;
  11207. }
  11208. party_invite(sd, t_sd);
  11209. }
  11210. /// Party invitation reply
  11211. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11212. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11213. /// flag:
  11214. /// 0 = reject
  11215. /// 1 = accept
  11216. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11217. {
  11218. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11219. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11220. RFIFOL(fd,info->pos[1]));
  11221. }
  11222. //(CZ_PARTY_JOIN_REQ_ACK)
  11223. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11224. {
  11225. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11226. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11227. RFIFOB(fd,info->pos[1]));
  11228. }
  11229. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11230. /// 0100
  11231. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11232. {
  11233. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11234. clif_displaymessage(fd, msg_txt(sd,227));
  11235. return;
  11236. }
  11237. party_leave(sd);
  11238. }
  11239. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11240. /// 0103 <account id>.L <char name>.24B
  11241. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11242. {
  11243. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11244. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11245. clif_displaymessage(fd, msg_txt(sd,227));
  11246. return;
  11247. }
  11248. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11249. RFIFOCP(fd,info->pos[1]));
  11250. }
  11251. /// Request to change party options.
  11252. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11253. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11254. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11255. {
  11256. struct party_data *p;
  11257. int i,expflag;
  11258. int cmd = RFIFOW(fd,0);
  11259. struct s_packet_db* info = &packet_db[cmd];
  11260. if( !sd->status.party_id )
  11261. return;
  11262. p = party_search(sd->status.party_id);
  11263. if( p == NULL )
  11264. return;
  11265. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11266. if( i == MAX_PARTY )
  11267. return; //Shouldn't happen
  11268. if( !p->party.member[i].leader )
  11269. return;
  11270. expflag = RFIFOL(fd,info->pos[0]);
  11271. if(cmd == 0x0102){ //Client can't change the item-field
  11272. party_changeoption(sd, expflag, p->party.item);
  11273. }
  11274. else {
  11275. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11276. party_changeoption(sd, expflag, itemflag);
  11277. }
  11278. }
  11279. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11280. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11281. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11282. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11283. // validate packet and retrieve name and message
  11284. if( !clif_process_message( sd, false, name, message, output ) )
  11285. return;
  11286. party_send_message(sd, output, strlen(output) + 1 );
  11287. }
  11288. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11289. /// 07da <account id>.L
  11290. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11291. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11292. }
  11293. /// Party Booking in KRO [Spiria]
  11294. ///
  11295. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11296. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11297. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11298. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11299. short level = RFIFOW(fd,info->pos[0]);
  11300. short mapid = RFIFOW(fd,info->pos[1]);
  11301. int idxpbj = info->pos[2];
  11302. short job[MAX_PARTY_BOOKING_JOBS];
  11303. int i;
  11304. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11305. job[i] = RFIFOB(fd,idxpbj+i*2);
  11306. party_booking_register(sd, level, mapid, job);
  11307. }
  11308. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11309. /// 0803 <result>.W
  11310. /// result:
  11311. /// 0 = success
  11312. /// 1 = failure
  11313. /// 2 = already registered
  11314. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11315. {
  11316. int fd = sd->fd;
  11317. WFIFOHEAD(fd,packet_len(0x803));
  11318. WFIFOW(fd,0) = 0x803;
  11319. WFIFOW(fd,2) = flag;
  11320. WFIFOSET(fd,packet_len(0x803));
  11321. }
  11322. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11323. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11324. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11325. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11326. short level = RFIFOW(fd,info->pos[0]);
  11327. short mapid = RFIFOW(fd,info->pos[1]);
  11328. short job = RFIFOW(fd,info->pos[2]);
  11329. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11330. short resultcount = RFIFOW(fd,info->pos[4]);
  11331. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11332. }
  11333. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11334. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11335. /// more results:
  11336. /// 0 = no
  11337. /// 1 = yes
  11338. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11339. {
  11340. int i, j;
  11341. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11342. struct party_booking_ad_info *pb_ad;
  11343. WFIFOHEAD(fd,size*count + 5);
  11344. WFIFOW(fd,0) = 0x805;
  11345. WFIFOW(fd,2) = size*count + 5;
  11346. WFIFOB(fd,4) = more_result;
  11347. for(i=0; i<count; i++)
  11348. {
  11349. pb_ad = results[i];
  11350. WFIFOL(fd,i*size+5) = pb_ad->index;
  11351. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11352. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11353. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11354. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11355. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11356. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11357. }
  11358. WFIFOSET(fd,WFIFOW(fd,2));
  11359. }
  11360. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11361. /// 0806
  11362. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11363. {
  11364. if(party_booking_delete(sd))
  11365. clif_PartyBookingDeleteAck(sd, 0);
  11366. }
  11367. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11368. /// 0807 <result>.W
  11369. /// result:
  11370. /// 0 = success
  11371. /// 1 = success (auto-removed expired ad)
  11372. /// 2 = failure
  11373. /// 3 = nothing registered
  11374. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11375. {
  11376. int fd = sd->fd;
  11377. WFIFOHEAD(fd,packet_len(0x807));
  11378. WFIFOW(fd,0) = 0x807;
  11379. WFIFOW(fd,2) = flag;
  11380. WFIFOSET(fd,packet_len(0x807));
  11381. }
  11382. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11383. /// 0808 { <job>.W }*6
  11384. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11385. {
  11386. short job[MAX_PARTY_BOOKING_JOBS];
  11387. int i;
  11388. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11389. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11390. job[i] = RFIFOW(fd,idxpbu+i*2);
  11391. party_booking_update(sd, job);
  11392. }
  11393. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11394. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11395. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11396. {
  11397. int i;
  11398. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11399. if(pb_ad == NULL) return;
  11400. WBUFW(buf,0) = 0x809;
  11401. WBUFL(buf,2) = pb_ad->index;
  11402. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11403. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11404. WBUFW(buf,34) = pb_ad->p_detail.level;
  11405. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11406. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11407. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11408. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11409. }
  11410. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11411. /// 080a <index>.L { <job>.W }*6
  11412. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11413. {
  11414. int i;
  11415. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11416. if(pb_ad == NULL) return;
  11417. WBUFW(buf,0) = 0x80a;
  11418. WBUFL(buf,2) = pb_ad->index;
  11419. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11420. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11421. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11422. }
  11423. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11424. /// 080b <index>.L
  11425. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11426. {
  11427. uint8 buf[6];
  11428. WBUFW(buf,0) = 0x80b;
  11429. WBUFL(buf,2) = index;
  11430. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11431. }
  11432. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11433. /// 012e
  11434. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11435. {
  11436. vending_closevending(sd);
  11437. }
  11438. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11439. /// 0130 <account id>.L
  11440. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11441. {
  11442. if( sd->npc_id ) {// using an NPC
  11443. return;
  11444. }
  11445. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11446. }
  11447. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11448. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11449. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11450. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11451. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11452. int id = (int)RFIFOL(fd,info->pos[1]);
  11453. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11454. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11455. // whether it fails or not, the buy window is closed
  11456. sd->vended_id = 0;
  11457. }
  11458. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11459. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11460. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11461. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11462. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11463. int aid = (int)RFIFOL(fd,info->pos[1]);
  11464. int uid = (int)RFIFOL(fd,info->pos[2]);
  11465. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11466. vending_purchasereq(sd, aid, uid, data, len/4);
  11467. // whether it fails or not, the buy window is closed
  11468. sd->vended_id = 0;
  11469. }
  11470. /// Confirm or cancel the shop preparation window.
  11471. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11472. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11473. /// result:
  11474. /// 0 = canceled
  11475. /// 1 = open
  11476. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11477. int cmd = RFIFOW(fd,0);
  11478. struct s_packet_db* info = &packet_db[cmd];
  11479. short len = (short)RFIFOW(fd,info->pos[0]);
  11480. const char* message = RFIFOCP(fd,info->pos[1]);
  11481. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11482. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11483. len -= 84;
  11484. }
  11485. else { //(CZ_REQ_OPENSTORE2)
  11486. bool flag;
  11487. len -= 85;
  11488. flag = RFIFOB(fd,info->pos[2]) != 0;
  11489. if (!flag) {
  11490. sd->state.prevend = 0;
  11491. sd->state.workinprogress = WIP_DISABLE_NONE;
  11492. }
  11493. }
  11494. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11495. return;
  11496. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11497. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11498. return;
  11499. }
  11500. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11501. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11502. return;
  11503. }
  11504. if( message[0] == '\0' ) // invalid input
  11505. return;
  11506. vending_openvending(sd, message, data, len/8, NULL);
  11507. }
  11508. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11509. /// 0165 <char id>.L <guild name>.24B
  11510. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11511. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11512. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11513. name[NAME_LENGTH-1] = '\0';
  11514. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11515. clif_displaymessage(fd, msg_txt(sd,228));
  11516. return;
  11517. }
  11518. if(sd->clan){
  11519. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11520. return;
  11521. }
  11522. guild_create(sd, name);
  11523. }
  11524. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11525. /// 014d
  11526. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11527. {
  11528. clif_guild_masterormember(sd);
  11529. }
  11530. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11531. /// 014f <type>.L
  11532. /// type:
  11533. /// 0 = basic info
  11534. /// 1 = member manager
  11535. /// 2 = positions
  11536. /// 3 = skills
  11537. /// 4 = expulsion list
  11538. /// 5 = unknown (GM_ALLGUILDLIST)
  11539. /// 6 = notice
  11540. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11541. {
  11542. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11543. if( !sd->status.guild_id && !sd->bg_id )
  11544. return;
  11545. switch( type )
  11546. {
  11547. case 0: // Basic Information Guild, hostile alliance information
  11548. clif_guild_basicinfo(sd);
  11549. clif_guild_allianceinfo(sd);
  11550. break;
  11551. case 1: // Members list, list job title
  11552. clif_guild_positionnamelist(sd);
  11553. clif_guild_memberlist(sd);
  11554. break;
  11555. case 2: // List job title, title information list
  11556. clif_guild_positionnamelist(sd);
  11557. clif_guild_positioninfolist(sd);
  11558. break;
  11559. case 3: // Skill list
  11560. clif_guild_skillinfo(sd);
  11561. break;
  11562. case 4: // Expulsion list
  11563. clif_guild_expulsionlist(sd);
  11564. break;
  11565. default:
  11566. ShowError("clif: guild request info: unknown type %d\n", type);
  11567. break;
  11568. }
  11569. }
  11570. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11571. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11572. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11573. {
  11574. int i;
  11575. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11576. int len = RFIFOW(fd,info->pos[0]);
  11577. int idxgpos = info->pos[1];
  11578. if(!sd->state.gmaster_flag)
  11579. return;
  11580. for(i = idxgpos; i < len; i += 40 ){
  11581. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11582. }
  11583. }
  11584. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11585. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11586. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11587. {
  11588. int i;
  11589. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11590. int len = RFIFOW(fd,info->pos[0]);
  11591. int idxgpos = info->pos[1];
  11592. if(!sd->state.gmaster_flag)
  11593. return;
  11594. // Guild leadership change
  11595. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11596. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11597. clif_msg(sd, GUILD_MASTER_WOE);
  11598. return;
  11599. }
  11600. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11601. clif_msg(sd, GUILD_MASTER_DELAY);
  11602. return;
  11603. }
  11604. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11605. return;
  11606. }
  11607. for(i=idxgpos;i<len;i+=12){
  11608. int position = RFIFOL(fd,i+8);
  11609. if( position > 0 ){
  11610. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11611. }
  11612. }
  11613. }
  11614. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11615. /// 0151 <guild id>.L
  11616. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11617. {
  11618. struct guild* g;
  11619. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11620. if( (g = guild_search(guild_id)) != NULL )
  11621. clif_guild_emblem(sd,g);
  11622. }
  11623. /// Validates data of a guild emblem (compressed bitmap)
  11624. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11625. EMBVALIDATE_SUCCESS = 0,
  11626. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11627. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11628. };
  11629. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11630. {
  11631. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11632. unsigned long buf_len = sizeof(buf);
  11633. int offset = 0;
  11634. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11635. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11636. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11637. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11638. ))
  11639. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11640. if(battle_config.emblem_transparency_limit != 100) {
  11641. int i, transcount = 1, tmp[3];
  11642. for(i = offset; i < buf_len-1; i++) {
  11643. int j = i%3;
  11644. tmp[j] = RBUFL(buf,i);
  11645. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11646. transcount++;
  11647. }
  11648. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11649. return EMBVALIDATE_ERR_TRANSPARENCY;
  11650. }
  11651. return EMBVALIDATE_SUCCESS;
  11652. }
  11653. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11654. /// 0153 <packet len>.W <emblem data>.?B
  11655. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11656. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11657. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11658. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11659. int emb_val=0;
  11660. if( !emblem_len || !sd->state.gmaster_flag )
  11661. return;
  11662. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11663. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11664. return;
  11665. }
  11666. emb_val = clif_validate_emblem(emblem, emblem_len);
  11667. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11668. 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);
  11669. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11670. return;
  11671. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11672. char output[128];
  11673. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11674. 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"
  11675. return;
  11676. }
  11677. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11678. }
  11679. /// Guild notice update request (CZ_GUILD_NOTICE).
  11680. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11681. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11682. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11683. int guild_id = RFIFOL(fd,info->pos[0]);
  11684. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11685. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11686. if(!sd->state.gmaster_flag)
  11687. return;
  11688. // compensate for some client defects when using multilanguage mode
  11689. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11690. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11691. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11692. guild_change_notice(sd, guild_id, msg1, msg2);
  11693. }
  11694. // Helper function for guild invite functions
  11695. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11696. {
  11697. if (t_sd == NULL) // not online or does not exist
  11698. return 1;
  11699. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11700. clif_displaymessage(fd, msg_txt(sd,228));
  11701. return 1;
  11702. }
  11703. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11704. clif_noask_sub(sd, t_sd, 2);
  11705. return 1;
  11706. }
  11707. // Players in a clan can not join a guild
  11708. if(t_sd && t_sd->clan){
  11709. return 1;
  11710. }
  11711. guild_invite(sd, t_sd);
  11712. return 0;
  11713. }
  11714. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11715. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11716. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11717. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11718. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11719. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11720. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11721. if (clif_sub_guild_invite(fd, sd, t_sd))
  11722. return;
  11723. }
  11724. /// Guild invite request (/guildinvite)
  11725. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11726. void
  11727. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11728. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11729. if (clif_sub_guild_invite(fd, sd, t_sd))
  11730. return;
  11731. }
  11732. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11733. /// 016b <guild id>.L <answer>.L
  11734. /// answer:
  11735. /// 0 = refuse
  11736. /// 1 = accept
  11737. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11738. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11739. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11740. RFIFOL(fd,info->pos[1]));
  11741. }
  11742. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11743. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11744. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11745. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11746. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11747. clif_displaymessage(fd, msg_txt(sd,228));
  11748. return;
  11749. }
  11750. if( sd->bg_id ) {
  11751. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11752. return;
  11753. }
  11754. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11755. RFIFOL(fd,info->pos[1]),
  11756. RFIFOL(fd,info->pos[2]),
  11757. RFIFOCP(fd,info->pos[3]));
  11758. }
  11759. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11760. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11761. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11762. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11763. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11764. { // Guild locked.
  11765. clif_displaymessage(fd, msg_txt(sd,228));
  11766. return;
  11767. }
  11768. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11769. RFIFOL(fd,info->pos[1]),
  11770. RFIFOL(fd,info->pos[2]),
  11771. RFIFOCP(fd,info->pos[3]));
  11772. }
  11773. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11774. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11775. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11776. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11777. // validate packet and retrieve name and message
  11778. if( !clif_process_message( sd, false, name, message, output ) )
  11779. return;
  11780. if( sd->bg_id )
  11781. bg_send_message(sd, output, strlen(output) );
  11782. else
  11783. guild_send_message(sd, output, strlen(output) );
  11784. }
  11785. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11786. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11787. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11788. {
  11789. struct map_session_data *t_sd;
  11790. if(!sd->state.gmaster_flag)
  11791. return;
  11792. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11793. clif_displaymessage(fd, msg_txt(sd,228));
  11794. return;
  11795. }
  11796. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11797. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11798. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11799. // @noask [LuzZza]
  11800. if(t_sd && t_sd->state.noask) {
  11801. clif_noask_sub(sd, t_sd, 3);
  11802. return;
  11803. }
  11804. guild_reqalliance(sd,t_sd);
  11805. }
  11806. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11807. /// 0172 <inviter account id>.L <answer>.L
  11808. /// answer:
  11809. /// 0 = refuse
  11810. /// 1 = accept
  11811. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11812. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11813. guild_reply_reqalliance(sd,
  11814. RFIFOL(fd,info->pos[0]),
  11815. RFIFOL(fd,info->pos[1]));
  11816. }
  11817. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11818. /// 0183 <opponent guild id>.L <relation>.L
  11819. /// relation:
  11820. /// 0 = Ally
  11821. /// 1 = Enemy
  11822. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11823. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11824. if(!sd->state.gmaster_flag)
  11825. return;
  11826. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11827. clif_displaymessage(fd, msg_txt(sd,228));
  11828. return;
  11829. }
  11830. guild_delalliance(sd,
  11831. RFIFOL(fd,info->pos[0]),
  11832. RFIFOL(fd,info->pos[1]));
  11833. }
  11834. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11835. /// 0180 <account id>.L
  11836. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11837. {
  11838. struct map_session_data *t_sd;
  11839. if(!sd->state.gmaster_flag)
  11840. return;
  11841. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11842. clif_displaymessage(fd, msg_txt(sd,228));
  11843. return;
  11844. }
  11845. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11846. // @noask [LuzZza]
  11847. if(t_sd && t_sd->state.noask) {
  11848. clif_noask_sub(sd, t_sd, 4);
  11849. return;
  11850. }
  11851. guild_opposition(sd,t_sd);
  11852. }
  11853. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11854. /// 015d <key>.40B
  11855. /// key:
  11856. /// now guild name; might have been (intended) email, since the
  11857. /// field name and size is same as the one in CH_DELETE_CHAR.
  11858. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11859. {
  11860. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11861. clif_displaymessage(fd, msg_txt(sd,228));
  11862. return;
  11863. }
  11864. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11865. }
  11866. /// Pet
  11867. ///
  11868. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11869. /// 01a1 <type>.B
  11870. /// type:
  11871. /// 0 = pet information
  11872. /// 1 = feed
  11873. /// 2 = performance
  11874. /// 3 = return to egg
  11875. /// 4 = unequip accessory
  11876. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11877. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11878. }
  11879. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11880. /// 019f <id>.L
  11881. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11882. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11883. }
  11884. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11885. /// 01a7 <index>.W
  11886. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11887. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11888. return;
  11889. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11890. clif_menuskill_clear(sd);
  11891. }
  11892. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11893. /// 01a9 <data>.L
  11894. /// data:
  11895. /// is either emotion (@see enum emotion_type) or a compound value
  11896. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11897. /// entry (given in parentheses) in data\pettalktable.xml
  11898. /// act id:
  11899. /// 0 = feeding
  11900. /// 1 = hunting
  11901. /// 2 = danger
  11902. /// 3 = dead
  11903. /// 4 = normal (stand)
  11904. /// 5 = special performance (perfor_s)
  11905. /// 6 = level up (levelup)
  11906. /// 7 = performance 1 (perfor_1)
  11907. /// 8 = performance 2 (perfor_2)
  11908. /// 9 = performance 3 (perfor_3)
  11909. /// 10 = log-in greeting (connect)
  11910. /// hungry value:
  11911. /// 0 = very hungry (hungry)
  11912. /// 1 = hungry (bit_hungry)
  11913. /// 2 = satisfied (noting)
  11914. /// 3 = stuffed (full)
  11915. /// 4 = full (so_full)
  11916. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11917. {
  11918. if(sd->pd)
  11919. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11920. }
  11921. /// Request to change pet's name (CZ_RENAME_PET).
  11922. /// 01a5 <name>.24B
  11923. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11924. {
  11925. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11926. }
  11927. /// /kill (CZ_DISCONNECT_CHARACTER).
  11928. /// Request to disconnect a character.
  11929. /// 00cc <account id>.L
  11930. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11931. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11932. {
  11933. struct block_list *target;
  11934. int tid;
  11935. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11936. target = map_id2bl(tid);
  11937. if (!target) {
  11938. clif_GM_kickack(sd, 0);
  11939. return;
  11940. }
  11941. switch (target->type) {
  11942. case BL_PC:
  11943. {
  11944. char command[NAME_LENGTH+6];
  11945. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11946. is_atcommand(fd, sd, command, 1);
  11947. }
  11948. break;
  11949. /**
  11950. * This one does not invoke any atcommand, so we need to check for permissions.
  11951. */
  11952. case BL_MOB:
  11953. {
  11954. char command[100];
  11955. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11956. clif_GM_kickack(sd, 0);
  11957. return;
  11958. }
  11959. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11960. log_atcommand(sd, command);
  11961. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11962. }
  11963. break;
  11964. case BL_NPC:
  11965. {
  11966. struct npc_data* nd = (struct npc_data *)target;
  11967. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11968. npc_unload_duplicates(nd);
  11969. npc_unload(nd,true);
  11970. npc_read_event_script();
  11971. }
  11972. }
  11973. break;
  11974. default:
  11975. clif_GM_kickack(sd, 0);
  11976. }
  11977. }
  11978. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11979. /// Request to disconnect all characters.
  11980. /// 00ce
  11981. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11982. char cmd[15];
  11983. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11984. is_atcommand(fd, sd, cmd, 1);
  11985. }
  11986. /// /remove (CZ_REMOVE_AID).
  11987. /// Request to warp to a character with given login ID.
  11988. /// 01ba <account name>.24B
  11989. /// /shift (CZ_SHIFT).
  11990. /// Request to warp to a character with given name.
  11991. /// 01bb <char name>.24B
  11992. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11993. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11994. char *player_name;
  11995. char command[NAME_LENGTH+8];
  11996. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11997. player_name[NAME_LENGTH-1] = '\0';
  11998. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11999. is_atcommand(fd, sd, command, 1);
  12000. }
  12001. /// /remove (CZ_REMOVE_AID_SSO).
  12002. /// Request to warp to a character with given account ID.
  12003. /// 0843 <account id>.L
  12004. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  12005. {
  12006. uint32 account_id;
  12007. struct map_session_data* pl_sd;
  12008. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12009. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12010. char command[NAME_LENGTH+8];
  12011. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12012. is_atcommand(fd, sd, command, 1);
  12013. }
  12014. }
  12015. /// /recall (CZ_RECALL).
  12016. /// Request to summon a player with given login ID to own position.
  12017. /// 01bc <account name>.24B
  12018. /// /summon (CZ_RECALL_GID).
  12019. /// Request to summon a player with given name to own position.
  12020. /// 01bd <char name>.24B
  12021. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  12022. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12023. char *player_name;
  12024. char command [NAME_LENGTH+8];
  12025. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12026. player_name[NAME_LENGTH-1] = '\0';
  12027. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12028. is_atcommand(fd, sd, command, 1);
  12029. }
  12030. /// /recall (CZ_RECALL_SSO).
  12031. /// Request to summon a player with given account ID to own position.
  12032. /// 0842 <account id>.L
  12033. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  12034. {
  12035. uint32 account_id;
  12036. struct map_session_data* pl_sd;
  12037. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12038. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12039. char command[NAME_LENGTH+8];
  12040. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12041. is_atcommand(fd, sd, command, 1);
  12042. }
  12043. }
  12044. /// /item /monster (CZ_ITEM_CREATE).
  12045. /// Request to execute GM commands.
  12046. /// Usage:
  12047. /// /item n - summon n monster or acquire n item/s
  12048. /// /item money - grants 2147483647 zenies
  12049. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12050. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12051. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12052. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12053. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12054. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12055. /// 013f <item/mob name>.24B
  12056. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12057. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  12058. {
  12059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12060. int mob_id = 0;
  12061. struct item_data *id = NULL;
  12062. struct mob_db *mob = NULL;
  12063. StringBuf command;
  12064. char *str;
  12065. //#if PACKETVER >= 20131218
  12066. // char str[100];
  12067. //#else
  12068. // char str[24];
  12069. //#endif
  12070. str = RFIFOCP(fd,info->pos[0]);
  12071. if (!str || str[0] == '\0')
  12072. return;
  12073. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12074. return;
  12075. trim(str);
  12076. // Zeny
  12077. if( strcmpi(str, "money") == 0 ) {
  12078. StringBuf_Init(&command);
  12079. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12080. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12081. StringBuf_Destroy(&command);
  12082. return;
  12083. }
  12084. // Item
  12085. if( (id = itemdb_searchname(str)) ) {
  12086. StringBuf_Init(&command);
  12087. if( !itemdb_isstackable2(id) ) //Nonstackable
  12088. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12089. else {
  12090. if (id->flag.guid)
  12091. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12092. else
  12093. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12094. }
  12095. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12096. StringBuf_Destroy(&command);
  12097. return;
  12098. }
  12099. // Monster
  12100. if ((mob_id = mobdb_searchname(str)) == 0)
  12101. mob_id = mobdb_checkid(atoi(str));
  12102. if( (mob = mob_db(mob_id)) ) {
  12103. StringBuf_Init(&command);
  12104. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12105. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12106. StringBuf_Destroy(&command);
  12107. return;
  12108. }
  12109. }
  12110. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12111. /// 019d <effect state>.L
  12112. /// effect state:
  12113. /// TODO: Any OPTION_* ?
  12114. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12115. char cmd[6];
  12116. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12117. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12118. is_atcommand(fd, sd, cmd, 1);
  12119. }
  12120. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12121. /// 0149 <account id>.L <type>.B <value>.W
  12122. /// type:
  12123. /// 0 = positive points
  12124. /// 1 = negative points
  12125. /// 2 = self mute (+10 minutes)
  12126. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12127. {
  12128. int id, type, value;
  12129. struct map_session_data *dstsd;
  12130. char command[NAME_LENGTH+15];
  12131. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12132. id = RFIFOL(fd,info->pos[0]);
  12133. type = RFIFOB(fd,info->pos[1]);
  12134. value = RFIFOW(fd,info->pos[2]);
  12135. if( type == 0 )
  12136. value = -value;
  12137. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12138. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12139. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12140. return;
  12141. dstsd = map_id2sd(id);
  12142. if( dstsd == NULL )
  12143. return;
  12144. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12145. is_atcommand(fd, sd, command, 1);
  12146. }
  12147. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12148. /// GM adjustment of a player's manner value by -60.
  12149. /// 0212 <char name>.24B
  12150. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12151. {
  12152. char command[NAME_LENGTH+15];
  12153. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12154. name[NAME_LENGTH-1] = '\0';
  12155. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12156. is_atcommand(fd, sd, command, 1);
  12157. }
  12158. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12159. /// 01e0 <account id>.L <account name>.24B
  12160. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12161. {
  12162. WFIFOHEAD(fd,packet_len(0x1e0));
  12163. WFIFOW(fd,0) = 0x1e0;
  12164. WFIFOL(fd,2) = account_id;
  12165. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12166. WFIFOSET(fd,packet_len(0x1e0));
  12167. }
  12168. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12169. /// 01df <account id>.L
  12170. //! TODO: Figure out how does this actually work
  12171. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12172. {
  12173. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12174. /*
  12175. char query[30];
  12176. safesnprintf(query,sizeof(query),"%d", account_id);
  12177. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12178. */
  12179. clif_account_name(fd, account_id, "");
  12180. }
  12181. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12182. /// GM single cell type change request.
  12183. /// 0198 <x>.W <y>.W <type>.W
  12184. /// type:
  12185. /// 0 = not walkable
  12186. /// 1 = walkable
  12187. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12188. {
  12189. int x,y,type;
  12190. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12191. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12192. return;
  12193. x = RFIFOW(fd,info->pos[0]);
  12194. y = RFIFOW(fd,info->pos[1]);
  12195. type = RFIFOW(fd,info->pos[2]);
  12196. map_setgatcell(sd->bl.m,x,y,type);
  12197. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12198. //FIXME: once players leave the map, the client 'forgets' this information.
  12199. }
  12200. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12201. /// Request to allow/deny whispers from a nick.
  12202. /// 00cf <nick>.24B <type>.B
  12203. /// type:
  12204. /// 0 = (/ex nick) deny speech from nick
  12205. /// 1 = (/in nick) allow speech from nick
  12206. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12207. {
  12208. char* nick;
  12209. uint8 type;
  12210. int i;
  12211. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12212. nick = RFIFOCP(fd,info->pos[0]);
  12213. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12214. type = RFIFOB(fd,info->pos[1]);
  12215. if( type == 0 ) { // Add name to ignore list (block)
  12216. if (strcmp(wisp_server_name, nick) == 0) {
  12217. clif_wisexin(sd, type, 1); // fail
  12218. return;
  12219. }
  12220. // try to find a free spot, while checking for duplicates at the same time
  12221. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12222. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12223. clif_wisexin(sd, type, 2); // too many blocks
  12224. return;
  12225. }
  12226. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12227. clif_wisexin(sd, type, 0); // Aegis reports success.
  12228. return;
  12229. }
  12230. //Insert in position i
  12231. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12232. } else { // Remove name from ignore list (unblock)
  12233. // find entry
  12234. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12235. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12236. clif_wisexin(sd, type, 1); // fail
  12237. return;
  12238. }
  12239. // move everything one place down to overwrite removed entry
  12240. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12241. // wipe last entry
  12242. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12243. }
  12244. clif_wisexin(sd, type, 0); // success
  12245. }
  12246. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12247. /// Request to allow/deny all whispers.
  12248. /// 00d0 <type>.B
  12249. /// type:
  12250. /// 0 = (/exall) deny all speech
  12251. /// 1 = (/inall) allow all speech
  12252. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12253. {
  12254. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12255. if( type == 0 ) {// Deny all
  12256. if( sd->state.ignoreAll ) {
  12257. flag = 1; // fail
  12258. } else {
  12259. sd->state.ignoreAll = 1;
  12260. flag = 0; // success
  12261. }
  12262. } else {//Unblock everyone
  12263. if( sd->state.ignoreAll ) {
  12264. sd->state.ignoreAll = 0;
  12265. flag = 0; // success
  12266. } else {
  12267. if (sd->ignore[0].name[0] != '\0')
  12268. { //Wipe the ignore list.
  12269. memset(sd->ignore, 0, sizeof(sd->ignore));
  12270. flag = 0; // success
  12271. } else {
  12272. flag = 1; // fail
  12273. }
  12274. }
  12275. }
  12276. clif_wisall(sd, type, flag);
  12277. }
  12278. /// Whisper ignore list (ZC_WHISPER_LIST).
  12279. /// 00d4 <packet len>.W { <char name>.24B }*
  12280. void clif_PMIgnoreList(struct map_session_data* sd)
  12281. {
  12282. int i, fd = sd->fd;
  12283. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12284. WFIFOW(fd,0) = 0xd4;
  12285. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12286. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12287. }
  12288. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12289. WFIFOSET(fd,WFIFOW(fd,2));
  12290. }
  12291. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12292. /// 00d3
  12293. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12294. {
  12295. clif_PMIgnoreList(sd);
  12296. }
  12297. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12298. /// 01e7
  12299. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12300. {
  12301. if (sd->state.doridori) return;
  12302. switch (sd->class_&MAPID_UPPERMASK) {
  12303. case MAPID_SOUL_LINKER:
  12304. case MAPID_STAR_GLADIATOR:
  12305. case MAPID_TAEKWON:
  12306. if (!sd->state.rest)
  12307. break;
  12308. case MAPID_SUPER_NOVICE:
  12309. case MAPID_SUPER_BABY:
  12310. case MAPID_SUPER_NOVICE_E:
  12311. case MAPID_SUPER_BABY_E:
  12312. sd->state.doridori=1;
  12313. break;
  12314. }
  12315. }
  12316. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12317. /// 01ed
  12318. /// Note: This packet is caused by 7 lines of any text, followed by
  12319. /// the prayer and an another line of any text. The prayer is
  12320. /// defined by lines 790~793 in data\msgstringtable.txt
  12321. /// "Dear angel, can you hear my voice?"
  12322. /// "I am" (space separated player name) "Super Novice~"
  12323. /// "Help me out~ Please~ T_T"
  12324. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12325. {
  12326. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12327. unsigned int next = pc_nextbaseexp(sd);
  12328. if( next ) {
  12329. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12330. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12331. 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]
  12332. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12333. }
  12334. }
  12335. }
  12336. }
  12337. /// Friends List
  12338. ///
  12339. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12340. /// 0206 <account id>.L <char id>.L <state>.B
  12341. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12342. /// state:
  12343. /// 0 = online
  12344. /// 1 = offline
  12345. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12346. {
  12347. int i, fd = sd->fd;
  12348. //Seek friend.
  12349. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12350. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12351. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12352. return; //Not found
  12353. WFIFOHEAD(fd,packet_len(0x206));
  12354. WFIFOW(fd, 0) = 0x206;
  12355. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12356. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12357. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12358. #if PACKETVER >= 20180221
  12359. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12360. #endif
  12361. WFIFOSET(fd, packet_len(0x206));
  12362. }
  12363. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12364. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12365. {
  12366. uint32 account_id, char_id, online;
  12367. account_id = va_arg(ap, int);
  12368. char_id = va_arg(ap, int);
  12369. online = va_arg(ap, int);
  12370. clif_friendslist_toggle(sd, account_id, char_id, online);
  12371. return 0;
  12372. }
  12373. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12374. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12375. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12376. void clif_friendslist_send(struct map_session_data *sd)
  12377. {
  12378. int i = 0, n, fd = sd->fd;
  12379. #if PACKETVER >= 20180221
  12380. const int size = 8;
  12381. #else
  12382. const int size = 8 + NAME_LENGTH;
  12383. #endif
  12384. // Send friends list
  12385. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12386. WFIFOW(fd, 0) = 0x201;
  12387. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12388. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12389. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12390. #if PACKETVER < 20180221
  12391. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12392. #endif
  12393. }
  12394. if (i) {
  12395. WFIFOW(fd,2) = 4 + size * i;
  12396. WFIFOSET(fd, WFIFOW(fd,2));
  12397. }
  12398. for (n = 0; n < i; n++) { //Sending the online players
  12399. if (map_charid2sd(sd->status.friends[n].char_id))
  12400. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12401. }
  12402. }
  12403. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12404. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12405. /// result:
  12406. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12407. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12408. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12409. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12410. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12411. {
  12412. int fd;
  12413. nullpo_retv(sd);
  12414. fd = sd->fd;
  12415. WFIFOHEAD(fd,packet_len(0x209));
  12416. WFIFOW(fd,0) = 0x209;
  12417. WFIFOW(fd,2) = type;
  12418. if (f_sd) {
  12419. WFIFOL(fd,4) = f_sd->status.account_id;
  12420. WFIFOL(fd,8) = f_sd->status.char_id;
  12421. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12422. }
  12423. WFIFOSET(fd, packet_len(0x209));
  12424. }
  12425. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12426. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12427. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12428. {
  12429. int fd = sd->fd;
  12430. WFIFOHEAD(fd,packet_len(0x207));
  12431. WFIFOW(fd,0) = 0x207;
  12432. WFIFOL(fd,2) = account_id;
  12433. WFIFOL(fd,6) = char_id;
  12434. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12435. WFIFOSET(fd,packet_len(0x207));
  12436. }
  12437. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12438. /// 0202 <name>.24B
  12439. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12440. {
  12441. struct map_session_data *f_sd;
  12442. int i;
  12443. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12444. // Friend doesn't exist (no player with this name)
  12445. if (f_sd == NULL) {
  12446. clif_displaymessage(fd, msg_txt(sd,3));
  12447. return;
  12448. }
  12449. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12450. return;
  12451. }
  12452. // ensure that the request player's friend list is not full
  12453. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12454. if( i == MAX_FRIENDS ){
  12455. clif_friendslist_reqack(sd, f_sd, 2);
  12456. return;
  12457. }
  12458. // @noask [LuzZza]
  12459. if(f_sd->state.noask) {
  12460. clif_noask_sub(sd, f_sd, 5);
  12461. return;
  12462. }
  12463. // Friend already exists
  12464. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12465. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12466. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12467. return;
  12468. }
  12469. }
  12470. f_sd->friend_req = sd->status.char_id;
  12471. sd->friend_req = f_sd->status.char_id;
  12472. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12473. }
  12474. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12475. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12476. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12477. /// reply:
  12478. /// 0 = rejected
  12479. /// 1 = accepted
  12480. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12481. {
  12482. struct map_session_data *f_sd;
  12483. uint32 account_id;
  12484. char reply;
  12485. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12486. account_id = RFIFOL(fd,info->pos[0]);
  12487. //char_id = RFIFOL(fd,info->pos[1]);
  12488. #if PACKETVER < 6
  12489. reply = RFIFOB(fd,info->pos[2]);
  12490. #else
  12491. reply = RFIFOL(fd,info->pos[2]);
  12492. #endif
  12493. if( sd->bl.id == account_id ) {// adding oneself as friend
  12494. return;
  12495. }
  12496. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12497. if (f_sd == NULL)
  12498. return;
  12499. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12500. clif_friendslist_reqack(f_sd, sd, 1);
  12501. else {
  12502. int i;
  12503. // Find an empty slot
  12504. for (i = 0; i < MAX_FRIENDS; i++)
  12505. if (f_sd->status.friends[i].char_id == 0)
  12506. break;
  12507. if (i == MAX_FRIENDS) {
  12508. clif_friendslist_reqack(f_sd, sd, 2);
  12509. return;
  12510. }
  12511. f_sd->status.friends[i].account_id = sd->status.account_id;
  12512. f_sd->status.friends[i].char_id = sd->status.char_id;
  12513. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12514. clif_friendslist_reqack(f_sd, sd, 0);
  12515. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12516. if (battle_config.friend_auto_add) {
  12517. // Also add f_sd to sd's friendlist.
  12518. for (i = 0; i < MAX_FRIENDS; i++) {
  12519. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12520. return; //No need to add anything.
  12521. if (sd->status.friends[i].char_id == 0)
  12522. break;
  12523. }
  12524. if (i == MAX_FRIENDS) {
  12525. clif_friendslist_reqack(sd, f_sd, 2);
  12526. return;
  12527. }
  12528. sd->status.friends[i].account_id = f_sd->status.account_id;
  12529. sd->status.friends[i].char_id = f_sd->status.char_id;
  12530. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12531. clif_friendslist_reqack(sd, f_sd, 0);
  12532. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12533. }
  12534. }
  12535. }
  12536. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12537. /// 0203 <account id>.L <char id>.L
  12538. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12539. {
  12540. struct map_session_data *f_sd = NULL;
  12541. uint32 account_id, char_id;
  12542. int i, j;
  12543. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12544. account_id = RFIFOL(fd,info->pos[0]);
  12545. char_id = RFIFOL(fd,info->pos[1]);
  12546. // Search friend
  12547. for (i = 0; i < MAX_FRIENDS &&
  12548. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12549. if (i == MAX_FRIENDS) {
  12550. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12551. return;
  12552. }
  12553. //remove from friend's list first
  12554. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12555. for (i = 0; i < MAX_FRIENDS &&
  12556. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12557. if (i != MAX_FRIENDS) {
  12558. // move all chars up
  12559. for(j = i + 1; j < MAX_FRIENDS; j++)
  12560. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12561. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12562. //should the guy be notified of some message? we should add it here if so
  12563. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12564. WFIFOW(f_sd->fd,0) = 0x20a;
  12565. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12566. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12567. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12568. }
  12569. } else { //friend not online -- ask char server to delete from his friendlist
  12570. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12571. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12572. return;
  12573. }
  12574. }
  12575. // We can now delete from original requester
  12576. for (i = 0; i < MAX_FRIENDS &&
  12577. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12578. // move all chars up
  12579. for(j = i + 1; j < MAX_FRIENDS; j++)
  12580. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12581. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12582. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12583. WFIFOHEAD(fd,packet_len(0x20a));
  12584. WFIFOW(fd,0) = 0x20a;
  12585. WFIFOL(fd,2) = account_id;
  12586. WFIFOL(fd,6) = char_id;
  12587. WFIFOSET(fd, packet_len(0x20a));
  12588. }
  12589. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12590. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12591. void clif_PVPInfo(struct map_session_data* sd)
  12592. {
  12593. int fd = sd->fd;
  12594. WFIFOHEAD(fd,packet_len(0x210));
  12595. WFIFOW(fd,0) = 0x210;
  12596. WFIFOL(fd,2) = sd->status.char_id;
  12597. WFIFOL(fd,6) = sd->status.account_id;
  12598. WFIFOL(fd,10) = sd->pvp_won; // times won
  12599. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12600. WFIFOL(fd,18) = sd->pvp_point;
  12601. WFIFOSET(fd, packet_len(0x210));
  12602. }
  12603. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12604. /// 020f <char id>.L <account id>.L
  12605. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12606. {
  12607. // TODO: Is there a way to use this on an another player (char/acc id)?
  12608. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12609. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12610. clif_PVPInfo(sd);
  12611. }
  12612. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12613. /// 0254 <which>.B
  12614. /// which: (unused atm for security purpose)
  12615. /// 0 = sun
  12616. /// 1 = moon
  12617. /// 2 = star
  12618. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12619. {
  12620. int i;
  12621. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12622. if (sd->menuskill_id != SG_FEEL)
  12623. return;
  12624. i = sd->menuskill_val-1;
  12625. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12626. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12627. sd->feel_map[i].m = sd->bl.m;
  12628. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12629. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12630. // clif_misceffect2(&sd->bl, 0x1b0);
  12631. // clif_misceffect2(&sd->bl, 0x21f);
  12632. clif_feel_info(sd, i, 0);
  12633. clif_menuskill_clear(sd);
  12634. }
  12635. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12636. /// 0253 <which>.B
  12637. /// which:
  12638. /// 0 = sun
  12639. /// 1 = moon
  12640. /// 2 = star
  12641. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12642. {
  12643. WFIFOHEAD(fd,packet_len(0x253));
  12644. WFIFOW(fd,0)=0x253;
  12645. WFIFOB(fd,2)=TOB(skill_lv-1);
  12646. WFIFOSET(fd, packet_len(0x253));
  12647. sd->menuskill_id = SG_FEEL;
  12648. sd->menuskill_val = skill_lv;
  12649. }
  12650. /// Request to change homunculus' name (CZ_RENAME_MER).
  12651. /// 0231 <name>.24B
  12652. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12653. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12654. }
  12655. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12656. /// 0234 <id>.L
  12657. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12658. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12659. struct block_list *bl = NULL;
  12660. struct unit_data *ud = NULL;
  12661. if( sd->md && sd->md->bl.id == id )
  12662. bl = &sd->md->bl;
  12663. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12664. bl = &sd->hd->bl; // Moving Homunculus
  12665. else
  12666. return;
  12667. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12668. ud = unit_bl2ud(bl);
  12669. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12670. }
  12671. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12672. /// 0232 <id>.L <position data>.3B
  12673. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12674. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12675. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12676. struct block_list *bl = NULL;
  12677. short x, y;
  12678. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12679. if( sd->md && sd->md->bl.id == id )
  12680. bl = &sd->md->bl; // Moving Mercenary
  12681. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12682. bl = &sd->hd->bl; // Moving Homunculus
  12683. else
  12684. return;
  12685. unit_walktoxy(bl, x, y, 4);
  12686. }
  12687. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12688. /// 0233 <id>.L <target id>.L <action>.B
  12689. /// action:
  12690. /// always 0
  12691. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12692. {
  12693. struct block_list *bl = NULL;
  12694. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12695. int id = RFIFOL(fd,info->pos[0]);
  12696. int target_id = RFIFOL(fd,info->pos[1]);
  12697. int action_type = RFIFOB(fd,info->pos[2]);
  12698. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12699. bl = &sd->hd->bl;
  12700. else if( sd->md && sd->md->bl.id == id )
  12701. bl = &sd->md->bl;
  12702. else return;
  12703. unit_stop_attack(bl);
  12704. unit_attack(bl, target_id, action_type != 0);
  12705. }
  12706. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12707. /// 022d <type>.W <command>.B
  12708. /// type:
  12709. /// always 0
  12710. /// command:
  12711. /// 0 = homunculus information
  12712. /// 1 = feed
  12713. /// 2 = delete
  12714. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12715. { //[orn]
  12716. int cmd = RFIFOW(fd,0);
  12717. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12718. if(!hom_is_active(sd->hd))
  12719. return;
  12720. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12721. }
  12722. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12723. /// 0292
  12724. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12725. {
  12726. pc_revive_item(sd);
  12727. }
  12728. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12729. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12730. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12731. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12732. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12733. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12734. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12735. void clif_check(int fd, struct map_session_data* pl_sd)
  12736. {
  12737. WFIFOHEAD(fd,packet_len(0x214));
  12738. WFIFOW(fd, 0) = 0x214;
  12739. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12740. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12741. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12742. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12743. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12744. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12745. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12746. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12747. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12748. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12749. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12750. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12751. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12752. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12753. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12754. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12755. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12756. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12757. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12758. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12759. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12760. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12761. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12762. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12763. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12764. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12765. WFIFOSET(fd,packet_len(0x214));
  12766. }
  12767. /// /check (CZ_REQ_STATUS_GM).
  12768. /// Request character's status values.
  12769. /// 0213 <char name>.24B
  12770. void clif_parse_Check(int fd, struct map_session_data *sd)
  12771. {
  12772. char charname[NAME_LENGTH];
  12773. struct map_session_data* pl_sd;
  12774. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12775. return;
  12776. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12777. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12778. {
  12779. return;
  12780. }
  12781. clif_check(fd, pl_sd);
  12782. }
  12783. /// MAIL SYSTEM
  12784. /// By Zephyrus
  12785. ///
  12786. /// Notification about the result of adding an item to mail
  12787. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12788. /// result:
  12789. /// 0 = success
  12790. /// 1 = failure
  12791. /// 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)
  12792. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12793. /// result:
  12794. /// 0 = success
  12795. /// 1 = over weight
  12796. /// 2 = fatal error
  12797. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12798. {
  12799. int fd = sd->fd;
  12800. #if PACKETVER < 20150513
  12801. WFIFOHEAD(fd,packet_len(0x255));
  12802. WFIFOW(fd,0) = 0x255;
  12803. WFIFOW(fd,2) = index;
  12804. WFIFOB(fd,4) = flag;
  12805. WFIFOSET(fd,packet_len(0x255));
  12806. #else
  12807. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12808. int i, total = 0;
  12809. WFIFOHEAD(fd, 53);
  12810. WFIFOW(fd, 0) = 0xa05;
  12811. WFIFOB(fd, 2) = flag;
  12812. WFIFOW(fd, 3) = index;
  12813. WFIFOW(fd, 5) = amount;
  12814. WFIFOW(fd, 7) = item->nameid;
  12815. WFIFOB(fd, 9) = itemtype(item->nameid);
  12816. WFIFOB(fd, 10) = item->identify;
  12817. WFIFOB(fd, 11) = item->attribute;
  12818. WFIFOB(fd, 12) = item->refine;
  12819. clif_addcards(WFIFOP(fd,13), item);
  12820. clif_add_random_options(WFIFOP(fd,21), item);
  12821. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12822. if( sd->mail.item[i].nameid == 0 ){
  12823. break;
  12824. }
  12825. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12826. }
  12827. WFIFOW(fd, 46) = total;
  12828. // 5 empty unknown bytes
  12829. memset(WFIFOP(fd, 48), 0, 5);
  12830. WFIFOSET(fd, 53);
  12831. #endif
  12832. }
  12833. /// Notification about the result of retrieving a mail attachment
  12834. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12835. /// result:
  12836. /// 0 = success
  12837. /// 1 = failure
  12838. /// 2 = too many items
  12839. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12840. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12841. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12842. int fd = sd->fd;
  12843. #if PACKETVER < 20150513
  12844. WFIFOHEAD(fd,packet_len(0x245));
  12845. WFIFOW(fd,0) = 0x245;
  12846. WFIFOB(fd,2) = result;
  12847. WFIFOSET(fd,packet_len(0x245));
  12848. #else
  12849. switch( type ){
  12850. case MAIL_ATT_ITEM:
  12851. case MAIL_ATT_ZENY:
  12852. break;
  12853. default:
  12854. return;
  12855. }
  12856. WFIFOHEAD(fd, 12);
  12857. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12858. WFIFOQ(fd, 2) = msg->id;
  12859. WFIFOB(fd, 10) = msg->type;
  12860. WFIFOB(fd, 11) = result;
  12861. WFIFOSET(fd, 12);
  12862. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12863. #endif
  12864. }
  12865. /// Notification about the result of sending a mail
  12866. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12867. /// result:
  12868. /// 0 = success
  12869. /// 1 = recipinent does not exist
  12870. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12871. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12872. int fd = sd->fd;
  12873. #if PACKETVER < 20150513
  12874. WFIFOHEAD(fd,packet_len(0x249));
  12875. WFIFOW(fd,0) = 0x249;
  12876. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12877. WFIFOSET(fd,packet_len(0x249));
  12878. #else
  12879. WFIFOHEAD(fd, 3);
  12880. WFIFOW(fd, 0) = 0x9ed;
  12881. WFIFOB(fd, 2) = result;
  12882. WFIFOSET(fd, 3);
  12883. #endif
  12884. }
  12885. /// Notification about the result of deleting a mail.
  12886. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12887. /// result:
  12888. /// 0 = success
  12889. /// 1 = failure
  12890. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12891. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12892. int fd = sd->fd;
  12893. #if PACKETVER < 20150513
  12894. WFIFOHEAD(fd, packet_len(0x257));
  12895. WFIFOW(fd,0) = 0x257;
  12896. WFIFOL(fd,2) = msg->id;
  12897. WFIFOW(fd,6) = !success;
  12898. WFIFOSET(fd, packet_len(0x257));
  12899. #else
  12900. // This is only a success notification
  12901. if( success ){
  12902. WFIFOHEAD(fd, 11);
  12903. WFIFOW(fd, 0) = 0x9f6;
  12904. WFIFOB(fd, 2) = msg->type;
  12905. WFIFOQ(fd, 3) = msg->id;
  12906. WFIFOSET(fd, 11);
  12907. }
  12908. #endif
  12909. }
  12910. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12911. /// 0274 <mail id>.L <result>.W
  12912. /// result:
  12913. /// 0 = success
  12914. /// 1 = failure
  12915. void clif_Mail_return(int fd, int mail_id, short fail)
  12916. {
  12917. WFIFOHEAD(fd,packet_len(0x274));
  12918. WFIFOW(fd,0) = 0x274;
  12919. WFIFOL(fd,2) = mail_id;
  12920. WFIFOW(fd,6) = fail;
  12921. WFIFOSET(fd,packet_len(0x274));
  12922. }
  12923. /// Notification about new mail.
  12924. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12925. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12926. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12927. int fd = sd->fd;
  12928. #if PACKETVER < 20150513
  12929. WFIFOHEAD(fd,packet_len(0x24a));
  12930. WFIFOW(fd,0) = 0x24a;
  12931. WFIFOL(fd,2) = mail_id;
  12932. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12933. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12934. WFIFOSET(fd,packet_len(0x24a));
  12935. #else
  12936. WFIFOHEAD(fd,3);
  12937. WFIFOW(fd,0) = 0x9e7;
  12938. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12939. WFIFOSET(fd,3);
  12940. #endif
  12941. }
  12942. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12943. /// 0260 <type>.L
  12944. /// type:
  12945. /// 0 = open
  12946. /// 1 = close
  12947. void clif_Mail_window(int fd, int flag)
  12948. {
  12949. WFIFOHEAD(fd,packet_len(0x260));
  12950. WFIFOW(fd,0) = 0x260;
  12951. WFIFOL(fd,2) = flag;
  12952. WFIFOSET(fd,packet_len(0x260));
  12953. }
  12954. /// Lists mails stored in inbox.
  12955. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12956. /// read:
  12957. /// 0 = unread
  12958. /// 1 = read
  12959. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12960. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12961. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12962. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12963. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12964. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12965. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12966. #if PACKETVER < 20150513
  12967. int fd = sd->fd;
  12968. struct mail_data *md = &sd->mail.inbox;
  12969. struct mail_message *msg;
  12970. int len, i, j;
  12971. len = 8 + (73 * md->amount);
  12972. WFIFOHEAD(fd,len);
  12973. WFIFOW(fd,0) = 0x240;
  12974. WFIFOW(fd,2) = len;
  12975. WFIFOL(fd,4) = md->amount;
  12976. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12977. {
  12978. msg = &md->msg[i];
  12979. if (msg->id < 1)
  12980. continue;
  12981. WFIFOL(fd,8+73*j) = msg->id;
  12982. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12983. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12984. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12985. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12986. j++;
  12987. }
  12988. WFIFOSET(fd,len);
  12989. if( md->full ) {// TODO: is this official?
  12990. char output[100];
  12991. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12992. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12993. }
  12994. #else
  12995. int fd = sd->fd;
  12996. struct mail_data *md = &sd->mail.inbox;
  12997. struct mail_message *msg;
  12998. int i, j, k, offset, titleLength;
  12999. uint8 mailType, amount, remaining;
  13000. uint32 now = (uint32)time(NULL);
  13001. #if PACKETVER >= 20170419
  13002. int cmd = 0xac2;
  13003. #elif PACKETVER >= 20160601
  13004. int cmd = 0xa7d;
  13005. #else
  13006. int cmd = 0x9f0;
  13007. #endif
  13008. if( battle_config.mail_daily_count ){
  13009. mail_refresh_remaining_amount(sd);
  13010. }
  13011. #if PACKETVER >= 20170419
  13012. // Always send all
  13013. i = md->amount;
  13014. #else
  13015. // If a starting mail id was sent
  13016. if( mailID != 0 ){
  13017. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13018. // Unknown mail
  13019. if( i == md->amount ){
  13020. // Ignore the request for now
  13021. return; // TODO: Should we just show the first page instead?
  13022. }
  13023. // It was actually the oldest/first mail, there is no further page
  13024. if( i == 0 ){
  13025. return;
  13026. }
  13027. // We actually want the next/older mail
  13028. i -= 1;
  13029. }else{
  13030. i = md->amount;
  13031. }
  13032. #endif
  13033. // Count the remaining mails from the starting mail or the beginning
  13034. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13035. for( j = i, remaining = 0; j >= 0; j-- ){
  13036. msg = &md->msg[j];
  13037. if (msg->id < 1)
  13038. continue;
  13039. #if PACKETVER < 20170419
  13040. if (msg->type != type)
  13041. continue;
  13042. #endif
  13043. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13044. continue;
  13045. remaining++;
  13046. }
  13047. #if PACKETVER >= 20170419
  13048. // Always send all
  13049. amount = remaining;
  13050. #else
  13051. if( remaining > MAIL_PAGE_SIZE ){
  13052. amount = MAIL_PAGE_SIZE;
  13053. }else{
  13054. amount = remaining;
  13055. }
  13056. #endif
  13057. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13058. WFIFOW(fd, 0) = cmd;
  13059. #if PACKETVER >= 20170419
  13060. WFIFOB(fd, 4) = 1; // Unknown
  13061. offset = 5;
  13062. #else
  13063. WFIFOB(fd, 4) = type;
  13064. WFIFOB(fd, 5) = amount;
  13065. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13066. offset = 7;
  13067. #endif
  13068. for( amount = 0; i >= 0; i-- ){
  13069. msg = &md->msg[i];
  13070. if (msg->id < 1)
  13071. continue;
  13072. #if PACKETVER < 20170419
  13073. if (msg->type != type)
  13074. continue;
  13075. #endif
  13076. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13077. continue;
  13078. #if PACKETVER >= 20170419
  13079. WFIFOB(fd, offset) = msg->type;
  13080. offset += 1;
  13081. #endif
  13082. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13083. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13084. mailType = MAIL_TYPE_TEXT; // Normal letter
  13085. if( msg->zeny > 0 ){
  13086. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13087. }
  13088. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13089. if( msg->item[k].nameid > 0 ){
  13090. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13091. break;
  13092. }
  13093. }
  13094. #if PACKETVER >= 20170419
  13095. // If it came from an npc?
  13096. if( !msg->send_id ){
  13097. mailType |= MAIL_TYPE_NPC;
  13098. }
  13099. #endif
  13100. WFIFOB(fd, offset + 9) = mailType;
  13101. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13102. #if PACKETVER < 20170419
  13103. // How much time has passed since you received the mail
  13104. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13105. offset += 4;
  13106. #endif
  13107. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13108. if( msg->scheduled_deletion > 0 ){
  13109. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13110. }else{
  13111. // Fake the scheduled deletion to one year in the future
  13112. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13113. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13114. }
  13115. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13116. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13117. offset += 40 + titleLength;
  13118. }
  13119. WFIFOW(fd, 2) = (int16)offset;
  13120. WFIFOSET(fd, offset);
  13121. #endif
  13122. }
  13123. /// Mail inbox list request.
  13124. /// 023f (CZ_MAIL_GET_LIST)
  13125. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13126. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13127. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13128. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13129. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13130. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13131. #if PACKETVER < 20150513
  13132. struct mail_data* md = &sd->mail.inbox;
  13133. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13134. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13135. else
  13136. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13137. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13138. mail_removezeny(sd, false);
  13139. #else
  13140. int cmd = RFIFOW(fd, 0);
  13141. #if PACKETVER < 20170419
  13142. uint8 openType = RFIFOB(fd, 2);
  13143. uint64 mailId = RFIFOQ(fd, 3);
  13144. #else
  13145. uint8 openType;
  13146. uint64 mailId = RFIFOQ(fd, 2);
  13147. int i;
  13148. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13149. if( i == MAIL_MAX_INBOX ){
  13150. openType = MAIL_INBOX_NORMAL;
  13151. mailId = 0;
  13152. }else{
  13153. openType = sd->mail.inbox.msg[i].type;
  13154. mailId = 0;
  13155. }
  13156. #endif
  13157. switch( openType ){
  13158. case MAIL_INBOX_NORMAL:
  13159. case MAIL_INBOX_ACCOUNT:
  13160. case MAIL_INBOX_RETURNED:
  13161. break;
  13162. default:
  13163. // Unknown type: ignore request
  13164. return;
  13165. }
  13166. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13167. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13168. return;
  13169. }
  13170. // If it is not a next page request
  13171. if( cmd != 0x9ee ){
  13172. mailId = 0;
  13173. }
  13174. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13175. #endif
  13176. }
  13177. /// Opens a mail
  13178. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13179. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13180. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13181. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13182. /// { }*n
  13183. // TODO: Packet description => for repeated block
  13184. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13185. {
  13186. int i, fd = sd->fd;
  13187. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13188. if( i == MAIL_MAX_INBOX ) {
  13189. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13190. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13191. return;
  13192. } else {
  13193. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13194. struct item *item;
  13195. struct item_data *data;
  13196. int msg_len = strlen(msg->body), len;
  13197. #if PACKETVER >= 20150513
  13198. int offset, j, itemsize, count = 0;
  13199. #endif
  13200. if( msg_len == 0 ) {
  13201. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13202. msg_len = strlen(msg->body);
  13203. }
  13204. #if PACKETVER < 20150513
  13205. item = &msg->item[0];
  13206. len = 101 + msg_len;
  13207. WFIFOHEAD(fd,len);
  13208. WFIFOW(fd,0) = 0x242;
  13209. WFIFOW(fd,2) = len;
  13210. WFIFOL(fd,4) = msg->id;
  13211. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13212. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13213. WFIFOL(fd,72) = 0;
  13214. WFIFOL(fd,76) = msg->zeny;
  13215. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13216. WFIFOL(fd,80) = item->amount;
  13217. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13218. WFIFOW(fd,86) = data->type;
  13219. WFIFOB(fd,88) = item->identify;
  13220. WFIFOB(fd,89) = item->attribute;
  13221. WFIFOB(fd,90) = item->refine;
  13222. WFIFOW(fd,91) = item->card[0];
  13223. WFIFOW(fd,93) = item->card[1];
  13224. WFIFOW(fd,95) = item->card[2];
  13225. WFIFOW(fd,97) = item->card[3];
  13226. } else // no item, set all to zero
  13227. memset(WFIFOP(fd,80), 0x00, 19);
  13228. WFIFOB(fd,99) = (unsigned char)msg_len;
  13229. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13230. WFIFOSET(fd,len);
  13231. #else
  13232. // Count the attached items
  13233. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13234. msg_len += 1; // Zero Termination
  13235. itemsize = 24 + 5 * 5;
  13236. len = 24 + msg_len+1 + itemsize * count;
  13237. WFIFOHEAD(fd, len);
  13238. WFIFOW(fd, 0) = 0x9eb;
  13239. WFIFOW(fd, 2) = len;
  13240. WFIFOB(fd, 4) = msg->type;
  13241. WFIFOQ(fd, 5) = msg->id;
  13242. WFIFOW(fd, 13) = msg_len;
  13243. WFIFOQ(fd, 15) = msg->zeny;
  13244. WFIFOB(fd, 23) = (uint8)count; // item count
  13245. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13246. offset = 24 + msg_len;
  13247. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13248. item = &msg->item[j];
  13249. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13250. WFIFOW(fd, offset) = item->amount;
  13251. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13252. WFIFOB(fd, offset + 4) = item->identify;
  13253. WFIFOB(fd, offset + 5) = item->attribute;
  13254. WFIFOB(fd, offset + 6) = item->refine;
  13255. clif_addcards(WFIFOP(fd, offset + 7), item);
  13256. // 4B unsigned long location
  13257. WFIFOB(fd, offset + 15 + 4) = data->type;
  13258. // 2B unsigned short wItemSpriteNumber
  13259. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13260. // 2B unsigned short bindOnEquipType
  13261. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13262. offset += itemsize;
  13263. }
  13264. }
  13265. WFIFOSET(fd, len);
  13266. #endif
  13267. if (msg->status == MAIL_UNREAD) {
  13268. msg->status = MAIL_READ;
  13269. intif_Mail_read(mail_id);
  13270. clif_parse_Mail_refreshinbox(fd, sd);
  13271. sd->mail.inbox.unread--;
  13272. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13273. }
  13274. }
  13275. }
  13276. /// Request to open a mail.
  13277. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13278. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13279. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13280. #if PACKETVER < 20150513
  13281. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13282. #else
  13283. //uint8 openType = RFIFOB(fd, 2);
  13284. int mail_id = (int)RFIFOQ(fd, 3);
  13285. #endif
  13286. if( mail_id <= 0 )
  13287. return;
  13288. if( mail_invalid_operation(sd) )
  13289. return;
  13290. clif_Mail_read(sd, mail_id);
  13291. }
  13292. /// Allow a player to begin writing a mail
  13293. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13294. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13295. int fd = sd->fd;
  13296. WFIFOHEAD(fd, 27);
  13297. WFIFOW(fd, 0) = 0xa12;
  13298. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13299. WFIFOB(fd, 26) = success;
  13300. WFIFOSET(fd, 27);
  13301. }
  13302. /// Request to start writing a mail
  13303. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13304. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13305. char name[NAME_LENGTH];
  13306. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13307. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13308. clif_send_Mail_beginwrite_ack(sd, name, false);
  13309. return;
  13310. }
  13311. mail_clear(sd);
  13312. sd->state.mail_writing = true;
  13313. clif_send_Mail_beginwrite_ack(sd, name,true);
  13314. }
  13315. /// Notification that the client cancelled writing a mail
  13316. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13317. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13318. sd->state.mail_writing = false;
  13319. }
  13320. /// Give the client information about the recipient, if available
  13321. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13322. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13323. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13324. int fd = sd->fd;
  13325. #if PACKETVER <= 20160302
  13326. int cmd = 0xa14;
  13327. #else
  13328. int cmd = 0xa51;
  13329. #endif
  13330. WFIFOHEAD(fd, packet_len(cmd));
  13331. WFIFOW(fd, 0) = cmd;
  13332. WFIFOL(fd, 2) = char_id;
  13333. WFIFOW(fd, 6) = class_;
  13334. WFIFOW(fd, 8) = level;
  13335. #if PACKETVER >= 20160302
  13336. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13337. #endif
  13338. WFIFOSET(fd, packet_len(cmd));
  13339. }
  13340. /// Request information about the recipient
  13341. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13342. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13343. static char name[NAME_LENGTH];
  13344. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13345. intif_mail_checkreceiver(sd, name);
  13346. }
  13347. /// Request to receive mail's attachment.
  13348. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13349. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13350. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13351. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13352. int i;
  13353. struct mail_message* msg;
  13354. #if PACKETVER < 20150513
  13355. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13356. int attachment = MAIL_ATT_ALL;
  13357. #else
  13358. uint16 packet_id = RFIFOW(fd, 0);
  13359. int mail_id = (int)RFIFOQ(fd, 2);
  13360. //int openType = RFIFOB(fd, 10);
  13361. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13362. #endif
  13363. if( !chrif_isconnected() )
  13364. return;
  13365. if( mail_id <= 0 )
  13366. return;
  13367. if( mail_invalid_operation(sd) )
  13368. return;
  13369. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13370. if( i == MAIL_MAX_INBOX )
  13371. return;
  13372. msg = &sd->mail.inbox.msg[i];
  13373. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13374. attachment &= ~MAIL_ATT_ZENY;
  13375. }
  13376. if( attachment&MAIL_ATT_ITEM ){
  13377. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13378. // No items were found
  13379. if( i == MAIL_MAX_ITEM ){
  13380. attachment &= ~MAIL_ATT_ITEM;
  13381. }
  13382. }
  13383. // Either no attachment requested at all or there are no zeny or items in the mail
  13384. if( attachment == MAIL_ATT_NONE ){
  13385. return;
  13386. }
  13387. if( attachment&MAIL_ATT_ZENY ){
  13388. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13389. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13390. return;
  13391. }else{
  13392. // To make sure another request fails
  13393. msg->zeny = 0;
  13394. }
  13395. }
  13396. if( attachment&MAIL_ATT_ITEM ){
  13397. int new_ = 0, totalweight = 0;
  13398. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13399. struct item* item = &msg->item[i];
  13400. if( item->nameid > 0 && item->amount > 0 ){
  13401. struct item_data *data;
  13402. if((data = itemdb_exists(item->nameid)) == NULL)
  13403. continue;
  13404. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13405. case CHKADDITEM_NEW:
  13406. new_++;
  13407. break;
  13408. case CHKADDITEM_OVERAMOUNT:
  13409. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13410. return;
  13411. }
  13412. totalweight += data->weight * item->amount;
  13413. }
  13414. }
  13415. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13416. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13417. return;
  13418. }else if( pc_inventoryblank(sd) < new_ ){
  13419. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13420. return;
  13421. }
  13422. // To make sure another request fails
  13423. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13424. }
  13425. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13426. clif_Mail_read(sd, mail_id);
  13427. }
  13428. /// Request to delete a mail.
  13429. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13430. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13431. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13432. #if PACKETVER < 20150513
  13433. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13434. #else
  13435. //int openType = RFIFOB(fd, 2);
  13436. int mail_id = (int)RFIFOQ(fd, 3);
  13437. #endif
  13438. int i, j;
  13439. if( !chrif_isconnected() )
  13440. return;
  13441. if( mail_id <= 0 )
  13442. return;
  13443. if( mail_invalid_operation(sd) )
  13444. return;
  13445. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13446. if (i < MAIL_MAX_INBOX) {
  13447. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13448. // can't delete mail without removing zeny first
  13449. if( msg->zeny > 0 ){
  13450. clif_mail_delete(sd, msg, false);
  13451. return;
  13452. }
  13453. // can't delete mail without removing attachment(s) first
  13454. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13455. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13456. clif_mail_delete(sd, msg, false);
  13457. return;
  13458. }
  13459. }
  13460. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13461. sd->mail.inbox.unread--;
  13462. clif_Mail_new(sd,0,NULL,NULL);
  13463. }
  13464. }
  13465. }
  13466. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13467. /// 0273 <mail id>.L <receive name>.24B
  13468. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13469. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13470. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13471. int i;
  13472. if( mail_id <= 0 )
  13473. return;
  13474. if( mail_invalid_operation(sd) )
  13475. return;
  13476. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13477. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13478. intif_Mail_return(sd->status.char_id, mail_id);
  13479. else
  13480. clif_Mail_return(sd->fd, mail_id, 1);
  13481. }
  13482. /// Request to add an item or Zeny to mail.
  13483. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13484. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13485. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13486. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13487. int idx = RFIFOW(fd,info->pos[0]);
  13488. #if PACKETVER < 20150513
  13489. int amount = RFIFOL(fd,info->pos[1]);
  13490. #else
  13491. int amount = RFIFOW(fd,info->pos[1]);
  13492. #endif
  13493. unsigned char flag;
  13494. if( !chrif_isconnected() )
  13495. return;
  13496. if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
  13497. return;
  13498. flag = mail_setitem(sd, idx, amount);
  13499. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13500. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13501. }else{
  13502. clif_Mail_setattachment(sd,idx,amount,flag);
  13503. }
  13504. }
  13505. /// Remove an item from a mail
  13506. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13507. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13508. int fd = sd->fd;
  13509. WFIFOHEAD(fd, 9);
  13510. WFIFOW(fd, 0) = 0xa07;
  13511. WFIFOB(fd, 2) = success;
  13512. WFIFOW(fd, 3) = index;
  13513. WFIFOW(fd, 5) = amount;
  13514. int total = 0;
  13515. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13516. if( sd->mail.item[i].nameid == 0 ){
  13517. break;
  13518. }
  13519. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13520. }
  13521. WFIFOW(fd, 7) = total;
  13522. WFIFOSET(fd, 9);
  13523. }
  13524. /// Request to reset mail item and/or Zeny
  13525. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13526. /// type:
  13527. /// 0 = reset all
  13528. /// 1 = remove item
  13529. /// 2 = remove zeny
  13530. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13531. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13532. {
  13533. #if PACKETVER < 20150513
  13534. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13535. if (type == 0 || type == 1)
  13536. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13537. if (type == 0 || type == 2)
  13538. mail_removezeny(sd, false);
  13539. #else
  13540. uint16 index = RFIFOW(fd, 2);
  13541. uint16 count = RFIFOW(fd, 4);
  13542. mail_removeitem(sd,0,index,count);
  13543. #endif
  13544. }
  13545. /// Request to send mail
  13546. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13547. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13548. /// 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)
  13549. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13550. #if PACKETVER < 20150513
  13551. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13552. if( !chrif_isconnected() )
  13553. return;
  13554. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13555. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13556. return;
  13557. }
  13558. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13559. #else
  13560. uint16 length = RFIFOW(fd, 2);
  13561. if( length < 0x3e ){
  13562. ShowWarning("Too short...\n");
  13563. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13564. return;
  13565. }
  13566. // Forged request without a begin writing packet?
  13567. if( !sd->state.mail_writing ){
  13568. return; // Ignore it
  13569. }
  13570. char receiver[NAME_LENGTH];
  13571. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13572. // char sender[NAME_LENGTH];
  13573. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13574. uint64 zeny = RFIFOQ(fd, 52);
  13575. uint16 titleLength = RFIFOW(fd, 60);
  13576. uint16 textLength = RFIFOW(fd, 62);
  13577. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13578. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13579. char title[MAIL_TITLE_LENGTH];
  13580. char text[MAIL_BODY_LENGTH];
  13581. #if PACKETVER <= 20160330
  13582. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13583. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13584. #else
  13585. // 64 = <char id>.L
  13586. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13587. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13588. #endif
  13589. if( zeny > 0 ){
  13590. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13591. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13592. return;
  13593. }
  13594. }
  13595. mail_send(sd, receiver, title, text, realTextLength);
  13596. #endif
  13597. }
  13598. /// AUCTION SYSTEM
  13599. /// By Zephyrus
  13600. ///
  13601. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13602. /// 025f <type>.L
  13603. /// type:
  13604. /// 0 = open
  13605. /// 1 = close
  13606. void clif_Auction_openwindow(struct map_session_data *sd)
  13607. {
  13608. int fd = sd->fd;
  13609. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13610. return;
  13611. if( !battle_config.feature_auction )
  13612. return;
  13613. WFIFOHEAD(fd,packet_len(0x25f));
  13614. WFIFOW(fd,0) = 0x25f;
  13615. WFIFOL(fd,2) = 0;
  13616. WFIFOSET(fd,packet_len(0x25f));
  13617. }
  13618. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13619. /// 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 }*
  13620. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13621. {
  13622. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13623. struct auction_data auction;
  13624. struct item_data *item;
  13625. WFIFOHEAD(fd,12 + (count * 83));
  13626. WFIFOW(fd,0) = 0x252;
  13627. WFIFOW(fd,2) = 12 + (count * 83);
  13628. WFIFOL(fd,4) = pages;
  13629. WFIFOL(fd,8) = count;
  13630. for( i = 0; i < count; i++ ) {
  13631. int k = 12 + (i * 83);
  13632. memcpy(&auction, RBUFP(buf,i * len), len);
  13633. WFIFOL(fd,k) = auction.auction_id;
  13634. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13635. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13636. WFIFOW(fd,28+k) = item->view_id;
  13637. else
  13638. WFIFOW(fd,28+k) = auction.item.nameid;
  13639. WFIFOL(fd,30+k) = auction.type;
  13640. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13641. WFIFOB(fd,36+k) = auction.item.identify;
  13642. WFIFOB(fd,37+k) = auction.item.attribute;
  13643. WFIFOB(fd,38+k) = auction.item.refine;
  13644. WFIFOW(fd,39+k) = auction.item.card[0];
  13645. WFIFOW(fd,41+k) = auction.item.card[1];
  13646. WFIFOW(fd,43+k) = auction.item.card[2];
  13647. WFIFOW(fd,45+k) = auction.item.card[3];
  13648. WFIFOL(fd,47+k) = auction.price;
  13649. WFIFOL(fd,51+k) = auction.buynow;
  13650. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13651. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13652. }
  13653. WFIFOSET(fd,WFIFOW(fd,2));
  13654. }
  13655. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13656. /// 0256 <index>.W <result>.B
  13657. /// result:
  13658. /// 0 = success
  13659. /// 1 = failure
  13660. static void clif_Auction_setitem(int fd, int index, bool fail)
  13661. {
  13662. WFIFOHEAD(fd,packet_len(0x256));
  13663. WFIFOW(fd,0) = 0x256;
  13664. WFIFOW(fd,2) = index;
  13665. WFIFOB(fd,4) = fail;
  13666. WFIFOSET(fd,packet_len(0x256));
  13667. }
  13668. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13669. /// 024b <type>.W
  13670. /// type:
  13671. /// 0 = create (any other action in auction window)
  13672. /// 1 = cancel (cancel pressed on register tab)
  13673. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13674. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13675. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13676. if( sd->auction.amount > 0 )
  13677. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13678. sd->auction.amount = 0;
  13679. }
  13680. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13681. /// 024c <index>.W <count>.L
  13682. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13683. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13684. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13685. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13686. struct item_data *item;
  13687. if( !battle_config.feature_auction )
  13688. return;
  13689. if( sd->auction.amount > 0 )
  13690. sd->auction.amount = 0;
  13691. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13692. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13693. return;
  13694. }
  13695. 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.
  13696. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13697. return;
  13698. }
  13699. 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) )
  13700. { // Consumable or pets are not allowed
  13701. clif_Auction_setitem(sd->fd, idx, true);
  13702. return;
  13703. }
  13704. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13705. !sd->inventory.u.items_inventory[idx].identify ||
  13706. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13707. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13708. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13709. clif_Auction_setitem(sd->fd, idx, true);
  13710. return;
  13711. }
  13712. sd->auction.index = idx;
  13713. sd->auction.amount = amount;
  13714. clif_Auction_setitem(fd, idx + 2, false);
  13715. }
  13716. /// Result from an auction action (ZC_AUCTION_RESULT).
  13717. /// 0250 <result>.B
  13718. /// result:
  13719. /// 0 = You have failed to bid into the auction
  13720. /// 1 = You have successfully bid in the auction
  13721. /// 2 = The auction has been canceled
  13722. /// 3 = An auction with at least one bidder cannot be canceled
  13723. /// 4 = You cannot register more than 5 items in an auction at a time
  13724. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13725. /// 6 = You have won the auction
  13726. /// 7 = You have failed to win the auction
  13727. /// 8 = You do not have enough Zeny
  13728. /// 9 = You cannot place more than 5 bids at a time
  13729. void clif_Auction_message(int fd, unsigned char flag)
  13730. {
  13731. WFIFOHEAD(fd,packet_len(0x250));
  13732. WFIFOW(fd,0) = 0x250;
  13733. WFIFOB(fd,2) = flag;
  13734. WFIFOSET(fd,packet_len(0x250));
  13735. }
  13736. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13737. /// 025e <result>.W
  13738. /// result:
  13739. /// 0 = You have ended the auction
  13740. /// 1 = You cannot end the auction
  13741. /// 2 = Auction ID is incorrect
  13742. void clif_Auction_close(int fd, unsigned char flag)
  13743. {
  13744. WFIFOHEAD(fd,packet_len(0x25e));
  13745. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13746. WFIFOW(fd,2) = flag;
  13747. WFIFOSET(fd,packet_len(0x25e));
  13748. }
  13749. /// Request to add an auction (CZ_AUCTION_ADD).
  13750. /// 024d <now money>.L <max money>.L <delete hour>.W
  13751. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13752. {
  13753. struct auction_data auction;
  13754. struct item_data *item;
  13755. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13756. if( !battle_config.feature_auction )
  13757. return;
  13758. auction.price = RFIFOL(fd,info->pos[0]);
  13759. auction.buynow = RFIFOL(fd,info->pos[1]);
  13760. auction.hours = RFIFOW(fd,info->pos[2]);
  13761. // Invalid Situations...
  13762. if( sd->auction.amount < 1 ) {
  13763. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13764. return;
  13765. }
  13766. if( auction.price >= auction.buynow ) {
  13767. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13768. return;
  13769. }
  13770. if( auction.hours < 1 || auction.hours > 48 ) {
  13771. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13772. return;
  13773. }
  13774. // Auction checks...
  13775. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13776. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13777. clif_Auction_message(fd, 2); // The auction has been canceled
  13778. return;
  13779. }
  13780. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13781. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13782. return;
  13783. }
  13784. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13785. auction.buynow = battle_config.auction_maximumprice;
  13786. if( auction.price >= auction.buynow )
  13787. auction.price = auction.buynow - 1;
  13788. }
  13789. auction.auction_id = 0;
  13790. auction.seller_id = sd->status.char_id;
  13791. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13792. auction.buyer_id = 0;
  13793. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13794. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13795. {
  13796. clif_Auction_message(fd, 2); // The auction has been canceled
  13797. return;
  13798. }
  13799. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13800. { // Just in case
  13801. clif_Auction_message(fd, 2); // The auction has been canceled
  13802. return;
  13803. }
  13804. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13805. auction.type = item->type;
  13806. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13807. auction.item.amount = 1;
  13808. auction.timestamp = 0;
  13809. if( !intif_Auction_register(&auction) )
  13810. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13811. else
  13812. {
  13813. int zeny = auction.hours*battle_config.auction_feeperhour;
  13814. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13815. sd->auction.amount = 0;
  13816. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13817. }
  13818. }
  13819. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13820. /// 024e <auction id>.L
  13821. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13822. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13823. intif_Auction_cancel(sd->status.char_id, auction_id);
  13824. }
  13825. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13826. /// 025d <auction id>.L
  13827. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13828. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13829. intif_Auction_close(sd->status.char_id, auction_id);
  13830. }
  13831. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13832. /// 024f <auction id>.L <money>.L
  13833. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13834. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13835. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13836. int bid = RFIFOL(fd,info->pos[1]);
  13837. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13838. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13839. return;
  13840. }
  13841. if( bid <= 0 )
  13842. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13843. else if( bid > sd->status.zeny )
  13844. clif_Auction_message(fd, 8); // You do not have enough zeny
  13845. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13846. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13847. else {
  13848. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13849. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13850. }
  13851. }
  13852. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13853. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13854. /// search type:
  13855. /// 0 = armor
  13856. /// 1 = weapon
  13857. /// 2 = card
  13858. /// 3 = misc
  13859. /// 4 = name search
  13860. /// 5 = auction id search
  13861. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13862. char search_text[NAME_LENGTH];
  13863. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13864. short type = RFIFOW(fd,info->pos[0]);
  13865. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13866. int page = RFIFOW(fd,info->pos[3]);
  13867. if( !battle_config.feature_auction )
  13868. return;
  13869. clif_parse_Auction_cancelreg(fd, sd);
  13870. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13871. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13872. }
  13873. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13874. /// 025c <type>.W
  13875. /// type:
  13876. /// 0 = sell (own auctions)
  13877. /// 1 = buy (own bids)
  13878. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13879. {
  13880. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13881. if( !battle_config.feature_auction )
  13882. return;
  13883. clif_parse_Auction_cancelreg(fd, sd);
  13884. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13885. }
  13886. /// CASH/POINT SHOP
  13887. ///
  13888. void clif_cashshop_open( struct map_session_data* sd ){
  13889. WFIFOHEAD( sd->fd, 10 );
  13890. WFIFOW( sd->fd, 0 ) = 0x845;
  13891. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13892. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13893. WFIFOSET( sd->fd, 10 );
  13894. }
  13895. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13896. sd->state.cashshop_open = true;
  13897. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13898. clif_cashshop_open( sd );
  13899. }
  13900. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13901. sd->state.cashshop_open = false;
  13902. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13903. // No need to do anything here
  13904. }
  13905. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13906. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13907. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13908. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13909. int j;
  13910. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13911. return;
  13912. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13913. WFIFOW(fd, 0) = 0x8c0;
  13914. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13915. WFIFOL(fd, 4) = tab;
  13916. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13917. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13918. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13919. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13920. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13921. }
  13922. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13923. }
  13924. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13925. void clif_cashshop_list( int fd ){
  13926. int tab;
  13927. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13928. int length = 8 + cash_shop_items[tab].count * 6;
  13929. int i, offset;
  13930. WFIFOHEAD( fd, length );
  13931. WFIFOW( fd, 0 ) = 0x8ca;
  13932. WFIFOW( fd, 2 ) = length;
  13933. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13934. WFIFOW( fd, 6 ) = tab;
  13935. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13936. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13937. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13938. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13939. }
  13940. WFIFOSET( fd, length );
  13941. }
  13942. }
  13943. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13944. if( !sd->status.cashshop_sent ) {
  13945. clif_cashshop_list( fd );
  13946. #if PACKETVER_SUPPORTS_SALES
  13947. sale_notify_login(sd);
  13948. #endif
  13949. sd->status.cashshop_sent = true;
  13950. }
  13951. }
  13952. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13953. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13954. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13955. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13956. {
  13957. int fd, i, cost[2] = { 0, 0 };
  13958. #if PACKETVER < 20070711
  13959. const int offset = 8;
  13960. #else
  13961. const int offset = 12;
  13962. #endif
  13963. nullpo_retv(sd);
  13964. nullpo_retv(nd);
  13965. fd = sd->fd;
  13966. sd->npc_shopid = nd->bl.id;
  13967. npc_shop_currency_type(sd, nd, cost, true);
  13968. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13969. WFIFOW(fd,0) = 0x287;
  13970. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13971. WFIFOL(fd,4) = cost[0];
  13972. #if PACKETVER >= 20070711
  13973. WFIFOL(fd,8) = cost[1];
  13974. #endif
  13975. for( i = 0; i < nd->u.shop.count; i++ ) {
  13976. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13977. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13978. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13979. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13980. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13981. }
  13982. WFIFOSET(fd,WFIFOW(fd,2));
  13983. }
  13984. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13985. /// 0289 <cash point>.L <error>.W
  13986. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13987. /// error:
  13988. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13989. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13990. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13991. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13992. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13993. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13994. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13995. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13996. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13997. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13998. {
  13999. int fd, cost[2] = { 0, 0 };
  14000. struct npc_data *nd;
  14001. nullpo_retv(sd);
  14002. fd = sd->fd;
  14003. nd = map_id2nd(sd->npc_shopid);
  14004. npc_shop_currency_type(sd, nd, cost, false);
  14005. WFIFOHEAD(fd, packet_len(0x289));
  14006. WFIFOW(fd,0) = 0x289;
  14007. WFIFOL(fd,2) = cost[0];
  14008. #if PACKETVER < 20070711
  14009. WFIFOW(fd,6) = TOW(error);
  14010. #else
  14011. WFIFOL(fd,6) = cost[1];
  14012. WFIFOW(fd,10) = TOW(error);
  14013. #endif
  14014. WFIFOSET(fd, packet_len(0x289));
  14015. }
  14016. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  14017. WFIFOHEAD( sd->fd, 16 );
  14018. WFIFOW( sd->fd, 0 ) = 0x849;
  14019. WFIFOL( sd->fd, 2 ) = item_id;
  14020. WFIFOW( sd->fd, 6 ) = result;
  14021. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  14022. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  14023. WFIFOSET( sd->fd, 16 );
  14024. }
  14025. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  14026. /// 0288 <name id>.W <amount>.W
  14027. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14028. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14029. /// 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)
  14030. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  14031. struct s_packet_db* info;
  14032. int cmd = RFIFOW(fd,0);
  14033. nullpo_retv(sd);
  14034. info = &packet_db[cmd];
  14035. if( sd->state.trading || !sd->npc_shopid ) {
  14036. clif_cashshop_ack(sd,1);
  14037. return;
  14038. }
  14039. else {
  14040. #if PACKETVER < 20101116
  14041. short nameid = RFIFOW(fd,info->pos[0]);
  14042. short amount = RFIFOW(fd,info->pos[1]);
  14043. int points = RFIFOL(fd,info->pos[2]);
  14044. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  14045. #else
  14046. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  14047. int len = RFIFOW(fd,info->pos[0]);
  14048. int points = RFIFOL(fd,info->pos[1]);
  14049. int count = RFIFOW(fd,info->pos[2]);
  14050. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14051. if( len < 10 || len != 10 + count * s_itl){
  14052. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  14053. return;
  14054. }
  14055. if(cmd==0x848){
  14056. if (cashshop_buylist( sd, points, count, item_list))
  14057. clif_cashshop_ack(sd,0);
  14058. return;
  14059. } else {
  14060. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  14061. return;
  14062. }
  14063. #endif
  14064. }
  14065. }
  14066. /// Adoption System
  14067. ///
  14068. /// Adoption message (ZC_BABYMSG).
  14069. /// 0216 <msg>.L
  14070. /// msg:
  14071. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14072. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14073. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14074. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14075. {
  14076. int fd = sd->fd;
  14077. WFIFOHEAD(fd,6);
  14078. WFIFOW(fd,0) = 0x216;
  14079. WFIFOL(fd,2) = type;
  14080. WFIFOSET(fd,6);
  14081. }
  14082. /// Adoption confirmation (ZC_REQ_BABY).
  14083. /// 01f6 <account id>.L <char id>.L <name>.B
  14084. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14085. {
  14086. int fd = sd->fd;
  14087. WFIFOHEAD(fd,34);
  14088. WFIFOW(fd,0) = 0x1f6;
  14089. WFIFOL(fd,2) = src->status.account_id;
  14090. WFIFOL(fd,6) = p_id;
  14091. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14092. WFIFOSET(fd,34);
  14093. }
  14094. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14095. /// 01f9 <account id>.L
  14096. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14097. {
  14098. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14099. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14100. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14101. {
  14102. tsd->adopt_invite = sd->status.account_id;
  14103. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14104. }
  14105. }
  14106. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14107. /// 01f7 <account id>.L <char id>.L <answer>.L
  14108. /// answer:
  14109. /// 0 = rejected
  14110. /// 1 = accepted
  14111. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14112. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14113. int p1_id = RFIFOL(fd,info->pos[0]);
  14114. int p2_id = RFIFOL(fd,info->pos[1]);
  14115. int result = RFIFOL(fd,info->pos[2]);
  14116. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14117. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14118. int pid = sd->adopt_invite;
  14119. sd->adopt_invite = 0;
  14120. if( p1_sd == NULL || p2_sd == NULL )
  14121. return; // Both players need to be online
  14122. if( pid != p1_sd->status.account_id )
  14123. return; // Incorrect values
  14124. if( result == 0 )
  14125. return; // Rejected
  14126. pc_adoption(p1_sd, p2_sd, sd);
  14127. }
  14128. /// Convex Mirror (ZC_BOSS_INFO).
  14129. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14130. /// infoType:
  14131. /// BOSS_INFO_NOT = No boss on this map.
  14132. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14133. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14134. /// BOSS_INFO_DEAD = Boss is dead.
  14135. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14136. {
  14137. int fd = sd->fd;
  14138. WFIFOHEAD(fd,70);
  14139. memset(WFIFOP(fd,0),0,70);
  14140. WFIFOW(fd,0) = 0x293;
  14141. switch (flag) {
  14142. case BOSS_INFO_NOT:
  14143. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14144. // No data required
  14145. break;
  14146. case BOSS_INFO_ALIVE:
  14147. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14148. // Update X/Y
  14149. WFIFOL(fd,3) = md->bl.x;
  14150. WFIFOL(fd,7) = md->bl.y;
  14151. break;
  14152. case BOSS_INFO_ALIVE_WITHMSG:
  14153. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14154. // Current X/Y
  14155. WFIFOL(fd,3) = md->bl.x;
  14156. WFIFOL(fd,7) = md->bl.y;
  14157. break;
  14158. case BOSS_INFO_DEAD:
  14159. {
  14160. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14161. unsigned int seconds;
  14162. int hours, minutes;
  14163. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14164. hours = seconds / (60 * 60);
  14165. seconds = seconds - (60 * 60 * hours);
  14166. minutes = seconds / 60;
  14167. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14168. // Add respawn info
  14169. WFIFOW(fd,11) = hours; // Hours
  14170. WFIFOW(fd,13) = minutes; // Minutes
  14171. }
  14172. break;
  14173. }
  14174. if (md != NULL)
  14175. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14176. WFIFOSET(fd,70);
  14177. }
  14178. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14179. /// 02d6 <account id>.L
  14180. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14181. {
  14182. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14183. struct map_session_data* tsd = map_id2sd(aid);
  14184. if (!tsd)
  14185. return;
  14186. if (sd->bl.m != tsd->bl.m)
  14187. return;
  14188. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14189. clif_viewequip_ack(sd, tsd);
  14190. else
  14191. clif_msg(sd, VIEW_EQUIP_FAIL);
  14192. }
  14193. /// Request to a configuration.
  14194. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14195. /// type: see enum e_config_type
  14196. /// flag:
  14197. /// false = disabled
  14198. /// true = enabled
  14199. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14200. int cmd = RFIFOW(fd,0);
  14201. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14202. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14203. switch( type ){
  14204. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14205. sd->status.show_equip = flag;
  14206. break;
  14207. case CONFIG_PET_AUTOFEED:
  14208. // Player can not click this if he does not have a pet
  14209. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14210. return;
  14211. }
  14212. sd->pd->pet.autofeed = flag;
  14213. break;
  14214. case CONFIG_HOMUNCULUS_AUTOFEED:
  14215. // Player can not click this if he does not have a homunculus or it is vaporized
  14216. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14217. return;
  14218. }
  14219. sd->hd->homunculus.autofeed = flag;
  14220. break;
  14221. default:
  14222. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14223. return;
  14224. }
  14225. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14226. }
  14227. /// Request to change party invitation tick.
  14228. /// value:
  14229. /// 0 = disabled
  14230. /// 1 = enabled
  14231. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14232. {
  14233. bool flag = RFIFOB(fd,6) ? true : false;
  14234. sd->status.allow_party = flag;
  14235. clif_partytickack(sd, flag);
  14236. }
  14237. /// Questlog System [Kevin] [Inkfish]
  14238. ///
  14239. /**
  14240. * Safe check to init packet len & quest num for player.
  14241. * @param def_len
  14242. * @param info_len Length of each quest info.
  14243. * @param avail_quests Avail quests that player has.
  14244. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14245. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14246. **/
  14247. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14248. (*limit_out) = (0xFFFF - def_len) / info_len;
  14249. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14250. (*len_out) = ((*limit_out) * info_len) + def_len;
  14251. }
  14252. /// Sends list of all quest states
  14253. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14254. /// 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)
  14255. /// 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)
  14256. void clif_quest_send_list(struct map_session_data *sd)
  14257. {
  14258. int fd = sd->fd;
  14259. int i;
  14260. int offset = 8;
  14261. int limit = 0;
  14262. #if PACKETVER >= 20141022
  14263. #if PACKETVER >= 20150513
  14264. int size = 22 + NAME_LENGTH;
  14265. #else
  14266. int size = 10 + NAME_LENGTH;
  14267. #endif
  14268. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14269. WFIFOHEAD(fd,i);
  14270. #if PACKETVER >= 20150513
  14271. WFIFOW(fd, 0) = 0x9f8;
  14272. #else
  14273. WFIFOW(fd, 0) = 0x97a;
  14274. #endif
  14275. WFIFOL(fd, 4) = limit;
  14276. for (i = 0; i < limit; i++) {
  14277. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14278. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14279. offset += 4;
  14280. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14281. offset++;
  14282. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14283. offset += 4;
  14284. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14285. offset += 4;
  14286. WFIFOW(fd, offset) = qi->objectives_count;
  14287. offset += 2;
  14288. if( qi->objectives_count > 0 ){
  14289. int j;
  14290. struct mob_db *mob;
  14291. for( j = 0; j < qi->objectives_count; j++ ){
  14292. mob = mob_db(qi->objectives[j].mob);
  14293. #if PACKETVER >= 20150513
  14294. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14295. offset += 4;
  14296. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14297. offset += 4;
  14298. #endif
  14299. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14300. offset += 4;
  14301. #if PACKETVER >= 20150513
  14302. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14303. offset += 2;
  14304. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14305. offset += 2;
  14306. #endif
  14307. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14308. offset += 2;
  14309. WFIFOW(fd, offset) = qi->objectives[j].count;
  14310. offset += 2;
  14311. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14312. offset += NAME_LENGTH;
  14313. }
  14314. }
  14315. }
  14316. WFIFOW(fd, 2) = offset;
  14317. WFIFOSET(fd, offset);
  14318. #else
  14319. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14320. WFIFOHEAD(fd,i);
  14321. WFIFOW(fd, 0) = 0x2b1;
  14322. WFIFOL(fd, 4) = limit;
  14323. for (i = 0; i < limit; i++) {
  14324. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14325. offset += 4;
  14326. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14327. offset += 1;
  14328. }
  14329. WFIFOW(fd, 2) = offset;
  14330. WFIFOSET(fd, offset);
  14331. #endif
  14332. }
  14333. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14334. /// 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
  14335. void clif_quest_send_mission(struct map_session_data *sd)
  14336. {
  14337. int fd = sd->fd;
  14338. int i, j, limit = 0;
  14339. int len = sd->avail_quests*104+8;
  14340. struct mob_db *mob;
  14341. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14342. WFIFOHEAD(fd, len);
  14343. WFIFOW(fd, 0) = 0x2b2;
  14344. WFIFOW(fd, 2) = len;
  14345. WFIFOL(fd, 4) = limit;
  14346. for (i = 0; i < limit; i++) {
  14347. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14348. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14349. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14350. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14351. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14352. for (j = 0 ; j < qi->objectives_count; j++) {
  14353. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14354. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14355. mob = mob_db(qi->objectives[j].mob);
  14356. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14357. }
  14358. }
  14359. WFIFOSET(fd, len);
  14360. }
  14361. /// Notification about a new quest
  14362. /// 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)
  14363. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14364. /// 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)
  14365. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14366. {
  14367. int fd = sd->fd;
  14368. int i, offset;
  14369. struct quest_db *qi = quest_search(qd->quest_id);
  14370. #if PACKETVER >= 20150513
  14371. int cmd = 0x9f9;
  14372. #else
  14373. int cmd = 0x2b3;
  14374. #endif
  14375. WFIFOHEAD(fd, packet_len(cmd));
  14376. WFIFOW(fd, 0) = cmd;
  14377. WFIFOL(fd, 2) = qd->quest_id;
  14378. WFIFOB(fd, 6) = qd->state;
  14379. WFIFOB(fd, 7) = qd->time - qi->time;
  14380. WFIFOL(fd, 11) = qd->time;
  14381. WFIFOW(fd, 15) = qi->objectives_count;
  14382. for (i = 0, offset = 17; i < qi->objectives_count; i++) {
  14383. struct mob_db *mob;
  14384. #if PACKETVER >= 20150513
  14385. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14386. offset += 4;
  14387. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14388. offset += 4;
  14389. #endif
  14390. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14391. offset += 4;
  14392. #if PACKETVER >= 20150513
  14393. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14394. offset += 2;
  14395. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14396. offset += 2;
  14397. #endif
  14398. WFIFOW(fd, offset) = qd->count[i];
  14399. offset += 2;
  14400. mob = mob_db(qi->objectives[i].mob);
  14401. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14402. offset += NAME_LENGTH;
  14403. }
  14404. WFIFOSET(fd, packet_len(cmd));
  14405. #if PACKETVER >= 20150513
  14406. int len = 4 + qi->objectives_count * 12;
  14407. WFIFOHEAD(fd, len);
  14408. WFIFOW(fd, 0) = 0x8fe;
  14409. WFIFOW(fd, 2) = len;
  14410. for( i = 0, offset = 4; i < qi->objectives_count; i++, offset += 12 ){
  14411. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14412. WFIFOL(fd, offset+4) = qi->objectives[i].mob;
  14413. WFIFOW(fd, offset + 10) = qi->objectives[i].count;
  14414. WFIFOW(fd, offset + 12) = qd->count[i];
  14415. }
  14416. WFIFOSET(fd, len);
  14417. #endif
  14418. }
  14419. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14420. /// 02b4 <quest id>.L
  14421. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14422. {
  14423. int fd = sd->fd;
  14424. WFIFOHEAD(fd, packet_len(0x2b4));
  14425. WFIFOW(fd, 0) = 0x2b4;
  14426. WFIFOL(fd, 2) = quest_id;
  14427. WFIFOSET(fd, packet_len(0x2b4));
  14428. }
  14429. /// Notification of an update to the hunting mission counter
  14430. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14431. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14432. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14433. {
  14434. int fd = sd->fd;
  14435. int i, offset;
  14436. struct quest_db *qi = quest_search(qd->quest_id);
  14437. int len = qi->objectives_count * 12 + 6;
  14438. #if PACKETVER >= 20150513
  14439. int cmd = 0x9fa;
  14440. #else
  14441. int cmd = 0x2b5;
  14442. #endif
  14443. WFIFOHEAD(fd, len);
  14444. WFIFOW(fd, 0) = cmd;
  14445. WFIFOW(fd, 4) = qi->objectives_count;
  14446. for (i = 0, offset = 6; i < qi->objectives_count; i++) {
  14447. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14448. WFIFOL(fd, offset) = qd->quest_id;
  14449. offset += 4;
  14450. #if PACKETVER >= 20150513
  14451. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14452. offset += 4;
  14453. #else
  14454. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14455. offset += 4;
  14456. #endif
  14457. WFIFOW(fd, offset) = qi->objectives[i].count;
  14458. offset += 2;
  14459. WFIFOW(fd, offset) = qd->count[i];
  14460. offset += 2;
  14461. }
  14462. }
  14463. WFIFOW(fd, 2) = offset;
  14464. WFIFOSET(fd, offset);
  14465. }
  14466. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14467. /// 02b6 <quest id>.L <active>.B
  14468. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14469. {
  14470. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14471. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14472. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14473. }
  14474. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14475. /// 02b7 <quest id>.L <active>.B
  14476. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14477. {
  14478. int fd = sd->fd;
  14479. WFIFOHEAD(fd, packet_len(0x2b7));
  14480. WFIFOW(fd, 0) = 0x2b7;
  14481. WFIFOL(fd, 2) = quest_id;
  14482. WFIFOB(fd, 6) = active;
  14483. WFIFOSET(fd, packet_len(0x2b7));
  14484. }
  14485. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14486. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14487. /// effect:
  14488. /// 0 = none
  14489. /// 1 = exclamation mark icon
  14490. /// 2 = question mark icon
  14491. /// color:
  14492. /// 0 = yellow
  14493. /// 1 = orange
  14494. /// 2 = green
  14495. /// 3 = purple
  14496. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14497. {
  14498. #if PACKETVER >= 20090218
  14499. nullpo_retv(sd);
  14500. nullpo_retv(bl);
  14501. int fd = sd->fd;
  14502. WFIFOHEAD(fd, packet_len(0x446));
  14503. WFIFOW(fd, 0) = 0x446;
  14504. WFIFOL(fd, 2) = bl->id;
  14505. WFIFOW(fd, 6) = bl->x;
  14506. WFIFOW(fd, 8) = bl->y;
  14507. WFIFOW(fd, 10) = effect;
  14508. WFIFOW(fd, 12) = color;
  14509. WFIFOSET(fd, packet_len(0x446));
  14510. #endif
  14511. }
  14512. /// Mercenary System
  14513. ///
  14514. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14515. /// 02a2 <var id>.W <value>.L
  14516. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14517. {
  14518. struct mercenary_data *md;
  14519. struct status_data *status;
  14520. int fd;
  14521. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14522. return;
  14523. fd = sd->fd;
  14524. status = &md->battle_status;
  14525. WFIFOHEAD(fd,packet_len(0x2a2));
  14526. WFIFOW(fd,0) = 0x2a2;
  14527. WFIFOW(fd,2) = type;
  14528. switch( type ) {
  14529. case SP_ATK1:
  14530. {
  14531. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14532. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14533. }
  14534. break;
  14535. case SP_MATK1:
  14536. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14537. break;
  14538. case SP_HIT:
  14539. WFIFOL(fd,4) = status->hit;
  14540. break;
  14541. case SP_CRITICAL:
  14542. WFIFOL(fd,4) = status->cri/10;
  14543. break;
  14544. case SP_DEF1:
  14545. WFIFOL(fd,4) = status->def;
  14546. break;
  14547. case SP_MDEF1:
  14548. WFIFOL(fd,4) = status->mdef;
  14549. break;
  14550. case SP_MERCFLEE:
  14551. WFIFOL(fd,4) = status->flee;
  14552. break;
  14553. case SP_ASPD:
  14554. WFIFOL(fd,4) = status->amotion;
  14555. break;
  14556. case SP_HP:
  14557. WFIFOL(fd,4) = status->hp;
  14558. break;
  14559. case SP_MAXHP:
  14560. WFIFOL(fd,4) = status->max_hp;
  14561. break;
  14562. case SP_SP:
  14563. WFIFOL(fd,4) = status->sp;
  14564. break;
  14565. case SP_MAXSP:
  14566. WFIFOL(fd,4) = status->max_sp;
  14567. break;
  14568. case SP_MERCKILLS:
  14569. WFIFOL(fd,4) = md->mercenary.kill_count;
  14570. break;
  14571. case SP_MERCFAITH:
  14572. WFIFOL(fd,4) = mercenary_get_faith(md);
  14573. break;
  14574. }
  14575. WFIFOSET(fd,packet_len(0x2a2));
  14576. }
  14577. /// Mercenary base status data (ZC_MER_INIT).
  14578. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14579. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14580. /// <calls>.L <kills>.L <atk range>.W
  14581. void clif_mercenary_info(struct map_session_data *sd)
  14582. {
  14583. int fd;
  14584. struct mercenary_data *md;
  14585. struct status_data *status;
  14586. int atk;
  14587. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14588. return;
  14589. fd = sd->fd;
  14590. status = &md->battle_status;
  14591. WFIFOHEAD(fd,packet_len(0x29b));
  14592. WFIFOW(fd,0) = 0x29b;
  14593. WFIFOL(fd,2) = md->bl.id;
  14594. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14595. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14596. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14597. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14598. WFIFOW(fd,10) = status->hit;
  14599. WFIFOW(fd,12) = status->cri/10;
  14600. WFIFOW(fd,14) = status->def;
  14601. WFIFOW(fd,16) = status->mdef;
  14602. WFIFOW(fd,18) = status->flee;
  14603. WFIFOW(fd,20) = status->amotion;
  14604. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14605. WFIFOW(fd,46) = md->db->lv;
  14606. WFIFOL(fd,48) = status->hp;
  14607. WFIFOL(fd,52) = status->max_hp;
  14608. WFIFOL(fd,56) = status->sp;
  14609. WFIFOL(fd,60) = status->max_sp;
  14610. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  14611. WFIFOW(fd,68) = mercenary_get_faith(md);
  14612. WFIFOL(fd,70) = mercenary_get_calls(md);
  14613. WFIFOL(fd,74) = md->mercenary.kill_count;
  14614. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14615. WFIFOSET(fd,packet_len(0x29b));
  14616. }
  14617. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14618. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14619. void clif_mercenary_skillblock(struct map_session_data *sd)
  14620. {
  14621. struct mercenary_data *md;
  14622. int fd, i, len = 4;
  14623. if( sd == NULL || (md = sd->md) == NULL )
  14624. return;
  14625. fd = sd->fd;
  14626. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14627. WFIFOW(fd,0) = 0x29d;
  14628. for( i = 0; i < MAX_MERCSKILL; i++ )
  14629. {
  14630. uint16 id;
  14631. short idx = -1;
  14632. if( (id = md->db->skill[i].id) == 0 )
  14633. continue;
  14634. if ((idx = mercenary_skill_get_index(id)) == -1)
  14635. continue;
  14636. WFIFOW(fd,len) = id;
  14637. WFIFOL(fd,len+2) = skill_get_inf(id);
  14638. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14639. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14640. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14641. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14642. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14643. len += 37;
  14644. }
  14645. WFIFOW(fd,2) = len;
  14646. WFIFOSET(fd,len);
  14647. }
  14648. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14649. /// 029f <command>.B
  14650. /// 1 = mercenary information
  14651. /// 2 = delete
  14652. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14653. {
  14654. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14655. if( sd->md == NULL )
  14656. return;
  14657. if( option == 2 ) mercenary_delete(sd->md, 2);
  14658. }
  14659. /// Mercenary Message
  14660. /// message:
  14661. /// 0 = Mercenary soldier's duty hour is over.
  14662. /// 1 = Your mercenary soldier has been killed.
  14663. /// 2 = Your mercenary soldier has been fired.
  14664. /// 3 = Your mercenary soldier has ran away.
  14665. void clif_mercenary_message(struct map_session_data* sd, int message){
  14666. clif_msg(sd, MERC_MSG_BASE + message);
  14667. }
  14668. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14669. /// 0298 <name id>.W <seconds>.L
  14670. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14671. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14672. WFIFOHEAD(fd,packet_len(0x298));
  14673. WFIFOW(fd,0) = 0x298;
  14674. WFIFOW(fd,2) = nameid;
  14675. WFIFOL(fd,4) = seconds;
  14676. WFIFOSET(fd,packet_len(0x298));
  14677. }
  14678. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14679. /// 0299 <index>.W <name id>.W
  14680. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14681. { // '<ItemName>' item has been deleted from the Inventory
  14682. WFIFOHEAD(fd,packet_len(0x299));
  14683. WFIFOW(fd,0) = 0x299;
  14684. WFIFOW(fd,2) = index+2;
  14685. WFIFOW(fd,4) = nameid;
  14686. WFIFOSET(fd,packet_len(0x299));
  14687. }
  14688. /// Book Reading (ZC_READ_BOOK).
  14689. /// 0294 <book id>.L <page>.L
  14690. void clif_readbook(int fd, int book_id, int page)
  14691. {
  14692. WFIFOHEAD(fd,packet_len(0x294));
  14693. WFIFOW(fd,0) = 0x294;
  14694. WFIFOL(fd,2) = book_id;
  14695. WFIFOL(fd,6) = page;
  14696. WFIFOSET(fd,packet_len(0x294));
  14697. }
  14698. /// Battlegrounds
  14699. ///
  14700. /// Updates HP bar of a camp member.
  14701. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14702. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14703. void clif_bg_hp(struct map_session_data *sd) {
  14704. #if PACKETVER < 20140613
  14705. unsigned char buf[34];
  14706. const int cmd = 0x2e0;
  14707. #else
  14708. unsigned char buf[14];
  14709. const int cmd = 0xa0e;
  14710. #endif
  14711. nullpo_retv(sd);
  14712. WBUFW(buf,0) = cmd;
  14713. WBUFL(buf,2) = sd->status.account_id;
  14714. #if PACKETVER < 20140613
  14715. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14716. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14717. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14718. WBUFW(buf,32) = 100;
  14719. } else {
  14720. WBUFW(buf,30) = sd->battle_status.hp;
  14721. WBUFW(buf,32) = sd->battle_status.max_hp;
  14722. }
  14723. #else
  14724. if( sd->battle_status.max_hp > INT32_MAX ) {
  14725. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14726. WBUFL(buf,10) = 100;
  14727. } else {
  14728. WBUFL(buf,6) = sd->battle_status.hp;
  14729. WBUFL(buf,10) = sd->battle_status.max_hp;
  14730. }
  14731. #endif
  14732. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14733. }
  14734. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14735. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14736. void clif_bg_xy(struct map_session_data *sd)
  14737. {
  14738. unsigned char buf[36];
  14739. nullpo_retv(sd);
  14740. WBUFW(buf,0)=0x2df;
  14741. WBUFL(buf,2)=sd->status.account_id;
  14742. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14743. WBUFW(buf,30)=sd->status.class_;
  14744. WBUFW(buf,32)=sd->bl.x;
  14745. WBUFW(buf,34)=sd->bl.y;
  14746. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14747. }
  14748. void clif_bg_xy_remove(struct map_session_data *sd)
  14749. {
  14750. unsigned char buf[36];
  14751. nullpo_retv(sd);
  14752. WBUFW(buf,0)=0x2df;
  14753. WBUFL(buf,2)=sd->status.account_id;
  14754. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14755. WBUFW(buf,30)=0;
  14756. WBUFW(buf,32)=-1;
  14757. WBUFW(buf,34)=-1;
  14758. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14759. }
  14760. /// Notifies clients of a battleground message.
  14761. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  14762. void clif_bg_message( struct battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  14763. struct map_session_data *sd = bg_getavailablesd( bg );
  14764. if( sd == nullptr ){
  14765. return;
  14766. }
  14767. // limit length
  14768. len = min( len + 1, CHAT_SIZE_MAX );
  14769. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  14770. WBUFW(buf,0) = 0x2dc;
  14771. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14772. WBUFL(buf,4) = src_id;
  14773. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14774. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  14775. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14776. }
  14777. /// Validates and processes battlechat messages.
  14778. /// All messages that are sent after enabling battleground chat with /battlechat.
  14779. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  14780. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14781. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14782. if( !clif_process_message( sd, false, name, message, output ) )
  14783. return;
  14784. bg_send_message(sd, output, strlen(output) );
  14785. }
  14786. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14787. /// 02de <camp A points>.W <camp B points>.W
  14788. void clif_bg_updatescore(int16 m)
  14789. {
  14790. struct block_list bl;
  14791. unsigned char buf[6];
  14792. struct map_data *mapdata = map_getmapdata(m);
  14793. bl.id = 0;
  14794. bl.type = BL_NUL;
  14795. bl.m = m;
  14796. WBUFW(buf,0) = 0x2de;
  14797. WBUFW(buf,2) = mapdata->bgscore_lion;
  14798. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14799. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14800. }
  14801. void clif_bg_updatescore_single(struct map_session_data *sd)
  14802. {
  14803. int fd;
  14804. nullpo_retv(sd);
  14805. fd = sd->fd;
  14806. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14807. WFIFOHEAD(fd,packet_len(0x2de));
  14808. WFIFOW(fd,0) = 0x2de;
  14809. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14810. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14811. WFIFOSET(fd,packet_len(0x2de));
  14812. }
  14813. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14814. /// 02dd <account id>.L <name>.24B <camp>.W
  14815. void clif_sendbgemblem_area(struct map_session_data *sd)
  14816. {
  14817. unsigned char buf[33];
  14818. nullpo_retv(sd);
  14819. WBUFW(buf, 0) = 0x2dd;
  14820. WBUFL(buf,2) = sd->bl.id;
  14821. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14822. WBUFW(buf,30) = sd->bg_id;
  14823. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14824. }
  14825. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14826. {
  14827. nullpo_retv(sd);
  14828. WFIFOHEAD(fd,32);
  14829. WFIFOW(fd,0) = 0x2dd;
  14830. WFIFOL(fd,2) = sd->bl.id;
  14831. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14832. WFIFOW(fd,30) = sd->bg_id;
  14833. WFIFOSET(fd,packet_len(0x2dd));
  14834. }
  14835. /// Custom Fonts (ZC_NOTIFY_FONT).
  14836. /// 02ef <account_id>.L <font id>.W
  14837. void clif_font(struct map_session_data *sd)
  14838. {
  14839. #if PACKETVER >= 20080102
  14840. unsigned char buf[8];
  14841. nullpo_retv(sd);
  14842. WBUFW(buf,0) = 0x2ef;
  14843. WBUFL(buf,2) = sd->bl.id;
  14844. WBUFW(buf,6) = sd->status.font;
  14845. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14846. #endif
  14847. }
  14848. /// Required to start the instancing information window on Client
  14849. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14850. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14851. void clif_instance_create(unsigned short instance_id, int num)
  14852. {
  14853. #if PACKETVER >= 20071128
  14854. struct instance_db *db = NULL;
  14855. struct map_session_data *sd = NULL;
  14856. enum send_target target = PARTY;
  14857. unsigned char buf[65];
  14858. instance_getsd(instance_id, &sd, &target);
  14859. if (!sd)
  14860. return;
  14861. db = instance_searchtype_db(instance_data[instance_id].type);
  14862. if (!db)
  14863. return;
  14864. WBUFW(buf,0) = 0x2cb;
  14865. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14866. WBUFW(buf,63) = num;
  14867. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14868. #endif
  14869. return;
  14870. }
  14871. /// To announce Instancing queue creation if no maps available
  14872. /// S 0x2cc <Standby Position>.W
  14873. void clif_instance_changewait(unsigned short instance_id, int num)
  14874. {
  14875. #if PACKETVER >= 20071128
  14876. struct map_session_data *sd = NULL;
  14877. enum send_target target = PARTY;
  14878. unsigned char buf[4];
  14879. instance_getsd(instance_id, &sd, &target);
  14880. if (!sd)
  14881. return;
  14882. WBUFW(buf,0) = 0x2cc;
  14883. WBUFW(buf,2) = num;
  14884. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14885. #endif
  14886. return;
  14887. }
  14888. /// Notify the current status to members
  14889. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14890. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14891. {
  14892. #if PACKETVER >= 20071128
  14893. struct instance_db *db = NULL;
  14894. struct map_session_data *sd = NULL;
  14895. enum send_target target = PARTY;
  14896. unsigned char buf[71];
  14897. instance_getsd(instance_id, &sd, &target);
  14898. if (!sd)
  14899. return;
  14900. db = instance_searchtype_db(instance_data[instance_id].type);
  14901. if (!db)
  14902. return;
  14903. WBUFW(buf,0) = 0x2cd;
  14904. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14905. WBUFL(buf,63) = limit1;
  14906. WBUFL(buf,67) = limit2;
  14907. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14908. #endif
  14909. return;
  14910. }
  14911. /// Notify a status change to members
  14912. /// S 0x2ce <Message ID>.L
  14913. /// 0 = Notification (EnterLimitDate update?)
  14914. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14915. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14916. /// 3 = The Memorial Dungeon has been removed.
  14917. /// 4 = Create failure (removes the instance window)
  14918. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14919. {
  14920. #if PACKETVER >= 20071128
  14921. struct map_session_data *sd = NULL;
  14922. enum send_target target = PARTY;
  14923. unsigned char buf[10];
  14924. instance_getsd(instance_id, &sd, &target);
  14925. if (!sd)
  14926. return;
  14927. WBUFW(buf,0) = 0x2ce;
  14928. WBUFL(buf,2) = type;
  14929. WBUFL(buf,6) = limit;
  14930. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14931. #endif
  14932. return;
  14933. }
  14934. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14935. /// 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
  14936. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14937. {
  14938. #if PACKETVER >= 20071002
  14939. unsigned char buf[22];
  14940. struct item_data* id = itemdb_search(item_data->nameid);
  14941. WBUFW(buf,0) = 0x2b8;
  14942. WBUFL(buf,2) = sd->status.account_id;
  14943. WBUFW(buf,6) = item_data->nameid;
  14944. WBUFB(buf,8) = item_data->identify;
  14945. WBUFB(buf,9) = item_data->attribute;
  14946. WBUFB(buf,10) = item_data->refine;
  14947. clif_addcards(WBUFP(buf,11), item_data);
  14948. WBUFW(buf,19) = id->equip; // equip location
  14949. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14950. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14951. #endif
  14952. }
  14953. /** Display gained exp.
  14954. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14955. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14956. * amount: INT32_MIN ~ INT32_MAX
  14957. * var id:
  14958. * SP_BASEEXP, SP_JOBEXP
  14959. * exp type:
  14960. * 0 = normal exp gained/lost
  14961. * 1 = quest exp gained/lost
  14962. * @param sd Player
  14963. * @param exp EXP value gained/loss
  14964. * @param type SP_BASEEXP, SP_JOBEXP
  14965. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14966. * @param lost True:if lossing EXP
  14967. */
  14968. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14969. {
  14970. int fd;
  14971. int offset;
  14972. #if PACKETVER >= 20170830
  14973. int cmd = 0xacc;
  14974. #else
  14975. int cmd = 0x7f6;
  14976. #endif
  14977. nullpo_retv(sd);
  14978. fd = sd->fd;
  14979. WFIFOHEAD(fd, packet_len(cmd));
  14980. WFIFOW(fd,0) = cmd;
  14981. WFIFOL(fd,2) = sd->bl.id;
  14982. #if PACKETVER >= 20170830
  14983. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14984. offset = 4;
  14985. #else
  14986. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14987. offset = 0;
  14988. #endif
  14989. WFIFOW(fd,10+offset) = type;
  14990. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14991. WFIFOSET(fd,packet_len(cmd));
  14992. }
  14993. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14994. /// type:
  14995. /// 0 = Displays 'value' for 5 seconds.
  14996. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14997. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14998. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14999. /// value:
  15000. /// 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).
  15001. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  15002. {
  15003. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15004. WFIFOW(sd->fd,0) = 0x1b1;
  15005. WFIFOB(sd->fd,2) = type;
  15006. WFIFOL(sd->fd,3) = value;
  15007. WFIFOSET(sd->fd, packet_len(0x1b1));
  15008. }
  15009. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15010. /// 021d <state>.L
  15011. /// state:
  15012. /// 0 = Full effects
  15013. /// 1 = Reduced effects
  15014. ///
  15015. /// NOTE: The state is used on Aegis for sending skill unit packet
  15016. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15017. /// whenever possible. Due to the way the decision check is
  15018. /// constructed, this state tracking was rendered useless,
  15019. /// as the only skill unit, that is sent with 0x1c9 is
  15020. /// Graffiti.
  15021. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  15022. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15023. sd->state.lesseffect = ( isLess != 0 );
  15024. }
  15025. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15026. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  15027. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15028. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15029. int type = RFIFOL(fd,info->pos[1]);
  15030. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15031. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15032. if( sd->state.trading || sd->npc_shopid )
  15033. return;
  15034. if( flag == 0 || n == 0) {
  15035. clif_menuskill_clear(sd);
  15036. return; // Canceled by player.
  15037. }
  15038. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15039. clif_menuskill_clear(sd);
  15040. return; // Prevent hacking.
  15041. }
  15042. switch( type ) {
  15043. case 0: // Change Material
  15044. skill_changematerial(sd,n,item_list);
  15045. break;
  15046. case 1: // Level 1: Pure to Rough
  15047. case 2: // Level 2: Rough to Pure
  15048. skill_elementalanalysis(sd,n,type,item_list);
  15049. break;
  15050. }
  15051. clif_menuskill_clear(sd);
  15052. return;
  15053. }
  15054. /*==========================================
  15055. * Elemental System
  15056. *==========================================*/
  15057. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  15058. struct elemental_data *ed;
  15059. struct status_data *status;
  15060. int fd;
  15061. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15062. return;
  15063. fd = sd->fd;
  15064. status = &ed->battle_status;
  15065. WFIFOHEAD(fd,8);
  15066. WFIFOW(fd,0) = 0x81e;
  15067. WFIFOW(fd,2) = type;
  15068. switch( type ) {
  15069. case SP_HP:
  15070. WFIFOL(fd,4) = status->hp;
  15071. break;
  15072. case SP_MAXHP:
  15073. WFIFOL(fd,4) = status->max_hp;
  15074. break;
  15075. case SP_SP:
  15076. WFIFOL(fd,4) = status->sp;
  15077. break;
  15078. case SP_MAXSP:
  15079. WFIFOL(fd,4) = status->max_sp;
  15080. break;
  15081. }
  15082. WFIFOSET(fd,8);
  15083. }
  15084. void clif_elemental_info(struct map_session_data *sd) {
  15085. int fd;
  15086. struct elemental_data *ed;
  15087. struct status_data *status;
  15088. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15089. return;
  15090. fd = sd->fd;
  15091. status = &ed->battle_status;
  15092. WFIFOHEAD(fd,22);
  15093. WFIFOW(fd, 0) = 0x81d;
  15094. WFIFOL(fd, 2) = ed->bl.id;
  15095. WFIFOL(fd, 6) = status->hp;
  15096. WFIFOL(fd,10) = status->max_hp;
  15097. WFIFOL(fd,14) = status->sp;
  15098. WFIFOL(fd,18) = status->max_sp;
  15099. WFIFOSET(fd,22);
  15100. }
  15101. /// Buying Store System
  15102. ///
  15103. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15104. /// 0810 <slots>.B
  15105. void clif_buyingstore_open(struct map_session_data* sd)
  15106. {
  15107. int fd = sd->fd;
  15108. WFIFOHEAD(fd,packet_len(0x810));
  15109. WFIFOW(fd,0) = 0x810;
  15110. WFIFOB(fd,2) = sd->buyingstore.slots;
  15111. WFIFOSET(fd,packet_len(0x810));
  15112. }
  15113. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15114. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15115. /// result:
  15116. /// 0 = cancel
  15117. /// 1 = open
  15118. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  15119. {
  15120. const unsigned int blocksize = 8;
  15121. uint8* itemlist;
  15122. char storename[MESSAGE_SIZE];
  15123. unsigned char result;
  15124. int zenylimit;
  15125. unsigned int count, packet_len;
  15126. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15127. packet_len = RFIFOW(fd,info->pos[0]);
  15128. // TODO: Make this check global for all variable length packets.
  15129. if( packet_len < 89 )
  15130. {// minimum packet length
  15131. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  15132. return;
  15133. }
  15134. zenylimit = RFIFOL(fd,info->pos[1]);
  15135. result = RFIFOL(fd,info->pos[2]);
  15136. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  15137. itemlist = RFIFOP(fd,info->pos[4]);
  15138. // so that buyingstore_create knows, how many elements it has access to
  15139. packet_len-= info->pos[4];
  15140. if( packet_len%blocksize )
  15141. {
  15142. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15143. return;
  15144. }
  15145. count = packet_len/blocksize;
  15146. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  15147. }
  15148. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15149. /// 0812 <result>.W <total weight>.L
  15150. /// result:
  15151. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15152. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15153. /// 8 = "No sale (purchase) information available." (0x705)
  15154. /// ? = nothing
  15155. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15156. {
  15157. int fd = sd->fd;
  15158. WFIFOHEAD(fd,packet_len(0x812));
  15159. WFIFOW(fd,0) = 0x812;
  15160. WFIFOW(fd,2) = result;
  15161. WFIFOL(fd,4) = weight;
  15162. WFIFOSET(fd,packet_len(0x812));
  15163. }
  15164. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15165. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15166. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  15167. {
  15168. int fd = sd->fd;
  15169. unsigned int i;
  15170. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  15171. WFIFOW(fd,0) = 0x813;
  15172. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  15173. WFIFOL(fd,4) = sd->bl.id;
  15174. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  15175. for( i = 0; i < sd->buyingstore.slots; i++ )
  15176. {
  15177. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  15178. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  15179. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  15180. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  15181. }
  15182. WFIFOSET(fd,WFIFOW(fd,2));
  15183. }
  15184. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15185. /// 0814 <account id>.L <store name>.80B
  15186. void clif_buyingstore_entry(struct map_session_data* sd)
  15187. {
  15188. uint8 buf[MESSAGE_SIZE+6];
  15189. WBUFW(buf,0) = 0x814;
  15190. WBUFL(buf,2) = sd->bl.id;
  15191. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15192. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15193. }
  15194. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15195. {
  15196. int fd = sd->fd;
  15197. WFIFOHEAD(fd,packet_len(0x814));
  15198. WFIFOW(fd,0) = 0x814;
  15199. WFIFOL(fd,2) = pl_sd->bl.id;
  15200. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15201. WFIFOSET(fd,packet_len(0x814));
  15202. }
  15203. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15204. /// 0815
  15205. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15206. {
  15207. buyingstore_close(sd);
  15208. }
  15209. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15210. /// 0816 <account id>.L
  15211. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15212. {
  15213. uint8 buf[6];
  15214. WBUFW(buf,0) = 0x816;
  15215. WBUFL(buf,2) = sd->bl.id;
  15216. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15217. }
  15218. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15219. {
  15220. int fd = sd->fd;
  15221. WFIFOHEAD(fd,packet_len(0x816));
  15222. WFIFOW(fd,0) = 0x816;
  15223. WFIFOL(fd,2) = pl_sd->bl.id;
  15224. WFIFOSET(fd,packet_len(0x816));
  15225. }
  15226. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15227. /// 0817 <account id>.L
  15228. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15229. {
  15230. uint32 account_id;
  15231. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15232. buyingstore_open(sd, account_id);
  15233. }
  15234. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  15235. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  15236. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  15237. {
  15238. int fd = sd->fd;
  15239. unsigned int i;
  15240. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  15241. WFIFOW(fd,0) = 0x818;
  15242. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  15243. WFIFOL(fd,4) = pl_sd->bl.id;
  15244. WFIFOL(fd,8) = pl_sd->buyer_id;
  15245. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  15246. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  15247. {
  15248. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  15249. 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.
  15250. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  15251. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  15252. }
  15253. WFIFOSET(fd,WFIFOW(fd,2));
  15254. }
  15255. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  15256. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  15257. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  15258. {
  15259. const unsigned int blocksize = 6;
  15260. uint8* itemlist;
  15261. uint32 account_id;
  15262. unsigned int count, packet_len, buyer_id;
  15263. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15264. packet_len = RFIFOW(fd,info->pos[0]);
  15265. if( packet_len < 12 )
  15266. {// minimum packet length
  15267. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15268. return;
  15269. }
  15270. account_id = RFIFOL(fd,info->pos[1]);
  15271. buyer_id = RFIFOL(fd,info->pos[2]);
  15272. itemlist = RFIFOP(fd,info->pos[3]);
  15273. // so that buyingstore_trade knows, how many elements it has access to
  15274. packet_len-= info->pos[3];
  15275. if( packet_len%blocksize )
  15276. {
  15277. 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);
  15278. return;
  15279. }
  15280. count = packet_len/blocksize;
  15281. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15282. }
  15283. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15284. /// 081a <result>.W
  15285. /// result:
  15286. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15287. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15288. /// ? = nothing
  15289. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15290. {
  15291. int fd = sd->fd;
  15292. WFIFOHEAD(fd,packet_len(0x81a));
  15293. WFIFOW(fd,0) = 0x81a;
  15294. WFIFOW(fd,2) = result;
  15295. WFIFOSET(fd,packet_len(0x81a));
  15296. }
  15297. /// Updates the zeny limit and an item in the buying store item list.
  15298. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15299. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15300. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15301. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15302. const int cmd = 0x81b;
  15303. #else
  15304. const int cmd = 0x9e6;
  15305. #endif
  15306. int offset = 0;
  15307. int fd = sd->fd;
  15308. WFIFOHEAD(fd,packet_len(cmd));
  15309. WFIFOW(fd,0) = cmd;
  15310. WFIFOW(fd,2) = nameid;
  15311. WFIFOW(fd,4) = amount; // amount of nameid received
  15312. #if PACKETVER >= 20141016
  15313. WFIFOL(fd,6) = zeny; // zeny
  15314. offset += 4;
  15315. #endif
  15316. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15317. #if PACKETVER >= 20141016
  15318. WFIFOL(fd,10+offset) = char_id; // GID
  15319. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15320. #endif
  15321. WFIFOSET(fd,packet_len(cmd));
  15322. }
  15323. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15324. /// 081c <index>.W <amount>.W <price>.L
  15325. /// message:
  15326. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15327. ///
  15328. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15329. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15330. {
  15331. int fd = sd->fd;
  15332. WFIFOHEAD(fd,packet_len(0x81c));
  15333. WFIFOW(fd,0) = 0x81c;
  15334. WFIFOW(fd,2) = index+2;
  15335. WFIFOW(fd,4) = amount;
  15336. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15337. WFIFOSET(fd,packet_len(0x81c));
  15338. }
  15339. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15340. /// 0824 <result>.W <name id>.W
  15341. /// result:
  15342. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15343. /// 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)
  15344. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15345. /// ? = nothing
  15346. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15347. {
  15348. int fd = sd->fd;
  15349. WFIFOHEAD(fd,packet_len(0x824));
  15350. WFIFOW(fd,0) = 0x824;
  15351. WFIFOW(fd,2) = result;
  15352. WFIFOW(fd,4) = nameid;
  15353. WFIFOSET(fd,packet_len(0x824));
  15354. }
  15355. /// Search Store Info System
  15356. ///
  15357. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15358. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15359. /// type:
  15360. /// 0 = Vending
  15361. /// 1 = Buying Store
  15362. ///
  15363. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15364. /// amount of card slots. If the client does not know about the item it
  15365. /// cannot be searched.
  15366. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15367. {
  15368. const unsigned int blocksize = 2;
  15369. const uint8* itemlist;
  15370. const uint8* cardlist;
  15371. unsigned char type;
  15372. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15373. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15374. packet_len = RFIFOW(fd,info->pos[0]);
  15375. if( packet_len < 15 )
  15376. {// minimum packet length
  15377. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15378. return;
  15379. }
  15380. type = RFIFOB(fd,info->pos[1]);
  15381. max_price = RFIFOL(fd,info->pos[2]);
  15382. min_price = RFIFOL(fd,info->pos[3]);
  15383. item_count = RFIFOB(fd,info->pos[4]);
  15384. card_count = RFIFOB(fd,info->pos[5]);
  15385. itemlist = RFIFOP(fd,info->pos[6]);
  15386. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15387. // check, if there is enough data for the claimed count of items
  15388. packet_len-= info->pos[6];
  15389. if( packet_len%blocksize )
  15390. {
  15391. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15392. return;
  15393. }
  15394. count = packet_len/blocksize;
  15395. if( count < item_count+card_count )
  15396. {
  15397. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15398. return;
  15399. }
  15400. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15401. }
  15402. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15403. /// 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 }*
  15404. /// is first page:
  15405. /// 0 = appends to existing results
  15406. /// 1 = clears previous results before displaying this result set
  15407. /// is next page:
  15408. /// 0 = no "next" label
  15409. /// 1 = "next" label to retrieve more results
  15410. void clif_search_store_info_ack(struct map_session_data* sd)
  15411. {
  15412. #if PACKETVER >= 20150225
  15413. const unsigned int blocksize = MESSAGE_SIZE+26+5*5;
  15414. #else
  15415. const unsigned int blocksize = MESSAGE_SIZE+26;
  15416. #endif
  15417. int fd = sd->fd;
  15418. unsigned int i, start, end;
  15419. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15420. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15421. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15422. WFIFOW(fd,0) = 0x836;
  15423. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15424. WFIFOB(fd,4) = !sd->searchstore.pages;
  15425. WFIFOB(fd,5) = searchstore_querynext(sd);
  15426. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15427. for( i = start; i < end; i++ ) {
  15428. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15429. struct item it;
  15430. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15431. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15432. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15433. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15434. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15435. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15436. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15437. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15438. // make-up an item for clif_addcards
  15439. memset(&it, 0, sizeof(it));
  15440. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15441. it.nameid = ssitem->nameid;
  15442. it.amount = ssitem->amount;
  15443. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15444. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15445. }
  15446. WFIFOSET(fd,WFIFOW(fd,2));
  15447. }
  15448. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15449. /// 0837 <reason>.B
  15450. /// reason:
  15451. /// 0 = "No matching stores were found." (0x70b)
  15452. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15453. /// 2 = "You cannot search anymore." (0x706)
  15454. /// 3 = "You cannot search yet." (0x708)
  15455. /// 4 = "No sale (purchase) information available." (0x705)
  15456. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15457. {
  15458. int fd = sd->fd;
  15459. WFIFOHEAD(fd,packet_len(0x837));
  15460. WFIFOW(fd,0) = 0x837;
  15461. WFIFOB(fd,2) = reason;
  15462. WFIFOSET(fd,packet_len(0x837));
  15463. }
  15464. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15465. /// 0838
  15466. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15467. {
  15468. searchstore_next(sd);
  15469. }
  15470. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15471. /// 083a <type>.W <remaining uses>.B
  15472. /// type:
  15473. /// 0 = Search Stores
  15474. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15475. void clif_open_search_store_info(struct map_session_data* sd)
  15476. {
  15477. int fd = sd->fd;
  15478. WFIFOHEAD(fd,packet_len(0x83a));
  15479. WFIFOW(fd,0) = 0x83a;
  15480. WFIFOW(fd,2) = sd->searchstore.effect;
  15481. #if PACKETVER > 20100701
  15482. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15483. #endif
  15484. WFIFOSET(fd,packet_len(0x83a));
  15485. }
  15486. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15487. /// 083b
  15488. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15489. {
  15490. searchstore_close(sd);
  15491. }
  15492. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15493. /// 083c <account id>.L <store id>.L <nameid>.W
  15494. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15495. {
  15496. unsigned short nameid;
  15497. uint32 account_id, store_id;
  15498. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15499. account_id = RFIFOL(fd,info->pos[0]);
  15500. store_id = RFIFOL(fd,info->pos[1]);
  15501. nameid = RFIFOW(fd,info->pos[2]);
  15502. searchstore_click(sd, account_id, store_id, nameid);
  15503. }
  15504. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15505. /// 083d <xPos>.W <yPos>.W
  15506. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15507. {
  15508. int fd = sd->fd;
  15509. WFIFOHEAD(fd,packet_len(0x83d));
  15510. WFIFOW(fd,0) = 0x83d;
  15511. WFIFOW(fd,2) = x;
  15512. WFIFOW(fd,4) = y;
  15513. WFIFOSET(fd,packet_len(0x83d));
  15514. }
  15515. /// Parse function for packet debugging.
  15516. void clif_parse_debug(int fd,struct map_session_data *sd)
  15517. {
  15518. int cmd, packet_len;
  15519. // clif_parse ensures, that there is at least 2 bytes of data
  15520. cmd = RFIFOW(fd,0);
  15521. if( sd ) {
  15522. packet_len = packet_db[cmd].len;
  15523. if( packet_len == 0 )
  15524. {// unknown
  15525. packet_len = RFIFOREST(fd);
  15526. }
  15527. else if( packet_len == -1 )
  15528. {// variable length
  15529. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15530. }
  15531. 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);
  15532. }
  15533. else
  15534. {
  15535. packet_len = RFIFOREST(fd);
  15536. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15537. }
  15538. ShowDump(RFIFOP(fd,0), packet_len);
  15539. }
  15540. /*==========================================
  15541. * Server tells client to display a window similar to Magnifier (item) one
  15542. * Server populates the window with avilable elemental converter options according to player's inventory
  15543. *------------------------------------------*/
  15544. int clif_elementalconverter_list(struct map_session_data *sd) {
  15545. int i,c,view,fd;
  15546. nullpo_ret(sd);
  15547. /// Main client packet processing function
  15548. fd=sd->fd;
  15549. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15550. WFIFOW(fd, 0)=0x1ad;
  15551. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15552. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15553. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15554. WFIFOW(fd,c*2+ 4)= view;
  15555. else
  15556. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15557. c++;
  15558. }
  15559. }
  15560. WFIFOW(fd,2) = c*2+4;
  15561. WFIFOSET(fd, WFIFOW(fd,2));
  15562. if (c > 0) {
  15563. sd->menuskill_id = SA_CREATECON;
  15564. sd->menuskill_val = c;
  15565. }
  15566. return 0;
  15567. }
  15568. /**
  15569. * Rune Knight
  15570. **/
  15571. void clif_millenniumshield(struct block_list *bl, short shields) {
  15572. #if PACKETVER >= 20081217
  15573. unsigned char buf[10];
  15574. WBUFW(buf,0) = 0x440;
  15575. WBUFL(buf,2) = bl->id;
  15576. WBUFW(buf,6) = shields;
  15577. WBUFW(buf,8) = 0;
  15578. clif_send(buf,packet_len(0x440),bl,AREA);
  15579. #endif
  15580. }
  15581. /**
  15582. * Warlock
  15583. **/
  15584. /*==========================================
  15585. * Spellbook list [LimitLine/3CeAM]
  15586. *------------------------------------------*/
  15587. int clif_spellbook_list(struct map_session_data *sd)
  15588. {
  15589. int i, c;
  15590. int fd;
  15591. nullpo_ret(sd);
  15592. fd = sd->fd;
  15593. WFIFOHEAD(fd, 8 * 8 + 8);
  15594. WFIFOW(fd,0) = 0x1ad;
  15595. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15596. {
  15597. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15598. {
  15599. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15600. c++;
  15601. }
  15602. }
  15603. if( c > 0 )
  15604. {
  15605. WFIFOW(fd,2) = c * 2 + 4;
  15606. WFIFOSET(fd, WFIFOW(fd, 2));
  15607. sd->menuskill_id = WL_READING_SB;
  15608. sd->menuskill_val = c;
  15609. }
  15610. else{
  15611. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15612. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15613. }
  15614. return 1;
  15615. }
  15616. /**
  15617. * Mechanic
  15618. **/
  15619. /*==========================================
  15620. * Magic Decoy Material List
  15621. *------------------------------------------*/
  15622. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15623. int i, c;
  15624. int fd;
  15625. nullpo_ret(sd);
  15626. fd = sd->fd;
  15627. WFIFOHEAD(fd, 8 * 8 + 8);
  15628. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15629. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15630. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15631. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15632. c ++;
  15633. }
  15634. }
  15635. if( c > 0 ) {
  15636. sd->menuskill_id = NC_MAGICDECOY;
  15637. sd->menuskill_val = skill_lv;
  15638. sd->sc.comet_x = x;
  15639. sd->sc.comet_y = y;
  15640. WFIFOW(fd,2) = c * 2 + 4;
  15641. WFIFOSET(fd, WFIFOW(fd, 2));
  15642. } else {
  15643. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15644. return 0;
  15645. }
  15646. return 1;
  15647. }
  15648. /*==========================================
  15649. * Guillotine Cross Poisons List
  15650. *------------------------------------------*/
  15651. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15652. int i, c;
  15653. int fd;
  15654. nullpo_ret(sd);
  15655. fd = sd->fd;
  15656. WFIFOHEAD(fd, 8 * 8 + 8);
  15657. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15658. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15659. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15660. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15661. c ++;
  15662. }
  15663. }
  15664. if( c > 0 ) {
  15665. sd->menuskill_id = GC_POISONINGWEAPON;
  15666. sd->menuskill_val = skill_lv;
  15667. WFIFOW(fd,2) = c * 2 + 4;
  15668. WFIFOSET(fd, WFIFOW(fd, 2));
  15669. } else {
  15670. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15671. return 0;
  15672. }
  15673. return 1;
  15674. }
  15675. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15676. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15677. int fd, i, c;
  15678. nullpo_ret(sd);
  15679. fd = sd->fd;
  15680. if( !fd )
  15681. return 0;
  15682. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15683. return 0;
  15684. WFIFOHEAD(fd, 2 * 6 + 4);
  15685. WFIFOW(fd,0) = 0x442;
  15686. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15687. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15688. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15689. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15690. {
  15691. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15692. c++;
  15693. }
  15694. if( c > 0 ) {
  15695. WFIFOW(fd,2) = 8 + c * 2;
  15696. WFIFOL(fd,4) = c;
  15697. WFIFOSET(fd,WFIFOW(fd,2));
  15698. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15699. sd->menuskill_val = c;
  15700. } else {
  15701. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15702. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15703. }
  15704. return 1;
  15705. }
  15706. /*===========================================
  15707. * Skill list for Four Elemental Analysis
  15708. * and Change Material skills.
  15709. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15710. *------------------------------------------*/
  15711. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15712. #if PACKETVER >= 20090922
  15713. int fd = sd->fd;
  15714. nullpo_ret(sd);
  15715. sd->menuskill_id = skill_id; // To prevent hacking.
  15716. sd->menuskill_val = skill_lv;
  15717. if( skill_id == GN_CHANGEMATERIAL )
  15718. skill_lv = 0; // Changematerial
  15719. WFIFOHEAD(fd, packet_len(0x7e3));
  15720. WFIFOW(fd,0) = 0x7e3;
  15721. WFIFOL(fd,2) = skill_lv;
  15722. WFIFOL(fd,4) = 0;
  15723. WFIFOSET(fd, packet_len(0x7e3));
  15724. #endif
  15725. return 1;
  15726. }
  15727. /*==========================================
  15728. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15729. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15730. * RFIFOL(fd,2) - type (currently not used)
  15731. *------------------------------------------*/
  15732. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15733. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15734. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15735. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15736. return;
  15737. if( pc_istrading(sd) ) {
  15738. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15739. clif_menuskill_clear(sd);
  15740. return;
  15741. }
  15742. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15743. clif_menuskill_clear(sd);
  15744. }
  15745. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15746. /// 08cf <id>.L <type>.W <num>.W
  15747. void clif_spiritcharm(struct map_session_data *sd) {
  15748. unsigned char buf[10];
  15749. nullpo_retv(sd);
  15750. WBUFW(buf,0) = 0x08cf;
  15751. WBUFL(buf,2) = sd->bl.id;
  15752. WBUFW(buf,6) = sd->spiritcharm_type;
  15753. WBUFW(buf,8) = sd->spiritcharm;
  15754. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15755. }
  15756. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15757. /// 0907 <index>.W
  15758. ///
  15759. /// R 0908 <index>.w <type>.b
  15760. /// type:
  15761. /// 0 = move item to personal tab
  15762. /// 1 = move item to normal tab
  15763. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15764. #if PACKETVER >= 20111122
  15765. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15766. int index = RFIFOW(fd,info->pos[0]) - 2;
  15767. int type = RFIFOB(fd, info->pos[1]);
  15768. /* can't move while dead. */
  15769. if(pc_isdead(sd)) {
  15770. return;
  15771. }
  15772. if (index < 0 || index >= MAX_INVENTORY)
  15773. return;
  15774. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15775. sd->inventory.u.items_inventory[index].favorite = 0;
  15776. else if( type == 0 )
  15777. sd->inventory.u.items_inventory[index].favorite = 1;
  15778. else
  15779. return;/* nothing to do. */
  15780. clif_favorite_item(sd, index);
  15781. #endif
  15782. }
  15783. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15784. /// 0900 <index>.W <favorite>.B
  15785. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15786. int fd = sd->fd;
  15787. WFIFOHEAD(fd,packet_len(0x908));
  15788. WFIFOW(fd,0) = 0x908;
  15789. WFIFOW(fd,2) = index+2;
  15790. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15791. WFIFOSET(fd,packet_len(0x908));
  15792. }
  15793. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15794. void clif_snap( struct block_list *bl, short x, short y ) {
  15795. unsigned char buf[10];
  15796. WBUFW(buf,0) = 0x8d2;
  15797. WBUFL(buf,2) = bl->id;
  15798. WBUFW(buf,6) = x;
  15799. WBUFW(buf,8) = y;
  15800. if( disguised(bl) )
  15801. {
  15802. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15803. WBUFL(buf,2) = -bl->id;
  15804. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15805. } else
  15806. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15807. }
  15808. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15809. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15810. #if PACKETVER >= 20120404
  15811. WFIFOHEAD(fd,packet_len(0x977));
  15812. WFIFOW(fd,0) = 0x977;
  15813. WFIFOL(fd,2) = md->bl.id;
  15814. WFIFOL(fd,6) = md->status.hp;
  15815. WFIFOL(fd,10) = md->status.max_hp;
  15816. WFIFOSET(fd,packet_len(0x977));
  15817. #endif
  15818. }
  15819. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15820. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15821. return;
  15822. }
  15823. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15824. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15825. WFIFOW(sd->fd,0) = 0x2c9;
  15826. WFIFOB(sd->fd,2) = flag;
  15827. WFIFOSET(sd->fd, packet_len(0x2c9));
  15828. }
  15829. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15830. /// 0979 <world name>.24B <char name>.24B
  15831. void clif_ackworldinfo(struct map_session_data* sd) {
  15832. int fd;
  15833. nullpo_retv(sd);
  15834. fd = sd->fd;
  15835. WFIFOHEAD(fd,packet_len(0x979));
  15836. WFIFOW(fd,0)=0x979;
  15837. //AID -> world name ?
  15838. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15839. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15840. WFIFOSET(fd,packet_len(0x979));
  15841. }
  15842. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15843. /// 0978 <AID>.L
  15844. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15845. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15846. if(sd)
  15847. clif_ackworldinfo(sd);
  15848. }
  15849. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15850. /// 0447
  15851. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15852. //if(sd)
  15853. ;
  15854. }
  15855. /// req world info (CZ_CLIENT_VERSION)
  15856. /// 044A <version>.L
  15857. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15858. //if(sd)
  15859. ;
  15860. }
  15861. /// Ranking list
  15862. /// ranking pointlist { <name>.24B <point>.L }*10
  15863. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15864. struct fame_list* list;
  15865. int i, size = MAX_FAME_LIST;
  15866. switch(rankingtype) {
  15867. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15868. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15869. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15870. // PK currently unsupported
  15871. case RANK_KILLER: list = NULL; size = 0; break;
  15872. default:
  15873. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15874. return;
  15875. }
  15876. //Packet size limits this list to 10 elements. [Skotlex]
  15877. for (i = 0; i < min(10,size); i++) {
  15878. if (list[i].id > 0) {
  15879. const char* name;
  15880. if (strcmp(list[i].name, "-") == 0 &&
  15881. (name = map_charid2nick(list[i].id)) != NULL)
  15882. {
  15883. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15884. } else {
  15885. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15886. }
  15887. } else {
  15888. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15889. }
  15890. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15891. }
  15892. for(;i < 10; i++) { //In case the MAX is less than 10.
  15893. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15894. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15895. }
  15896. }
  15897. /// Request for the blacksmith ranklist.
  15898. /// /blacksmith command sends this packet to the server.
  15899. /// 0217 (CZ_BLACKSMITH_RANK)
  15900. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15901. clif_ranklist(sd,RANK_BLACKSMITH);
  15902. }
  15903. /// Request for the alchemist ranklist.
  15904. /// /alchemist command sends this packet to the server.
  15905. /// 0218 (CZ_ALCHEMIST_RANK)
  15906. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15907. clif_ranklist(sd,RANK_ALCHEMIST);
  15908. }
  15909. /// Request for the taekwon ranklist.
  15910. /// /taekwon command sends this packet to the server.
  15911. /// 0225 (CZ_TAEKWON_RANK)
  15912. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15913. clif_ranklist(sd,RANK_TAEKWON);
  15914. }
  15915. /// Request for the killer ranklist.
  15916. /// /pk command sends this packet to the server.
  15917. /// 0237 (CZ_KILLER_RANK)
  15918. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15919. clif_ranklist(sd,RANK_KILLER);
  15920. }
  15921. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15922. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15923. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15924. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15925. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15926. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15927. enum e_rank rank;
  15928. #if PACKETVER < 20130710
  15929. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15930. short cmd;
  15931. switch( rankingType ){
  15932. case RANK_BLACKSMITH: cmd = 0x219; break;
  15933. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15934. case RANK_TAEKWON: cmd = 0x226; break;
  15935. case RANK_KILLER: cmd = 0x238; break;
  15936. default:
  15937. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15938. return;
  15939. }
  15940. // Can be safely casted here, since we validated it before
  15941. rank = (enum e_rank)rankingType;
  15942. WBUFW(buf,0) = cmd;
  15943. clif_sub_ranklist(buf,2,sd,rank);
  15944. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15945. #else
  15946. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15947. int mypoint = 0;
  15948. switch( rankingType ){
  15949. case RANK_BLACKSMITH:
  15950. case RANK_ALCHEMIST:
  15951. case RANK_TAEKWON:
  15952. case RANK_KILLER:
  15953. break;
  15954. default:
  15955. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15956. return;
  15957. }
  15958. // Can be safely casted here, since we validated it before
  15959. rank = (enum e_rank)rankingType;
  15960. WBUFW(buf,0) = 0x97d;
  15961. WBUFW(buf,2) = rank;
  15962. clif_sub_ranklist(buf,4,sd,rank);
  15963. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15964. case MAPID_BLACKSMITH:
  15965. case MAPID_ALCHEMIST:
  15966. case MAPID_TAEKWON:
  15967. mypoint = sd->status.fame;
  15968. }
  15969. WBUFL(buf,284) = mypoint; //mypoint
  15970. clif_send(buf, 288, &sd->bl, SELF);
  15971. #endif
  15972. }
  15973. /*
  15974. * 097c <type> (CZ_REQ_RANKING)
  15975. * type
  15976. * 0: /blacksmith
  15977. * 1: /alchemist
  15978. * 2: /taekwon
  15979. * 3: /pk
  15980. * */
  15981. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15982. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15983. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15984. clif_ranklist(sd,rankingtype);
  15985. }
  15986. /// Updates the fame rank points for the given ranking.
  15987. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15988. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15989. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15990. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15991. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15992. int fd=sd->fd;
  15993. #if PACKETVER < 20130710
  15994. short cmd;
  15995. switch(rankingtype){
  15996. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15997. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15998. case RANK_TAEKWON: cmd = 0x224; break;
  15999. default:
  16000. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16001. return;
  16002. }
  16003. WFIFOHEAD(fd,packet_len(cmd));
  16004. WFIFOW(fd,0) = cmd;
  16005. WFIFOL(fd,2) = point;
  16006. WFIFOL(fd,6) = sd->status.fame;
  16007. WFIFOSET(fd, packet_len(cmd));
  16008. #else
  16009. WFIFOHEAD(fd,packet_len(0x97e));
  16010. WFIFOW(fd,0) = 0x97e;
  16011. WFIFOW(fd,2) = rankingtype;
  16012. WFIFOL(fd,4) = point;
  16013. WFIFOL(fd,8) = sd->status.fame;
  16014. WFIFOSET(fd,packet_len(0x97e));
  16015. #endif
  16016. }
  16017. /**
  16018. * Transmit personal information to player. (rates)
  16019. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16020. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16021. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16022. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16023. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16024. * FIXME!
  16025. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16026. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16027. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16028. */
  16029. #ifdef VIP_ENABLE
  16030. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  16031. if (sd) {
  16032. struct s_packet_db* info;
  16033. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  16034. int cmd = 0, fd, i = 0;
  16035. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  16036. int details_bexp[PINFO_MAX];
  16037. int details_drop[PINFO_MAX];
  16038. int details_penalty[PINFO_MAX];
  16039. /**
  16040. * Set for EXP
  16041. */
  16042. //0:PCRoom
  16043. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  16044. if (details_bexp[0] == 100 || !details_bexp[0])
  16045. details_bexp[0] = 0;
  16046. else {
  16047. if (details_bexp[0] < 100) {
  16048. details_bexp[0] = 100 - details_bexp[0];
  16049. details_bexp[0] = 0 - details_bexp[0];
  16050. }
  16051. else
  16052. details_bexp[0] = details_bexp[0] - 100;
  16053. }
  16054. //1:Premium
  16055. if (pc_isvip(sd)) {
  16056. details_bexp[1] = battle_config.vip_base_exp_increase * 10;
  16057. if (details_bexp[1] < 0)
  16058. details_bexp[1] = 0 - details_bexp[1];
  16059. }
  16060. else
  16061. details_bexp[1] = 0;
  16062. //2:Server
  16063. details_bexp[2] = battle_config.base_exp_rate;
  16064. if (details_bexp[2] == 100)
  16065. details_bexp[2] = 0;
  16066. else {
  16067. if (details_bexp[2] < 100) {
  16068. details_bexp[2] = 100 - details_bexp[2];
  16069. details_bexp[2] = 0 - details_bexp[2];
  16070. }
  16071. else
  16072. details_bexp[2] = details_bexp[2] - 100;
  16073. }
  16074. //3:TPLUS
  16075. details_bexp[3] = 0;
  16076. /* End - EXP set*/
  16077. /**
  16078. * Set for Drop rate
  16079. */
  16080. //0:PCRoom
  16081. details_drop[0] = 0;
  16082. //1:Premium
  16083. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16084. if (pc_isvip(sd)) {
  16085. if (details_drop[1] < 0)
  16086. details_drop[1] = 0 - details_drop[1];
  16087. }
  16088. else
  16089. details_drop[1] = 0;
  16090. //2:Server
  16091. details_drop[2] = battle_config.item_rate_common;
  16092. if (details_drop[2] == 100)
  16093. details_drop[2] = 0;
  16094. else {
  16095. if (details_drop[2] < 100) {
  16096. details_drop[2] = 100 - details_drop[2];
  16097. details_drop[2] = 0 - details_drop[2];
  16098. }
  16099. else
  16100. details_drop[2] = details_drop[2] - 100;
  16101. }
  16102. //3:TPLUS
  16103. details_drop[3] = 0;
  16104. /* End - Drop set*/
  16105. /**
  16106. * Set for Penalty rate
  16107. */
  16108. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16109. //0:PCRoom
  16110. details_penalty[0] = 0;
  16111. //1:Premium
  16112. if (pc_isvip(sd)) {
  16113. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16114. if (details_penalty[1] == 100)
  16115. details_penalty[1] = 0;
  16116. else {
  16117. if (details_penalty[1] < 100) {
  16118. details_penalty[1] = 100 - details_penalty[1];
  16119. details_penalty[1] = 0 - details_penalty[1];
  16120. }
  16121. else
  16122. details_penalty[1] = details_penalty[1] - 100;
  16123. }
  16124. }
  16125. else
  16126. details_penalty[1] = 0;
  16127. //2:Server
  16128. details_penalty[2] = battle_config.death_penalty_base;
  16129. if (details_penalty[2] == 100)
  16130. details_penalty[2] = 0;
  16131. else {
  16132. if (details_penalty[2] < 100) {
  16133. details_penalty[2] = 100 - details_penalty[2];
  16134. details_penalty[2] = 0 - details_penalty[2];
  16135. }
  16136. else
  16137. details_penalty[2] = details_penalty[2] - 100;
  16138. }
  16139. //3:TPLUS
  16140. details_penalty[3] = 0;
  16141. /* End - Penalty set*/
  16142. cmd = packet_db_ack[cmdtype];
  16143. info = &packet_db[cmd];
  16144. len = info->len; //this is the base len without details
  16145. if(!len) return; //version as packet disable
  16146. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16147. szdetails = 7;
  16148. factor = 1;
  16149. }
  16150. else if (cmd == 0x097b) {
  16151. tot_baseexp *= factor;
  16152. tot_drop *= factor;
  16153. tot_penalty *= factor;
  16154. }
  16155. fd = sd->fd;
  16156. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16157. WFIFOW(fd,0) = cmd;
  16158. for (i = 0; i < maxinfotype; i++) {
  16159. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16160. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16161. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16162. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16163. tot_baseexp += details_bexp[i]*factor;
  16164. tot_drop += details_penalty[i]*factor;
  16165. tot_penalty += details_drop[i]*factor;
  16166. len += szdetails;
  16167. }
  16168. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16169. if (cmd == 0x08cb) { //0x08cb version
  16170. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16171. WFIFOW(fd,info->pos[2]) = tot_drop;
  16172. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16173. }
  16174. else { //2013-08-07aRagexe uses 0x097b
  16175. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16176. WFIFOL(fd,info->pos[2]) = tot_drop;
  16177. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16178. }
  16179. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16180. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16181. WFIFOSET(fd,len);
  16182. }
  16183. }
  16184. #endif
  16185. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16186. char cmd[30];
  16187. int t_aid = RFIFOL(fd,2);
  16188. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16189. is_atcommand(fd, sd, cmd, 1);
  16190. }
  16191. /**
  16192. * Marks Crimson Marker target on mini-map to the caster
  16193. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16194. * @param fd
  16195. * @param bl Crimson Marker target
  16196. **/
  16197. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16198. struct s_packet_db* info;
  16199. int cmd = 0;
  16200. int16 len;
  16201. unsigned char buf[11];
  16202. nullpo_retv(sd);
  16203. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16204. if (!cmd)
  16205. cmd = 0x09C1; //default
  16206. info = &packet_db[cmd];
  16207. if (!(len = info->len))
  16208. return;
  16209. WBUFW(buf, 0) = cmd;
  16210. WBUFL(buf, info->pos[0]) = bl->id;
  16211. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16212. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16213. clif_send(buf, len, &sd->bl, SELF);
  16214. }
  16215. /**
  16216. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16217. **/
  16218. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16219. struct s_packet_db *info = NULL;
  16220. int cmd = 0;
  16221. nullpo_retv(sd);
  16222. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16223. info = &packet_db[cmd];
  16224. if (!cmd || !info->len)
  16225. return;
  16226. WFIFOHEAD(sd->fd, info->len);
  16227. WFIFOW(sd->fd, 0) = cmd;
  16228. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16229. WFIFOSET(sd->fd, info->len);
  16230. }
  16231. /**
  16232. * [Ind/Hercules]
  16233. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16234. **/
  16235. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16236. char buf[256];
  16237. size_t len;
  16238. nullpo_retv(bl);
  16239. if(!message)
  16240. return;
  16241. len = strlen(message)+1;
  16242. if( len > sizeof(buf)-8 ) {
  16243. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16244. len = sizeof(buf)-8;
  16245. }
  16246. WBUFW(buf,0) = 0x8b3;
  16247. WBUFW(buf,2) = (uint16)(len+8);
  16248. WBUFL(buf,4) = bl->id;
  16249. safestrncpy(WBUFCP(buf,8), message, len);
  16250. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16251. }
  16252. /**
  16253. * [Ind/Hercules]
  16254. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16255. **/
  16256. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16257. unsigned char buf[10];
  16258. nullpo_retv(sd);
  16259. WBUFW(buf,0) = 0x7fc;
  16260. WBUFL(buf,2) = prev_leader_aid;
  16261. WBUFL(buf,6) = new_leader_aid;
  16262. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16263. }
  16264. /**
  16265. * Sends a clan message to a player
  16266. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16267. **/
  16268. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16269. #if PACKETVER >= 20131223
  16270. struct map_session_data *sd;
  16271. uint8 buf[256];
  16272. if( len == 0 ){
  16273. return;
  16274. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16275. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16276. len = sizeof(buf)-5-NAME_LENGTH;
  16277. }
  16278. WBUFW(buf, 0) = 0x98e;
  16279. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16280. // 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
  16281. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16282. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16283. if((sd = clan_getavailablesd(clan)) != NULL)
  16284. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16285. #endif
  16286. }
  16287. /**
  16288. * Parses a clan message from a player.
  16289. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16290. **/
  16291. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16292. #if PACKETVER >= 20131223
  16293. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16294. // validate packet and retrieve name and message
  16295. if( !clif_process_message(sd, false, name, message, output ) )
  16296. return;
  16297. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16298. #endif
  16299. }
  16300. /**
  16301. * Sends the basic clan informations to the client.
  16302. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16303. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16304. **/
  16305. void clif_clan_basicinfo( struct map_session_data *sd ){
  16306. #if PACKETVER >= 20131223
  16307. int fd, offset, length, i, flag;
  16308. struct clan* clan;
  16309. char mapname[MAP_NAME_LENGTH_EXT];
  16310. nullpo_retv( sd );
  16311. nullpo_retv( clan = sd->clan );
  16312. // Check if the player has a valid session and is not autotrading
  16313. if( !clif_session_isValid( sd ) ){
  16314. return;
  16315. }
  16316. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16317. fd = sd->fd;
  16318. WFIFOHEAD(fd,length);
  16319. memset( WFIFOP(fd, 0), 0, length );
  16320. WFIFOW( fd, 0 ) = 0x98a;
  16321. WFIFOL( fd, 4 ) = clan->id;
  16322. offset = 8;
  16323. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16324. offset += NAME_LENGTH;
  16325. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16326. offset += NAME_LENGTH;
  16327. mapindex_getmapname_ext( clan->map, mapname );
  16328. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16329. offset += MAP_NAME_LENGTH_EXT;
  16330. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16331. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16332. for( flag = 0; flag < 2; flag++ ){
  16333. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16334. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16335. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16336. offset += NAME_LENGTH;
  16337. }
  16338. }
  16339. }
  16340. WFIFOW( fd, 2 ) = offset;
  16341. WFIFOSET(fd,offset);
  16342. #endif
  16343. }
  16344. /**
  16345. * Updates the online and maximum player count of a clan.
  16346. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16347. **/
  16348. void clif_clan_onlinecount( struct clan* clan ){
  16349. #if PACKETVER >= 20131223
  16350. uint8 buf[6];
  16351. struct map_session_data *sd;
  16352. WBUFW(buf,0) = 0x988;
  16353. WBUFW(buf,2) = clan->connect_member;
  16354. WBUFW(buf,4) = clan->max_member;
  16355. if((sd = clan_getavailablesd(clan)) != NULL)
  16356. clif_send(buf, 6, &sd->bl, CLAN);
  16357. #endif
  16358. }
  16359. /**
  16360. * Notifies the client that the player has left his clan.
  16361. * 0989 (ZC_ACK_CLAN_LEAVE)
  16362. **/
  16363. void clif_clan_leave( struct map_session_data* sd ){
  16364. #if PACKETVER >= 20131223
  16365. int fd;
  16366. nullpo_retv( sd );
  16367. if( !clif_session_isValid( sd ) ){
  16368. return;
  16369. }
  16370. fd = sd->fd;
  16371. WFIFOHEAD(fd,2);
  16372. WFIFOW(fd,0) = 0x989;
  16373. WFIFOSET(fd,2);
  16374. #endif
  16375. }
  16376. /**
  16377. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16378. * 0A2F <result>.B <title_id>.L
  16379. */
  16380. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16381. {
  16382. #if PACKETVER >= 20150513
  16383. int fd;
  16384. nullpo_retv(sd);
  16385. if (!clif_session_isValid(sd))
  16386. return;
  16387. fd = sd->fd;
  16388. WFIFOHEAD(fd, packet_len(0xa2f));
  16389. WFIFOW(fd, 0) = 0xa2f;
  16390. WFIFOB(fd, 2) = result;
  16391. WFIFOL(fd, 3) = title_id;
  16392. WFIFOSET(fd, packet_len(0xa2f));
  16393. #endif
  16394. }
  16395. /**
  16396. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16397. * 0A2E <title_id>.L
  16398. */
  16399. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16400. {
  16401. int title_id;
  16402. nullpo_retv(sd);
  16403. title_id = RFIFOL(fd, 2);
  16404. if( title_id == sd->status.title_id ){
  16405. // It is exactly the same as the old one
  16406. return;
  16407. }else if( title_id <= 0 ){
  16408. sd->status.title_id = 0;
  16409. }else{
  16410. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16411. clif_change_title_ack(sd, 1, title_id);
  16412. return;
  16413. }
  16414. sd->status.title_id = title_id;
  16415. }
  16416. clif_name_area(&sd->bl);
  16417. clif_change_title_ack(sd, 0, title_id);
  16418. }
  16419. #ifdef DUMP_UNKNOWN_PACKET
  16420. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16421. {
  16422. const char* packet_txt = "save/packet.txt";
  16423. FILE* fp;
  16424. time_t time_server;
  16425. struct tm *datetime;
  16426. char datestr[512];
  16427. time(&time_server); // get time in seconds since 1/1/1970
  16428. datetime = localtime(&time_server); // convert seconds in structure
  16429. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16430. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16431. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16432. if( sd ) {
  16433. 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);
  16434. } else {
  16435. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16436. }
  16437. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16438. fprintf(fp, "\n");
  16439. fclose(fp);
  16440. } else {
  16441. ShowError("Failed to write '%s'.\n", packet_txt);
  16442. // Dump on console instead
  16443. if( sd ) {
  16444. 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);
  16445. } else {
  16446. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16447. }
  16448. ShowDump(RFIFOP(fd,0), packet_len);
  16449. }
  16450. }
  16451. #endif
  16452. /// Roulette System
  16453. /// Author: Yommy
  16454. /// Opens the roulette window
  16455. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16456. void clif_roulette_open( struct map_session_data* sd ){
  16457. nullpo_retv(sd);
  16458. int fd = sd->fd;
  16459. WFIFOHEAD(fd,packet_len(0xa1a));
  16460. WFIFOW(fd,0) = 0xa1a;
  16461. WFIFOB(fd,2) = 0; // result
  16462. WFIFOL(fd,3) = 0; // serial
  16463. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16464. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16465. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16466. WFIFOL(fd,11) = sd->roulette_point.gold;
  16467. WFIFOL(fd,15) = sd->roulette_point.silver;
  16468. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16469. WFIFOSET(fd,packet_len(0xa1a));
  16470. }
  16471. /// Request to open the roulette window
  16472. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16473. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16474. nullpo_retv(sd);
  16475. if (!battle_config.feature_roulette) {
  16476. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16477. return;
  16478. }
  16479. clif_roulette_open(sd);
  16480. }
  16481. /// Sends the info about the available roulette rewards to the client
  16482. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16483. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16484. void clif_roulette_info( struct map_session_data* sd ){
  16485. nullpo_retv(sd);
  16486. int fd = sd->fd;
  16487. int len = 8; // Initialize to header size
  16488. #if PACKETVER < 20180516
  16489. int size = 8;
  16490. #else
  16491. int size = 12;
  16492. #endif
  16493. for( int i = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16494. len += (MAX_ROULETTE_COLUMNS - i) * size;
  16495. }
  16496. WFIFOHEAD(fd,len);
  16497. WFIFOW(fd,0) = 0xa1c;
  16498. WFIFOW(fd,2) = len;
  16499. WFIFOL(fd,4) = 1; // serial
  16500. for(int i = 0, offset = 8; i < MAX_ROULETTE_LEVEL; i++) {
  16501. for(int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16502. WFIFOW(fd,offset + 0) = i;
  16503. WFIFOW(fd,offset + 2) = j;
  16504. #if PACKETVER < 20180516
  16505. WFIFOW(fd,offset + 4) = rd.nameid[i][j];
  16506. WFIFOW(fd,offset + 6) = rd.qty[i][j];
  16507. #else
  16508. WFIFOL(fd,offset + 4) = rd.nameid[i][j];
  16509. WFIFOL(fd,offset + 8) = rd.qty[i][j];
  16510. #endif
  16511. offset += size;
  16512. }
  16513. }
  16514. WFIFOSET(fd,len);
  16515. }
  16516. /// Request the roulette reward data
  16517. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16518. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16519. nullpo_retv(sd);
  16520. if (!battle_config.feature_roulette) {
  16521. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16522. return;
  16523. }
  16524. clif_roulette_info(sd);
  16525. }
  16526. /// Notification of the client that the roulette window was closed
  16527. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16528. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16529. nullpo_retv(sd);
  16530. if (!battle_config.feature_roulette) {
  16531. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16532. return;
  16533. }
  16534. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16535. }
  16536. /// Response to a item reward request
  16537. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16538. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16539. #if PACKETVER >= 20141016
  16540. nullpo_retv(sd);
  16541. int fd = sd->fd;
  16542. WFIFOHEAD(fd,packet_len(0xa22));
  16543. WFIFOW(fd,0) = 0xa22;
  16544. WFIFOB(fd,2) = type;
  16545. WFIFOW(fd,3) = 0; //! TODO: Additional item
  16546. WFIFOSET(fd,packet_len(0xa22));
  16547. #endif
  16548. }
  16549. /**
  16550. * Claim roulette reward
  16551. * @param sd Player
  16552. * @return 0:Success
  16553. **/
  16554. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16555. struct item it;
  16556. uint8 res = 1;
  16557. nullpo_retr(1, sd);
  16558. if (sd->roulette.prizeIdx < 0)
  16559. return RECV_ITEM_FAILED;
  16560. memset(&it, 0, sizeof(it));
  16561. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16562. it.identify = 1;
  16563. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16564. ; // onSuccess
  16565. }
  16566. sd->roulette.claimPrize = false;
  16567. sd->roulette.prizeStage = 0;
  16568. sd->roulette.prizeIdx = -1;
  16569. sd->roulette.stage = 0;
  16570. return res;
  16571. }
  16572. /// Update Roulette window with current stats
  16573. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16574. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16575. nullpo_retv(sd);
  16576. int fd = sd->fd;
  16577. WFIFOHEAD(fd,packet_len(0xa20));
  16578. WFIFOW(fd,0) = 0xa20;
  16579. WFIFOB(fd,2) = result;
  16580. WFIFOW(fd,3) = stage;
  16581. WFIFOW(fd,5) = prizeIdx;
  16582. WFIFOW(fd,7) = bonusItemID;
  16583. WFIFOL(fd,9) = sd->roulette_point.gold;
  16584. WFIFOL(fd,13) = sd->roulette_point.silver;
  16585. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16586. WFIFOSET(fd,packet_len(0xa20));
  16587. }
  16588. /// Request to start the roulette
  16589. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16590. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16591. enum GENERATE_ROULETTE_ACK result;
  16592. nullpo_retv(sd);
  16593. if (!battle_config.feature_roulette) {
  16594. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16595. return;
  16596. }
  16597. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16598. return;
  16599. }
  16600. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16601. sd->roulette.stage = 0;
  16602. sd->roulette.claimPrize = false;
  16603. sd->roulette.prizeStage = 0;
  16604. sd->roulette.prizeIdx = -1;
  16605. }
  16606. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16607. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16608. }else{
  16609. if (!sd->roulette.stage) {
  16610. if (sd->roulette_point.bronze > 0) {
  16611. sd->roulette_point.bronze -= 1;
  16612. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16613. } else if (sd->roulette_point.silver > 9) {
  16614. sd->roulette_point.silver -= 10;
  16615. sd->roulette.stage = 2;
  16616. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16617. } else if (sd->roulette_point.gold > 9) {
  16618. sd->roulette_point.gold -= 10;
  16619. sd->roulette.stage = 4;
  16620. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16621. }
  16622. }
  16623. sd->roulette.prizeStage = sd->roulette.stage;
  16624. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16625. sd->roulette.claimPrize = true;
  16626. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16627. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16628. result = GENERATE_ROULETTE_LOSING;
  16629. sd->roulette.stage = 0;
  16630. }else{
  16631. result = GENERATE_ROULETTE_SUCCESS;
  16632. sd->roulette.stage++;
  16633. }
  16634. }
  16635. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16636. }
  16637. /// Request to claim a prize
  16638. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16639. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16640. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16641. nullpo_retv(sd);
  16642. if (!battle_config.feature_roulette) {
  16643. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16644. return;
  16645. }
  16646. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16647. return;
  16648. }
  16649. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16650. switch (clif_roulette_getitem(sd)) {
  16651. case ADDITEM_SUCCESS:
  16652. type = RECV_ITEM_SUCCESS;
  16653. break;
  16654. case ADDITEM_INVALID:
  16655. case ADDITEM_OVERITEM:
  16656. case ADDITEM_OVERAMOUNT:
  16657. type = RECV_ITEM_OVERCOUNT;
  16658. break;
  16659. case ADDITEM_OVERWEIGHT:
  16660. type = RECV_ITEM_OVERWEIGHT;
  16661. break;
  16662. case ADDITEM_STACKLIMIT:
  16663. default:
  16664. type = RECV_ITEM_FAILED;
  16665. break;
  16666. }
  16667. }
  16668. clif_roulette_recvitem_ack(sd,type);
  16669. }
  16670. /// MERGE ITEM
  16671. /**
  16672. * Acknowledge the client about item merger result
  16673. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16674. * @param fd
  16675. * @param sd
  16676. **/
  16677. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16678. unsigned char buf[9];
  16679. struct s_packet_db *info = NULL;
  16680. short cmd = 0;
  16681. nullpo_retv(sd);
  16682. if (!clif_session_isValid(sd))
  16683. return;
  16684. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16685. return;
  16686. if (!(info = &packet_db[cmd]) || info->len == 0)
  16687. return;
  16688. WBUFW(buf, 0) = cmd;
  16689. WBUFW(buf, info->pos[0]) = index;
  16690. WBUFW(buf, info->pos[1]) = count;
  16691. WBUFB(buf, info->pos[2]) = type;
  16692. clif_send(buf, info->len, &sd->bl, SELF);
  16693. }
  16694. /**
  16695. * Check if item has the pair to be merged
  16696. * @param sd
  16697. * @param it Item
  16698. * @return True if has pair, False if not
  16699. **/
  16700. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16701. struct item *it_;
  16702. unsigned short i;
  16703. nullpo_retr(false, sd);
  16704. 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);
  16705. if (i < MAX_INVENTORY)
  16706. return true;
  16707. return false;
  16708. }
  16709. /**
  16710. * Check if item can be merged
  16711. * @param id Item Data
  16712. * @param it Item
  16713. * @return True if can be merged, False if not
  16714. **/
  16715. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16716. if (!id || !it)
  16717. return false;
  16718. if (id->type == IT_CASH)
  16719. return false;
  16720. if (!itemdb_isstackable2(id))
  16721. return false;
  16722. if (itemdb_isspecial(it->card[0]))
  16723. return false;
  16724. if (!it->unique_id)
  16725. return false;
  16726. return true;
  16727. }
  16728. /**
  16729. * Open available item to be merged.
  16730. * Only show 1 item in 1 process.
  16731. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16732. * @param sd
  16733. **/
  16734. void clif_merge_item_open(struct map_session_data *sd) {
  16735. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16736. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16737. int len = 0;
  16738. struct s_packet_db *info = NULL;
  16739. struct item *it;
  16740. nullpo_retv(sd);
  16741. if (!clif_session_isValid(sd))
  16742. return;
  16743. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16744. return;
  16745. if (!(info = &packet_db[cmd]) || info->len == 0)
  16746. return;
  16747. // Get entries
  16748. for (i = 0; i < MAX_INVENTORY; i++) {
  16749. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16750. continue;
  16751. if (clif_merge_item_has_pair(sd, it))
  16752. indexes[n++] = i;
  16753. }
  16754. if (n < 2) { // No item need to be merged
  16755. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16756. return;
  16757. }
  16758. WBUFW(buf, 0) = cmd;
  16759. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16760. for (i = 0; i < n; i++) {
  16761. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16762. }
  16763. clif_send(buf, len, &sd->bl, SELF);
  16764. }
  16765. /**
  16766. * Process item merger
  16767. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16768. * @param fd
  16769. * @param sd
  16770. **/
  16771. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16772. struct s_packet_db *info = NULL;
  16773. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16774. unsigned int count = 0;
  16775. struct item_data *id = NULL;
  16776. nullpo_retv(sd);
  16777. if (!clif_session_isValid(sd))
  16778. return;
  16779. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16780. return;
  16781. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16782. if (n < 2) { // No item need to be merged
  16783. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16784. return;
  16785. }
  16786. for (i = 0, j = 0; i < n; i++) {
  16787. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16788. if( idx < 0 || idx >= MAX_INVENTORY ){
  16789. return;
  16790. }
  16791. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16792. continue;
  16793. indexes[j] = idx;
  16794. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16795. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16796. return;
  16797. }
  16798. count += sd->inventory.u.items_inventory[idx].amount;
  16799. j++;
  16800. }
  16801. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16802. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16803. return;
  16804. }
  16805. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16806. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16807. return;
  16808. }
  16809. // Merrrrge!!!!
  16810. for (i = 1; i < n; i++) {
  16811. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16812. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16813. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16814. sd->inventory_data[idx] = NULL;
  16815. clif_delitem(sd, idx, amt, 0);
  16816. }
  16817. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16818. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16819. }
  16820. /**
  16821. * Cancel item merge
  16822. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16823. * @param fd
  16824. * @param sd
  16825. **/
  16826. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16827. return; // Nothing todo yet
  16828. }
  16829. /**
  16830. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16831. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16832. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16833. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16834. **/
  16835. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type) {
  16836. unsigned char buf[9 + NAME_LENGTH * 2];
  16837. unsigned short cmd = 0;
  16838. struct s_packet_db *info = NULL;
  16839. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16840. return;
  16841. if (!(info = &packet_db[cmd]) || info->len == 0)
  16842. return;
  16843. WBUFW(buf, 0) = 0x7fd;
  16844. WBUFB(buf, 4) = type;
  16845. WBUFW(buf, 5) = nameid;
  16846. WBUFB(buf, 7) = NAME_LENGTH;
  16847. if (battle_config.broadcast_hide_name) {
  16848. std::string dispname = std::string(char_name);
  16849. int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
  16850. dispname.replace(dispname.length() - hide, hide, hide, '*');
  16851. safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
  16852. }
  16853. else
  16854. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16855. switch (type) {
  16856. case ITEMOBTAIN_TYPE_BOXITEM:
  16857. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16858. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16859. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16860. break;
  16861. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16862. {
  16863. struct mob_db *db = mob_db(container);
  16864. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16865. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16866. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16867. }
  16868. break;
  16869. case ITEMOBTAIN_TYPE_NPC:
  16870. default:
  16871. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16872. break;
  16873. }
  16874. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16875. }
  16876. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16877. /// 0A02 <view>.W
  16878. /// Value <flag> has the following effects:
  16879. /// 1: Open a Dress Room window.
  16880. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16881. #if PACKETVER >= 20150513
  16882. int fd = sd->fd;
  16883. nullpo_retv(sd);
  16884. WFIFOHEAD(fd, packet_len(0xa02));
  16885. WFIFOW(fd,0) = 0xa02;
  16886. WFIFOW(fd,2) = flag;
  16887. WFIFOSET(fd, packet_len(0xa02));
  16888. #endif
  16889. }
  16890. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16891. /// 0A35 <result>.W
  16892. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16893. #if PACKETVER >= 20150513
  16894. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16895. // Ignore the request
  16896. // - Invalid item index
  16897. // - Invalid item ID or item doesn't exist
  16898. // - Item is already identified
  16899. if (idx < 0 || idx >= MAX_INVENTORY ||
  16900. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16901. sd->inventory.u.items_inventory[idx].identify)
  16902. return;
  16903. // Ignore the request - No magnifiers in inventory
  16904. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16905. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16906. return;
  16907. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16908. return;
  16909. skill_identify(sd, idx);
  16910. #endif
  16911. }
  16912. /// Starts navigation to the given target on client side
  16913. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16914. #if PACKETVER >= 20111010
  16915. int fd = sd->fd;
  16916. WFIFOHEAD(fd,27);
  16917. WFIFOW(fd,0) = 0x08e2;
  16918. // How detailed will our navigation be?
  16919. if( mob_id > 0 ){
  16920. x = 0;
  16921. y = 0;
  16922. WFIFOB(fd,2) = 3; // monster with destination field
  16923. }else if( x > 0 && y > 0 ){
  16924. WFIFOB(fd,2) = 0; // with coordinates
  16925. }else{
  16926. x = 0;
  16927. y = 0;
  16928. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16929. }
  16930. // Which services can be used for transportation?
  16931. WFIFOB(fd,3) = flag;
  16932. // If this flag is set, the navigation window will not be opened up
  16933. WFIFOB(fd,4) = hideWindow;
  16934. // Target map
  16935. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16936. // Target x
  16937. WFIFOW(fd,21) = x;
  16938. // Target y
  16939. WFIFOW(fd,23) = y;
  16940. // Target monster ID
  16941. WFIFOW(fd,25) = mob_id;
  16942. WFIFOSET(fd,27);
  16943. #endif
  16944. }
  16945. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16946. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16947. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16948. #if PACKETVER >= 20150513
  16949. unsigned char* buf;
  16950. int len,i;
  16951. struct map_session_data *tsd;
  16952. struct block_list* tbl;
  16953. if( target == SELF ){
  16954. tsd = BL_CAST(BL_PC,bl);
  16955. tbl = &sd->bl;
  16956. }else{
  16957. tsd = sd;
  16958. tbl = bl;
  16959. }
  16960. if( !tsd->hatEffectCount )
  16961. return;
  16962. len = 9 + tsd->hatEffectCount * 2;
  16963. buf = (unsigned char*)aMalloc( len );
  16964. WBUFW(buf,0) = 0xa3b;
  16965. WBUFW(buf,2) = len;
  16966. WBUFL(buf,4) = tsd->bl.id;
  16967. WBUFB(buf,8) = 1;
  16968. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16969. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16970. }
  16971. clif_send(buf, len,tbl,target);
  16972. aFree(buf);
  16973. #endif
  16974. }
  16975. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16976. #if PACKETVER >= 20150513
  16977. unsigned char buf[13];
  16978. WBUFW(buf,0) = 0xa3b;
  16979. WBUFW(buf,2) = 13;
  16980. WBUFL(buf,4) = sd->bl.id;
  16981. WBUFB(buf,8) = enable;
  16982. WBUFL(buf,9) = effectId;
  16983. clif_send(buf,13,&sd->bl,AREA);
  16984. #endif
  16985. }
  16986. /// Notify the client that a sale has started
  16987. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16988. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16989. #if PACKETVER_SUPPORTS_SALES
  16990. unsigned char buf[8];
  16991. WBUFW(buf, 0) = 0x9b2;
  16992. WBUFW(buf, 2) = sale_item->nameid;
  16993. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16994. clif_send(buf, 8, bl, target);
  16995. #endif
  16996. }
  16997. /// Notify the clien that a sale has ended
  16998. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16999. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17000. #if PACKETVER_SUPPORTS_SALES
  17001. unsigned char buf[4];
  17002. WBUFW(buf, 0) = 0x9b3;
  17003. WBUFW(buf, 2) = sale_item->nameid;
  17004. clif_send(buf, 4, bl, target);
  17005. #endif
  17006. }
  17007. /// Update the remaining amount of a sale item.
  17008. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17009. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17010. #if PACKETVER_SUPPORTS_SALES
  17011. unsigned char buf[8];
  17012. WBUFW(buf, 0) = 0x9c4;
  17013. WBUFW(buf, 2) = sale_item->nameid;
  17014. WBUFL(buf, 4) = sale_item->amount;
  17015. clif_send(buf, 8, bl, target);
  17016. #endif
  17017. }
  17018. /// The client requested a refresh of the current remaining count of a sale item
  17019. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17020. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  17021. #if PACKETVER_SUPPORTS_SALES
  17022. struct sale_item_data* sale;
  17023. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17024. return;
  17025. }
  17026. sale = sale_find_item( RFIFOW(fd, 6), true );
  17027. if( sale == NULL ){
  17028. return;
  17029. }
  17030. clif_sale_amount(sale, &sd->bl, SELF);
  17031. #endif
  17032. }
  17033. /// Opens the sale administration window on the client
  17034. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17035. void clif_sale_open( struct map_session_data* sd ){
  17036. #if PACKETVER_SUPPORTS_SALES
  17037. nullpo_retv(sd);
  17038. if( sd->state.sale_open ){
  17039. return;
  17040. }
  17041. sd->state.sale_open = true;
  17042. int fd = sd->fd;
  17043. WFIFOHEAD(fd, 2);
  17044. WFIFOW(fd, 0) = 0x9b5;
  17045. WFIFOSET(fd, 2);
  17046. #endif
  17047. }
  17048. /// Client request to open the sale administration window.
  17049. /// This is sent by /limitedsale
  17050. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17051. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  17052. #if PACKETVER_SUPPORTS_SALES
  17053. nullpo_retv(sd);
  17054. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17055. return;
  17056. }
  17057. char command[CHAT_SIZE_MAX];
  17058. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17059. is_atcommand(fd, sd, command, 1);
  17060. #endif
  17061. }
  17062. /// Closes the sale administration window on the client.
  17063. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17064. void clif_sale_close(struct map_session_data* sd) {
  17065. #if PACKETVER_SUPPORTS_SALES
  17066. nullpo_retv(sd);
  17067. if( !sd->state.sale_open ){
  17068. return;
  17069. }
  17070. sd->state.sale_open = false;
  17071. int fd = sd->fd;
  17072. WFIFOHEAD(fd, 2);
  17073. WFIFOW(fd, 0) = 0x9bd;
  17074. WFIFOSET(fd, 2);
  17075. #endif
  17076. }
  17077. /// Client request to close the sale administration window.
  17078. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17079. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  17080. #if PACKETVER_SUPPORTS_SALES
  17081. nullpo_retv(sd);
  17082. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17083. return;
  17084. }
  17085. clif_sale_close(sd);
  17086. #endif
  17087. }
  17088. /// Reply to a item search request for item sale administration.
  17089. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17090. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17091. #if PACKETVER_SUPPORTS_SALES
  17092. int fd = sd->fd;
  17093. WFIFOHEAD(fd, 10);
  17094. WFIFOW(fd, 0) = 0x9ad;
  17095. if( item != NULL ){
  17096. WFIFOW(fd, 2) = 0;
  17097. WFIFOW(fd, 4) = item->nameid;
  17098. WFIFOL(fd, 6) = item->price;
  17099. }else{
  17100. WFIFOW(fd, 2) = 1;
  17101. WFIFOW(fd, 4) = 0;
  17102. WFIFOL(fd, 6) = 0;
  17103. }
  17104. WFIFOSET(fd, 10);
  17105. #endif
  17106. }
  17107. /// Search request for an item sale administration.
  17108. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17109. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17110. #if PACKETVER_SUPPORTS_SALES
  17111. char item_name[ITEM_NAME_LENGTH];
  17112. struct item_data *id = NULL;
  17113. nullpo_retv(sd);
  17114. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17115. return;
  17116. }
  17117. if( !sd->state.sale_open ){
  17118. return;
  17119. }
  17120. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17121. id = itemdb_searchname(item_name);
  17122. if( id ){
  17123. int i;
  17124. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17125. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17126. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17127. return;
  17128. }
  17129. }
  17130. }
  17131. // not found
  17132. clif_sale_search_reply( sd, NULL );
  17133. #endif
  17134. }
  17135. /// Reply if an item was successfully put on sale or not.
  17136. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17137. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17138. #if PACKETVER_SUPPORTS_SALES
  17139. int fd = sd->fd;
  17140. WFIFOHEAD(fd, 4);
  17141. WFIFOW(fd, 0) = 0x9af;
  17142. WFIFOW(fd, 2) = (uint16)result;
  17143. WFIFOSET(fd, 4);
  17144. #endif
  17145. }
  17146. /// A client request to put an item on sale.
  17147. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17148. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  17149. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17150. #if PACKETVER_SUPPORTS_SALES
  17151. int32 count;
  17152. int16 nameid;
  17153. int startTime;
  17154. int endTime;
  17155. uint16 sellingHours;
  17156. nullpo_retv(sd);
  17157. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17158. return;
  17159. }
  17160. if( !sd->state.sale_open ){
  17161. return;
  17162. }
  17163. nameid = RFIFOW(fd, 6);
  17164. count = RFIFOL(fd, 8);
  17165. startTime = RFIFOL(fd, 12);
  17166. #if PACKETVER >= 20150520
  17167. if( RFIFOW(fd,0) == 0xa3d )
  17168. sellingHours = RFIFOW(fd, 16);
  17169. else
  17170. #endif
  17171. sellingHours = RFIFOB(fd, 16);
  17172. endTime = startTime + sellingHours * 60 * 60;
  17173. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  17174. #endif
  17175. }
  17176. /// Reply to an item removal from sale.
  17177. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17178. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17179. #if PACKETVER_SUPPORTS_SALES
  17180. int fd = sd->fd;
  17181. WFIFOHEAD(fd, 4);
  17182. WFIFOW(fd, 0) = 0x9b1;
  17183. WFIFOW(fd, 2) = failed;
  17184. WFIFOSET(fd, 4);
  17185. #endif
  17186. }
  17187. /// Request to remove an item from sale.
  17188. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17189. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17190. #if PACKETVER_SUPPORTS_SALES
  17191. nullpo_retv(sd);
  17192. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17193. return;
  17194. }
  17195. if( !sd->state.sale_open ){
  17196. return;
  17197. }
  17198. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  17199. #endif
  17200. }
  17201. /// Achievement System
  17202. /// Author: Luxuri, Aleos
  17203. /**
  17204. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17205. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17206. */
  17207. void clif_achievement_list_all(struct map_session_data *sd)
  17208. {
  17209. nullpo_retv(sd);
  17210. if (!battle_config.feature_achievement) {
  17211. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17212. return;
  17213. }
  17214. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17215. if (count == 0)
  17216. return;
  17217. int len = (50 * count) + 22;
  17218. int fd = sd->fd;
  17219. int *info = achievement_level(sd, true);
  17220. WFIFOHEAD(fd,len);
  17221. WFIFOW(fd, 0) = 0xa23;
  17222. WFIFOW(fd, 2) = len;
  17223. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17224. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17225. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17226. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17227. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17228. for (int i = 0; i < count; i++) {
  17229. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17230. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17231. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17232. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17233. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17234. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17235. }
  17236. WFIFOSET(fd, len);
  17237. }
  17238. /**
  17239. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17240. * 0a24 <packetType>.W <ACHPoint>.L
  17241. */
  17242. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17243. {
  17244. nullpo_retv(sd);
  17245. if (!battle_config.feature_achievement) {
  17246. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17247. return;
  17248. }
  17249. int fd = sd->fd;
  17250. int *info = achievement_level(sd, true);
  17251. WFIFOHEAD(fd, packet_len(0xa24));
  17252. WFIFOW(fd, 0) = 0xa24;
  17253. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17254. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17255. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17256. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17257. if (ach) {
  17258. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17259. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17260. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17261. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17262. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17263. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17264. } else
  17265. memset(WFIFOP(fd, 16), 0, 40);
  17266. WFIFOSET(fd, packet_len(0xa24));
  17267. }
  17268. /**
  17269. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17270. * 0a25 <packetType>.W <achievementID>.L
  17271. */
  17272. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17273. {
  17274. nullpo_retv(sd);
  17275. if( sd->achievement_data.save )
  17276. intif_achievement_save(sd);
  17277. achievement_check_reward(sd, RFIFOL(fd,2));
  17278. }
  17279. /**
  17280. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17281. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17282. */
  17283. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17284. {
  17285. WFIFOHEAD(fd, packet_len(0xa26));
  17286. WFIFOW(fd, 0) = 0xa26;
  17287. WFIFOB(fd, 2) = result;
  17288. WFIFOL(fd, 3) = achievement_id;
  17289. WFIFOSET(fd, packet_len(0xa26));
  17290. }
  17291. /// Process the pet evolution request
  17292. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17293. void clif_parse_pet_evolution( int fd, struct map_session_data *sd ){
  17294. #if PACKETVER >= 20141008
  17295. auto pet = pet_db_search(RFIFOW(fd, 4), PET_EGG);
  17296. if (!pet) {
  17297. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17298. return;
  17299. }
  17300. pet_evolution(sd, pet->class_);
  17301. #endif
  17302. }
  17303. /// Sends the result of the evolution to the client.
  17304. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17305. void clif_pet_evolution_result( struct map_session_data* sd, e_pet_evolution_result result ){
  17306. #if PACKETVER >= 20141008
  17307. int fd = sd->fd;
  17308. WFIFOHEAD(fd, packet_len(0x9fc));
  17309. WFIFOW(fd, 0) = 0x9fc;
  17310. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17311. WFIFOSET(fd, packet_len(0x9fc));
  17312. #endif
  17313. }
  17314. /*
  17315. * This packet is sent by /changedress or /nocosplay
  17316. *
  17317. * 0ae8
  17318. */
  17319. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17320. #if PACKETVER >= 20180103
  17321. char command[CHAT_SIZE_MAX];
  17322. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17323. is_atcommand( fd, sd, command, 1 );
  17324. #endif
  17325. }
  17326. /// Opens an UI window of the given type and initializes it with the given data
  17327. /// 0AE2 <type>.B <data>.L
  17328. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17329. nullpo_retv(sd);
  17330. int fd = sd->fd;
  17331. WFIFOHEAD(fd,packet_len(0xae2));
  17332. WFIFOW(fd,0) = 0xae2;
  17333. WFIFOB(fd,2) = ui_type;
  17334. WFIFOL(fd,3) = data;
  17335. WFIFOSET(fd,packet_len(0xae2));
  17336. }
  17337. /// Request to open an UI window of the given type
  17338. /// 0A68 <type>.B
  17339. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17340. switch( RFIFOB(fd,2) ){
  17341. case IN_UI_ATTENDANCE:
  17342. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17343. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17344. }else if( pc_attendance_enabled() ){
  17345. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17346. }else{
  17347. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17348. }
  17349. break;
  17350. }
  17351. }
  17352. /// Response for attedance request
  17353. /// 0AF0 <unknown>.L <data>.L
  17354. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17355. nullpo_retv(sd);
  17356. int fd = sd->fd;
  17357. WFIFOHEAD(fd,packet_len(0xAF0));
  17358. WFIFOW(fd,0) = 0xAF0;
  17359. WFIFOL(fd,2) = 0;
  17360. WFIFOL(fd,6) = data;
  17361. WFIFOSET(fd,packet_len(0xAF0));
  17362. }
  17363. /// Request from the client to retrieve today's attendance reward
  17364. /// 0AEF
  17365. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17366. pc_attendance_claim_reward(sd);
  17367. }
  17368. /// Send out the percentage of weight that causes it to be displayed in red.
  17369. /// 0ADE <percentage>.L
  17370. void clif_weight_limit( struct map_session_data* sd ){
  17371. #if PACKETVER >= 20171025
  17372. nullpo_retv(sd);
  17373. int fd = sd->fd;
  17374. WFIFOHEAD(fd, packet_len(0xADE));
  17375. WFIFOW(fd, 0) = 0xADE;
  17376. #ifdef RENEWAL
  17377. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17378. #else
  17379. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17380. #endif
  17381. WFIFOSET(fd, packet_len(0xADE));
  17382. #endif
  17383. }
  17384. enum e_private_airship_response : uint32{
  17385. PRIVATEAIRSHIP_OK,
  17386. PRIVATEAIRSHIP_RETRY,
  17387. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17388. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17389. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17390. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17391. };
  17392. /// Send out the response to a private airship request
  17393. /// 0A4A <response>.L
  17394. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17395. #if PACKETVER >= 20180321
  17396. nullpo_retv( sd );
  17397. int fd = sd->fd;
  17398. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17399. WFIFOW( fd, 0 ) = 0xA4A;
  17400. WFIFOL( fd, 2 ) = response;
  17401. WFIFOSET( fd, packet_len( 0xA4A ) );
  17402. #endif
  17403. }
  17404. /// Parses a request for a private airship
  17405. /// 0A49 <mapname>.16B <itemid>.W
  17406. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17407. #if PACKETVER >= 20180321
  17408. // Check if the feature is enabled
  17409. if( !battle_config.feature_privateairship ){
  17410. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17411. return;
  17412. }
  17413. // Check if the player is allowed to warp from the source map
  17414. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17415. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17416. return;
  17417. }
  17418. char mapname[MAP_NAME_LENGTH_EXT];
  17419. safestrncpy( mapname, RFIFOCP( fd, 2 ), MAP_NAME_LENGTH_EXT );
  17420. int16 mapindex = mapindex_name2id( mapname );
  17421. // Check if we know the mapname
  17422. if( mapindex < 0 ){
  17423. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17424. return;
  17425. }
  17426. int16 mapid = map_mapindex2mapid( mapindex );
  17427. // Check if the map is available on this server
  17428. if( mapid < 0 ){
  17429. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17430. return;
  17431. }
  17432. // Check if the player tried to warp to the map he is on
  17433. if( sd->bl.m == mapid ){
  17434. // This is blocked by the client, but just to be sure
  17435. return;
  17436. }
  17437. // This can only be a hack, so we prevent it
  17438. if( map_getmapdata( mapid )->instance_id ){
  17439. // Ignore requests to warp directly into a running instance
  17440. return;
  17441. }
  17442. // Check if the player is allowed to warp to the target map
  17443. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17444. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17445. return;
  17446. }
  17447. uint16 item_id = RFIFOW( fd, 2 + MAP_NAME_LENGTH_EXT );
  17448. // Check if the item sent by the client is known to us
  17449. if( !itemdb_group_item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17450. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17451. return;
  17452. }
  17453. int idx = pc_search_inventory( sd, item_id );
  17454. // Check if the player has the item at all
  17455. if( idx < 0 ){
  17456. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17457. return;
  17458. }
  17459. // Delete the chosen item
  17460. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17461. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17462. return;
  17463. }
  17464. // Warp the player to a random spot on the destination map
  17465. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17466. #endif
  17467. }
  17468. /// Sends out the usage history of the guild storage
  17469. /// 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
  17470. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17471. void clif_guild_storage_log( struct map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17472. #if PACKETVER >= 20140205
  17473. nullpo_retv( sd );
  17474. int fd = sd->fd;
  17475. int size = 8;
  17476. int sub = 83;
  17477. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17478. size += log.size() * sub;
  17479. }else{
  17480. log.clear();
  17481. }
  17482. WFIFOHEAD(fd, size);
  17483. WFIFOW(fd, 0) = 0x9DA;
  17484. WFIFOW(fd, 2) = size;
  17485. WFIFOW(fd, 4) = result;
  17486. WFIFOW(fd, 6) = (uint16)log.size();
  17487. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17488. for (int offset = 8, i = 0; i < log.size(); i++, offset += sub) {
  17489. struct guild_log_entry& entry = log[i];
  17490. uint16 viewid = itemdb_viewid( entry.item.nameid );
  17491. WFIFOL(fd, offset) = entry.id;
  17492. WFIFOW(fd, offset + 4) = viewid > 0 ? viewid : entry.item.nameid;
  17493. WFIFOL(fd, offset + 6) = (uint16)(entry.amount > 0 ? entry.amount : (entry.amount * -1));
  17494. WFIFOB(fd, offset + 10) = entry.amount > 0; // action = true(put), false(get)
  17495. WFIFOL(fd, offset + 11) = entry.item.refine;
  17496. WFIFOQ(fd, offset + 15) = entry.item.unique_id;
  17497. WFIFOB(fd, offset + 23) = entry.item.identify;
  17498. WFIFOW(fd, offset + 24) = itemtype(entry.item.nameid);
  17499. clif_addcards(WFIFOP(fd, offset + 26), &entry.item);
  17500. safestrncpy(WFIFOCP(fd, offset + 34), entry.name, NAME_LENGTH);
  17501. safestrncpy(WFIFOCP(fd, offset + 34 + NAME_LENGTH), entry.time, NAME_LENGTH);
  17502. WFIFOB(fd, offset + 34 + 2 * NAME_LENGTH) = entry.item.attribute;
  17503. }
  17504. }
  17505. WFIFOSET(fd, size);
  17506. #endif
  17507. }
  17508. /// Activates the client camera info or updates the client camera with the given values.
  17509. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  17510. void clif_camerainfo( struct map_session_data* sd, bool show, float range, float rotation, float latitude ){
  17511. #if PACKETVER >= 20160525
  17512. int fd = sd->fd;
  17513. WFIFOHEAD(fd, packet_len(0xa78));
  17514. WFIFOW(fd, 0) = 0xa78;
  17515. WFIFOB(fd, 2) = show;
  17516. WFIFOF(fd, 3) = range;
  17517. WFIFOF(fd, 7) = rotation;
  17518. WFIFOF(fd, 11) = latitude;
  17519. WFIFOSET(fd, packet_len(0xa78));
  17520. #endif
  17521. }
  17522. /// Activates or deactives the client camera info or updates the camera settings.
  17523. /// This packet is triggered by /viewpointvalue or /setcamera
  17524. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  17525. void clif_parse_camerainfo( int fd, struct map_session_data* sd ){
  17526. char command[CHAT_SIZE_MAX];
  17527. // /viewpointvalue
  17528. if( RFIFOB( fd, 2 ) == 1 ){
  17529. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  17530. // /setcamera
  17531. }else{
  17532. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  17533. }
  17534. is_atcommand( fd, sd, command, 1 );
  17535. }
  17536. /// Send the full list of items in the equip switch window
  17537. /// 0a9b <length>.W { <index>.W <position>.L }*
  17538. void clif_equipswitch_list( struct map_session_data* sd ){
  17539. #if PACKETVER >= 20170208
  17540. int fd = sd->fd;
  17541. int offset, i, position;
  17542. WFIFOW(fd, 0) = 0xa9b;
  17543. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  17544. short index = sd->equip_switch_index[i];
  17545. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  17546. WFIFOW(fd, offset) = index + 2;
  17547. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  17548. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  17549. offset += 6;
  17550. }
  17551. }
  17552. WFIFOW(fd, 2) = offset;
  17553. WFIFOSET(fd, offset);
  17554. #endif
  17555. }
  17556. /// Acknowledgement for removing an equip to the equip switch window
  17557. /// 0a9a <index>.W <position.>.L <failure>.W
  17558. void clif_equipswitch_remove( struct map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  17559. #if PACKETVER >= 20170208
  17560. int fd = sd->fd;
  17561. WFIFOHEAD(fd, packet_len(0xa9a));
  17562. WFIFOW(fd, 0) = 0xa9a;
  17563. WFIFOW(fd, 2) = index + 2;
  17564. WFIFOL(fd, 4) = pos;
  17565. WFIFOW(fd, 8) = failed;
  17566. WFIFOSET(fd, packet_len(0xa9a));
  17567. #endif
  17568. }
  17569. /// Request to remove an equip from the equip switch window
  17570. /// 0a99 <index>.W <position>.L <= 20170502
  17571. /// 0a99 <index>.W
  17572. void clif_parse_equipswitch_remove( int fd, struct map_session_data* sd ){
  17573. #if PACKETVER >= 20170208
  17574. uint16 index = RFIFOW(fd, 2) - 2;
  17575. bool removed = false;
  17576. if( !battle_config.feature_equipswitch ){
  17577. return;
  17578. }
  17579. // Check if the index is valid
  17580. if( index >= MAX_INVENTORY ){
  17581. return;
  17582. }
  17583. pc_equipswitch_remove( sd, index );
  17584. #endif
  17585. }
  17586. /// Acknowledgement for adding an equip to the equip switch window
  17587. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  17588. /// 0a98 <index>.W <position.>.L <flag>.W
  17589. void clif_equipswitch_add( struct map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  17590. #if PACKETVER >= 20170208
  17591. int fd = sd->fd;
  17592. WFIFOHEAD(fd, packet_len(0xa98));
  17593. WFIFOW(fd, 0) = 0xa98;
  17594. WFIFOW(fd, 2) = index + 2;
  17595. WFIFOL(fd, 4) = pos;
  17596. #if PACKETVER <= 20170502
  17597. WFIFOL(fd, 8) = flag;
  17598. #else
  17599. WFIFOW(fd, 8) = flag;
  17600. #endif
  17601. WFIFOSET(fd,packet_len(0xa98));
  17602. #endif
  17603. }
  17604. /// Request to add an equip to the equip switch window
  17605. /// 0a97 <index>.W <position>.L
  17606. void clif_parse_equipswitch_add( int fd, struct map_session_data* sd ){
  17607. #if PACKETVER >= 20170208
  17608. uint16 index = RFIFOW(fd, 2) - 2;
  17609. uint32 position = RFIFOL(fd, 4);
  17610. if( !battle_config.feature_equipswitch ){
  17611. return;
  17612. }
  17613. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  17614. return;
  17615. }
  17616. if( sd->state.trading || sd->npc_shopid ){
  17617. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  17618. return;
  17619. }
  17620. if( sd->inventory_data[index]->type == IT_AMMO ){
  17621. position = EQP_AMMO;
  17622. }
  17623. pc_equipitem( sd, index, position, true );
  17624. #endif
  17625. }
  17626. /// Acknowledgement packet for the full equip switch
  17627. /// 0a9d <failed>.W
  17628. void clif_equipswitch_reply( struct map_session_data* sd, bool failed ){
  17629. #if PACKETVER >= 20170208
  17630. int fd = sd->fd;
  17631. WFIFOHEAD(fd, packet_len(0xa9d));
  17632. WFIFOW(fd, 0) = 0xa9d;
  17633. WFIFOW(fd, 2) = failed;
  17634. WFIFOSET(fd, packet_len(0xa9d));
  17635. #endif
  17636. }
  17637. /// Request to do a full equip switch
  17638. /// 0a9c
  17639. void clif_parse_equipswitch_request( int fd, struct map_session_data* sd ){
  17640. #if PACKETVER >= 20170208
  17641. int i;
  17642. t_tick tick = gettick();
  17643. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  17644. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  17645. // Client will not let you send a request
  17646. return;
  17647. }
  17648. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  17649. if( !battle_config.feature_equipswitch ){
  17650. return;
  17651. }
  17652. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  17653. if( i == EQI_MAX ){
  17654. // client will show: "There is no item to replace." and should not even come here
  17655. clif_equipswitch_reply( sd, false );
  17656. return;
  17657. }
  17658. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  17659. return;
  17660. }
  17661. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  17662. #endif
  17663. }
  17664. /// Request to do a single equip switch
  17665. /// 0ace <index>.W
  17666. void clif_parse_equipswitch_request_single( int fd, struct map_session_data* sd ){
  17667. #if PACKETVER >= 20170502
  17668. uint16 index = RFIFOW(fd, 2) - 2;
  17669. if( !battle_config.feature_equipswitch ){
  17670. return;
  17671. }
  17672. // Check if the index is valid
  17673. if( index >= MAX_INVENTORY ){
  17674. return;
  17675. }
  17676. // Check if the item exists
  17677. if (sd->inventory_data[index] == nullptr)
  17678. return;
  17679. // Check if the item was already added to equip switch
  17680. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  17681. if( sd->npc_id ){
  17682. #ifdef RENEWAL
  17683. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  17684. clif_msg( sd, WORK_IN_PROGRESS );
  17685. return;
  17686. }
  17687. #endif
  17688. if( !sd->npc_item_flag ){
  17689. return;
  17690. }
  17691. }
  17692. pc_equipswitch( sd, index );
  17693. return;
  17694. }
  17695. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  17696. #endif
  17697. }
  17698. /*==========================================
  17699. * Main client packet processing function
  17700. *------------------------------------------*/
  17701. static int clif_parse(int fd)
  17702. {
  17703. int cmd, packet_len;
  17704. TBL_PC* sd;
  17705. int pnum;
  17706. #ifdef PACKET_OBFUSCATION
  17707. int cmd2;
  17708. #endif
  17709. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17710. // Note: "click masters" can do 80+ clicks in 10 seconds
  17711. 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]
  17712. { // begin main client packet processing loop
  17713. sd = (TBL_PC *)session[fd]->session_data;
  17714. if (session[fd]->flag.eof) {
  17715. if (sd) {
  17716. if (sd->state.autotrade) {
  17717. //Disassociate character from the socket connection.
  17718. session[fd]->session_data = NULL;
  17719. sd->fd = 0;
  17720. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17721. } else
  17722. if (sd->state.active) {
  17723. // Player logout display [Valaris]
  17724. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17725. clif_quitsave(fd, sd);
  17726. } else {
  17727. //Unusual logout (during log on/off/map-changer procedure)
  17728. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17729. map_quit(sd);
  17730. }
  17731. } else {
  17732. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17733. }
  17734. do_close(fd);
  17735. return 0;
  17736. }
  17737. if (RFIFOREST(fd) < 2)
  17738. return 0;
  17739. cmd = RFIFOW(fd, 0);
  17740. #ifdef PACKET_OBFUSCATION
  17741. // Check if it is a player that tries to connect to the map server.
  17742. if( sd ){
  17743. // Decrypt the current packet ID with the last key stored in the session.
  17744. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17745. }else{
  17746. // Store the original value for checking
  17747. cmd2 = cmd;
  17748. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17749. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17750. }
  17751. #endif
  17752. // filter out invalid / unsupported packets
  17753. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17754. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17755. #ifdef DUMP_INVALID_PACKET
  17756. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17757. #endif
  17758. #ifdef PACKET_OBFUSCATION_WARN
  17759. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17760. if( !sd ){
  17761. #ifdef PACKET_OBFUSCATION
  17762. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17763. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17764. }
  17765. #else
  17766. // Try to use the initial keys for the decryption of the packet ID.
  17767. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17768. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17769. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17770. }
  17771. #endif
  17772. }
  17773. #endif
  17774. set_eof(fd);
  17775. return 0;
  17776. }
  17777. // determine real packet length
  17778. packet_len = packet_db[cmd].len;
  17779. if (packet_len == -1) { // variable-length packet
  17780. if (RFIFOREST(fd) < 4)
  17781. return 0;
  17782. packet_len = RFIFOW(fd,2);
  17783. if (packet_len < 4 || packet_len > 32768) {
  17784. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17785. #ifdef DUMP_INVALID_PACKET
  17786. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17787. #endif
  17788. set_eof(fd);
  17789. return 0;
  17790. }
  17791. }
  17792. if ((int)RFIFOREST(fd) < packet_len)
  17793. return 0; // not enough data received to form the packet
  17794. #ifdef PACKET_OBFUSCATION
  17795. RFIFOW(fd, 0) = cmd;
  17796. if (sd)
  17797. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17798. #endif
  17799. if( packet_db[cmd].func == clif_parse_debug )
  17800. packet_db[cmd].func(fd, sd);
  17801. else if( packet_db[cmd].func != NULL ) {
  17802. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17803. ; //Only valid packet when there is no session
  17804. else
  17805. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17806. ; //Only valid packet when player is not on a map
  17807. else
  17808. packet_db[cmd].func(fd, sd);
  17809. }
  17810. #ifdef DUMP_UNKNOWN_PACKET
  17811. else DumpUnknown(fd,sd,cmd,packet_len);
  17812. #endif
  17813. RFIFOSKIP(fd, packet_len);
  17814. }; // main loop end
  17815. return 0;
  17816. }
  17817. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17818. va_list argp;
  17819. int i;
  17820. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17821. return;
  17822. packet_db[cmd].len = length;
  17823. packet_db[cmd].func = func;
  17824. va_start(argp, func);
  17825. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17826. int offset = va_arg(argp, int);
  17827. if( offset == 0 ){
  17828. break;
  17829. }
  17830. packet_db[cmd].pos[i] = offset;
  17831. }
  17832. if( i == MAX_PACKET_POS ){
  17833. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17834. }
  17835. va_end(argp);
  17836. }
  17837. /*==========================================
  17838. * Reads packets and setups its array reference
  17839. *------------------------------------------*/
  17840. void packetdb_readdb(){
  17841. memset(packet_db,0,sizeof(packet_db));
  17842. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17843. #include "clif_packetdb.hpp"
  17844. #include "clif_shuffle.hpp"
  17845. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17846. #ifdef PACKET_OBFUSCATION
  17847. 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]);
  17848. #else
  17849. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17850. #endif
  17851. }
  17852. /*==========================================
  17853. *
  17854. *------------------------------------------*/
  17855. void do_init_clif(void) {
  17856. const char* colors[COLOR_MAX] = {
  17857. "0x00FF00",
  17858. "0xFF0000",
  17859. "0xFFFFFF",
  17860. "0xFFFF00",
  17861. "0x00FFFF",
  17862. "0xB5FFB5",
  17863. };
  17864. int i;
  17865. /**
  17866. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17867. **/
  17868. for(i = 0; i < COLOR_MAX; i++) {
  17869. color_table[i] = strtoul(colors[i],NULL,0);
  17870. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17871. }
  17872. packetdb_readdb();
  17873. set_defaultparse(clif_parse);
  17874. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17875. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17876. exit(EXIT_FAILURE);
  17877. }
  17878. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17879. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17880. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17881. }
  17882. void do_final_clif(void) {
  17883. ers_destroy(delay_clearunit_ers);
  17884. }